Skip to content

Commit

Permalink
Merge branch 'main' into test-container-use-nbs-db
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Peels authored and Michael Peels committed Dec 11, 2024
2 parents 968b5a4 + 69de32e commit a686dd6
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.cdc.dataingestion.camel.routes;

import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import gov.cdc.dataingestion.reportstatus.model.EdxActivityLogStatus;
import gov.cdc.dataingestion.reportstatus.model.MessageStatus;
import gov.cdc.dataingestion.reportstatus.service.ReportStatusService;
Expand Down Expand Up @@ -51,15 +53,16 @@ public String process(String body){
} else if (messageStatus.getNbsInfo().getNbsInterfaceStatus() != null && messageStatus.getNbsInfo().getNbsInterfaceStatus().equals(FAILURE)) {
StringBuilder activityLogSb = new StringBuilder();
activityLogSb.append("Status: Failure ");
List<EdxActivityLogStatus> edxActivityLogList= messageStatus.getNbsIngestionInfo();
for(EdxActivityLogStatus edxActivityLogStatus:edxActivityLogList){
List<EdxActivityDetailLog> edxActivityLogList= messageStatus.getEdxLogStatus().getEdxActivityDetailLogList();
EdxActivityLog edxActivityLogParent = messageStatus.getEdxLogStatus().getEdxActivityLog();
for(EdxActivityDetailLog edxActivityLogStatus:edxActivityLogList){
String logComment=edxActivityLogStatus.getLogComment();
if(logComment!=null && logComment.length()>200){
logComment=logComment.substring(0,200);
}
String activityLog = "\n\nRecordType: " + edxActivityLogStatus.getRecordType() + " \nLog Type: "
+ edxActivityLogStatus.getLogType() + " \nLog Comment: " + logComment
+ " \nRecord Status Time: " + edxActivityLogStatus.getRecordStatusTime();
+ " \nRecord Status Time: " + edxActivityLogParent.getRecordStatusTime();
activityLogSb.append(activityLog);
}
activityLogSb.append(" \n\n"+ELR_ID+": " + elrId+" \n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
@Repository
public interface IEdxActivityLogRepository extends JpaRepository<EdxActivityDetailLog, Long> {
@Query(value = """
select eadl.record_id as recordId ,eadl.record_type as recordType ,eadl.log_type as logType,eadl.log_comment as logComment,
eal.record_status_time as recordStatusTime from NBS_ODSE.dbo.EDX_activity_detail_log eadl,NBS_ODSE.dbo.EDX_activity_log eal
select eadl.* from NBS_ODSE.dbo.EDX_activity_detail_log eadl,NBS_ODSE.dbo.EDX_activity_log eal
where eal.source_uid = :nbsSourceId and eadl.edx_activity_log_uid =eal.edx_activity_log_uid
""",
nativeQuery = true)
List<EdxActivityLogModelView> getEdxActivityLogDetailsBySourceId(@Param("nbsSourceId") Long sourceId);
List<EdxActivityDetailLog> getEdxActivityLogDetailsBySourceId(@Param("nbsSourceId") Long sourceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gov.cdc.dataingestion.odse.repository;

import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLogModelView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IEdxActivityParentLogRepository extends JpaRepository<EdxActivityLog, Long> {
@Query(value = """
select top 1 * from EDX_activity_log
where source_uid = :nbsSourceId
""",
nativeQuery = true)
EdxActivityLog getParentEdxActivity(@Param("nbsSourceId") Long sourceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package gov.cdc.dataingestion.odse.repository.model;

import jakarta.persistence.*;
import lombok.Data;

@Entity
@Table(name = "EDX_activity_log")
@Data
public class EdxActivityLog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "edx_activity_log_uid")
private Long edxActivityLogUid;

@Column(name = "source_uid")
private Long sourceUid;

@Column(name = "target_uid")
private Long targetUid;

@Column(name = "doc_type")
private String docType;

@Column(name = "record_status_cd")
private String recordStatusCd;

@Column(name = "record_status_time")
private java.util.Date recordStatusTime;

@Column(name = "exception_txt")
private String exceptionTxt;

@Column(name = "imp_exp_ind_cd", columnDefinition = "CHAR(1)")
private String impExpIndCd;

@Column(name = "source_type_cd")
private String sourceTypeCd;

@Column(name = "target_type_cd")
private String targetTypeCd;

@Column(name = "business_obj_localId")
private String businessObjLocalId;

@Column(name = "doc_nm")
private String docNm;

@Column(name = "source_nm")
private String sourceNm;

@Column(name = "algorithm_action")
private String algorithmAction;

@Column(name = "algorithm_name")
private String algorithmName;

@Column(name = "Message_id")
private String messageId;

@Column(name = "Entity_nm")
private String entityNm;

@Column(name = "Accession_nbr")
private String accessionNbr;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gov.cdc.dataingestion.reportstatus.model;

import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class EdxLogStatus {
private EdxActivityLog edxActivityLog;
private List<EdxActivityDetailLog> edxActivityDetailLogList = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class MessageStatus {
private RawMessageStatus rawInfo = new RawMessageStatus();
private ValidatedMessageStatus validatedInfo = new ValidatedMessageStatus();
private NbsMessageStatus nbsInfo = new NbsMessageStatus();
private List<EdxActivityLogStatus> nbsIngestionInfo=new ArrayList<>();
// private List<EdxActivityLogStatus> nbsIngestionInfo=new ArrayList<>();
private EdxLogStatus edxLogStatus = new EdxLogStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import gov.cdc.dataingestion.nbs.repository.NbsInterfaceRepository;
import gov.cdc.dataingestion.nbs.repository.model.NbsInterfaceModel;
import gov.cdc.dataingestion.odse.repository.IEdxActivityLogRepository;
import gov.cdc.dataingestion.odse.repository.IEdxActivityParentLogRepository;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLogModelView;
import gov.cdc.dataingestion.report.repository.IRawELRRepository;
import gov.cdc.dataingestion.report.repository.model.RawERLModel;
Expand All @@ -30,6 +33,7 @@
@SuppressWarnings({"java:S1118","java:S125", "java:S6126", "java:S1135"})
public class ReportStatusService {
private final IReportStatusRepository iReportStatusRepository;
private final IEdxActivityParentLogRepository iEdxActivityParentLogRepository;
private final NbsInterfaceRepository nbsInterfaceRepository;

private final IRawELRRepository iRawELRRepository;
Expand All @@ -43,12 +47,13 @@ public class ReportStatusService {
private static final String DLT_ORIGIN_VALIDATED = "VALIDATED";

public ReportStatusService(IReportStatusRepository iReportStatusRepository,
NbsInterfaceRepository nbsInterfaceRepository,
IEdxActivityParentLogRepository iEdxActivityParentLogRepository, NbsInterfaceRepository nbsInterfaceRepository,
IRawELRRepository iRawELRRepository,
IValidatedELRRepository iValidatedELRRepository,
IElrDeadLetterRepository iElrDeadLetterRepository,
IEdxActivityLogRepository iEdxActivityLogRepository) {
this.iReportStatusRepository = iReportStatusRepository;
this.iEdxActivityParentLogRepository = iEdxActivityParentLogRepository;
this.nbsInterfaceRepository = nbsInterfaceRepository;
this.iRawELRRepository = iRawELRRepository;
this.iValidatedELRRepository = iValidatedELRRepository;
Expand Down Expand Up @@ -86,15 +91,16 @@ public MessageStatus getMessageStatus(String rawMessageID) {
}

if(msgStatus.getNbsInfo().getNbsInterfaceStatus() !=null) {
List<EdxActivityLogModelView> edxActivityStatusList = iEdxActivityLogRepository.
getEdxActivityLogDetailsBySourceId(Long.valueOf(msgStatus.getNbsInfo().getNbsInterfaceId()));
if(!edxActivityStatusList.isEmpty()) {
EdxActivityLog edxActivityLog = iEdxActivityParentLogRepository.getParentEdxActivity(Long.valueOf(msgStatus.getNbsInfo().getNbsInterfaceId()));
List<EdxActivityDetailLog> edxActivityStatusList = iEdxActivityLogRepository.getEdxActivityLogDetailsBySourceId(Long.valueOf(msgStatus.getNbsInfo().getNbsInterfaceId()));
if(!edxActivityStatusList.isEmpty() && edxActivityLog != null) {
msgStatus.getEdxLogStatus().setEdxActivityLog(edxActivityLog);
Set<String> seenComments = new HashSet<>();
for(EdxActivityLogModelView edxActivityLogModel:edxActivityStatusList){
for(EdxActivityDetailLog edxActivityLogModel:edxActivityStatusList){
String logComment = edxActivityLogModel.getLogComment();
if (seenComments.add(logComment)) {
EdxActivityLogStatus edxActivityLogStatus = getEdxActivityLogStatus(edxActivityLogModel);
msgStatus.getNbsIngestionInfo().add(edxActivityLogStatus);
// EdxActivityLogStatus edxActivityLogStatus = getEdxActivityLogStatus(edxActivityLogModel);
msgStatus.getEdxLogStatus().getEdxActivityDetailLogList().add(edxActivityLogModel);
}

}
Expand All @@ -104,12 +110,12 @@ public MessageStatus getMessageStatus(String rawMessageID) {
return msgStatus;
}

private static EdxActivityLogStatus getEdxActivityLogStatus(EdxActivityLogModelView edxActivityLogModel) {
private static EdxActivityLogStatus getEdxActivityLogStatus(EdxActivityDetailLog edxActivityLogModel) {
EdxActivityLogStatus edxActivityLogStatus=new EdxActivityLogStatus();
edxActivityLogStatus.setRecordType(edxActivityLogModel.getRecordType());
edxActivityLogStatus.setLogType(edxActivityLogModel.getLogType());
edxActivityLogStatus.setLogComment(edxActivityLogModel.getLogComment());
edxActivityLogStatus.setRecordStatusTime(edxActivityLogModel.getRecordStatusTime());
// edxActivityLogStatus.setRecordStatusTime(edxActivityLogModel.getRecordStatusTime());
return edxActivityLogStatus;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.cdc.dataingestion.camel.routes;

import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import gov.cdc.dataingestion.reportstatus.model.DltMessageStatus;
import gov.cdc.dataingestion.reportstatus.model.EdxActivityLogStatus;
import gov.cdc.dataingestion.reportstatus.model.MessageStatus;
Expand Down Expand Up @@ -73,7 +75,7 @@ void testProcessForNbsFailure(){
edxActivityLogStatus.setLogType("Test Log Type");
edxActivityLogStatus.setLogComment("Test Log Comment");
edxActivityLogStatus.setRecordStatusTime(new Timestamp(System.currentTimeMillis()));
status.getNbsIngestionInfo().add(edxActivityLogStatus);
// status.getNbsIngestionInfo().add(edxActivityLogStatus);
when(reportStatusServiceMock.getMessageStatus(rawId)).thenReturn(
status
);
Expand All @@ -88,12 +90,14 @@ void testProcessForNbsFailureWithLogCommentWithMorethan200(){
MessageStatus status = new MessageStatus();
status.getNbsInfo().setNbsInterfaceStatus("Failure");
String logComment= "Test Log Comment123 Test Log Comment123 Test Log Comment123 Test Log Comment234 Test Log Comment345 Test Log Comment456 Test Log Comment567 Test Log Comment678 Test Log Comment678 Test Log Comment78901";
EdxActivityLogStatus edxActivityLogStatus=new EdxActivityLogStatus();
EdxActivityDetailLog edxActivityLogStatus=new EdxActivityDetailLog();
edxActivityLogStatus.setRecordType("Test Record Type");
edxActivityLogStatus.setLogType("Test Log Type");
edxActivityLogStatus.setLogComment(logComment);
edxActivityLogStatus.setRecordStatusTime(new Timestamp(System.currentTimeMillis()));
status.getNbsIngestionInfo().add(edxActivityLogStatus);
status.getEdxLogStatus().getEdxActivityDetailLogList().add(edxActivityLogStatus);
var edx = new EdxActivityLog();
edx.setRecordStatusTime(new Timestamp(System.currentTimeMillis()));
status.getEdxLogStatus().setEdxActivityLog(edx);
when(reportStatusServiceMock.getMessageStatus(rawId)).thenReturn(
status
);
Expand All @@ -107,12 +111,14 @@ void testProcessForNbsFailureWithLogComment_null(){

MessageStatus status = new MessageStatus();
status.getNbsInfo().setNbsInterfaceStatus("Failure");
EdxActivityLogStatus edxActivityLogStatus=new EdxActivityLogStatus();
EdxActivityDetailLog edxActivityLogStatus=new EdxActivityDetailLog();
edxActivityLogStatus.setRecordType("Test Record Type");
edxActivityLogStatus.setLogType("Test Log Type");
edxActivityLogStatus.setLogComment(null);
edxActivityLogStatus.setRecordStatusTime(new Timestamp(System.currentTimeMillis()));
status.getNbsIngestionInfo().add(edxActivityLogStatus);
status.getEdxLogStatus().getEdxActivityDetailLogList().add(edxActivityLogStatus);
var edx = new EdxActivityLog();
edx.setRecordStatusTime(new Timestamp(System.currentTimeMillis()));
status.getEdxLogStatus().setEdxActivityLog(edx);
when(reportStatusServiceMock.getMessageStatus(rawId)).thenReturn(
status
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import gov.cdc.dataingestion.nbs.repository.NbsInterfaceRepository;
import gov.cdc.dataingestion.nbs.repository.model.NbsInterfaceModel;
import gov.cdc.dataingestion.odse.repository.IEdxActivityLogRepository;
import gov.cdc.dataingestion.odse.repository.IEdxActivityParentLogRepository;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityDetailLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLog;
import gov.cdc.dataingestion.odse.repository.model.EdxActivityLogModelView;
import gov.cdc.dataingestion.report.repository.IRawELRRepository;
import gov.cdc.dataingestion.report.repository.model.RawERLModel;
Expand Down Expand Up @@ -40,6 +43,8 @@ class ReportStatusServiceTest {
@Mock
private IReportStatusRepository iReportStatusRepositoryMock;
@Mock
private IEdxActivityParentLogRepository edxActivityParentLogRepository;
@Mock
private NbsInterfaceRepository nbsInterfaceRepositoryMock;
@Mock
private IRawELRRepository iRawELRRepository;
Expand Down Expand Up @@ -100,7 +105,7 @@ void testGetMessageDetailStatus_RawExist_ValidateExist_ReportExist_NbsExist() {
when(iValidatedELRRepository.findByRawId(id)).thenReturn(Optional.of(validatedELRModel));
when(iReportStatusRepositoryMock.findByRawMessageId(id)).thenReturn(Optional.of(reportStatusIdModel));
when(nbsInterfaceRepositoryMock.findByNbsInterfaceUid(nbsId)).thenReturn(Optional.of(nbsModel));

when(edxActivityParentLogRepository.getParentEdxActivity(Long.valueOf(nbsId))).thenReturn(new EdxActivityLog());
var msgStatus = reportStatusServiceMock.getMessageStatus(id);
assertEquals(id, msgStatus.getRawInfo().getRawMessageId());
assertEquals("validate-id", msgStatus.getValidatedInfo().getValidatedMessageId());
Expand Down Expand Up @@ -363,13 +368,13 @@ void testGetMessageDetailStatus_RawExist_ValidateExist_ReportExist_NbsExist_Odse
reportStatusIdModel.setCreatedOn(getCurrentTimeStamp());
reportStatusIdModel.setNbsInterfaceUid(nbsId);

List<EdxActivityLogModelView> edxActivityLogList=new ArrayList();
EdxActivityLogModelView edxActivityLogModelProjection=mock(EdxActivityLogModelView.class);
List<EdxActivityDetailLog> edxActivityLogList=new ArrayList();
EdxActivityDetailLog edxActivityLogModelProjection=mock(EdxActivityDetailLog.class);
when(edxActivityLogModelProjection.getLogComment()).thenReturn("Test activity log");
when(edxActivityLogModelProjection.getLogType()).thenReturn("Test log type");
when(edxActivityLogModelProjection.getRecordId()).thenReturn("Test Record Id");
when(edxActivityLogModelProjection.getRecordType()).thenReturn("Test Record Type");
when(edxActivityLogModelProjection.getRecordStatusTime()).thenReturn(new Timestamp(System.currentTimeMillis()));
// when(edxActivityLogModelProjection.getRecordStatusTime()).thenReturn(new Timestamp(System.currentTimeMillis()));

edxActivityLogList.add(edxActivityLogModelProjection);

Expand All @@ -382,14 +387,15 @@ void testGetMessageDetailStatus_RawExist_ValidateExist_ReportExist_NbsExist_Odse
when(iReportStatusRepositoryMock.findByRawMessageId(id)).thenReturn(Optional.of(reportStatusIdModel));
when(nbsInterfaceRepositoryMock.findByNbsInterfaceUid(nbsId)).thenReturn(Optional.of(nbsModel));
when (iEdxActivityLogRepository.getEdxActivityLogDetailsBySourceId(Long.valueOf(nbsId))).thenReturn(edxActivityLogList);
when(edxActivityParentLogRepository.getParentEdxActivity(Long.valueOf(nbsId))).thenReturn(new EdxActivityLog());

var msgStatus = reportStatusServiceMock.getMessageStatus(id);
assertEquals(id, msgStatus.getRawInfo().getRawMessageId());
assertEquals("validate-id", msgStatus.getValidatedInfo().getValidatedMessageId());
assertEquals(nbsId, msgStatus.getNbsInfo().getNbsInterfaceId());
assertNotNull( msgStatus.getNbsInfo().getNbsCreatedOn());
assertNull( msgStatus.getNbsInfo().getDltInfo());
assertEquals("Test log type",msgStatus.getNbsIngestionInfo().get(0).getLogType());
assertEquals("Test log type",msgStatus.getEdxLogStatus().getEdxActivityDetailLogList().get(0).getLogType());
}

}
4 changes: 3 additions & 1 deletion data-processing-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.boot:spring-boot-starter-actuator:3.3.4'
implementation 'org.simpleframework:simple-xml:2.7.1'
// implementation 'org.simpleframework:simple-xml:2.7.1'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.2'


implementation 'io.prometheus:simpleclient:0.16.0'
implementation 'io.prometheus:simpleclient_hotspot:0.16.0'
Expand Down
Loading

0 comments on commit a686dd6

Please sign in to comment.