Skip to content

Commit

Permalink
Added short circuiting of update to rejection count in all Types
Browse files Browse the repository at this point in the history
  • Loading branch information
sripooja committed Aug 2, 2016
1 parent d956057 commit 417b011
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 81 deletions.
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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 @@ -92,6 +93,8 @@ public void importFrontLineWorker(Map<String, Object> 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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public boolean importMotherRecord(Map<String, Object> 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);
Expand Down Expand Up @@ -254,7 +254,7 @@ public boolean importChildRecord(Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion mcts/src/main/resources/MctsAuditModification.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading

0 comments on commit 417b011

Please sign in to comment.