Summary Table

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

File Content

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

import java.util.List;
import java.util.Optional;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.dao.ars.IClaimAttachmentsViewRepository;
import gov.va.med.ars.dao.ars.ITransactionsRepository;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.model.request.JsonArrayModel;
import gov.va.med.ars.service.IArchiveService;
import gov.va.med.domain.ars.ClaimattachmentsView;

/**
* @author
DNS
*
*/
@Service
public class ArchiveServiceImpl implements IArchiveService {

private static final Logger logger = LogManager.getLogger(ArchiveServiceImpl.class);

@Autowired
IClaimAttachmentsViewRepository iClaimAttachmentsViewRepository;

@Autowired
ITransactionsRepository transactionsRepository;

@Override
public boolean archiveAttachments(JsonArrayModel archiveAttachments) throws GenericException {
boolean isArchived = false;
archiveAttachments = (JsonArrayModel) ObjectUtils.defaultIfNull(archiveAttachments, null);
try {
if (archiveAttachments != null && CollectionUtils.isNotEmpty(archiveAttachments.getAcceptedValues())) {
List<ClaimattachmentsView> attachmentIdLx = iClaimAttachmentsViewRepository
.findByAttachIdLxIn(archiveAttachments.getAcceptedValues());
if (attachmentIdLx.size() == archiveAttachments.getAcceptedValues().size()) {
String status = generateStatus(archiveAttachments);
Integer archiveAttachmentsInTransactions = transactionsRepository
.archiveAttachments(archiveAttachments.getAcceptedValues(), status);
if (Optional.ofNullable(archiveAttachmentsInTransactions).orElse(0).intValue() != 0) {
isArchived = true;
}
} else {
logger.error("Attachments sent to archive do not match with the values in the database "
+ archiveAttachments.getAcceptedValues());
throw new GenericException(ErrorMessages.DATA_ACCESS_ERROR,
"A few Attachments Ids passed didn't match with the values in the database",
HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
throw new GenericException(ErrorMessages.BAD_REQUEST, "Required Data is missing",
HttpStatus.BAD_REQUEST);
}
} catch (Exception e) {
throw new GenericException(ErrorMessages.BAD_REQUEST, e.getMessage(), HttpStatus.BAD_REQUEST);
}
return isArchived;
}

private String generateStatus(JsonArrayModel archiveAttachments) {
if(archiveAttachments.isStatus()) {
return "Inactive";
} else {
return "Active";
}
}

}