Summary Table

Categories Total Count
PII 0
URL 1
DNS 2
EKL 0
IP 0
PORT 1
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

/**
*
*/
package gov.va.med.ars.service.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import gov.va.med.ars.constants.ErrorMessages;
import gov.va.med.ars.constants.IAuditLogConstants;
import gov.va.med.ars.dao.ars.IAuditLoggerRepository;
import gov.va.med.ars.dao.ars.IClaimAttachmentsViewRepository;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.model.request.AuditLogger;
import gov.va.med.ars.model.request.ExportAsPDF;
import gov.va.med.ars.service.IAuditLoggerService;
import gov.va.med.domain.ars.Arsauditlog;
import gov.va.med.domain.ars.ClaimattachmentsView;

/**
* @author
DNS
*
*/
@Service
public class AuditLoggerServiceImpl implements IAuditLoggerService {

@Autowired
IClaimAttachmentsViewRepository claimAttachmentRepository;

@Autowired
IAuditLoggerRepository auditLoggerRepository;

@Override
public String getPathForExportAsPDF(ExportAsPDF request) throws GenericException {
if(request == null) {
throw new GenericException(ErrorMessages.BAD_REQUEST, "Required Data is missing", HttpStatus.BAD_REQUEST);
}

String attachmentPath = null;
ClaimattachmentsView cv = claimAttachmentRepository.findOneByAttachIdLx(request.getAttachIdLx());
if (cv == null || cv.getAttachIdLx() == null || cv.getAttachmentPath() == null) {
throw new GenericException(ErrorMessages.NOT_FOUND, "Data not found for ExportAsPDF AttachIdLx", HttpStatus.NOT_FOUND);
}
attachmentPath = cv.getAttachmentPath();
attachmentPath = extractAttachment(attachmentPath);

// ?? This seems to be left-over code to patch-up some database paths that have been changed.
// The proper thing to do is update the database!!
// attachmentPath = attachmentPath.replace("https://
DNS.URL:PORT ", "/u02");

Arsauditlog arsAuditLog = new Arsauditlog(
IAuditLogConstants.METHODNAME,
request.getVhaName(),
request.getAttachIdLx(),
new Date(),
"ClaimAttachIdLx=" + request.getAttachIdLx(), // IAuditLogConstants.REQUESTARGS + request.getAttachIdLx(),
IAuditLogConstants.EXPORTPDFACTION,
true,
1L);
if (arsAuditLog != null) {
auditLoggerRepository.save(arsAuditLog);
}
return attachmentPath;

}

@Override
public String getPathForTheAttachment(AuditLogger auditLogger) throws GenericException {
// auditLogger = (AuditLogger) ObjectUtils.defaultIfNull(auditLogger, null);
// ?? effectively, if (auditLogger==null) auditLogger = null; // Why?

if(auditLogger == null) {
throw new GenericException(ErrorMessages.BAD_REQUEST, "Required Data is missing", HttpStatus.BAD_REQUEST);
}

String attachmentPath = null;
ClaimattachmentsView cv = claimAttachmentRepository.findOneByAttachIdLx(auditLogger.getAttachIdLx());
if (cv == null || cv.getAttachIdLx() == null || cv.getAttachmentPath() == null) {
throw new GenericException(ErrorMessages.NOT_FOUND, "Data not found for a given AttachIdLx", HttpStatus.NOT_FOUND);
}
attachmentPath = cv.getAttachmentPath();
attachmentPath = extractAttachment(attachmentPath); // Not sure about this ??

Arsauditlog arsAuditLog = setAuditLogData(attachmentPath, auditLogger);
if (arsAuditLog != null) {
auditLoggerRepository.save(arsAuditLog);
}
return attachmentPath;
}

public String extractAttachment(String multiplePathAddress) {
// It would be good to know why XML is being treated specially.
List<String> pathAddress = Arrays.asList(multiplePathAddress.split("<"));
if (pathAddress.size() > 1) {
for (String path: pathAddress) {
if (path.toUpperCase().contains("XML")) {
return path;
}
}
}
return pathAddress.get(0);
}

private Arsauditlog setAuditLogData(String attachmentPath, AuditLogger auditLogger) {
Arsauditlog arsAuditLog = null;
String auditAction = auditLogger.getIsDownload() != null && auditLogger.getIsDownload()
? IAuditLogConstants.DOWNLOADACTION
: IAuditLogConstants.VIEWACTION;
arsAuditLog = new Arsauditlog(IAuditLogConstants.METHODNAME, auditLogger.getVhaName(), auditLogger.getAttachIdLx(), new Date(),
IAuditLogConstants.REQUESTARGS+auditLogger.getAttachIdLx(), auditAction, true, 1L);
return arsAuditLog;
}


}