use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class EventGeometryCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
ProgramStage programStage = ctx.getProgramStage(scheme, event.getProgramStage());
if (Objects.nonNull(event.getGeometry()) && programStageFeatureCompatibleWithEventGeometry(event, programStage)) {
return new ImportSummary(ImportStatus.ERROR, "Geometry (" + event.getGeometry().getGeometryType() + ") does not conform to the feature type (" + programStage.getFeatureType().value() + ") specified for the program stage: " + programStage.getUid()).setReference(event.getEvent()).incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class ExpirationDaysCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
final ImportOptions importOptions = ctx.getImportOptions();
final Program program = ctx.getProgramsMap().get(event.getProgram());
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getEvent());
if (importOptions == null || importOptions.getUser() == null || importOptions.getUser().isAuthorized(Authorities.F_EDIT_EXPIRED.getAuthority())) {
return success();
}
if (program != null) {
ImportSummary importSummary = checkEventOrPsiCompletedDate(program, event, programStageInstance);
if (importSummary.isStatus(ImportStatus.ERROR)) {
return importSummary;
}
return checkEventOrPsiExpirationDate(program, event, programStageInstance);
}
return success();
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class TrackedEntityInstanceCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
Program program = ctx.getProgramsMap().get(event.getProgram());
final Optional<TrackedEntityInstance> trackedEntityInstance = ctx.getTrackedEntityInstance(event.getUid());
if (program.isRegistration() && !trackedEntityInstance.isPresent()) {
return new ImportSummary(ImportStatus.ERROR, "Event.trackedEntityInstance does not point to a valid tracked entity instance: " + event.getTrackedEntityInstance()).setReference(event.getEvent()).incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class DefaultSynchronizationManager method executeDataValuePush.
/**
* Executes a push of data values to the given remote instance.
*
* @param instance the remote system instance.
* @return an ImportSummary.
*/
private ImportConflicts executeDataValuePush(SystemInstance instance) throws WebMessageParseException {
// ---------------------------------------------------------------------
// Set time for last success to start of process to make data saved
// subsequently part of next synch process without being ignored
// ---------------------------------------------------------------------
final Date startTime = new Date();
final Date lastSuccessTime = SyncUtils.getLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC);
final Date skipChangedBefore = systemSettingManager.getDateSetting(SettingKey.SKIP_SYNCHRONIZATION_FOR_DATA_CHANGED_BEFORE);
final Date lastUpdatedAfter = lastSuccessTime.after(skipChangedBefore) ? lastSuccessTime : skipChangedBefore;
final int objectsToSynchronize = dataValueService.getDataValueCountLastUpdatedAfter(lastUpdatedAfter, true);
log.info("DataValues last changed before " + skipChangedBefore + " will not be synchronized.");
if (objectsToSynchronize == 0) {
SyncUtils.setLastSyncSuccess(systemSettingManager, SettingKey.LAST_SUCCESSFUL_DATA_VALUE_SYNC, startTime);
log.debug("Skipping data values push, no new or updated data values");
ImportCount importCount = new ImportCount(0, 0, 0, 0);
return new ImportSummary(ImportStatus.SUCCESS, "No new or updated data values to push.", importCount);
}
log.info("Data Values: " + objectsToSynchronize + " to push since last synchronization success: " + lastSuccessTime);
log.info("Remote server POST URL: " + instance.getUrl());
final RequestCallback requestCallback = request -> {
request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
request.getHeaders().add(HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString(instance.getUsername(), instance.getPassword()));
dataValueSetService.exportDataValueSetJson(lastUpdatedAfter, request.getBody(), new IdSchemes());
};
final int maxSyncAttempts = systemSettingManager.getIntSetting(SettingKey.MAX_SYNC_ATTEMPTS);
Optional<AbstractWebMessageResponse> responseSummary = SyncUtils.runSyncRequest(restTemplate, requestCallback, SyncEndpoint.DATA_VALUE_SETS.getKlass(), instance.getUrl(), maxSyncAttempts);
ImportSummary summary = null;
if (responseSummary.isPresent()) {
summary = (ImportSummary) responseSummary.get();
if (ImportStatus.SUCCESS.equals(summary.getStatus())) {
log.info("Push successful: " + summary);
} else {
log.warn("Push failed: " + summary);
}
}
return summary;
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment.
/**
* FIXME luciano: this is ignored because there is a bug in tracker, so that
* new events that fail to validate are reported as success.
*/
@Disabled
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
Event event1 = new Event();
event1.setEnrollment(enrollment1.getEnrollment());
event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event1.setOrgUnit(organisationUnitA.getUid());
event1.setProgram(programA.getUid());
event1.setProgramStage(programStageA1.getUid());
event1.setStatus(EventStatus.ACTIVE);
event1.setTrackedEntityInstance(maleA.getUid());
enrollment1.setEvents(singletonList(event1));
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
// This is required because the Event creation takes place using JDBC,
// therefore Hibernate does not
// "see" the new event in the context of this session
sessionFactory.getCurrentSession().clear();
trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
assertNotNull(trackedEntityInstance.getEnrollments().get(0).getEvents());
assertEquals(1, trackedEntityInstance.getEnrollments().get(0).getEvents().size());
enrollment1 = trackedEntityInstance.getEnrollments().get(0);
enrollment1.setStatus(EnrollmentStatus.COMPLETED);
enrollment1.setCompletedBy("test");
enrollment1.setCompletedDate(new Date());
event1 = enrollment1.getEvents().get(0);
event1.setStatus(EventStatus.COMPLETED);
event1.setCompletedBy("test");
event1.setCompletedDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
}
Aggregations