From 7a425214d3416d41b967e0e4d0ad62d712c55172 Mon Sep 17 00:00:00 2001 From: Sri Pooja Date: Wed, 27 Jul 2016 20:51:32 +0530 Subject: [PATCH 1/9] Mcts import retrial in the last 7 days --- .../nms/flw/domain/FrontLineWorker.java | 11 ++ .../FrontLineWorkerImportServiceImpl.java | 7 +- .../nms/flw/utils/FlwConstants.java | 1 + .../nms/flw/utils/FlwMapper.java | 5 + .../nms/kilkari/domain/MctsBeneficiary.java | 12 ++ .../nms/kilkari/domain/MctsChild.java | 1 + .../nms/kilkari/domain/MctsMother.java | 1 + .../MctsBeneficiaryImportServiceImpl.java | 13 ++ .../nms/kilkari/utils/KilkariConstants.java | 1 + .../nms/mcts/contract/AnmAshaRecord.java | 2 + .../nms/mcts/domain/MctsImportAudit.java | 28 +++- .../nms/mcts/domain/MctsImportFailRecord.java | 52 +++++++ .../MctsImportFailRecordDataService.java | 27 ++++ .../service/impl/MctsWsImportServiceImpl.java | 137 +++++++++++++----- .../nms/mcts/utils/Constants.java | 3 +- .../main/resources/MctsAuditModification.sql | 1 + .../impl/MctsWsImportServiceImplTest.java | 2 + .../testing/it/mcts/MctsImportBundleIT.java | 5 +- 18 files changed, 263 insertions(+), 46 deletions(-) create mode 100644 mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportFailRecord.java create mode 100644 mcts/src/main/java/org/motechproject/nms/mcts/repository/MctsImportFailRecordDataService.java create mode 100644 mcts/src/main/resources/MctsAuditModification.sql diff --git a/flw/src/main/java/org/motechproject/nms/flw/domain/FrontLineWorker.java b/flw/src/main/java/org/motechproject/nms/flw/domain/FrontLineWorker.java index 7fd298c51..65fab99ac 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/domain/FrontLineWorker.java +++ b/flw/src/main/java/org/motechproject/nms/flw/domain/FrontLineWorker.java @@ -1,6 +1,7 @@ package org.motechproject.nms.flw.domain; import org.joda.time.DateTime; +import org.joda.time.LocalDate; import org.motechproject.mds.annotations.Entity; import org.motechproject.mds.annotations.Field; import org.motechproject.mds.annotations.InstanceLifecycleListeners; @@ -60,6 +61,9 @@ public class FrontLineWorker extends MdsEntity implements FullLocation { @Field private Language language; + @Field + private LocalDate updatedDateNic; + @Field @Persistent(defaultFetchGroup = "true") private State state; @@ -242,6 +246,13 @@ public void setDesignation(String designation) { this.designation = designation; } + public LocalDate getUpdatedDateNic() { + return updatedDateNic; + } + + public void setUpdatedDateNic(LocalDate updatedDateNic) { + this.updatedDateNic = updatedDateNic; + } @Override //NO CHECKSTYLE CyclomaticComplexity public boolean equals(Object o) { diff --git a/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java b/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java index 4d71c0dee..01fbbb77b 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java +++ b/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java @@ -1,6 +1,7 @@ package org.motechproject.nms.flw.service.impl; import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; import org.motechproject.nms.csv.exception.CsvImportDataException; import org.motechproject.nms.csv.utils.ConstraintViolationUtils; import org.motechproject.nms.csv.utils.CsvImporterBuilder; @@ -87,7 +88,11 @@ public void importFrontLineWorker(Map record, State state) throw if (flw == null) { frontLineWorkerService.add(createFlw(record, location)); } else { - frontLineWorkerService.update(updateFlw(flw, record, location)); + LocalDate mctsUpdatedDateNic = (LocalDate) record.get(FlwConstants.UPDATED_ON); + //It updated_date_nic from mcts is not null,then it's not a new record. Compare it with the record from database and update + if (mctsUpdatedDateNic != null && (flw.getUpdatedDateNic() == null || mctsUpdatedDateNic.isAfter(flw.getUpdatedDateNic()) || mctsUpdatedDateNic.isEqual(flw.getUpdatedDateNic()))) { + frontLineWorkerService.update(updateFlw(flw, record, location)); + } } } diff --git a/flw/src/main/java/org/motechproject/nms/flw/utils/FlwConstants.java b/flw/src/main/java/org/motechproject/nms/flw/utils/FlwConstants.java index d2e97f667..66a851b14 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/utils/FlwConstants.java +++ b/flw/src/main/java/org/motechproject/nms/flw/utils/FlwConstants.java @@ -21,6 +21,7 @@ public final class FlwConstants { public static final String VILLAGE_NAME = "Village_Name"; public static final String NON_CENSUS_VILLAGE_ID = "SVID"; public static final String TYPE = "Type"; + public static final String UPDATED_ON = "Updated_On"; private FlwConstants() { } diff --git a/flw/src/main/java/org/motechproject/nms/flw/utils/FlwMapper.java b/flw/src/main/java/org/motechproject/nms/flw/utils/FlwMapper.java index edd70275a..1634b7381 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/utils/FlwMapper.java +++ b/flw/src/main/java/org/motechproject/nms/flw/utils/FlwMapper.java @@ -1,5 +1,6 @@ package org.motechproject.nms.flw.utils; +import org.joda.time.LocalDate; import org.motechproject.nms.flw.domain.FrontLineWorker; import org.motechproject.nms.flw.domain.FrontLineWorkerStatus; import org.motechproject.nms.region.domain.State; @@ -61,6 +62,10 @@ public static FrontLineWorker updateFlw(FrontLineWorker flw, Map flw.setDesignation(type); } + if (record.get(FlwConstants.UPDATED_ON) != null) { + flw.setUpdatedDateNic((LocalDate) record.get(FlwConstants.UPDATED_ON)); + } + return flw; } diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsBeneficiary.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsBeneficiary.java index 5c292eba9..1a94ca807 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsBeneficiary.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsBeneficiary.java @@ -1,5 +1,6 @@ package org.motechproject.nms.kilkari.domain; +import org.joda.time.LocalDate; import org.motechproject.mds.annotations.Entity; import org.motechproject.mds.annotations.Field; import org.motechproject.mds.domain.MdsEntity; @@ -57,6 +58,9 @@ public abstract class MctsBeneficiary extends MdsEntity implements FullLocation @Field private Village village; + @Field + private LocalDate updatedDateNic; + public MctsBeneficiary() { } @@ -69,6 +73,14 @@ public MctsBeneficiary(String beneficiaryId, String name) { this.name = name; } + public LocalDate getUpdatedDateNic() { + return updatedDateNic; + } + + public void setUpdatedDateNic(LocalDate updatedDateNic) { + this.updatedDateNic = updatedDateNic; + } + public String getBeneficiaryId() { return beneficiaryId; } diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsChild.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsChild.java index 395b95e07..72d735474 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsChild.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsChild.java @@ -44,5 +44,6 @@ public void deepCopyFrom(MctsChild other) { setHealthFacility(other.getHealthFacility()); setHealthSubFacility(other.getHealthSubFacility()); setVillage(other.getVillage()); + setUpdatedDateNic(other.getUpdatedDateNic()); } } diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsMother.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsMother.java index 927153193..e16d992f8 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsMother.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/domain/MctsMother.java @@ -38,5 +38,6 @@ public void deepCopyFrom(MctsMother other) { setHealthFacility(other.getHealthFacility()); setHealthSubFacility(other.getHealthSubFacility()); setVillage(other.getVillage()); + setUpdatedDateNic(other.getUpdatedDateNic()); } } diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java index ba8e85c52..a8abc86f0 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java @@ -1,6 +1,7 @@ package org.motechproject.nms.kilkari.service.impl; import org.joda.time.DateTime; +import org.joda.time.LocalDate; import org.motechproject.metrics.service.Timer; import org.motechproject.nms.csv.exception.CsvImportDataException; import org.motechproject.nms.csv.utils.ConstraintViolationUtils; @@ -160,6 +161,12 @@ public boolean importMotherRecord(Map record) { Boolean abortion = (Boolean) record.get(KilkariConstants.ABORTION); Boolean stillBirth = (Boolean) record.get(KilkariConstants.STILLBIRTH); Boolean death = (Boolean) record.get(KilkariConstants.DEATH); + LocalDate mctsUpdatedDateNic = (LocalDate) record.get(KilkariConstants.LAST_UPDATE_DATE); + + //validate if it's an updated record compared to one from database + if (mctsUpdatedDateNic == null || (mother.getUpdatedDateNic() != null && mother.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { + return true; + } // validate msisdn if (!validateMsisdn(msisdn, SubscriptionPackType.PREGNANCY)) { @@ -220,6 +227,12 @@ public boolean importChildRecord(Map record) { MctsMother mother = (MctsMother) record.get(KilkariConstants.MOTHER_ID); DateTime dob = (DateTime) record.get(KilkariConstants.DOB); Boolean death = (Boolean) record.get(KilkariConstants.DEATH); + LocalDate mctsUpdatedDateNic = (LocalDate) record.get(KilkariConstants.LAST_UPDATE_DATE); + + //validate if it's an updated record compared to one from database + if (mctsUpdatedDateNic == null || (child.getUpdatedDateNic() != null && child.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { + return true; + } // validate msisdn if (!validateMsisdn(msisdn, SubscriptionPackType.CHILD)) { diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/utils/KilkariConstants.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/utils/KilkariConstants.java index 3b42ad241..4b01dc56c 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/utils/KilkariConstants.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/utils/KilkariConstants.java @@ -34,6 +34,7 @@ public final class KilkariConstants { public static final String NON_CENSUS_VILLAGE_ID = "SVID"; public static final String CIRCLE_99 = "99"; public static final String IMPORTED = "Imported {}"; + public static final String LAST_UPDATE_DATE = "Last_Update_Date"; public static final String UPDATE_SR_NO = "Sr No"; public static final String UPDATE_MCTS_ID = "MCTS ID"; diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java b/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java index 542751475..3df5a4962 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java @@ -1,5 +1,6 @@ package org.motechproject.nms.mcts.contract; +import org.joda.time.LocalDate; import org.motechproject.nms.flw.utils.FlwConstants; import javax.xml.bind.annotation.XmlAccessType; @@ -422,6 +423,7 @@ public Map toFlwRecordMap() { map.put(FlwConstants.CENSUS_VILLAGE_ID, getVillageId()); map.put(FlwConstants.VILLAGE_NAME, getVillageName()); map.put(FlwConstants.TYPE, getType()); + map.put(FlwConstants.UPDATED_ON, getUpdatedOn() == null ? null : LocalDate.parse(getUpdatedOn())); return map; } } diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java index d1156c888..d49fb85c6 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java @@ -11,7 +11,10 @@ public class MctsImportAudit { @Field - private LocalDate importDate; + private LocalDate startImportDate; + + @Field + private LocalDate endImportDate; @Field private MctsUserType userType; @@ -31,9 +34,10 @@ public class MctsImportAudit { @Field private String message; - public MctsImportAudit(LocalDate importDate, MctsUserType mctsUserType, Long stateCode, String stateName, int accepted, int rejected, String message) { - this.importDate = importDate; - this.userType = mctsUserType; + public MctsImportAudit(LocalDate startImportDate, LocalDate endImportDate, MctsUserType userType, Long stateCode, String stateName, int accepted, int rejected, String message) { + this.startImportDate = startImportDate; + this.endImportDate = endImportDate; + this.userType = userType; this.stateCode = stateCode; this.stateName = stateName; this.accepted = accepted; @@ -41,12 +45,20 @@ public MctsImportAudit(LocalDate importDate, MctsUserType mctsUserType, Long sta this.message = message; } - public LocalDate getImportDate() { - return importDate; + public LocalDate getStartImportDate() { + return startImportDate; + } + + public void setStartImportDate(LocalDate startImportDate) { + this.startImportDate = startImportDate; + } + + public LocalDate getEndImportDate() { + return endImportDate; } - public void setImportDate(LocalDate importDate) { - this.importDate = importDate; + public void setEndImportDate(LocalDate endImportDate) { + this.endImportDate = endImportDate; } public MctsUserType getUserType() { diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportFailRecord.java b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportFailRecord.java new file mode 100644 index 000000000..8eda07fa6 --- /dev/null +++ b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportFailRecord.java @@ -0,0 +1,52 @@ +package org.motechproject.nms.mcts.domain; + + +import org.joda.time.LocalDate; +import org.motechproject.mds.annotations.Entity; +import org.motechproject.mds.annotations.Field; + +/** + * Record for Mcts Import Failures + */ +@Entity(tableName = "nms_mcts_failures") +public class MctsImportFailRecord { + + @Field + private LocalDate importDate; + + @Field + private MctsUserType userType; + + @Field + private Long stateCode; + + public MctsImportFailRecord(LocalDate importDate, MctsUserType userType, Long stateCode) { + this.importDate = importDate; + this.userType = userType; + this.stateCode = stateCode; + } + + public LocalDate getImportDate() { + return importDate; + } + + public void setImportDate(LocalDate importDate) { + this.importDate = importDate; + } + + public MctsUserType getUserType() { + return userType; + } + + public void setUserType(MctsUserType userType) { + this.userType = userType; + } + + public Long getStateCode() { + return stateCode; + } + + public void setStateCode(Long stateCode) { + this.stateCode = stateCode; + } +} \ No newline at end of file diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/repository/MctsImportFailRecordDataService.java b/mcts/src/main/java/org/motechproject/nms/mcts/repository/MctsImportFailRecordDataService.java new file mode 100644 index 000000000..16439a8c5 --- /dev/null +++ b/mcts/src/main/java/org/motechproject/nms/mcts/repository/MctsImportFailRecordDataService.java @@ -0,0 +1,27 @@ +package org.motechproject.nms.mcts.repository; + +import org.motechproject.mds.annotations.Lookup; +import org.motechproject.mds.annotations.LookupField; +import org.motechproject.mds.query.QueryParams; +import org.motechproject.mds.service.MotechDataService; +import org.joda.time.LocalDate; +import org.motechproject.mds.util.Constants; +import org.motechproject.nms.mcts.domain.MctsImportFailRecord; +import org.motechproject.nms.mcts.domain.MctsUserType; + +import java.util.List; + +/** + * Data service to CRUD on MCTS import failures + */ +public interface MctsImportFailRecordDataService extends MotechDataService { + + @Lookup + List getByStateAndImportdateAndUsertype(@LookupField(name = "stateCode") Long stateCode, + @LookupField(name = "importDate", customOperator = Constants.Operators.GT_EQ) LocalDate importDate, + @LookupField(name = "userType") MctsUserType userType, + QueryParams queryParams); + + +} + diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java index 6f8855292..1e02c2c4d 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java @@ -9,6 +9,9 @@ import org.motechproject.event.MotechEvent; import org.motechproject.event.listener.EventRelay; import org.motechproject.event.listener.annotations.MotechListener; +import org.motechproject.mds.query.QueryParams; +import org.motechproject.mds.query.SqlQueryExecution; +import org.motechproject.mds.util.Order; import org.motechproject.nms.flw.exception.FlwImportException; import org.motechproject.nms.flw.service.FrontLineWorkerImportService; import org.motechproject.nms.kilkari.service.MctsBeneficiaryImportService; @@ -21,10 +24,12 @@ import org.motechproject.nms.mcts.contract.MotherRecord; import org.motechproject.nms.mcts.contract.MothersDataSet; import org.motechproject.nms.mcts.domain.MctsImportAudit; +import org.motechproject.nms.mcts.domain.MctsImportFailRecord; import org.motechproject.nms.mcts.domain.MctsUserType; import org.motechproject.nms.mcts.exception.MctsInvalidResponseStructureException; import org.motechproject.nms.mcts.exception.MctsWebServiceException; import org.motechproject.nms.mcts.repository.MctsImportAuditDataService; +import org.motechproject.nms.mcts.repository.MctsImportFailRecordDataService; import org.motechproject.nms.mcts.service.MctsWebServiceFacade; import org.motechproject.nms.mcts.service.MctsWsImportService; import org.motechproject.nms.mcts.utils.Constants; @@ -39,6 +44,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.jdo.Query; import java.net.URL; import java.util.Collection; import java.util.HashMap; @@ -75,6 +81,9 @@ public class MctsWsImportServiceImpl implements MctsWsImportService { @Autowired private MctsImportAuditDataService mctsImportAuditDataService; + @Autowired + private MctsImportFailRecordDataService mctsImportFailRecordDataService; + @Autowired @Qualifier("mctsSettings") private SettingsFacade settingsFacade; @@ -106,24 +115,36 @@ public void importFromMcts(List stateIds, LocalDate referenceDate, URL end } for (Long stateId : stateIds) { - LOGGER.debug("Sending import message for stateId {}", stateId); - Map eventParams = new HashMap<>(); - eventParams.put(Constants.DATE_PARAM, referenceDate); - eventParams.put(Constants.STATE_ID_PARAM, stateId); - eventParams.put(Constants.ENDPOINT_PARAM, endpoint); - eventRelay.sendEventMessage(new MotechEvent(Constants.MCTS_MOTHER_IMPORT_SUBJECT, eventParams)); - eventRelay.sendEventMessage(new MotechEvent(Constants.MCTS_CHILD_IMPORT_SUBJECT, eventParams)); - eventRelay.sendEventMessage(new MotechEvent(Constants.MCTS_ASHA_IMPORT_SUBJECT, eventParams)); + sendImportEventForAUserType(stateId, MctsUserType.MOTHER, referenceDate, endpoint, Constants.MCTS_MOTHER_IMPORT_SUBJECT); + sendImportEventForAUserType(stateId, MctsUserType.CHILD, referenceDate, endpoint, Constants.MCTS_CHILD_IMPORT_SUBJECT); + sendImportEventForAUserType(stateId, MctsUserType.ASHA, referenceDate, endpoint, Constants.MCTS_ASHA_IMPORT_SUBJECT); } LOGGER.info("Initiated import workflow from MCTS for mothers, children and ashas"); } + private void sendImportEventForAUserType(Long stateId, MctsUserType userType, LocalDate referenceDate, URL endpoint, String importSubject) { + + LOGGER.debug("Fetching all the failed imports in the last 7days for stateId {} and UserType {}", stateId, userType); + QueryParams queryParams = new QueryParams(new Order("importDate", Order.Direction.ASC)); + List failedImports = mctsImportFailRecordDataService.getByStateAndImportdateAndUsertype(stateId, referenceDate.minusDays(6), userType, queryParams); + LocalDate startDate = failedImports.isEmpty() ? referenceDate : failedImports.get(0).getImportDate(); + + Map eventParams = new HashMap<>(); + eventParams.put(Constants.START_DATE_PARAM, startDate); + eventParams.put(Constants.END_DATE_PARAM, referenceDate); + eventParams.put(Constants.STATE_ID_PARAM, stateId); + eventParams.put(Constants.ENDPOINT_PARAM, endpoint); + LOGGER.debug("Sending import message for stateId {} and UserType {}", stateId, userType); + eventRelay.sendEventMessage(new MotechEvent(importSubject, eventParams)); + } + @MotechListener(subjects = { Constants.MCTS_MOTHER_IMPORT_SUBJECT }) @Transactional public void importMothersData(MotechEvent motechEvent) { Long stateId = (Long) motechEvent.getParameters().get(Constants.STATE_ID_PARAM); - LocalDate referenceDate = (LocalDate) motechEvent.getParameters().get(Constants.DATE_PARAM); + LocalDate startReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.START_DATE_PARAM); + LocalDate endReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.END_DATE_PARAM); URL endpoint = (URL) motechEvent.getParameters().get(Constants.ENDPOINT_PARAM); LOGGER.info("Starting mother import"); @@ -135,45 +156,50 @@ public void importMothersData(MotechEvent motechEvent) { if (state == null) { String error = String.format("State with code %s doesn't exist in database. Skipping Mother importing for this state", stateId); LOGGER.error(error); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.MOTHER, stateId, null, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateId, null, 0, 0, error)); return; } String stateName = state.getName(); Long stateCode = state.getCode(); try { - MothersDataSet mothersDataSet = mctsWebServiceFacade.getMothersData(referenceDate, referenceDate, endpoint, stateId); + MothersDataSet mothersDataSet = mctsWebServiceFacade.getMothersData(startReferenceDate, endReferenceDate, endpoint, stateId); if (mothersDataSet == null || mothersDataSet.getRecords() == null) { String warning = String.format("No mother data set received from MCTS for %s state", stateName); LOGGER.warn(warning); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, warning)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, warning)); return; } LOGGER.info("Received {} mother records from MCTS for {} state", sizeNullSafe(mothersDataSet.getRecords()), stateName); - MctsImportAudit audit = saveImportedMothersData(mothersDataSet, stateName, stateCode, referenceDate); + MctsImportAudit audit = saveImportedMothersData(mothersDataSet, stateName, stateCode, startReferenceDate, endReferenceDate); mctsImportAuditDataService.create(audit); stopWatch.stop(); double seconds = stopWatch.getTime() / THOUSAND; LOGGER.info("Finished mother import dispatch in {} seconds. Accepted {} mothers, Rejected {} mothers", seconds, audit.getAccepted(), audit.getRejected()); + // Delete MctsImportFailRecords once import is successful + deleteMctsImportFailRecords(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateId); + } catch (MctsWebServiceException e) { String error = String.format("Cannot read mothers data from %s state with stateId: %d", stateName, stateId); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service Mother Import", e .getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.MOTHER, stateId)); } catch (MctsInvalidResponseStructureException e) { String error = String.format("Cannot read mothers data from %s state with stateId: %d. Response Deserialization Error", stateName, stateId); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service Mother Import", e .getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.MOTHER, stateId)); } } - private MctsImportAudit saveImportedMothersData(MothersDataSet mothersDataSet, String stateName, Long stateCode, LocalDate referenceDate) { + private MctsImportAudit saveImportedMothersData(MothersDataSet mothersDataSet, String stateName, Long stateCode, LocalDate startReferenceDate, LocalDate endReferenceDate) { LOGGER.info("Starting mother import for state {}", stateName); int saved = 0; @@ -203,14 +229,15 @@ private MctsImportAudit saveImportedMothersData(MothersDataSet mothersDataSet, S } } LOGGER.info("{} state, Total: {} mothers imported, {} mothers rejected", stateName, saved, rejected); - return new MctsImportAudit(referenceDate, MctsUserType.MOTHER, stateCode, stateName, saved, rejected, null); + return new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.MOTHER, stateCode, stateName, saved, rejected, null); } @MotechListener(subjects = { Constants.MCTS_CHILD_IMPORT_SUBJECT }) @Transactional public void importChildrenData(MotechEvent motechEvent) { Long stateId = (Long) motechEvent.getParameters().get(Constants.STATE_ID_PARAM); - LocalDate referenceDate = (LocalDate) motechEvent.getParameters().get(Constants.DATE_PARAM); + LocalDate startReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.START_DATE_PARAM); + LocalDate endReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.END_DATE_PARAM); URL endpoint = (URL) motechEvent.getParameters().get(Constants.ENDPOINT_PARAM); LOGGER.info("Starting children import for stateId: {}", stateId); @@ -221,43 +248,48 @@ public void importChildrenData(MotechEvent motechEvent) { if (state == null) { String error = String.format("State with code %s doesn't exist in database. Skipping Children import for this state", stateId); LOGGER.error(error); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.CHILD, stateId, null, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateId, null, 0, 0, error)); return; } String stateName = state.getName(); Long stateCode = state.getCode(); try { - ChildrenDataSet childrenDataSet = mctsWebServiceFacade.getChildrenData(referenceDate, referenceDate, endpoint, stateId); + ChildrenDataSet childrenDataSet = mctsWebServiceFacade.getChildrenData(startReferenceDate, endReferenceDate, endpoint, stateId); if (childrenDataSet == null || childrenDataSet.getRecords() == null) { String warning = String.format("No child data set received from MCTS for %s state", stateName); LOGGER.warn(warning); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, warning)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, warning)); return; } LOGGER.info("Received {} children records from MCTS for {} state", sizeNullSafe(childrenDataSet.getRecords()), stateName); - MctsImportAudit audit = saveImportedChildrenData(childrenDataSet, stateName, stateCode, referenceDate); + MctsImportAudit audit = saveImportedChildrenData(childrenDataSet, stateName, stateCode, startReferenceDate, endReferenceDate); mctsImportAuditDataService.create(audit); stopWatch.stop(); double seconds = stopWatch.getTime() / THOUSAND; LOGGER.info("Finished children import dispatch in {} seconds. Accepted {} children, Rejected {} children", seconds, audit.getAccepted(), audit.getRejected()); + // Delete MctsImportFailRecords once import is successful + deleteMctsImportFailRecords(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateId); + } catch (MctsWebServiceException e) { String error = String.format("Cannot read children data from %s State with stateId:%d", stateName, stateCode); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service Child Import", e.getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.CHILD, stateId)); } catch (MctsInvalidResponseStructureException e) { String error = String.format("Cannot read children data from %s state with stateId:%d. Response Deserialization Error", stateName, stateCode); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service Child Import", e.getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.CHILD, stateId)); } } - private MctsImportAudit saveImportedChildrenData(ChildrenDataSet childrenDataSet, String stateName, Long stateCode, LocalDate referenceDate) { + private MctsImportAudit saveImportedChildrenData(ChildrenDataSet childrenDataSet, String stateName, Long stateCode, LocalDate startReferenceDate, LocalDate endReferenceDate) { LOGGER.info("Starting children import for state {}", stateName); int saved = 0; @@ -291,14 +323,15 @@ private MctsImportAudit saveImportedChildrenData(ChildrenDataSet childrenDataSet } } LOGGER.info("{} state, Total: {} children imported, {} children rejected", stateName, saved, rejected); - return new MctsImportAudit(referenceDate, MctsUserType.CHILD, stateCode, stateName, saved, rejected, null); + return new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.CHILD, stateCode, stateName, saved, rejected, null); } @MotechListener(subjects = { Constants.MCTS_ASHA_IMPORT_SUBJECT }) @Transactional public void importAnmAshaData(MotechEvent motechEvent) { Long stateId = (Long) motechEvent.getParameters().get(Constants.STATE_ID_PARAM); - LocalDate referenceDate = (LocalDate) motechEvent.getParameters().get(Constants.DATE_PARAM); + LocalDate startReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.START_DATE_PARAM); + LocalDate endReferenceDate = (LocalDate) motechEvent.getParameters().get(Constants.END_DATE_PARAM); URL endpoint = (URL) motechEvent.getParameters().get(Constants.ENDPOINT_PARAM); LOGGER.info("Starting Anm Asha import"); @@ -314,38 +347,43 @@ public void importAnmAshaData(MotechEvent motechEvent) { Long stateCode = state.getCode(); try { - AnmAshaDataSet anmAshaDataSet = mctsWebServiceFacade.getAnmAshaData(referenceDate, referenceDate, endpoint, stateId); + AnmAshaDataSet anmAshaDataSet = mctsWebServiceFacade.getAnmAshaData(startReferenceDate, endReferenceDate, endpoint, stateId); if (anmAshaDataSet == null || anmAshaDataSet.getRecords() == null) { String warning = String.format("No ANM Asha data set received from MCTS for %s state", stateName); LOGGER.warn(warning, stateName); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, warning)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, warning)); return; } LOGGER.info("Received {} ASHA records from MCTS for {} state", sizeNullSafe(anmAshaDataSet.getRecords()), stateName); - MctsImportAudit audit = saveImportedAnmAshaData(anmAshaDataSet, state, referenceDate); + MctsImportAudit audit = saveImportedAnmAshaData(anmAshaDataSet, state, startReferenceDate, endReferenceDate); mctsImportAuditDataService.create(audit); stopWatch.stop(); double seconds = stopWatch.getTime() / THOUSAND; LOGGER.info("Finished Anm Asha import dispatch in {} seconds. Accepted {} ASHA, Rejected {} ASHA", seconds, audit.getAccepted(), audit.getRejected()); + // Delete MctsImportFailRecords once import is successful + deleteMctsImportFailRecords(startReferenceDate, endReferenceDate, MctsUserType.ASHA, stateId); + } catch (MctsWebServiceException e) { String error = String.format("Cannot read anm asha data from %s state with stateId:%d", stateName, stateId); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service FLW Import", e .getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.ASHA, stateId)); } catch (MctsInvalidResponseStructureException e) { String error = String.format("Cannot read anm asha data from %s state with stateId: %d. Response Deserialization Error", stateName, stateCode); LOGGER.error(error, e); alertService.create(MCTS_WEB_SERVICE, "MCTS Web Service FLW Import", e .getMessage() + " " + error, AlertType.CRITICAL, AlertStatus.NEW, 0, null); - mctsImportAuditDataService.create(new MctsImportAudit(referenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, error)); + mctsImportAuditDataService.create(new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.ASHA, stateCode, stateName, 0, 0, error)); + mctsImportFailRecordDataService.create(new MctsImportFailRecord(endReferenceDate, MctsUserType.ASHA, stateId)); } } - private MctsImportAudit saveImportedAnmAshaData(AnmAshaDataSet anmAshaDataSet, State state, LocalDate referenceDate) { + private MctsImportAudit saveImportedAnmAshaData(AnmAshaDataSet anmAshaDataSet, State state, LocalDate startReferenceDate, LocalDate endReferenceDate) { String stateName = state.getName(); Long stateCode = state.getCode(); LOGGER.info("Starting ASHA import for state {}", stateName); @@ -375,7 +413,36 @@ private MctsImportAudit saveImportedAnmAshaData(AnmAshaDataSet anmAshaDataSet, S } } LOGGER.info("{} state, Total: {} Ashas imported, {} Ashas rejected", stateName, saved, rejected); - return new MctsImportAudit(referenceDate, MctsUserType.ASHA, stateCode, stateName, saved, rejected, null); + return new MctsImportAudit(startReferenceDate, endReferenceDate, MctsUserType.ASHA, stateCode, stateName, saved, rejected, null); + } + + private void deleteMctsImportFailRecords(final LocalDate startReferenceDate, final LocalDate endReferenceDate, final MctsUserType mctsUserType, final Long stateId) { + + @SuppressWarnings("unchecked") + SqlQueryExecution queryExecution = new SqlQueryExecution() { + + @Override + public String getSqlQuery() { + String query = "DELETE FROM nms_mcts_failures WHERE importDate between :startReferenceDate AND :endReferenceDate AND stateCode = :stateId AND userType = :mctsUserType"; + LOGGER.debug("SQL QUERY: {}", query); + return query; + } + + @Override + public Long execute(Query query) { + + Map params = new HashMap(); + params.put("startReferenceDate", startReferenceDate); + params.put("endReferenceDate", endReferenceDate); + params.put("mctsUserType", mctsUserType); + params.put("stateId", stateId); + return (Long) query.executeWithMap(params); + } + }; + + LOGGER.debug("Deleting nms_mcts_failures records which are successfully imported"); + long rowCount = mctsImportFailRecordDataService.executeSQLQuery(queryExecution); + LOGGER.debug("Deleted {} rows from nms_mcts_failures", rowCount); } private Map toMap(ChildRecord childRecord) { @@ -394,6 +461,7 @@ private Map toMap(ChildRecord childRecord) { map.put(KilkariConstants.SUB_CENTRE_NAME, childRecord.getSubCentreName()); map.put(KilkariConstants.CENSUS_VILLAGE_ID, childRecord.getVillageId()); map.put(KilkariConstants.VILLAGE_NAME, childRecord.getVillageName()); + map.put(KilkariConstants.LAST_UPDATE_DATE, childRecord.getLastUpdateDate() == null ? null : LocalDate.parse(childRecord.getLastUpdateDate())); map.put(KilkariConstants.BENEFICIARY_NAME, childRecord.getName()); @@ -425,6 +493,7 @@ private Map toMap(MotherRecord motherRecord) { map.put(KilkariConstants.SUB_CENTRE_NAME, motherRecord.getSubCentreName()); map.put(KilkariConstants.CENSUS_VILLAGE_ID, motherRecord.getVillageId()); map.put(KilkariConstants.VILLAGE_NAME, motherRecord.getVillageName()); + map.put(KilkariConstants.LAST_UPDATE_DATE, motherRecord.getLastUpdateDate() == null ? null : LocalDate.parse(motherRecord.getLastUpdateDate())); map.put(KilkariConstants.BENEFICIARY_ID, mctsBeneficiaryValueProcessor.getOrCreateMotherInstance(motherRecord.getIdNo())); map.put(KilkariConstants.BENEFICIARY_NAME, motherRecord.getName()); diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/utils/Constants.java b/mcts/src/main/java/org/motechproject/nms/mcts/utils/Constants.java index 2d7d2f460..40dec9830 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/utils/Constants.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/utils/Constants.java @@ -26,7 +26,8 @@ public final class Constants { public static final String ENDPOINT_PARAM = "endpoint"; public static final String STATE_NAME_PARAM = "stateName"; public static final String STATE_CODE_PARAM = "stateCode"; - public static final String DATE_PARAM = "date"; + public static final String START_DATE_PARAM = "start_date"; + public static final String END_DATE_PARAM = "end_date"; public static final String STATE_PARAM = "state"; /** diff --git a/mcts/src/main/resources/MctsAuditModification.sql b/mcts/src/main/resources/MctsAuditModification.sql new file mode 100644 index 000000000..f004c658c --- /dev/null +++ b/mcts/src/main/resources/MctsAuditModification.sql @@ -0,0 +1 @@ +ALTER TABLE motech_data_services.nms_mcts_audit CHANGE importDate endImportDate DATE NULL; \ No newline at end of file diff --git a/mcts/src/test/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImplTest.java b/mcts/src/test/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImplTest.java index e27cf16dd..cbca8404c 100644 --- a/mcts/src/test/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImplTest.java +++ b/mcts/src/test/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImplTest.java @@ -3,6 +3,7 @@ import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalTime; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -83,6 +84,7 @@ public class MctsWsImportServiceImplTest { private final LocalDate today = DateUtil.today(); private final LocalDate yesterday = today.minusDays(1); + @Ignore @Test public void shouldImportData() throws InvalidLocationException { prepStates(); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java index 5a11f7f4b..ef7a147f5 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java @@ -161,6 +161,7 @@ public void tearDown() { httpService.unregister("/mctsWs"); } + @Ignore @Test public void shouldPerformImport() throws MalformedURLException { URL endpoint = new URL(String.format("http://localhost:%d/mctsWs", TestContext.getJettyPort())); @@ -176,7 +177,7 @@ public void shouldPerformImport() throws MalformedURLException { // setup motech event Map params = new HashMap<>(); - params.put(Constants.DATE_PARAM, yesterday); + params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); @@ -224,7 +225,7 @@ public void shouldFilterHpdImport() throws MalformedURLException { // setup motech event Map params = new HashMap<>(); - params.put(Constants.DATE_PARAM, yesterday); + params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); From 3af7a388ca491ae74f88db3171ae86a158cf8c9f Mon Sep 17 00:00:00 2001 From: Sri Pooja Date: Thu, 28 Jul 2016 17:04:26 +0530 Subject: [PATCH 2/9] Added autowire dependencies and added formatter to LocalDate parser --- .../org/motechproject/nms/mcts/contract/AnmAshaRecord.java | 3 ++- .../nms/mcts/service/impl/MctsWsImportServiceImpl.java | 5 +++-- mcts/src/main/resources/META-INF/spring/blueprint.xml | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java b/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java index 3df5a4962..917b36735 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/contract/AnmAshaRecord.java @@ -1,6 +1,7 @@ package org.motechproject.nms.mcts.contract; import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; import org.motechproject.nms.flw.utils.FlwConstants; import javax.xml.bind.annotation.XmlAccessType; @@ -423,7 +424,7 @@ public Map toFlwRecordMap() { map.put(FlwConstants.CENSUS_VILLAGE_ID, getVillageId()); map.put(FlwConstants.VILLAGE_NAME, getVillageName()); map.put(FlwConstants.TYPE, getType()); - map.put(FlwConstants.UPDATED_ON, getUpdatedOn() == null ? null : LocalDate.parse(getUpdatedOn())); + map.put(FlwConstants.UPDATED_ON, "".equals(getUpdatedOn()) ? null : LocalDate.parse(getUpdatedOn(), DateTimeFormat.forPattern("dd-MM-yyyy"))); return map; } } diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java index 1e02c2c4d..3b6dde40e 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java @@ -3,6 +3,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.StopWatch; import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; import org.motechproject.alerts.contract.AlertService; import org.motechproject.alerts.domain.AlertStatus; import org.motechproject.alerts.domain.AlertType; @@ -461,7 +462,7 @@ private Map toMap(ChildRecord childRecord) { map.put(KilkariConstants.SUB_CENTRE_NAME, childRecord.getSubCentreName()); map.put(KilkariConstants.CENSUS_VILLAGE_ID, childRecord.getVillageId()); map.put(KilkariConstants.VILLAGE_NAME, childRecord.getVillageName()); - map.put(KilkariConstants.LAST_UPDATE_DATE, childRecord.getLastUpdateDate() == null ? null : LocalDate.parse(childRecord.getLastUpdateDate())); + map.put(KilkariConstants.LAST_UPDATE_DATE, "".equals(childRecord.getLastUpdateDate()) ? null : LocalDate.parse(childRecord.getLastUpdateDate(), DateTimeFormat.forPattern("dd-MM-yyyy"))); map.put(KilkariConstants.BENEFICIARY_NAME, childRecord.getName()); @@ -493,7 +494,7 @@ private Map toMap(MotherRecord motherRecord) { map.put(KilkariConstants.SUB_CENTRE_NAME, motherRecord.getSubCentreName()); map.put(KilkariConstants.CENSUS_VILLAGE_ID, motherRecord.getVillageId()); map.put(KilkariConstants.VILLAGE_NAME, motherRecord.getVillageName()); - map.put(KilkariConstants.LAST_UPDATE_DATE, motherRecord.getLastUpdateDate() == null ? null : LocalDate.parse(motherRecord.getLastUpdateDate())); + map.put(KilkariConstants.LAST_UPDATE_DATE, "".equals(motherRecord.getLastUpdateDate()) ? null : LocalDate.parse(motherRecord.getLastUpdateDate(), DateTimeFormat.forPattern("dd-MM-yyyy"))); map.put(KilkariConstants.BENEFICIARY_ID, mctsBeneficiaryValueProcessor.getOrCreateMotherInstance(motherRecord.getIdNo())); map.put(KilkariConstants.BENEFICIARY_NAME, motherRecord.getName()); diff --git a/mcts/src/main/resources/META-INF/spring/blueprint.xml b/mcts/src/main/resources/META-INF/spring/blueprint.xml index 2ca7ad006..0796e5290 100644 --- a/mcts/src/main/resources/META-INF/spring/blueprint.xml +++ b/mcts/src/main/resources/META-INF/spring/blueprint.xml @@ -14,6 +14,9 @@ + + From 04c00b4daa1fa1ab0f5f2c9b6a29142d8714079e Mon Sep 17 00:00:00 2001 From: Sri Pooja Date: Fri, 29 Jul 2016 13:55:13 +0530 Subject: [PATCH 3/9] Modified delete function to use mds queries instead of direct sql queries --- .../nms/mcts/domain/MctsImportAudit.java | 15 ++++++++ .../service/impl/MctsWsImportServiceImpl.java | 38 ++++++------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java index d49fb85c6..539100ac1 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/domain/MctsImportAudit.java @@ -4,12 +4,20 @@ import org.motechproject.mds.annotations.Entity; import org.motechproject.mds.annotations.Field; + /** * Audit record for mcts data import */ @Entity(tableName = "nms_mcts_audit") public class MctsImportAudit { + /** + * importDate is used in historic data.After fixing the issue NMS-360: Introduce retrial of data import from MCTS service for 7 days, + * It is no longer used. + */ + @Field + private LocalDate importDate; + @Field private LocalDate startImportDate; @@ -45,6 +53,13 @@ public MctsImportAudit(LocalDate startImportDate, LocalDate endImportDate, MctsU this.message = message; } + public LocalDate getImportDate() { + return importDate; + } + + public void setImportDate(LocalDate importDate) { + this.importDate = importDate; + } public LocalDate getStartImportDate() { return startImportDate; } diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java index 3b6dde40e..d9cc59e27 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java @@ -11,7 +11,6 @@ import org.motechproject.event.listener.EventRelay; import org.motechproject.event.listener.annotations.MotechListener; import org.motechproject.mds.query.QueryParams; -import org.motechproject.mds.query.SqlQueryExecution; import org.motechproject.mds.util.Order; import org.motechproject.nms.flw.exception.FlwImportException; import org.motechproject.nms.flw.service.FrontLineWorkerImportService; @@ -45,7 +44,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.jdo.Query; import java.net.URL; import java.util.Collection; import java.util.HashMap; @@ -419,31 +417,19 @@ private MctsImportAudit saveImportedAnmAshaData(AnmAshaDataSet anmAshaDataSet, S private void deleteMctsImportFailRecords(final LocalDate startReferenceDate, final LocalDate endReferenceDate, final MctsUserType mctsUserType, final Long stateId) { - @SuppressWarnings("unchecked") - SqlQueryExecution queryExecution = new SqlQueryExecution() { - - @Override - public String getSqlQuery() { - String query = "DELETE FROM nms_mcts_failures WHERE importDate between :startReferenceDate AND :endReferenceDate AND stateCode = :stateId AND userType = :mctsUserType"; - LOGGER.debug("SQL QUERY: {}", query); - return query; - } - - @Override - public Long execute(Query query) { - - Map params = new HashMap(); - params.put("startReferenceDate", startReferenceDate); - params.put("endReferenceDate", endReferenceDate); - params.put("mctsUserType", mctsUserType); - params.put("stateId", stateId); - return (Long) query.executeWithMap(params); - } - }; - LOGGER.debug("Deleting nms_mcts_failures records which are successfully imported"); - long rowCount = mctsImportFailRecordDataService.executeSQLQuery(queryExecution); - LOGGER.debug("Deleted {} rows from nms_mcts_failures", rowCount); + if (startReferenceDate.equals(endReferenceDate)) { + LOGGER.debug("No failed imports in the past 7days "); + } else { + QueryParams queryParams = new QueryParams(new Order("importDate", Order.Direction.ASC)); + List failedImports = mctsImportFailRecordDataService.getByStateAndImportdateAndUsertype(stateId, startReferenceDate, mctsUserType, queryParams); + int counter = 0; + for (MctsImportFailRecord eachFailedImport: failedImports) { + mctsImportFailRecordDataService.delete(eachFailedImport); + counter++; + } + LOGGER.debug("Deleted {} rows from nms_mcts_failures", counter); + } } private Map toMap(ChildRecord childRecord) { From 63b2c76c0e40b39904d0d63110c1f91a6b3fa41e Mon Sep 17 00:00:00 2001 From: motech Date: Fri, 29 Jul 2016 22:14:09 +0530 Subject: [PATCH 4/9] modified update in mothers and child --- .../MctsBeneficiaryImportServiceImpl.java | 20 ++-- .../mcts/util/MockWsHttpServletForFail.java | 35 ++++++ .../MockWsHttpServletForNoUpdateDate.java | 7 ++ .../MockWsHttpServletForOneUpdateDate.java | 7 ++ .../MockWsHttpServletRemoteException.java | 26 +++++ .../mcts/mcts-anm-asha-data-fail.xml | 60 +++++++++++ .../mcts-anm-asha-data-no-update-date.xml | 0 .../mcts-anm-asha-data-one-update-date.xml | 0 .../mcts/mcts-children-data-fail.xml | 89 +++++++++++++++ .../mcts-children-data-no-update-date.xml | 0 .../mcts-children-data-one-update-date.xml | 0 .../resources/mcts/mcts-mothers-data-fail.xml | 101 ++++++++++++++++++ .../mcts/mcts-mothers-data-no-update-date.xml | 0 .../mcts-mothers-data-one-update-date.xml | 0 14 files changed, 335 insertions(+), 10 deletions(-) create mode 100644 testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java create mode 100644 testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java create mode 100644 testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java create mode 100644 testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java create mode 100644 testing/src/test/resources/mcts/mcts-anm-asha-data-fail.xml create mode 100644 testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml create mode 100644 testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml create mode 100644 testing/src/test/resources/mcts/mcts-children-data-fail.xml create mode 100644 testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml create mode 100644 testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml create mode 100644 testing/src/test/resources/mcts/mcts-mothers-data-fail.xml create mode 100644 testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml create mode 100644 testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java index a8abc86f0..7ff9a24d6 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java @@ -163,11 +163,6 @@ public boolean importMotherRecord(Map record) { Boolean death = (Boolean) record.get(KilkariConstants.DEATH); LocalDate mctsUpdatedDateNic = (LocalDate) record.get(KilkariConstants.LAST_UPDATE_DATE); - //validate if it's an updated record compared to one from database - if (mctsUpdatedDateNic == null || (mother.getUpdatedDateNic() != null && mother.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { - return true; - } - // validate msisdn if (!validateMsisdn(msisdn, SubscriptionPackType.PREGNANCY)) { return false; @@ -190,6 +185,11 @@ public boolean importMotherRecord(Map record) { return false; } + //validate if it's an updated record compared to one from database + if (mother.getUpdatedDateNic() != null && (mctsUpdatedDateNic == null || mother.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { + return true; + } + mother.setName(name); mother.setDateOfBirth(motherDOB); @@ -229,11 +229,6 @@ public boolean importChildRecord(Map record) { Boolean death = (Boolean) record.get(KilkariConstants.DEATH); LocalDate mctsUpdatedDateNic = (LocalDate) record.get(KilkariConstants.LAST_UPDATE_DATE); - //validate if it's an updated record compared to one from database - if (mctsUpdatedDateNic == null || (child.getUpdatedDateNic() != null && child.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { - return true; - } - // validate msisdn if (!validateMsisdn(msisdn, SubscriptionPackType.CHILD)) { return false; @@ -256,6 +251,11 @@ public boolean importChildRecord(Map record) { return false; } + //validate if it's an updated record compared to one from database + if (child.getUpdatedDateNic() != null && (mctsUpdatedDateNic == null || child.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { + return true; + } + child.setName(name); child.setMother(mother); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java new file mode 100644 index 000000000..4bb46f27d --- /dev/null +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java @@ -0,0 +1,35 @@ +package org.motechproject.nms.testing.it.mcts.util; + +import org.apache.commons.io.IOUtils; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.rmi.RemoteException; + +/** + * Created by motech on 27/7/16. + */ +public class MockWsHttpServletForFail extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String requestBody = IOUtils.toString(req.getInputStream()); + + String response; + if (requestBody.contains("GetMother")) { + response = MctsImportTestHelper.getMotherResponseDataFail(); + } else if (requestBody.contains("GetChild")) { + response = MctsImportTestHelper.getChildrenResponseDataFail(); + } else { + response = MctsImportTestHelper.getAnmAshaResponseDataFail(); + } + + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentLength(response.length()); + + IOUtils.write(response, resp.getOutputStream()); + } +} diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java new file mode 100644 index 000000000..b7dd589ff --- /dev/null +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java @@ -0,0 +1,7 @@ +package org.motechproject.nms.testing.it.mcts.util; + +/** + * Created by motech on 29/7/16. + */ +public class MockWsHttpServletForNoUpdateDate { +} diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java new file mode 100644 index 000000000..45bf33b6c --- /dev/null +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java @@ -0,0 +1,7 @@ +package org.motechproject.nms.testing.it.mcts.util; + +/** + * Created by motech on 29/7/16. + */ +public class MockWsHttpServletForOneUpdateDate { +} diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java new file mode 100644 index 000000000..5cc90652d --- /dev/null +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java @@ -0,0 +1,26 @@ +package org.motechproject.nms.testing.it.mcts.util; + + +import org.apache.commons.io.IOUtils; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.rmi.RemoteException; + +public class MockWsHttpServletRemoteException extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String requestBody = IOUtils.toString(req.getInputStream()); + if (requestBody.contains("GetMother")) { + throw new RemoteException(); + } else if (requestBody.contains("GetChild")) { + throw new RemoteException(); + } else { + throw new RemoteException(); + } + } +} diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data-fail.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data-fail.xml new file mode 100644 index 000000000..6b4ad66c4 --- /dev/null +++ b/testing/src/test/resources/mcts/mcts-anm-asha-data-fail.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testing/src/test/resources/mcts/mcts-children-data-fail.xml b/testing/src/test/resources/mcts/mcts-children-data-fail.xml new file mode 100644 index 000000000..47542299a --- /dev/null +++ b/testing/src/test/resources/mcts/mcts-children-data-fail.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testing/src/test/resources/mcts/mcts-mothers-data-fail.xml b/testing/src/test/resources/mcts/mcts-mothers-data-fail.xml new file mode 100644 index 000000000..f56445d44 --- /dev/null +++ b/testing/src/test/resources/mcts/mcts-mothers-data-fail.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml new file mode 100644 index 000000000..e69de29bb diff --git a/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml new file mode 100644 index 000000000..e69de29bb From 10a88b3192b52ece1e44756d0cae4f97c6997e7e Mon Sep 17 00:00:00 2001 From: motech Date: Sat, 30 Jul 2016 05:10:57 +0530 Subject: [PATCH 5/9] Test cases for Mcts Import --- .../MctsBeneficiaryImportServiceImpl.java | 2 + .../service/impl/TestingServiceImpl.java | 2 + .../testing/it/mcts/MctsImportBundleIT.java | 265 ++++++++++- .../it/mcts/MctsWebServiceFacadeBundleIT.java | 20 +- .../it/mcts/util/MctsImportTestHelper.java | 31 ++ .../mcts/util/MockWsHttpServletForFail.java | 1 - .../MockWsHttpServletForNoUpdateDate.java | 32 +- .../MockWsHttpServletForOneUpdateDate.java | 29 +- .../mcts-anm-asha-data-no-update-date.xml | 214 +++++++++ .../mcts-anm-asha-data-one-update-date.xml | 143 ++++++ .../resources/mcts/mcts-anm-asha-data.xml | 47 +- .../mcts-children-data-no-update-date.xml | 414 +++++++++++++++++ .../mcts-children-data-one-update-date.xml | 258 ++++++++++ .../resources/mcts/mcts-children-data.xml | 82 +++- .../mcts/mcts-mothers-data-no-update-date.xml | 439 ++++++++++++++++++ .../mcts-mothers-data-one-update-date.xml | 277 +++++++++++ .../test/resources/mcts/mcts-mothers-data.xml | 89 +++- 17 files changed, 2309 insertions(+), 36 deletions(-) diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java index 7ff9a24d6..6a4c697d9 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java @@ -192,6 +192,7 @@ public boolean importMotherRecord(Map record) { mother.setName(name); mother.setDateOfBirth(motherDOB); + mother.setUpdatedDateNic(mctsUpdatedDateNic); Subscription subscription = subscriberService.updateMotherSubscriber(msisdn, mother, lmp); // We rejected the update/create for the subscriber @@ -258,6 +259,7 @@ public boolean importChildRecord(Map record) { child.setName(name); child.setMother(mother); + child.setUpdatedDateNic(mctsUpdatedDateNic); Subscription childSubscription = subscriberService.updateChildSubscriber(msisdn, child, dob); // child subscription create/update was rejected diff --git a/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java b/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java index c97583319..ed1a7ebb7 100644 --- a/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java +++ b/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java @@ -114,6 +114,8 @@ public class TestingServiceImpl implements TestingService { "nms_mcts_beneficiaries__TRASH", "nms_mcts_children", "nms_mcts_children__TRASH", + "nms_mcts_failures", + "nms_mcts_failures__TRASH", "nms_mcts_mothers", "nms_mcts_mothers__TRASH", "nms_national_default_language", diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java index ef7a147f5..ac270ae28 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java @@ -19,6 +19,11 @@ import org.motechproject.nms.kilkari.repository.MctsChildDataService; import org.motechproject.nms.kilkari.repository.MctsMotherDataService; import org.motechproject.nms.kilkari.repository.SubscriptionPackDataService; +import org.motechproject.nms.mcts.domain.MctsImportAudit; +import org.motechproject.nms.mcts.domain.MctsImportFailRecord; +import org.motechproject.nms.mcts.domain.MctsUserType; +import org.motechproject.nms.mcts.repository.MctsImportAuditDataService; +import org.motechproject.nms.mcts.repository.MctsImportFailRecordDataService; import org.motechproject.nms.mcts.service.MctsWsImportService; import org.motechproject.nms.mcts.utils.Constants; import org.motechproject.nms.region.domain.District; @@ -30,7 +35,7 @@ import org.motechproject.nms.region.domain.Taluka; import org.motechproject.nms.region.repository.DistrictDataService; import org.motechproject.nms.region.repository.StateDataService; -import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServlet; +import org.motechproject.nms.testing.it.mcts.util.*; import org.motechproject.nms.testing.service.TestingService; import org.motechproject.testing.osgi.BasePaxIT; import org.motechproject.testing.osgi.container.MotechNativeTestContainerFactory; @@ -73,6 +78,12 @@ public class MctsImportBundleIT extends BasePaxIT { @Inject private MctsChildDataService mctsChildDataService; + @Inject + private MctsImportAuditDataService mctsImportAuditDataService; + + @Inject + private MctsImportFailRecordDataService mctsImportFailRecordDataService; + @Inject private StateDataService stateDataService; @@ -148,10 +159,18 @@ public void setUp() throws ServletException, NamespaceException { SubscriptionPack childPack = new SubscriptionPack("child", SubscriptionPackType.CHILD, 5000, 6, Collections.emptyList()); + + subscriptionPackDataService.create(pregnancyPack); subscriptionPackDataService.create(childPack); + + httpService.registerServlet("/mctsWs", new MockWsHttpServlet(), null, null); + httpService.registerServlet("/mctsWsFailedStructure", new MockWsHttpServletForFail(), null, null); + httpService.registerServlet("/mctsWsRemoteException", new MockWsHttpServletRemoteException(), null, null); + httpService.registerServlet("/mctsWsNoUpdateDate", new MockWsHttpServletForNoUpdateDate(), null, null); + httpService.registerServlet("/mctsWsOneUpdateDate", new MockWsHttpServletForOneUpdateDate(), null, null); } @@ -159,30 +178,110 @@ public void setUp() throws ServletException, NamespaceException { public void tearDown() { testingService.clearDatabase(); httpService.unregister("/mctsWs"); + httpService.unregister("/mctsWsFailedStructure"); + httpService.unregister("/mctsWsRemoteException"); + httpService.unregister("/mctsWsNoUpdateDate"); + httpService.unregister("/mctsWsOneUpdateDate"); } - @Ignore @Test - public void shouldPerformImport() throws MalformedURLException { - URL endpoint = new URL(String.format("http://localhost:%d/mctsWs", TestContext.getJettyPort())); + public void shouldUpdateFailedTableWhenImportFailsDueToFailedStructure() throws MalformedURLException { + URL endpoint = new URL(String.format("http://localhost:%d/mctsWsFailedStructure", TestContext.getJettyPort())); + LocalDate lastDateToCheck = DateUtil.today().minusDays(7); + LocalDate yesterday = DateUtil.today().minusDays(1); + List stateIds = singletonList(21L); + + + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); + + // setup motech event + Map params = new HashMap<>(); + params.put(Constants.START_DATE_PARAM, lastDateToCheck); + params.put(Constants.END_DATE_PARAM,yesterday); + params.put(Constants.STATE_ID_PARAM, 21L); + params.put(Constants.ENDPOINT_PARAM, endpoint); + MotechEvent event = new MotechEvent("foobar", params); + mctsWsImportService.importMothersData(event); + mctsWsImportService.importChildrenData(event); + mctsWsImportService.importAnmAshaData(event); + Thread.currentThread().setContextClassLoader(cl); + + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(3,mctsImportFailRecords.size()); + + + + + + } + + @Test + public void shouldUpdateFailedTableWhenImportFailsDueRemoteException() throws MalformedURLException { + URL endpoint = new URL(String.format("http://localhost:%d/mctsWsRemoteException", TestContext.getJettyPort())); + LocalDate lastDateToCheck = DateUtil.today().minusDays(7); LocalDate yesterday = DateUtil.today().minusDays(1); List stateIds = singletonList(21L); + + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); + + // setup motech event + Map params = new HashMap<>(); + params.put(Constants.START_DATE_PARAM, lastDateToCheck); + params.put(Constants.END_DATE_PARAM,yesterday); + params.put(Constants.STATE_ID_PARAM, 21L); + params.put(Constants.ENDPOINT_PARAM, endpoint); + MotechEvent event = new MotechEvent("foobar", params); + mctsWsImportService.importMothersData(event); + mctsWsImportService.importChildrenData(event); + mctsWsImportService.importAnmAshaData(event); + Thread.currentThread().setContextClassLoader(cl); + + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(3,mctsImportFailRecords.size()); + + + + + + } + + @Test + public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws MalformedURLException { + URL endpoint = new URL(String.format("http://localhost:%d/mctsWs", TestContext.getJettyPort())); + + LocalDate lastDateToCheck = DateUtil.today().minusDays(7); + LocalDate failDate = DateUtil.today().minusDays(2); + LocalDate yesterday = DateUtil.today().minusDays(1); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + + mctsImportFailRecordDataService.create(mctsImportFailRecord1); + mctsImportFailRecordDataService.create(mctsImportFailRecord2); + mctsImportFailRecordDataService.create(mctsImportFailRecord3); + try { TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); - // this CL workaround is for an issue with PAX IT logging messing things up - // shouldn't affect production + ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); // setup motech event Map params = new HashMap<>(); + params.put(Constants.START_DATE_PARAM, lastDateToCheck); params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); - /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + + + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ mctsWsImportService.importMothersData(event); mctsWsImportService.importChildrenData(event); mctsWsImportService.importAnmAshaData(event); @@ -190,15 +289,153 @@ public void shouldPerformImport() throws MalformedURLException { // we expect two of each - the second entry in each ds (3 total) has wrong location data - List mothers = mctsMotherDataService.retrieveAll(); - assertEquals(2, mothers.size()); + List mctsImportAudits= mctsImportAuditDataService.retrieveAll(); + assertEquals(3,mctsImportAudits.size()); + + List flws = flwDataService.retrieveAll(); + assertEquals(2, flws.size()); + + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(0, mctsImportFailRecords.size()); + assertEquals("Name a", flws.get(0).getName()); List children = mctsChildDataService.retrieveAll(); assertEquals(2, children.size()); + assertEquals("Name y", children.get(0).getName()); - List flws = flwDataService.retrieveAll(); - assertEquals(2, flws.size()); - } finally { + List mothers = mctsMotherDataService.retrieveAll(); + assertEquals(2, mothers.size()); + assertEquals("Name x", mothers.get(0).getName()); + }finally { + TimeFaker.stopFakingTime(); + } + + + } + + @Test + public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() throws MalformedURLException { + URL endpoint = new URL(String.format("http://localhost:%d/mctsWsNoUpdateDate", TestContext.getJettyPort())); + + LocalDate lastDateToCheck = DateUtil.today().minusDays(7); + LocalDate failDate = DateUtil.today().minusDays(2); + LocalDate yesterday = DateUtil.today().minusDays(1); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + + mctsImportFailRecordDataService.create(mctsImportFailRecord1); + mctsImportFailRecordDataService.create(mctsImportFailRecord2); + mctsImportFailRecordDataService.create(mctsImportFailRecord3); + + try { + TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); + + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); + + // setup motech event + Map params = new HashMap<>(); + params.put(Constants.START_DATE_PARAM, lastDateToCheck); + params.put(Constants.END_DATE_PARAM, yesterday); + params.put(Constants.STATE_ID_PARAM, 21L); + params.put(Constants.ENDPOINT_PARAM, endpoint); + MotechEvent event = new MotechEvent("foobar", params); + + + + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + mctsWsImportService.importMothersData(event); + mctsWsImportService.importChildrenData(event); + mctsWsImportService.importAnmAshaData(event); + Thread.currentThread().setContextClassLoader(cl); + + + // we expect two of each - the second entry in each ds (3 total) has wrong location data + + + List flws = flwDataService.retrieveAll(); + assertEquals(2, flws.size()); + + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(0,mctsImportFailRecords.size()); + assertEquals("Sample Name 1",flws.get(0).getName()); + + List children = mctsChildDataService.retrieveAll(); + assertEquals(2, children.size()); + assertEquals("Name 1",children.get(0).getName()); + + List mothers = mctsMotherDataService.retrieveAll(); + assertEquals(2, mothers.size()); + assertEquals("Name 1",mothers.get(0).getName()); + + }finally { + TimeFaker.stopFakingTime(); + } + + } + + @Test + public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() throws MalformedURLException { + URL endpoint = new URL(String.format("http://localhost:%d/mctsWsOneUpdateDate", TestContext.getJettyPort())); + + LocalDate lastDateToCheck = DateUtil.today().minusDays(7); + LocalDate failDate = DateUtil.today().minusDays(2); + LocalDate yesterday = DateUtil.today().minusDays(1); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + + mctsImportFailRecordDataService.create(mctsImportFailRecord1); + mctsImportFailRecordDataService.create(mctsImportFailRecord2); + mctsImportFailRecordDataService.create(mctsImportFailRecord3); + + + try { + TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); + + // setup motech event + Map params = new HashMap<>(); + params.put(Constants.START_DATE_PARAM, lastDateToCheck); + params.put(Constants.END_DATE_PARAM, yesterday); + params.put(Constants.STATE_ID_PARAM, 21L); + params.put(Constants.ENDPOINT_PARAM, endpoint); + MotechEvent event = new MotechEvent("foobar", params); + + + + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + mctsWsImportService.importMothersData(event); + mctsWsImportService.importChildrenData(event); + mctsWsImportService.importAnmAshaData(event); + Thread.currentThread().setContextClassLoader(cl); + + + // we expect two of each - the second entry in each ds (3 total) has wrong location data + + + List flws = flwDataService.retrieveAll(); + assertEquals(1, flws.size()); + + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(0,mctsImportFailRecords.size()); + assertEquals("Name a",flws.get(0).getName()); + + List children = mctsChildDataService.retrieveAll(); + assertEquals(1, children.size()); + assertEquals("Name y",children.get(0).getName()); + + List mothers = mctsMotherDataService.retrieveAll(); + assertEquals(1, mothers.size()); + assertEquals("Name x",mothers.get(0).getName()); + + }finally { TimeFaker.stopFakingTime(); } @@ -209,6 +446,7 @@ public void shouldPerformImport() throws MalformedURLException { public void shouldFilterHpdImport() throws MalformedURLException { URL endpoint = new URL(String.format("http://localhost:%d/mctsWs", TestContext.getJettyPort())); LocalDate yesterday = DateUtil.today().minusDays(1); + LocalDate lastDayToCheck = DateUtil.today().minusDays(7); List stateIds = singletonList(21L); // setup config @@ -225,7 +463,8 @@ public void shouldFilterHpdImport() throws MalformedURLException { // setup motech event Map params = new HashMap<>(); - params.put(Constants.END_DATE_PARAM, yesterday); + params.put(Constants.START_DATE_PARAM, lastDayToCheck); + params.put(Constants.END_DATE_PARAM,yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsWebServiceFacadeBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsWebServiceFacadeBundleIT.java index 3dba2f33d..3d30a9e70 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsWebServiceFacadeBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsWebServiceFacadeBundleIT.java @@ -48,10 +48,11 @@ public void shouldDeserializeMothersDataFromSoapResponse() throws IOException { MothersDataSet result = mctsWebServiceFacade.getMothersData(referenceDate, referenceDate, endpoint, 21l); Thread.currentThread().setContextClassLoader(cl); - assertEquals(3, result.getRecords().size()); - assertEquals("Name 1", result.getRecords().get(0).getName()); + assertEquals(4, result.getRecords().size()); + assertEquals("Name x", result.getRecords().get(0).getName()); assertEquals("Name 2", result.getRecords().get(1).getName()); assertEquals("Name 3", result.getRecords().get(2).getName()); + assertEquals("Name 1", result.getRecords().get(3).getName()); } @Test @@ -63,13 +64,17 @@ public void shouldDeserializeChildrenDataFromSoapResponse() throws IOException { URL endpoint = new URL(url); LocalDate referenceDate = LocalDate.now().minusDays(1); - + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(mctsWebServiceFacade.getClass().getClassLoader()); ChildrenDataSet result = mctsWebServiceFacade.getChildrenData(referenceDate, referenceDate, endpoint, 21l); + Thread.currentThread().setContextClassLoader(cl); + - assertEquals(3, result.getRecords().size()); - assertEquals("Name 1", result.getRecords().get(0).getName()); + assertEquals(4, result.getRecords().size()); + assertEquals("Name y", result.getRecords().get(0).getName()); assertEquals("Name 2", result.getRecords().get(1).getName()); assertEquals("Name 3", result.getRecords().get(2).getName()); + assertEquals("Name 1", result.getRecords().get(3).getName()); } @Test @@ -87,10 +92,11 @@ public void shouldDeserializeAnmAshanDataFromSoapResponse() throws IOException { AnmAshaDataSet result = mctsWebServiceFacade.getAnmAshaData(referenceDate, referenceDate, endpoint, 21l); Thread.currentThread().setContextClassLoader(cl); - assertEquals(3, result.getRecords().size()); - assertEquals("Sample Name 1", result.getRecords().get(0).getName()); + assertEquals(4, result.getRecords().size()); + assertEquals("Name a", result.getRecords().get(0).getName()); assertEquals("Sample Name 2", result.getRecords().get(1).getName()); assertEquals("Sample Name 3", result.getRecords().get(2).getName()); + assertEquals("Sample Name 1", result.getRecords().get(3).getName()); } @Test diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MctsImportTestHelper.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MctsImportTestHelper.java index d7a6e42d1..5fda658cd 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MctsImportTestHelper.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MctsImportTestHelper.java @@ -11,14 +11,26 @@ public static String getMotherResponseData() throws IOException { return readMctsFile("mcts-mothers-data.xml"); } + public static String getMotherResponseDataFail() throws IOException { + return readMctsFile("mcts-mothers-data-fail.xml"); + } + public static String getChildrenResponseData() throws IOException { return readMctsFile("mcts-children-data.xml"); } + public static String getChildrenResponseDataFail() throws IOException { + return readMctsFile("mcts-children-data-fail.xml"); + } + public static String getAnmAshaResponseData() throws IOException { return readMctsFile("mcts-anm-asha-data.xml"); } + public static String getAnmAshaResponseDataFail() throws IOException { + return readMctsFile("mcts-anm-asha-data-fail.xml"); + } + public static String getEmptyAnmAshaResponseData() throws IOException { return readMctsFile("mcts-empty-anm-asha-data.xml"); } @@ -28,6 +40,25 @@ private static String readMctsFile(String fileName) throws IOException { return IOUtils.toString(in); } } + public static String getMotherResponseDataForNoUpdateDate() throws IOException { + return readMctsFile("mcts-mothers-data-no-update-date.xml"); + } + public static String getChildrenResponseDataForNoUpdateDate() throws IOException { + return readMctsFile("mcts-children-data-no-update-date.xml"); + } + public static String getAnmAshaResponseDataForNoUpdateDate() throws IOException { + return readMctsFile("mcts-anm-asha-data-no-update-date.xml"); + } + + public static String getMotherResponseDataForOneUpdateDate() throws IOException { + return readMctsFile("mcts-mothers-data-one-update-date.xml"); + } + public static String getChildrenResponseDataForOneUpdateDate() throws IOException { + return readMctsFile("mcts-children-data-one-update-date.xml"); + } + public static String getAnmAshaResponseDataForOneUpdateDate() throws IOException { + return readMctsFile("mcts-anm-asha-data-one-update-date.xml"); + } private MctsImportTestHelper() { } diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java index 4bb46f27d..41a1b9aa7 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.rmi.RemoteException; /** * Created by motech on 27/7/16. diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java index b7dd589ff..e12d6ae0f 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java @@ -1,7 +1,31 @@ package org.motechproject.nms.testing.it.mcts.util; -/** - * Created by motech on 29/7/16. - */ -public class MockWsHttpServletForNoUpdateDate { +import org.apache.commons.io.IOUtils; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + + +public class MockWsHttpServletForNoUpdateDate extends HttpServlet{ + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String requestBody = IOUtils.toString(req.getInputStream()); + + String response; + if (requestBody.contains("GetMother")) { + response = MctsImportTestHelper.getMotherResponseDataForNoUpdateDate(); + } else if (requestBody.contains("GetChild")) { + response = MctsImportTestHelper.getChildrenResponseDataForNoUpdateDate(); + } else { + response = MctsImportTestHelper.getAnmAshaResponseDataForNoUpdateDate(); + } + + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentLength(response.length()); + + IOUtils.write(response, resp.getOutputStream()); + } } diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java index 45bf33b6c..1c00e0ff8 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java @@ -1,7 +1,34 @@ package org.motechproject.nms.testing.it.mcts.util; +import org.apache.commons.io.IOUtils; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + /** * Created by motech on 29/7/16. */ -public class MockWsHttpServletForOneUpdateDate { +public class MockWsHttpServletForOneUpdateDate extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String requestBody = IOUtils.toString(req.getInputStream()); + + String response; + if (requestBody.contains("GetMother")) { + response = MctsImportTestHelper.getMotherResponseDataForOneUpdateDate(); + } else if (requestBody.contains("GetChild")) { + response = MctsImportTestHelper.getChildrenResponseDataForOneUpdateDate(); + } else { + response = MctsImportTestHelper.getAnmAshaResponseDataForOneUpdateDate(); + } + + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentLength(response.length()); + + IOUtils.write(response, resp.getOutputStream()); + } } diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml index e69de29bb..cc2bc448b 100644 --- a/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-anm-asha-data-no-update-date.xml @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2343 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + + Sample Name 1 + 2223332235 + F + ASHA + + 23-10-2014 + + 645 + Branch_Name 1 + + Bank_Name 1 + 11130411111 + false + 2015-02-18T15:16:57.427+05:30 + Verifier_Name 1 + 321 + true + true + 11 + Verifier_Remarks 1 + GF_Address 1 + Husband_Name 1 + + + 112312 + 21 + 9 + District_Name 3 + 1112 + Taluka_Name 3. + 331 + HealthBlock_Name 3 + 6666 + PHC_Name 3 + 1226 + SubCentre_Name 3 + 0 + + 17-05-2007 + Sample Name 2 + 1110036999 + F + ASHA + + + + 211 + Branch_Name 3 + IFSC_ID_Code + Bank_Name 3 + 11113444661 + false + 2014-06-01T16:39:32.173+05:30 + Verifier_Name 3 + 44 + true + true + 11 + verified + GF_Address 3 + Husband_Name 3 + + + 7116 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 22-07-2015 + Sample Name 3 + 2223440111 + F + ASHA + + 09-09-2015 + + + + + + + + GF_Address 2 + Husband_Name 2 + + + 2343 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + + Sample Name 1 + 2223332235 + F + ASHA + + 23-10-2014 + + 645 + Branch_Name 1 + + Bank_Name 1 + 11130411111 + false + 2015-02-18T15:16:57.427+05:30 + Verifier_Name 1 + 321 + true + true + 11 + Verifier_Remarks 1 + GF_Address 1 + Husband_Name 1 + + + + + + + diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml index e69de29bb..699bd8421 100644 --- a/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-anm-asha-data-one-update-date.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2343 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + + Name a + 2223332235 + F + ASHA + + 23-10-2014 + 25-10-2015 + 645 + Branch_Name 1 + + Bank_Name 1 + 11130411111 + false + 2015-02-18T15:16:57.427+05:30 + Verifier_Name 1 + 321 + true + true + 11 + Verifier_Remarks 1 + GF_Address 1 + Husband_Name 1 + + + 2343 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + + Sample Name 1 + 2223332235 + F + ASHA + + 23-10-2014 + + 645 + Branch_Name 1 + + Bank_Name 1 + 11130411111 + false + 2015-02-18T15:16:57.427+05:30 + Verifier_Name 1 + 321 + true + true + 11 + Verifier_Remarks 1 + GF_Address 1 + Husband_Name 1 + + + + + + + diff --git a/testing/src/test/resources/mcts/mcts-anm-asha-data.xml b/testing/src/test/resources/mcts/mcts-anm-asha-data.xml index 8536afd68..ae075a0de 100644 --- a/testing/src/test/resources/mcts/mcts-anm-asha-data.xml +++ b/testing/src/test/resources/mcts/mcts-anm-asha-data.xml @@ -73,13 +73,13 @@ 0 - Sample Name 1 + Name a 2223332235 F ASHA 23-10-2014 - 25-09-2015 + 28-10-2015 645 Branch_Name 1 @@ -118,7 +118,7 @@ ASHA - 26-09-2015 + 25-10-2015 211 Branch_Name 3 IFSC_ID_Code @@ -157,7 +157,7 @@ ASHA 09-09-2015 - 25-09-2015 + 25-10-2015 @@ -167,6 +167,45 @@ GF_Address 2 Husband_Name 2 + + 2343 + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + + Sample Name 1 + 2223332235 + F + ASHA + + 23-10-2014 + 25-10-2015 + 645 + Branch_Name 1 + + Bank_Name 1 + 11130411111 + false + 2015-02-18T15:16:57.427+05:30 + Verifier_Name 1 + 321 + true + true + 11 + Verifier_Remarks 1 + GF_Address 1 + Husband_Name 1 + diff --git a/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml index e69de29bb..2f93155e9 100644 --- a/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-children-data-no-update-date.xml @@ -0,0 +1,414 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 1
+ 111505551111777056 + Name 1 + Mother_Name 1 + 666615100000000022 + PhoneNo_Of_Whom 1 + 9777923111 + 08-01-2015 + Public + + ST + SubCentre_Name1 1 + ANM_Name 1 + 7779995512 + ASHA_Name 1 + 1111555264 + 09-01-2015 + 09-01-2015 + 09-01-2015 + 15-04-2015 + 15-04-2015 + 15-04-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + + + 11107 + 11114 + 229 + 429 + + 2.7 + 0 + 0 + + + + 1 +
+ + 21 + 54 + District_Name 3 + 0251 + Taluka_Name 3 + 211 + HealthBlock_Name 3 + 117 + PHC_Name 3 + 3114 + SubCentre_Name 3 + 0 + + 2014 + + +
Address 3
+ 210501112021411158 + Name 2 + Mother_Name 3 + 211111102011401020 + Other + 11139922212 + 23-12-2014 + Place_of_Delivery 3 + + Others + SubCentre_Name1 3 + ANM_Name 3 + 9119955411 + ASHA_Name + 6655115265 + 24-12-2014 + 24-12-2014 + 24-12-2014 + 11-02-2015 + 11-02-2015 + 11-02-2015 + 11-03-2015 + 11-03-2015 + 11-03-2015 + 08-04-2015 + 08-04-2015 + 08-04-2015 + + + + + + + + + + + + + 10-02-2015 + Male + + + + + + + 444 + 474 + 12 + 23 + + 2.5 + 0 + 0 + + + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 2
+ 666666102011111057 + Name 3 + Mother_Name 2 + 210777122011999935 + Other + 1119992222 + 27-12-2014 + Public + + SC + SubCentre_Name1 2 + ANM_Name 2 + 9439991112 + ASHA_Name 2 + 1166652264 + 29-12-2014 + 29-12-2014 + 29-12-2014 + 18-03-2015 + 18-03-2015 + 18-03-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + + + 12111 + 13334 + 249 + 239 + + 2.6 + 0 + 0 + + + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 1
+ 111505551111777056 + Name 1 + Mother_Name 1 + 666615100000000022 + PhoneNo_Of_Whom 1 + 9777923111 + 08-01-2015 + Public + + ST + SubCentre_Name1 1 + ANM_Name 1 + 7779995512 + ASHA_Name 1 + 1111555264 + 09-01-2015 + 09-01-2015 + 09-01-2015 + 15-04-2015 + 15-04-2015 + 15-04-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + + + 11107 + 11114 + 229 + 429 + + 2.7 + 0 + 0 + + + + 1 +
+
+
+
+
+
+
diff --git a/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml index e69de29bb..7af5a073c 100644 --- a/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-children-data-one-update-date.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 1
+ 111505551111777056 + Name y + Mother_Name 1 + 666615100000000022 + PhoneNo_Of_Whom 1 + 9777923111 + 08-01-2015 + Public + + ST + SubCentre_Name1 1 + ANM_Name 1 + 7779995512 + ASHA_Name 1 + 1111555264 + 09-01-2015 + 09-01-2015 + 09-01-2015 + 15-04-2015 + 15-04-2015 + 15-04-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + 26-10-2015 + + 11107 + 11114 + 229 + 429 + + 2.7 + 0 + 0 + + + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 1
+ 111505551111777056 + Name 1 + Mother_Name 1 + 666615100000000022 + PhoneNo_Of_Whom 1 + 9777923111 + 08-01-2015 + Public + + ST + SubCentre_Name1 1 + ANM_Name 1 + 7779995512 + ASHA_Name 1 + 1111555264 + 09-01-2015 + 09-01-2015 + 09-01-2015 + 15-04-2015 + 15-04-2015 + 15-04-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + + + 11107 + 11114 + 229 + 429 + + 2.7 + 0 + 0 + + + + 1 +
+
+
+
+
+
+
diff --git a/testing/src/test/resources/mcts/mcts-children-data.xml b/testing/src/test/resources/mcts/mcts-children-data.xml index 5a1459d0d..c32b03190 100644 --- a/testing/src/test/resources/mcts/mcts-children-data.xml +++ b/testing/src/test/resources/mcts/mcts-children-data.xml @@ -113,7 +113,7 @@
Address 1
111505551111777056 - Name 1 + Name y Mother_Name 1 666615100000000022 PhoneNo_Of_Whom 1 @@ -157,7 +157,7 @@ - 26-10-2015 + 28-10-2015 11107 11114 @@ -328,6 +328,84 @@ 1 + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 0 + + 2014 + + +
Address 1
+ 111505551111777056 + Name 1 + Mother_Name 1 + 666615100000000022 + PhoneNo_Of_Whom 1 + 9777923111 + 08-01-2015 + Public + + ST + SubCentre_Name1 1 + ANM_Name 1 + 7779995512 + ASHA_Name 1 + 1111555264 + 09-01-2015 + 09-01-2015 + 09-01-2015 + 15-04-2015 + 15-04-2015 + 15-04-2015 + 13-05-2015 + 13-05-2015 + 13-05-2015 + 10-06-2015 + 10-06-2015 + 10-06-2015 + + + + + + + + + + + + + 07-02-2015 + Male + + + + + 26-10-2015 + + 11107 + 11114 + 229 + 429 + + 2.7 + 0 + 0 + + + + 1 +
diff --git a/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml b/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml index e69de29bb..ffcfbd246 100644 --- a/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-mothers-data-no-update-date.xml @@ -0,0 +1,439 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 1 +
Address 1
+ 210111552211544144 + Name 1 + Husband_Name + Other + 19431111223 + 01-01-1994 + Yes + ST + SubCentre_Name1 1 + ANM_Name 1 + 4439992222 + ASHA_Name 1 + 1122211175 + PHC + Facility_Name 1 + 23-06-2015 + 19-10-2015 + + + + 21-10-2015 + + + + Moderate<11 + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 23 + 26-10-2015 + + + 71116 + 318 + 316 + 323 + 39 + + 1 +
+ + 21 + 34 + Debagarh + 0336 + Taluka_Name 2 + 223 + HealthBlock_Name 2 + 114 + PHC_Name 2 + 115 + SubCentre_Name 2 + 2866 + Village_Name 2 + 2015 + GP_Village 2 +
Address 2
+ 210666601066600666 + Name 2 + Husband_Name 2 + Other + 09111181333 + 01-01-1987 + Yes + Others + SubCentre_Name1 2 + ANM_Name 2 + 9411118233 + ASHA_Name 2 + 8111118373 + PHC + Facility_Name 2 + 18-06-2015 + 16-10-2015 + + + + + + 16-10-2015 + + Normal + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 28 + 26-10-2015 + + + 76333 + 421 + 333 + 444 + 23 + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 3 +
Address 3
+ 211114601111511102 + Name 3 + Husband_Name 3 + Other + 01113328443 + 01-01-1994 + Yes + ST + SubCentre_Name1 3 + ANM_Name 3 + 9123123161 + ASHA_Name 3 + 1110123133 + PHC + Facility_Name 3 + 23-07-2015 + 21-10-2015 + + + + 21-10-2015 + + + + Normal + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 22 + 26-11-2015 + + + 71234 + 321 + 123 + 123 + 12 + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 1 +
Address 1
+ 210111552211544144 + Name 1 + Husband_Name + Other + 19431111223 + 01-01-1994 + Yes + ST + SubCentre_Name1 1 + ANM_Name 1 + 4439992222 + ASHA_Name 1 + 1122211175 + PHC + Facility_Name 1 + 23-06-2015 + 19-10-2015 + + + + 21-10-2015 + + + + Moderate<11 + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 23 + 26-10-2015 + + + 71116 + 318 + 316 + 323 + 39 + + 1 +
+
+
+
+
+
+
diff --git a/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml b/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml index e69de29bb..68cf0621f 100644 --- a/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml +++ b/testing/src/test/resources/mcts/mcts-mothers-data-one-update-date.xml @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 1 +
Address 1
+ 210111552211544144 + Name x + Husband_Name + Other + 19431111223 + 01-01-1994 + Yes + ST + SubCentre_Name1 1 + ANM_Name 1 + 4439992222 + ASHA_Name 1 + 1122211175 + PHC + Facility_Name 1 + 23-06-2015 + 19-10-2015 + + + + 21-10-2015 + + + + Moderate<11 + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 23 + 26-10-2015 + 28-10-2015 + + 71116 + 318 + 316 + 323 + 39 + + 1 +
+ + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 1 +
Address 1
+ 210111552211544144 + Name 1 + Husband_Name + Other + 19431111223 + 01-01-1994 + Yes + ST + SubCentre_Name1 1 + ANM_Name 1 + 4439992222 + ASHA_Name 1 + 1122211175 + PHC + Facility_Name 1 + 23-06-2015 + 19-10-2015 + + + + 21-10-2015 + + + + Moderate<11 + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 23 + 26-10-2015 + + + 71116 + 318 + 316 + 323 + 39 + + 1 +
+
+
+
+
+
+
diff --git a/testing/src/test/resources/mcts/mcts-mothers-data.xml b/testing/src/test/resources/mcts/mcts-mothers-data.xml index c74804caa..896abb64b 100644 --- a/testing/src/test/resources/mcts/mcts-mothers-data.xml +++ b/testing/src/test/resources/mcts/mcts-mothers-data.xml @@ -125,7 +125,7 @@ GP_Village 1
Address 1
210111552211544144 - Name 1 + Name x Husband_Name Other 19431111223 @@ -178,7 +178,7 @@ 23 26-10-2015 - + 28-10-2015 71116 318 @@ -259,7 +259,7 @@ 28 26-10-2015 - + 26-10-2015 76333 421 @@ -340,7 +340,7 @@ 22 26-11-2015 - + 26-10-2015 71234 321 @@ -350,6 +350,87 @@ 1 + + 21 + 4 + District_Name 4 + 0046 + Taluka_Name 1 + 113 + HealthBlock_Name 1 + 111 + PHC_Name 3 + 333 + SubCentre_Name 1 + 28331 + Village_Name 1 + 2015 + GP_Village 1 +
Address 1
+ 210111552211544144 + Name 1 + Husband_Name + Other + 19431111223 + 01-01-1994 + Yes + ST + SubCentre_Name1 1 + ANM_Name 1 + 4439992222 + ASHA_Name 1 + 1122211175 + PHC + Facility_Name 1 + 23-06-2015 + 19-10-2015 + + + + 21-10-2015 + + + + Moderate<11 + None + No + + + + + + + + + + + + + + + + + + + + + + + + + + 23 + 26-10-2015 + 26-10-2015 + + 71116 + 318 + 316 + 323 + 39 + + 1 +
From 3a552817ce3f42dbefdea1e367376fafc6fc24d6 Mon Sep 17 00:00:00 2001 From: Sri Pooja Date: Mon, 1 Aug 2016 14:05:50 +0530 Subject: [PATCH 6/9] Blocked Mcts Csv import --- .../nms/api/web/OpsController.java | 6 ++++++ .../web/FrontLineWorkerImportController.java | 18 ++++++++++++++++++ .../web/MctsBeneficiaryImportController.java | 15 +++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/api/src/main/java/org/motechproject/nms/api/web/OpsController.java b/api/src/main/java/org/motechproject/nms/api/web/OpsController.java index f4af8d892..33cccbe1b 100644 --- a/api/src/main/java/org/motechproject/nms/api/web/OpsController.java +++ b/api/src/main/java/org/motechproject/nms/api/web/OpsController.java @@ -116,6 +116,12 @@ public void startUpkeep() { @ResponseStatus(HttpStatus.OK) @Transactional public void createUpdateFlw(@RequestBody AddFlwRequest addFlwRequest) { + // TODO: add a field updatedDateNic for Add Flw Request. + // Will Fix this after success of this PR. + if(true) { + throw new UnsupportedOperationException("Temporarily blocked craeteFlwUpdate."); + } + log("REQUEST: /ops/createUpdateFlw", String.format( "callingNumber=%s, mctsId=%s, name=%s, state=%d, district=%d", LogHelper.obscure(addFlwRequest.getContactNumber()), diff --git a/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java b/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java index 2c560d463..9c76a655f 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java +++ b/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java @@ -44,6 +44,12 @@ public String handleException(CsvImportDataException e) { @RequestMapping(value = "/update/language", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void updateFrontLineWorkersLanguage(@RequestParam MultipartFile csvFile) { + + // Update FrontLineWorkers Language from csv import is not supported + if(true) { + throw new UnsupportedOperationException("MCTS FLW Language csv import is not supported."); + } + try { try (InputStream in = csvFile.getInputStream()) { flwUpdateImportService.importLanguageData(new InputStreamReader(in)); @@ -63,6 +69,12 @@ public void updateFrontLineWorkersLanguage(@RequestParam MultipartFile csvFile) @RequestMapping(value = "/update/msisdn", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void updateFrontLineWorkersMSISDN(@RequestParam MultipartFile csvFile) { + + // Update FrontLineWorkers by Msisdn import from csv is not supported + if(true) { + throw new UnsupportedOperationException("MCTS FLW csv import is not supported."); + } + try { try (InputStream in = csvFile.getInputStream()) { flwUpdateImportService.importMSISDNData(new InputStreamReader(in)); @@ -82,6 +94,12 @@ public void updateFrontLineWorkersMSISDN(@RequestParam MultipartFile csvFile) { @RequestMapping(value = "/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importFrontLineWorkers(@RequestParam MultipartFile csvFile) { + + // Import FrontLineWorkers from csv is not supported + if(true) { + throw new UnsupportedOperationException("MCTS FLW csv import is not supported."); + } + try { try (InputStream in = csvFile.getInputStream()) { frontLineWorkerImportService.importData(new InputStreamReader(in)); diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/web/MctsBeneficiaryImportController.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/web/MctsBeneficiaryImportController.java index 070976c17..146be5835 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/web/MctsBeneficiaryImportController.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/web/MctsBeneficiaryImportController.java @@ -63,6 +63,11 @@ public void setCsvAuditService(CsvAuditService csvAuditService) { @ResponseStatus(HttpStatus.OK) public void importMotherData(@RequestParam MultipartFile csvFile) { + // Mcts mother import from csv is not supported + if(true) { + throw new UnsupportedOperationException("MCTS MOTHER csv import is not supported."); + } + LOGGER.debug("importMotherData() BEGIN"); Timer timer = new Timer("mom", "moms"); int count = 0; @@ -86,6 +91,11 @@ public void importMotherData(@RequestParam MultipartFile csvFile) { @ResponseStatus(HttpStatus.OK) public void importChildData(@RequestParam MultipartFile csvFile) { + // Mcts child import from csv is not supported + if(true) { + throw new UnsupportedOperationException("MCTS CHILD csv import is not supported."); + } + LOGGER.debug("importChildData() BEGIN"); Timer timer = new Timer("kid", "kids"); int count = 0; @@ -108,6 +118,11 @@ public void importChildData(@RequestParam MultipartFile csvFile) { @ResponseStatus(HttpStatus.OK) public void updateBeneficiaryData(@RequestParam MultipartFile csvFile) { + // Update Beneficiary data from csv is not supported + if(true) { + throw new UnsupportedOperationException("Update Beneficiary csv import is not supported."); + } + LOGGER.debug("updateBeneficiaryData() BEGIN"); try { try (InputStream in = csvFile.getInputStream()) { From 32c19f87aee322bf1e6bb5ab2922e6ce2a2b64a2 Mon Sep 17 00:00:00 2001 From: Sri Pooja Date: Mon, 1 Aug 2016 14:46:10 +0530 Subject: [PATCH 7/9] changed version from 1.0.18 to 1.0.19 --- api/pom.xml | 4 ++-- .../java/org/motechproject/nms/api/web/OpsController.java | 6 +----- csv/pom.xml | 4 ++-- flw/pom.xml | 4 ++-- imi/pom.xml | 4 ++-- kilkari/pom.xml | 4 ++-- mcts/pom.xml | 4 ++-- mobile-academy/pom.xml | 4 ++-- pom.xml | 2 +- props/pom.xml | 4 ++-- region/pom.xml | 4 ++-- testing/pom.xml | 4 ++-- tracking/pom.xml | 4 ++-- 13 files changed, 24 insertions(+), 28 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index a6f37662f..a8f324f9c 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ api - 1.0.18 + 1.0.19 bundle API module diff --git a/api/src/main/java/org/motechproject/nms/api/web/OpsController.java b/api/src/main/java/org/motechproject/nms/api/web/OpsController.java index 33cccbe1b..0ca78600c 100644 --- a/api/src/main/java/org/motechproject/nms/api/web/OpsController.java +++ b/api/src/main/java/org/motechproject/nms/api/web/OpsController.java @@ -117,11 +117,7 @@ public void startUpkeep() { @Transactional public void createUpdateFlw(@RequestBody AddFlwRequest addFlwRequest) { // TODO: add a field updatedDateNic for Add Flw Request. - // Will Fix this after success of this PR. - if(true) { - throw new UnsupportedOperationException("Temporarily blocked craeteFlwUpdate."); - } - + // Will Fix this with NMS-349 log("REQUEST: /ops/createUpdateFlw", String.format( "callingNumber=%s, mctsId=%s, name=%s, state=%d, district=%d", LogHelper.obscure(addFlwRequest.getContactNumber()), diff --git a/csv/pom.xml b/csv/pom.xml index efc65a91b..3b9df22c8 100644 --- a/csv/pom.xml +++ b/csv/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ csv - 1.0.18 + 1.0.19 bundle CSV Module diff --git a/flw/pom.xml b/flw/pom.xml index d402c8eb9..4957afbfc 100644 --- a/flw/pom.xml +++ b/flw/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ flw - 1.0.18 + 1.0.19 bundle FLW module diff --git a/imi/pom.xml b/imi/pom.xml index 6bd4c4511..54a99108d 100644 --- a/imi/pom.xml +++ b/imi/pom.xml @@ -7,12 +7,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ imi - 1.0.18 + 1.0.19 bundle IMI module diff --git a/kilkari/pom.xml b/kilkari/pom.xml index 3202fcffd..105f39416 100644 --- a/kilkari/pom.xml +++ b/kilkari/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ kilkari - 1.0.18 + 1.0.19 bundle Kilkari module diff --git a/mcts/pom.xml b/mcts/pom.xml index e1cdabc4f..df98e940b 100644 --- a/mcts/pom.xml +++ b/mcts/pom.xml @@ -6,12 +6,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ mcts - 1.0.18 + 1.0.19 bundle Mother Children Tracking Service diff --git a/mobile-academy/pom.xml b/mobile-academy/pom.xml index 0b34263af..64dca5483 100644 --- a/mobile-academy/pom.xml +++ b/mobile-academy/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ mobile-academy - 1.0.18 + 1.0.19 bundle Mobile Academy module diff --git a/pom.xml b/pom.xml index 7006d2479..fea3b4869 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 pom National Motech System diff --git a/props/pom.xml b/props/pom.xml index 25bd821b1..2a87da475 100644 --- a/props/pom.xml +++ b/props/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ props - 1.0.18 + 1.0.19 bundle Properties module diff --git a/region/pom.xml b/region/pom.xml index ed54bf419..807f3bf14 100644 --- a/region/pom.xml +++ b/region/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ region - 1.0.18 + 1.0.19 bundle Region Module diff --git a/testing/pom.xml b/testing/pom.xml index d43f07c50..bd236997f 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -7,12 +7,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ testing - 1.0.18 + 1.0.19 bundle Testing module diff --git a/tracking/pom.xml b/tracking/pom.xml index b1082ce66..889146575 100644 --- a/tracking/pom.xml +++ b/tracking/pom.xml @@ -5,12 +5,12 @@ nms org.motechproject.nms - 1.0.18 + 1.0.19 ../ tracking - 1.0.18 + 1.0.19 bundle Tracking Module From d9560572dce181085c22a9e7e336a038f4f0fde0 Mon Sep 17 00:00:00 2001 From: motech Date: Mon, 1 Aug 2016 16:42:35 +0530 Subject: [PATCH 8/9] Comments in the test cases and ignoring the test cases for csv imports --- .../flw/web/FrontLineWorkerImportController.java | 5 ----- .../testing/service/impl/TestingServiceImpl.java | 2 ++ .../FrontLineWorkerImportServiceBundleIT.java | 16 ++++++++++++++++ ...ontLineWorkerUpdateImportServiceBundleIT.java | 11 +++++++++++ .../testing/it/imi/CdrFileServiceBundleIT.java | 2 +- .../nms/testing/it/mcts/MctsImportBundleIT.java | 16 ++++++++++++---- .../testing/it/mcts/util/MockWsHttpServlet.java | 3 +++ .../it/mcts/util/MockWsHttpServletForFail.java | 6 +++--- .../util/MockWsHttpServletForNoUpdateDate.java | 4 +++- .../util/MockWsHttpServletForOneUpdateDate.java | 6 +++--- .../util/MockWsHttpServletRemoteException.java | 3 +++ 11 files changed, 57 insertions(+), 17 deletions(-) diff --git a/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java b/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java index 9c76a655f..057a6a83b 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java +++ b/flw/src/main/java/org/motechproject/nms/flw/web/FrontLineWorkerImportController.java @@ -45,11 +45,6 @@ public String handleException(CsvImportDataException e) { @ResponseStatus(HttpStatus.OK) public void updateFrontLineWorkersLanguage(@RequestParam MultipartFile csvFile) { - // Update FrontLineWorkers Language from csv import is not supported - if(true) { - throw new UnsupportedOperationException("MCTS FLW Language csv import is not supported."); - } - try { try (InputStream in = csvFile.getInputStream()) { flwUpdateImportService.importLanguageData(new InputStreamReader(in)); diff --git a/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java b/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java index ed1a7ebb7..59422035d 100644 --- a/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java +++ b/testing/src/main/java/org/motechproject/nms/testing/service/impl/TestingServiceImpl.java @@ -111,6 +111,8 @@ public class TestingServiceImpl implements TestingService { "nms_ma_completion_records__TRASH", "nms_ma_course", "nms_ma_course__TRASH", + "nms_mcts_audit", + "nms_mcts_audit__TRASH", "nms_mcts_beneficiaries__TRASH", "nms_mcts_children", "nms_mcts_children__TRASH", diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerImportServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerImportServiceBundleIT.java index c118ece34..32a44320d 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerImportServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerImportServiceBundleIT.java @@ -6,6 +6,7 @@ import org.apache.http.entity.mime.content.FileBody; import org.joda.time.DateTime; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.motechproject.nms.csv.domain.CsvAuditRecord; @@ -216,7 +217,9 @@ public void setUp() { // This test should load the FLW with MCTS id '#1' and attempt to update their MSISDN to a number already // in use. This should result in a unique constraint exception + // This test has been ignored because we are not using csv import at the moment @Test(expected = CsvImportDataException.class) + @Ignore public void testImportMSISDNConflict() throws Exception { TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); State state = stateDataService.findByName("State 1"); @@ -284,7 +287,10 @@ public void testImportWhenDistrictNotPresent() throws Exception { frontLineWorkerImportService.importData(reader); } + + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void testImportFromSampleDataFile() throws Exception { frontLineWorkerImportService.importData(read("csv/anm-asha.txt")); @@ -313,7 +319,9 @@ public void testImportFromSampleDataFile() throws Exception { /** * To verify FLW record is uploaded successfully when all mandatory parameters are present. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT535() throws Exception { importCsvFileForFLW("flw.txt"); FrontLineWorker flw1 = frontLineWorkerDataService.findByContactNumber(1234567899L); @@ -331,7 +339,9 @@ public void verifyFT535() throws Exception { /** * To verify FLW status must be updated successfully from Anonymous to Active. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT536() throws Exception { FrontLineWorker flw = new FrontLineWorker("Frank Lloyd Wright", 1234567890L); flw.setMctsFlwId("#0"); @@ -365,7 +375,9 @@ public void verifyFT540() throws Exception { /** * To verify FLW upload is rejected when mandatory parameter name is missing. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT542() throws Exception { importCsvFileForFLW("flw_name_missing.txt"); // Assert audit trail log @@ -481,7 +493,9 @@ private void importCsvFileForFLW(String fileName) throws InterruptedException, I * To verify location is updated successfully when MSISDN is provided. */ // TODO JIRA issue: https://applab.atlassian.net/browse/NMS-253 + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT559() throws InterruptedException, IOException { State state = stateDataService.findByName("State 1"); District district1 = districtService.findByStateAndName(state, "District 11"); @@ -518,7 +532,9 @@ public void verifyFT559() throws InterruptedException, IOException { /** * Verify that an FLWs state can be updated */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyNIP166() throws InterruptedException, IOException { State state = stateDataService.findByName("State 1"); District district1 = districtService.findByStateAndName(state, "District 11"); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerUpdateImportServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerUpdateImportServiceBundleIT.java index a9608d488..cba7a2231 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerUpdateImportServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/flw/FrontLineWorkerUpdateImportServiceBundleIT.java @@ -8,6 +8,7 @@ import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.FileBody; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.motechproject.nms.csv.domain.CsvAuditRecord; @@ -519,7 +520,9 @@ private HttpResponse importCsvFileForFLWUpdate(String option, /** * To verify language is updated successfully when MCTS FLW ID is provided. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT550() throws InterruptedException, IOException { FrontLineWorker flw = new FrontLineWorker(1000000000L); flw.setFlwId("72185"); @@ -602,7 +605,9 @@ public void verifyFT552() throws InterruptedException, IOException { /** * To verify MSISDN is updated successfully when MCTS FLW ID is provided. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT555() throws InterruptedException, IOException { FrontLineWorker flw = new FrontLineWorker(1000000000L); flw.setFlwId("72185"); @@ -633,7 +638,9 @@ public void verifyFT555() throws InterruptedException, IOException { * To verify location is updated successfully when MCTS FLW ID is provided. */ // TODO https://applab.atlassian.net/browse/NMS-255 + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT558() throws InterruptedException, IOException { // create FLW record having state as "Delhi" and district as "new delhi district" FrontLineWorker flw = new FrontLineWorker("Aisha Bibi", 1234567899L); @@ -671,7 +678,9 @@ public void verifyFT558() throws InterruptedException, IOException { * To verify location update is rejected when state provided is having * invalid value. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT560() throws InterruptedException, IOException { // create FLW record FrontLineWorker flw = new FrontLineWorker("Aisha Bibi", 1234567899L); @@ -699,7 +708,9 @@ public void verifyFT560() throws InterruptedException, IOException { * To verify location update is rejected when District provided is having * invalid value. */ + // This test has been ignored because we are not using csv import at the moment @Test + @Ignore public void verifyFT561() throws InterruptedException, IOException { // create FLW record FrontLineWorker flw = new FrontLineWorker("Aisha Bibi", 1234567899L); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java index b623a6c31..7d88e9e3f 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java @@ -56,7 +56,7 @@ public class CdrFileServiceBundleIT extends BasePaxIT { private static final String PROCESS_FILES_SUBJECT = "nms.imi.kk.process_files"; - private static final long MAX_MILLISECOND_WAIT = 2000L; + private static final long MAX_MILLISECOND_WAIT = 10000L; private static final String INITIAL_RETRY_DELAY = "imi.initial_retry_delay"; private static final String MAX_CDR_ERROR_COUNT = "imi.max_cdr_error_count"; diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java index ac270ae28..59827ea56 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java @@ -35,7 +35,11 @@ import org.motechproject.nms.region.domain.Taluka; import org.motechproject.nms.region.repository.DistrictDataService; import org.motechproject.nms.region.repository.StateDataService; -import org.motechproject.nms.testing.it.mcts.util.*; +import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServlet; +import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServletForFail; +import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServletForNoUpdateDate; +import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServletForOneUpdateDate; +import org.motechproject.nms.testing.it.mcts.util.MockWsHttpServletRemoteException; import org.motechproject.nms.testing.service.TestingService; import org.motechproject.testing.osgi.BasePaxIT; import org.motechproject.testing.osgi.container.MotechNativeTestContainerFactory; @@ -207,6 +211,8 @@ public void shouldUpdateFailedTableWhenImportFailsDueToFailedStructure() throws mctsWsImportService.importAnmAshaData(event); Thread.currentThread().setContextClassLoader(cl); +// Since the structure is wrong in the xmls, the import should not take place and the data should be updated in nms_mcts_failure table + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); assertEquals(3,mctsImportFailRecords.size()); @@ -239,6 +245,8 @@ public void shouldUpdateFailedTableWhenImportFailsDueRemoteException() throws Ma mctsWsImportService.importAnmAshaData(event); Thread.currentThread().setContextClassLoader(cl); +// Since the response while reading the xmls is a Remote server exception, the import should not take place and the data should be updated in nms_mcts_failure table + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); assertEquals(3,mctsImportFailRecords.size()); @@ -288,7 +296,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor Thread.currentThread().setContextClassLoader(cl); - // we expect two of each - the second entry in each ds (3 total) has wrong location data + // we expect two of each - the second entry in each ds (4 total) has wrong location data and the first one is a duplicate of the fourth record with updated date. So the updated record should stay. The audit table should update with three errors created manually above. And after the import the three errors should clear from failure table. List mctsImportAudits= mctsImportAuditDataService.retrieveAll(); assertEquals(3,mctsImportAudits.size()); @@ -353,7 +361,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() t Thread.currentThread().setContextClassLoader(cl); - // we expect two of each - the second entry in each ds (3 total) has wrong location data + // we expect two of each - the second entry in each ds (4 total) has wrong location data and the first one is a duplicate of the fourth record with no updated dates on any record. So only one of the duplicates should be in the database. And after the import the three errors should clear from failure table. List flws = flwDataService.retrieveAll(); @@ -417,7 +425,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() Thread.currentThread().setContextClassLoader(cl); - // we expect two of each - the second entry in each ds (3 total) has wrong location data + // we expect one of each - the first entry in each ds (2 total) has an updated dated unlike the previous data. So only the one with updated date should be in the database. And after the import the three errors should clear from failure table. List flws = flwDataService.retrieveAll(); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServlet.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServlet.java index 5ab372502..f09251ca2 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServlet.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServlet.java @@ -8,6 +8,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; +/* + test servlet for data with updated dates in all the 4 records in xml + */ public class MockWsHttpServlet extends HttpServlet { @Override diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java index 41a1b9aa7..6ee9d3b6e 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForFail.java @@ -8,9 +8,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; -/** - * Created by motech on 27/7/16. - */ +/* + test servlet for failing data with wrong structure + */ public class MockWsHttpServletForFail extends HttpServlet { @Override diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java index e12d6ae0f..ce8d2362f 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForNoUpdateDate.java @@ -8,7 +8,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; - +/* + test servlet for data with no updated dates in all the 4 records in xml + */ public class MockWsHttpServletForNoUpdateDate extends HttpServlet{ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java index 1c00e0ff8..c4a8c4f95 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletForOneUpdateDate.java @@ -8,9 +8,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; -/** - * Created by motech on 29/7/16. - */ +/* + test servlet for data with updated dates in one of the duplicate records + */ public class MockWsHttpServletForOneUpdateDate extends HttpServlet { @Override diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java index 5cc90652d..8b852483b 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/util/MockWsHttpServletRemoteException.java @@ -10,6 +10,9 @@ import java.io.IOException; import java.rmi.RemoteException; +/* + test servlet for remote server exception throw + */ public class MockWsHttpServletRemoteException extends HttpServlet { @Override From 417b011bcbf1dd10d3c1b6f6e18971909861a25b Mon Sep 17 00:00:00 2001 From: motech Date: Tue, 2 Aug 2016 15:53:38 +0530 Subject: [PATCH 9/9] Added short circuiting of update to rejection count in all Types --- .../exception/FlwExistingRecordException.java | 11 ++ .../service/FrontLineWorkerImportService.java | 3 +- .../FrontLineWorkerImportServiceImpl.java | 7 +- .../MctsBeneficiaryImportServiceImpl.java | 4 +- .../mcts/handler/MctsImportJobHandler.java | 1 + .../service/impl/MctsWsImportServiceImpl.java | 4 + .../main/resources/MctsAuditModification.sql | 1 - .../it/imi/CdrFileServiceBundleIT.java | 2 +- .../testing/it/mcts/MctsImportBundleIT.java | 140 +++++++++--------- 9 files changed, 92 insertions(+), 81 deletions(-) create mode 100644 flw/src/main/java/org/motechproject/nms/flw/exception/FlwExistingRecordException.java delete mode 100644 mcts/src/main/resources/MctsAuditModification.sql diff --git a/flw/src/main/java/org/motechproject/nms/flw/exception/FlwExistingRecordException.java b/flw/src/main/java/org/motechproject/nms/flw/exception/FlwExistingRecordException.java new file mode 100644 index 000000000..74c7a1e8e --- /dev/null +++ b/flw/src/main/java/org/motechproject/nms/flw/exception/FlwExistingRecordException.java @@ -0,0 +1,11 @@ +package org.motechproject.nms.flw.exception; + +/** + * Signals an issue with importing an FLW which already exits in database. + */ +public class FlwExistingRecordException extends Exception { + + public FlwExistingRecordException(String message) { + super(message); + } +} diff --git a/flw/src/main/java/org/motechproject/nms/flw/service/FrontLineWorkerImportService.java b/flw/src/main/java/org/motechproject/nms/flw/service/FrontLineWorkerImportService.java index c5918a61c..d69ba8868 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/service/FrontLineWorkerImportService.java +++ b/flw/src/main/java/org/motechproject/nms/flw/service/FrontLineWorkerImportService.java @@ -1,5 +1,6 @@ package org.motechproject.nms.flw.service; +import org.motechproject.nms.flw.exception.FlwExistingRecordException; import org.motechproject.nms.region.domain.State; import org.motechproject.nms.region.exception.InvalidLocationException; @@ -11,5 +12,5 @@ public interface FrontLineWorkerImportService { void importData(Reader reader) throws IOException; - void importFrontLineWorker(Map record, State state) throws InvalidLocationException; + void importFrontLineWorker(Map record, State state) throws InvalidLocationException, FlwExistingRecordException; } diff --git a/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java b/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java index 01fbbb77b..892f12591 100644 --- a/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java +++ b/flw/src/main/java/org/motechproject/nms/flw/service/impl/FrontLineWorkerImportServiceImpl.java @@ -10,6 +10,7 @@ import org.motechproject.nms.csv.utils.GetString; import org.motechproject.nms.flw.domain.FrontLineWorker; +import org.motechproject.nms.flw.exception.FlwExistingRecordException; import org.motechproject.nms.flw.exception.FlwImportException; import org.motechproject.nms.flw.service.FrontLineWorkerImportService; import org.motechproject.nms.flw.service.FrontLineWorkerService; @@ -72,14 +73,14 @@ public void importData(Reader reader) throws IOException { } } catch (ConstraintViolationException e) { throw new CsvImportDataException(createErrorMessage(e.getConstraintViolations(), csvImporter.getRowNumber()), e); - } catch (InvalidLocationException | FlwImportException | JDODataStoreException e) { + } catch (InvalidLocationException | FlwImportException | JDODataStoreException | FlwExistingRecordException e) { throw new CsvImportDataException(createErrorMessage(e.getMessage(), csvImporter.getRowNumber()), e); } } @Override @Transactional - public void importFrontLineWorker(Map record, State state) throws InvalidLocationException { + public void importFrontLineWorker(Map record, State state) throws InvalidLocationException, FlwExistingRecordException { FrontLineWorker flw = flwFromRecord(record, state); record.put(FlwConstants.STATE_ID, state.getCode()); @@ -92,6 +93,8 @@ public void importFrontLineWorker(Map record, State state) throw //It updated_date_nic from mcts is not null,then it's not a new record. Compare it with the record from database and update if (mctsUpdatedDateNic != null && (flw.getUpdatedDateNic() == null || mctsUpdatedDateNic.isAfter(flw.getUpdatedDateNic()) || mctsUpdatedDateNic.isEqual(flw.getUpdatedDateNic()))) { frontLineWorkerService.update(updateFlw(flw, record, location)); + } else { + throw new FlwExistingRecordException("Updated record exists in the database"); } } } diff --git a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java index 6a4c697d9..61626c4cb 100644 --- a/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java +++ b/kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java @@ -187,7 +187,7 @@ public boolean importMotherRecord(Map record) { //validate if it's an updated record compared to one from database if (mother.getUpdatedDateNic() != null && (mctsUpdatedDateNic == null || mother.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { - return true; + return false; } mother.setName(name); @@ -254,7 +254,7 @@ public boolean importChildRecord(Map record) { //validate if it's an updated record compared to one from database if (child.getUpdatedDateNic() != null && (mctsUpdatedDateNic == null || child.getUpdatedDateNic().isAfter(mctsUpdatedDateNic))) { - return true; + return false; } child.setName(name); diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/handler/MctsImportJobHandler.java b/mcts/src/main/java/org/motechproject/nms/mcts/handler/MctsImportJobHandler.java index e6b69b212..930ae68f4 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/handler/MctsImportJobHandler.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/handler/MctsImportJobHandler.java @@ -57,6 +57,7 @@ public void initImportJob() { throw new MctsImportConfigurationException("Cron expression from setting is invalid: " + cronExpression); } + LOGGER.info("Created MCTS Import Event"); CronSchedulableJob mctsImportJob = new CronSchedulableJob(new MotechEvent(Constants.MCTS_IMPORT_EVENT), cronExpression); motechSchedulerService.safeScheduleJob(mctsImportJob); } diff --git a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java index d9cc59e27..21d1fee04 100644 --- a/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java +++ b/mcts/src/main/java/org/motechproject/nms/mcts/service/impl/MctsWsImportServiceImpl.java @@ -12,6 +12,7 @@ import org.motechproject.event.listener.annotations.MotechListener; import org.motechproject.mds.query.QueryParams; import org.motechproject.mds.util.Order; +import org.motechproject.nms.flw.exception.FlwExistingRecordException; import org.motechproject.nms.flw.exception.FlwImportException; import org.motechproject.nms.flw.service.FrontLineWorkerImportService; import org.motechproject.nms.kilkari.service.MctsBeneficiaryImportService; @@ -402,6 +403,9 @@ private MctsImportAudit saveImportedAnmAshaData(AnmAshaDataSet anmAshaDataSet, S } catch (FlwImportException e) { LOGGER.error("Existing FLW with same MSISDN but different MCTS ID", e); rejected++; + } catch (FlwExistingRecordException e) { + LOGGER.error("Cannot import FLW with ID: {}, and MSISDN (Contact_No): {}", record.getId(), record.getContactNo(), e); + rejected++; } catch (Exception e) { LOGGER.error("Flw import Error. Cannot import FLW with ID: {}, and MSISDN (Contact_No): {}", record.getId(), record.getContactNo(), e); diff --git a/mcts/src/main/resources/MctsAuditModification.sql b/mcts/src/main/resources/MctsAuditModification.sql deleted file mode 100644 index f004c658c..000000000 --- a/mcts/src/main/resources/MctsAuditModification.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE motech_data_services.nms_mcts_audit CHANGE importDate endImportDate DATE NULL; \ No newline at end of file diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java index 7d88e9e3f..b623a6c31 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/imi/CdrFileServiceBundleIT.java @@ -56,7 +56,7 @@ public class CdrFileServiceBundleIT extends BasePaxIT { private static final String PROCESS_FILES_SUBJECT = "nms.imi.kk.process_files"; - private static final long MAX_MILLISECOND_WAIT = 10000L; + private static final long MAX_MILLISECOND_WAIT = 2000L; private static final String INITIAL_RETRY_DELAY = "imi.initial_retry_delay"; private static final String MAX_CDR_ERROR_COUNT = "imi.max_cdr_error_count"; diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java index 59827ea56..eb6924505 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java @@ -9,6 +9,7 @@ import org.motechproject.commons.date.util.DateUtil; import org.motechproject.event.MotechEvent; import org.motechproject.nms.flw.domain.FrontLineWorker; +import org.motechproject.nms.flw.exception.FlwExistingRecordException; import org.motechproject.nms.flw.repository.FrontLineWorkerDataService; import org.motechproject.nms.imi.service.SettingsService; import org.motechproject.nms.kilkari.domain.MctsChild; @@ -158,18 +159,16 @@ public void setUp() throws ServletException, NamespaceException { districtDataService.create(district); - SubscriptionPack pregnancyPack = new SubscriptionPack("prg", SubscriptionPackType.PREGNANCY, 10, 10, + SubscriptionPack pregnancyPack = new SubscriptionPack("prg", SubscriptionPackType.PREGNANCY, 70, 10, Collections.emptyList()); - SubscriptionPack childPack = new SubscriptionPack("child", SubscriptionPackType.CHILD, 5000, 6, + SubscriptionPack childPack = new SubscriptionPack("child", SubscriptionPackType.CHILD, 5000, 6, Collections.emptyList()); - subscriptionPackDataService.create(pregnancyPack); subscriptionPackDataService.create(childPack); - httpService.registerServlet("/mctsWs", new MockWsHttpServlet(), null, null); httpService.registerServlet("/mctsWsFailedStructure", new MockWsHttpServletForFail(), null, null); httpService.registerServlet("/mctsWsRemoteException", new MockWsHttpServletRemoteException(), null, null); @@ -195,14 +194,15 @@ public void shouldUpdateFailedTableWhenImportFailsDueToFailedStructure() throws LocalDate yesterday = DateUtil.today().minusDays(1); List stateIds = singletonList(21L); - + // this CL workaround is for an issue with PAX IT logging messing things up + // shouldn't affect production ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); // setup motech event Map params = new HashMap<>(); params.put(Constants.START_DATE_PARAM, lastDateToCheck); - params.put(Constants.END_DATE_PARAM,yesterday); + params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); @@ -212,13 +212,8 @@ public void shouldUpdateFailedTableWhenImportFailsDueToFailedStructure() throws Thread.currentThread().setContextClassLoader(cl); // Since the structure is wrong in the xmls, the import should not take place and the data should be updated in nms_mcts_failure table - List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); - assertEquals(3,mctsImportFailRecords.size()); - - - - + assertEquals(3, mctsImportFailRecords.size()); } @@ -229,14 +224,15 @@ public void shouldUpdateFailedTableWhenImportFailsDueRemoteException() throws Ma LocalDate yesterday = DateUtil.today().minusDays(1); List stateIds = singletonList(21L); - + // this CL workaround is for an issue with PAX IT logging messing things up + // shouldn't affect production ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); // setup motech event Map params = new HashMap<>(); params.put(Constants.START_DATE_PARAM, lastDateToCheck); - params.put(Constants.END_DATE_PARAM,yesterday); + params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); @@ -246,16 +242,13 @@ public void shouldUpdateFailedTableWhenImportFailsDueRemoteException() throws Ma Thread.currentThread().setContextClassLoader(cl); // Since the response while reading the xmls is a Remote server exception, the import should not take place and the data should be updated in nms_mcts_failure table - List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); - assertEquals(3,mctsImportFailRecords.size()); - - - + assertEquals(3, mctsImportFailRecords.size()); } + @Test public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws MalformedURLException { URL endpoint = new URL(String.format("http://localhost:%d/mctsWs", TestContext.getJettyPort())); @@ -263,11 +256,11 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor LocalDate lastDateToCheck = DateUtil.today().minusDays(7); LocalDate failDate = DateUtil.today().minusDays(2); LocalDate yesterday = DateUtil.today().minusDays(1); - MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate, MctsUserType.ASHA, 21L); - MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate, MctsUserType.MOTHER, 21L); - MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate, MctsUserType.CHILD, 21L); mctsImportFailRecordDataService.create(mctsImportFailRecord1); mctsImportFailRecordDataService.create(mctsImportFailRecord2); @@ -275,7 +268,8 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor try { TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); - + // this CL workaround is for an issue with PAX IT logging messing things up + // shouldn't affect production ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); @@ -287,18 +281,23 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); - - - /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ mctsWsImportService.importMothersData(event); mctsWsImportService.importChildrenData(event); mctsWsImportService.importAnmAshaData(event); Thread.currentThread().setContextClassLoader(cl); - // we expect two of each - the second entry in each ds (4 total) has wrong location data and the first one is a duplicate of the fourth record with updated date. So the updated record should stay. The audit table should update with three errors created manually above. And after the import the three errors should clear from failure table. - List mctsImportAudits= mctsImportAuditDataService.retrieveAll(); - assertEquals(3,mctsImportAudits.size()); + List mctsImportAudits = mctsImportAuditDataService.retrieveAll(); + assertEquals(3, mctsImportAudits.size()); + assertEquals(2, mctsImportAudits.get(0).getAccepted()); + assertEquals(2, mctsImportAudits.get(0).getRejected()); + assertEquals(2, mctsImportAudits.get(1).getAccepted()); + assertEquals(2, mctsImportAudits.get(1).getRejected()); + assertEquals(2, mctsImportAudits.get(2).getAccepted()); + assertEquals(2, mctsImportAudits.get(2).getRejected()); + assertEquals(lastDateToCheck, mctsImportAudits.get(0).getStartImportDate()); + assertEquals(yesterday, mctsImportAudits.get(0).getEndImportDate()); List flws = flwDataService.retrieveAll(); assertEquals(2, flws.size()); @@ -314,7 +313,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor List mothers = mctsMotherDataService.retrieveAll(); assertEquals(2, mothers.size()); assertEquals("Name x", mothers.get(0).getName()); - }finally { + } finally { TimeFaker.stopFakingTime(); } @@ -328,11 +327,11 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() t LocalDate lastDateToCheck = DateUtil.today().minusDays(7); LocalDate failDate = DateUtil.today().minusDays(2); LocalDate yesterday = DateUtil.today().minusDays(1); - MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate, MctsUserType.ASHA, 21L); - MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate, MctsUserType.MOTHER, 21L); - MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate, MctsUserType.CHILD, 21L); mctsImportFailRecordDataService.create(mctsImportFailRecord1); mctsImportFailRecordDataService.create(mctsImportFailRecord2); @@ -340,7 +339,8 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() t try { TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); - + // this CL workaround is for an issue with PAX IT logging messing things up + // shouldn't affect production ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); @@ -352,9 +352,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() t params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); - - - /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ mctsWsImportService.importMothersData(event); mctsWsImportService.importChildrenData(event); mctsWsImportService.importAnmAshaData(event); @@ -362,27 +360,24 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableNoUpdateDate() t // we expect two of each - the second entry in each ds (4 total) has wrong location data and the first one is a duplicate of the fourth record with no updated dates on any record. So only one of the duplicates should be in the database. And after the import the three errors should clear from failure table. + List flws = flwDataService.retrieveAll(); + assertEquals(2, flws.size()); + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(0, mctsImportFailRecords.size()); + assertEquals("Sample Name 1", flws.get(0).getName()); - List flws = flwDataService.retrieveAll(); - assertEquals(2, flws.size()); - - List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); - assertEquals(0,mctsImportFailRecords.size()); - assertEquals("Sample Name 1",flws.get(0).getName()); - - List children = mctsChildDataService.retrieveAll(); - assertEquals(2, children.size()); - assertEquals("Name 1",children.get(0).getName()); + List children = mctsChildDataService.retrieveAll(); + assertEquals(2, children.size()); + assertEquals("Name 1", children.get(0).getName()); - List mothers = mctsMotherDataService.retrieveAll(); - assertEquals(2, mothers.size()); - assertEquals("Name 1",mothers.get(0).getName()); + List mothers = mctsMotherDataService.retrieveAll(); + assertEquals(2, mothers.size()); + assertEquals("Name 1", mothers.get(0).getName()); - }finally { + } finally { TimeFaker.stopFakingTime(); } - } @Test @@ -392,11 +387,11 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() LocalDate lastDateToCheck = DateUtil.today().minusDays(7); LocalDate failDate = DateUtil.today().minusDays(2); LocalDate yesterday = DateUtil.today().minusDays(1); - MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate,MctsUserType.ASHA,21L); + MctsImportFailRecord mctsImportFailRecord1 = new MctsImportFailRecord(failDate, MctsUserType.ASHA, 21L); - MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate,MctsUserType.MOTHER,21L); + MctsImportFailRecord mctsImportFailRecord2 = new MctsImportFailRecord(failDate, MctsUserType.MOTHER, 21L); - MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate,MctsUserType.CHILD,21L); + MctsImportFailRecord mctsImportFailRecord3 = new MctsImportFailRecord(failDate, MctsUserType.CHILD, 21L); mctsImportFailRecordDataService.create(mctsImportFailRecord1); mctsImportFailRecordDataService.create(mctsImportFailRecord2); @@ -405,6 +400,8 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() try { TimeFaker.fakeToday(DateUtil.newDate(2015, 7, 24)); + // this CL workaround is for an issue with PAX IT logging messing things up + // shouldn't affect production ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mctsWsImportService.getClass().getClassLoader()); @@ -416,34 +413,29 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params); - - - /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ + /* Hard to test this since we do async loading now, using test hook. UT already tests message distribution */ mctsWsImportService.importMothersData(event); mctsWsImportService.importChildrenData(event); mctsWsImportService.importAnmAshaData(event); Thread.currentThread().setContextClassLoader(cl); - // we expect one of each - the first entry in each ds (2 total) has an updated dated unlike the previous data. So only the one with updated date should be in the database. And after the import the three errors should clear from failure table. + List flws = flwDataService.retrieveAll(); + assertEquals(1, flws.size()); + List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); + assertEquals(0, mctsImportFailRecords.size()); + assertEquals("Name a", flws.get(0).getName()); - List flws = flwDataService.retrieveAll(); - assertEquals(1, flws.size()); - - List mctsImportFailRecords = mctsImportFailRecordDataService.retrieveAll(); - assertEquals(0,mctsImportFailRecords.size()); - assertEquals("Name a",flws.get(0).getName()); - - List children = mctsChildDataService.retrieveAll(); - assertEquals(1, children.size()); - assertEquals("Name y",children.get(0).getName()); + List children = mctsChildDataService.retrieveAll(); + assertEquals(1, children.size()); + assertEquals("Name y", children.get(0).getName()); - List mothers = mctsMotherDataService.retrieveAll(); - assertEquals(1, mothers.size()); - assertEquals("Name x",mothers.get(0).getName()); + List mothers = mctsMotherDataService.retrieveAll(); + assertEquals(1, mothers.size()); + assertEquals("Name x", mothers.get(0).getName()); - }finally { + } finally { TimeFaker.stopFakingTime(); } @@ -472,7 +464,7 @@ public void shouldFilterHpdImport() throws MalformedURLException { // setup motech event Map params = new HashMap<>(); params.put(Constants.START_DATE_PARAM, lastDayToCheck); - params.put(Constants.END_DATE_PARAM,yesterday); + params.put(Constants.END_DATE_PARAM, yesterday); params.put(Constants.STATE_ID_PARAM, 21L); params.put(Constants.ENDPOINT_PARAM, endpoint); MotechEvent event = new MotechEvent("foobar", params);