Skip to content

Commit

Permalink
Merge pull request #693 from motech-implementations/mcts_retrial
Browse files Browse the repository at this point in the history
Mcts import retrial in the last 7 days
  • Loading branch information
atishbeehyv123 authored Aug 3, 2016
2 parents 315783b + 417b011 commit 7c67dec
Show file tree
Hide file tree
Showing 58 changed files with 2,997 additions and 90 deletions.
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.18</version>
<version>1.0.19</version>
<relativePath>../</relativePath>
</parent>

<artifactId>api</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>
<packaging>bundle</packaging>
<name>API module</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ 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 with NMS-349
log("REQUEST: /ops/createUpdateFlw", String.format(
"callingNumber=%s, mctsId=%s, name=%s, state=%d, district=%d",
LogHelper.obscure(addFlwRequest.getContactNumber()),
Expand Down
4 changes: 2 additions & 2 deletions csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.18</version>
<version>1.0.19</version>
<relativePath>../</relativePath>
</parent>

<artifactId>csv</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>
<packaging>bundle</packaging>
<name>CSV Module</name>

Expand Down
4 changes: 2 additions & 2 deletions flw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.18</version>
<version>1.0.19</version>
<relativePath>../</relativePath>
</parent>

<artifactId>flw</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>
<packaging>bundle</packaging>
<name>FLW module</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,5 +12,5 @@ public interface FrontLineWorkerImportService {

void importData(Reader reader) throws IOException;

void importFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException;
void importFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,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;
Expand Down Expand Up @@ -71,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<String, Object> record, State state) throws InvalidLocationException {
public void importFrontLineWorker(Map<String, Object> record, State state) throws InvalidLocationException, FlwExistingRecordException {
FrontLineWorker flw = flwFromRecord(record, state);

record.put(FlwConstants.STATE_ID, state.getCode());
Expand All @@ -87,7 +89,13 @@ public void importFrontLineWorker(Map<String, Object> 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));
} else {
throw new FlwExistingRecordException("Updated record exists in the database");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -61,6 +62,10 @@ public static FrontLineWorker updateFlw(FrontLineWorker flw, Map<String, Object>
flw.setDesignation(type);
}

if (record.get(FlwConstants.UPDATED_ON) != null) {
flw.setUpdatedDateNic((LocalDate) record.get(FlwConstants.UPDATED_ON));
}

return flw;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public String handleException(CsvImportDataException e) {
@RequestMapping(value = "/update/language", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public void updateFrontLineWorkersLanguage(@RequestParam MultipartFile csvFile) {

try {
try (InputStream in = csvFile.getInputStream()) {
flwUpdateImportService.importLanguageData(new InputStreamReader(in));
Expand All @@ -63,6 +64,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));
Expand All @@ -82,6 +89,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));
Expand Down
4 changes: 2 additions & 2 deletions imi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.18</version>
<version>1.0.19</version>
<relativePath>../</relativePath>
</parent>

<artifactId>imi</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>
<packaging>bundle</packaging>
<name>IMI module</name>

Expand Down
4 changes: 2 additions & 2 deletions kilkari/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>nms</artifactId>
<groupId>org.motechproject.nms</groupId>
<version>1.0.18</version>
<version>1.0.19</version>
<relativePath>../</relativePath>
</parent>

<artifactId>kilkari</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>
<packaging>bundle</packaging>
<name>Kilkari module</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -57,6 +58,9 @@ public abstract class MctsBeneficiary extends MdsEntity implements FullLocation
@Field
private Village village;

@Field
private LocalDate updatedDateNic;

public MctsBeneficiary() {
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public void deepCopyFrom(MctsChild other) {
setHealthFacility(other.getHealthFacility());
setHealthSubFacility(other.getHealthSubFacility());
setVillage(other.getVillage());
setUpdatedDateNic(other.getUpdatedDateNic());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ public void deepCopyFrom(MctsMother other) {
setHealthFacility(other.getHealthFacility());
setHealthSubFacility(other.getHealthSubFacility());
setVillage(other.getVillage());
setUpdatedDateNic(other.getUpdatedDateNic());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -160,6 +161,7 @@ public boolean importMotherRecord(Map<String, Object> 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 msisdn
if (!validateMsisdn(msisdn, SubscriptionPackType.PREGNANCY)) {
Expand All @@ -183,8 +185,14 @@ public boolean importMotherRecord(Map<String, Object> 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 false;
}

mother.setName(name);
mother.setDateOfBirth(motherDOB);
mother.setUpdatedDateNic(mctsUpdatedDateNic);

Subscription subscription = subscriberService.updateMotherSubscriber(msisdn, mother, lmp);
// We rejected the update/create for the subscriber
Expand Down Expand Up @@ -220,6 +228,7 @@ public boolean importChildRecord(Map<String, Object> 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 msisdn
if (!validateMsisdn(msisdn, SubscriptionPackType.CHILD)) {
Expand All @@ -243,8 +252,14 @@ public boolean importChildRecord(Map<String, Object> 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 false;
}

child.setName(name);
child.setMother(mother);
child.setUpdatedDateNic(mctsUpdatedDateNic);

Subscription childSubscription = subscriberService.updateChildSubscriber(msisdn, child, dob);
// child subscription create/update was rejected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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()) {
Expand Down
Loading

0 comments on commit 7c67dec

Please sign in to comment.