Skip to content

Commit bc46e19

Browse files
Merge pull request #765 from motech-implementations/Rch_fix_for_test
Rch fix for test
2 parents ca0ec47 + 55e73d4 commit bc46e19

File tree

20 files changed

+1289
-884
lines changed

20 files changed

+1289
-884
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.motechproject.nms.flw.exception;
2+
3+
/**
4+
* Signals an issue with importing an FLW which already exits in database.
5+
*/
6+
public class GfStatusInactiveException extends Exception {
7+
8+
public GfStatusInactiveException(String message) {
9+
super(message);
10+
}
11+
}

flw/src/main/java/org/motechproject/nms/flw/utils/FlwMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public static FrontLineWorker updateFlw(FrontLineWorker flw, Map<String, Object>
9696
flw.setJobStatus(jobStatus);
9797
}
9898

99-
setFrontLineWorkerLocation(flw, location);
99+
if (FlwJobStatus.ACTIVE.toString().equalsIgnoreCase(gfStatus)) {
100+
setFrontLineWorkerLocation(flw, location);
101+
}
100102

101103
if (flw.getLanguage() == null) {
102104
flw.setLanguage(flw.getDistrict().getLanguage());

flwUpdate/src/main/java/org/motechproject/nms/flwUpdate/service/FrontLineWorkerImportService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.motechproject.nms.flwUpdate.service;
22

33
import org.motechproject.nms.flw.exception.FlwExistingRecordException;
4+
import org.motechproject.nms.flw.exception.GfStatusInactiveException;
45
import org.motechproject.nms.kilkari.contract.AnmAshaRecord;
56
import org.motechproject.nms.kilkari.contract.RchAnmAshaRecord;
67
import org.motechproject.nms.kilkari.domain.SubscriptionOrigin;
@@ -13,11 +14,11 @@
1314

1415
public interface FrontLineWorkerImportService {
1516

16-
void importData(Reader reader, SubscriptionOrigin importOrigin) throws IOException;
17+
void importData(Reader reader, SubscriptionOrigin importOrigin) throws IOException, GfStatusInactiveException;
1718

1819
void importMctsFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException;
1920

20-
void importRchFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException;
21+
void importRchFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException, GfStatusInactiveException;
2122
/**
2223
* Used to create or update an FLW from mcts or other sync services
2324
* @param flwRecord key-value pair of properties for flw

flwUpdate/src/main/java/org/motechproject/nms/flwUpdate/service/impl/FrontLineWorkerImportServiceImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.motechproject.nms.flw.domain.ContactNumberAudit;
2323
import org.motechproject.nms.flw.exception.FlwExistingRecordException;
2424
import org.motechproject.nms.flw.exception.FlwImportException;
25+
import org.motechproject.nms.flw.exception.GfStatusInactiveException;
2526
import org.motechproject.nms.flw.repository.ContactNumberAuditDataService;
2627
import org.motechproject.nms.flw.repository.FlwErrorDataService;
2728
import org.motechproject.nms.flw.service.FrontLineWorkerService;
@@ -94,7 +95,7 @@ public class FrontLineWorkerImportServiceImpl implements FrontLineWorkerImportSe
9495
// CHECKSTYLE:OFF
9596
@Override
9697
@Transactional
97-
public void importData(Reader reader, SubscriptionOrigin importOrigin) throws IOException {
98+
public void importData(Reader reader, SubscriptionOrigin importOrigin) throws IOException, GfStatusInactiveException {
9899
BufferedReader bufferedReader = new BufferedReader(reader);
99100

100101
State state = importHeader(bufferedReader);
@@ -186,7 +187,7 @@ public void importMctsFrontLineWorker(Map<String, Object> record, State state) t
186187

187188
@Override //NO CHECKSTYLE CyclomaticComplexity
188189
@Transactional
189-
public void importRchFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException {
190+
public void importRchFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException, GfStatusInactiveException {
190191
String flwId = (String) record.get(FlwConstants.GF_ID);
191192
Long msisdn = (Long) record.get(FlwConstants.MOBILE_NO);
192193

@@ -235,6 +236,9 @@ public void importRchFrontLineWorker(Map<String, Object> record, State state) th
235236
FrontLineWorker newFlw = createRchFlw(record, location);
236237
if (newFlw != null) {
237238
frontLineWorkerService.add(newFlw);
239+
} else {
240+
LOGGER.debug("The flw has already resigned.");
241+
throw new GfStatusInactiveException("The gf status is inactive.");
238242
}
239243
}
240244
}

kilkari/src/main/java/org/motechproject/nms/kilkari/contract/ChildRecord.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class ChildRecord {
8484
private String childEIDTime;
8585
private String fatherName;
8686
private String birthCertificateNumber;
87-
private Integer entryType;
87+
private String entryType;
8888

8989
public Long getStateID() {
9090
return stateID;
@@ -762,12 +762,12 @@ public void setBirthCertificateNumber(String birthCertificateNumber) {
762762
this.birthCertificateNumber = birthCertificateNumber;
763763
}
764764

765-
public Integer getEntryType() {
765+
public String getEntryType() {
766766
return entryType;
767767
}
768768

769769
@XmlElement(name = "Entry_Type")
770-
public void setEntryType(Integer entryType) {
770+
public void setEntryType(String entryType) {
771771
this.entryType = entryType;
772772
}
773773
}

kilkari/src/main/java/org/motechproject/nms/kilkari/contract/RchChildRecord.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class RchChildRecord {
2727
private String birthdate;
2828
private String registrationNo;
2929
private String motherRegistrationNo;
30-
private Integer entryType;
30+
private String entryType;
3131
private String mctsId;
3232
private String mctsMotherIdNo;
3333
private String execDate;
@@ -213,12 +213,12 @@ public void setMctsMotherIdNo(String mctsMotherIdNo) {
213213
this.mctsMotherIdNo = mctsMotherIdNo;
214214
}
215215

216-
public Integer getEntryType() {
216+
public String getEntryType() {
217217
return entryType;
218218
}
219219

220220
@XmlElement(name = "Entry_Type")
221-
public void setEntryType(Integer entryType) {
221+
public void setEntryType(String entryType) {
222222
this.entryType = entryType;
223223
}
224224

kilkari/src/main/java/org/motechproject/nms/kilkari/domain/Subscription.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ public static boolean hasCompletedForStartDate(DateTime startDate, DateTime toda
278278
return totalDaysInPack < daysSinceStartDate;
279279
}
280280

281+
public static boolean notReadyForStartDate(DateTime startDate, DateTime today, SubscriptionPack pack) {
282+
int daysSinceStartDate = Days.daysBetween(startDate, today).getDays();
283+
284+
return daysSinceStartDate < 0;
285+
}
286+
281287

282288
/**
283289
* Helper method which determines if the given contentFileName corresponds to the last message of this

kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportReaderServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ public DateTime retrieve(String value) {
372372
mapping.put(KilkariConstants.DEATH, new Optional(new GetInstanceByString<Boolean>() {
373373
@Override
374374
public Boolean retrieve(String value) {
375+
LOGGER.debug("Entry type : {}", value);
375376
return mctsBeneficiaryValueProcessor.getDeathFromString(value);
376377
}
377378
}));

kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/MctsBeneficiaryImportServiceImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ public MotherImportRejection importMotherRecord(Map<String, Object> record, Subs
270270
subscriptionService.deactivateSubscription(subscription, DeactivationReason.MATERNAL_DEATH);
271271
}
272272
LOGGER.debug("MotherImportRejection::importMotherRecord Start synchronized block " + beneficiaryId);
273-
return createUpdateMotherRejections(flagForMcts, record, action, null, true);
273+
createUpdateMotherRejections(flagForMcts, record, action, null, true);
274+
return null;
274275

275276
}
276277
}
@@ -562,7 +563,7 @@ public void createOrUpdateRchChildRejections(Map<String, Object> rejectedRecords
562563
ChildImportRejection child;
563564
for (String rchId : rchIds) {
564565
child = (ChildImportRejection) rejectedRecords.get(rchId);
565-
if (childRejects.get(rchId) != null) {
566+
if (childRejects != null && childRejects.get(rchId) != null) {
566567
updateChildRejectionRecord(childRejects, rchId, child, updateObjects);
567568
continue;
568569
}
@@ -644,7 +645,7 @@ public void createOrUpdateMctsChildRejections(Map<String, Object> rejectedRecord
644645
ChildImportRejection child;
645646
for (String mctsId : mctsIds) {
646647
child = (ChildImportRejection) rejectedRecords.get(mctsId);
647-
if (childRejects.get(mctsId) != null) {
648+
if (childRejects != null && childRejects.get(mctsId) != null) {
648649
updateChildRejectionRecord(childRejects, mctsId, child, updateObjects);
649650
continue;
650651
}
@@ -703,7 +704,7 @@ public void createOrUpdateRchMotherRejections(Map<String, Object> rejectedRecord
703704
MotherImportRejection mother;
704705
for (String rchId : rchIds) {
705706
mother = (MotherImportRejection) rejectedRecords.get(rchId);
706-
if (motherRejects.get(rchId) != null) {
707+
if (motherRejects != null && motherRejects.get(rchId) != null) {
707708
updateMotherRejectionRecord(motherRejects, rchId, mother, updateObjects);
708709
continue;
709710
}
@@ -781,7 +782,7 @@ public void createOrUpdateMctsMotherRejections(Map<String, Object> rejectedRecor
781782
MotherImportRejection mother;
782783
for (String mctsId : mctsIds) {
783784
mother = (MotherImportRejection) rejectedRecords.get(mctsId);
784-
if (motherRejects.get(mctsId) != null) {
785+
if (motherRejects != null && motherRejects.get(mctsId) != null) {
785786
updateMotherRejectionRecord(motherRejects, mctsId, mother, updateObjects);
786787
continue;
787788
}

kilkari/src/main/java/org/motechproject/nms/kilkari/service/impl/SubscriberServiceImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ public ChildImportRejection updateChildSubscriber(Long msisdn, MctsChild childUp
501501

502502
liveBirthChildDeathCheck(finalSubscription, record);
503503

504-
return childRejectionMcts(convertMapToChild(record), true, null, action);
504+
childRejectionMcts(convertMapToChild(record), true, null, action);
505+
return null;
505506

506507
}
507508

@@ -530,6 +531,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
530531
Subscriber subscriberByRchId = getSubscriberByBeneficiary(childUpdate);
531532
Subscription finalSubscription = null;
532533
String motherRchId;
534+
String name = childUpdate.getName();
533535
if (childUpdate.getMother() != null) {
534536
motherRchId = childUpdate.getMother().getRchId();
535537
} else {
@@ -548,6 +550,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
548550
}
549551
Subscription subscription = subscriptionService.getActiveSubscription(subscriberByRchId, pack.getType());
550552
subscriberByRchId.setDateOfBirth(dob);
553+
subscriberByRchId.getChild().setName(name);
551554
subscriberByRchId.getChild().setModificationDate(DateTime.now());
552555
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
553556
} else {
@@ -562,6 +565,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
562565
subscriberByRchId.setDateOfBirth(dob);
563566
subscriberByRchId.getChild().setModificationDate(DateTime.now());
564567
subscriberByRchId.getChild().setDateOfBirth(dob);
568+
subscriberByRchId.getChild().setName(name);
565569
subscriberByRchId.setModificationDate(DateTime.now());
566570
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
567571
} else {
@@ -579,6 +583,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
579583
}
580584
Subscription subscription = subscriptionService.getActiveSubscription(subscriberByRchId, pack.getType());
581585
subscriberByRchId.setDateOfBirth(dob);
586+
subscriberByRchId.getChild().setName(name);
582587
subscriberByRchId.getChild().setModificationDate(DateTime.now());
583588
subscriberByRchId.setModificationDate(DateTime.now());
584589
finalSubscription = updateOrCreateSubscription(subscriberByRchId, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
@@ -616,6 +621,7 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
616621
subscriber.setChild(childUpdate);
617622
Subscription subscription = subscriptionService.getActiveSubscription(subscriber, pack.getType());
618623
subscriber.getChild().setModificationDate(DateTime.now());
624+
subscriberByRchId.getChild().setName(name);
619625
finalSubscription = updateOrCreateSubscription(subscriber, subscription, dob, pack, language, circle, SubscriptionOrigin.RCH_IMPORT, false);
620626
} else {
621627
if (subscriptionService.activeSubscriptionByMsisdnRch(subscribersByMsisdn,msisdn, SubscriptionPackType.CHILD, motherRchId, childUpdate.getRchId())) {
@@ -656,7 +662,8 @@ public ChildImportRejection updateRchChildSubscriber(Long msisdn, MctsChild chil
656662

657663
liveBirthChildDeathCheck(finalSubscription, record);
658664

659-
return childRejectionRch(convertMapToRchChild(record), true, null, action);
665+
childRejectionRch(convertMapToRchChild(record), true, null, action);
666+
return null;
660667
}
661668

662669
public Subscription updateOrCreateSubscription(Subscriber subscriber, Subscription subscription, DateTime dateTime, SubscriptionPack pack, Language language, Circle circle, SubscriptionOrigin origin, Boolean greaterCaseNo) { // NO CHECKSTYLE Cyclomatic Complexity

0 commit comments

Comments
 (0)