use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method addTrackedEntityInstance.
private ImportSummary addTrackedEntityInstance(TrackedEntityInstance dtoEntityInstance, ImportOptions importOptions, boolean handleEnrollments, boolean bulkImport) {
if (!bulkImport && teiService.trackedEntityInstanceExistsIncludingDeleted(dtoEntityInstance.getTrackedEntityInstance())) {
return new ImportSummary(ImportStatus.ERROR, "Tracked entity instance " + dtoEntityInstance.getTrackedEntityInstance() + " already exists or was deleted earlier").setReference(dtoEntityInstance.getTrackedEntityInstance()).incrementIgnored();
}
importOptions = updateImportOptions(importOptions);
dtoEntityInstance.trimValuesToNull();
ImportSummary importSummary = new ImportSummary(dtoEntityInstance.getTrackedEntityInstance());
checkTrackedEntityType(dtoEntityInstance, importOptions, importSummary);
checkAttributes(dtoEntityInstance, importOptions, importSummary, false);
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = createDAOTrackedEntityInstance(dtoEntityInstance, importOptions, importSummary);
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
if (daoEntityInstance == null) {
return importSummary;
}
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), daoEntityInstance);
if (!errors.isEmpty()) {
return new ImportSummary(ImportStatus.ERROR, errors.toString()).incrementIgnored();
}
teiService.addTrackedEntityInstance(daoEntityInstance);
addAttributeValues(dtoEntityInstance, daoEntityInstance, importOptions.getUser());
importSummary.setReference(daoEntityInstance.getUid());
importSummary.getImportCount().incrementImported();
if (handleEnrollments) {
importSummary.setEnrollments(handleEnrollments(dtoEntityInstance, daoEntityInstance, importOptions));
} else {
for (Enrollment enrollment : dtoEntityInstance.getEnrollments()) {
enrollment.setTrackedEntityType(dtoEntityInstance.getTrackedEntityType());
enrollment.setTrackedEntityInstance(daoEntityInstance.getUid());
}
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class EnrollmentRowCallbackHandler method getEnrollment.
private Enrollment getEnrollment(ResultSet rs) throws SQLException {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(rs.getString(getColumnName(UID)));
MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
enrollment.setFollowup(rs.wasNull() ? null : followup);
enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
enrollment.setId(rs.getLong(getColumnName(ID)));
return enrollment;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class TrackedEntityInstanceRowCallbackHandler method getTei.
private TrackedEntityInstance getTei(ResultSet rs) throws SQLException {
TrackedEntityInstance tei = new TrackedEntityInstance();
tei.setTrackedEntityInstance(rs.getString(getColumnName(UID)));
tei.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
tei.setTrackedEntityType(rs.getString(getColumnName(TYPE_UID)));
tei.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
tei.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(CREATED_BY), tei::setCreatedByUserInfo);
tei.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
tei.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), tei::setLastUpdatedByUserInfo);
tei.setInactive(rs.getBoolean(getColumnName(INACTIVE)));
tei.setDeleted(rs.getBoolean(getColumnName(DELETED)));
Optional<Geometry> geo = MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY)));
if (geo.isPresent()) {
tei.setGeometry(geo.get());
tei.setFeatureType(FeatureType.getTypeFromName(geo.get().getGeometryType()));
tei.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geo.get()));
}
return tei;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class EventImportTest method testAddAlreadyDeletedEvent.
@Test
void testAddAlreadyDeletedEvent() {
programInstanceService.addProgramInstance(pi);
ImportOptions importOptions = new ImportOptions();
eventService.addEvent(event, importOptions, false);
eventService.deleteEvent(event.getUid());
manager.flush();
importOptions.setImportStrategy(ImportStrategy.CREATE);
event.setDeleted(true);
ImportSummary importSummary = eventService.addEvent(event, importOptions, false);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals(1, importSummary.getImportCount().getIgnored());
assertTrue(importSummary.getDescription().contains("already exists or was deleted earlier"));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class EventImportTest method testAddAlreadyDeletedEventInBulk.
@Test
void testAddAlreadyDeletedEventInBulk() {
programInstanceService.addProgramInstance(pi);
ImportOptions importOptions = new ImportOptions();
eventService.addEvent(event, importOptions, false);
eventService.deleteEvent(event.getUid());
manager.flush();
Event event2 = createEvent("eventUid002");
Event event3 = createEvent("eventUid003");
importOptions.setImportStrategy(ImportStrategy.CREATE);
event.setDeleted(true);
List<Event> events = new ArrayList<>();
events.add(event);
events.add(event2);
events.add(event3);
ImportSummaries importSummaries = eventService.addEvents(events, importOptions, true);
assertEquals(ImportStatus.ERROR, importSummaries.getStatus());
assertEquals(1, importSummaries.getIgnored());
assertEquals(2, importSummaries.getImported());
assertTrue(importSummaries.getImportSummaries().stream().anyMatch(is -> is.getDescription().contains("already exists or was deleted earlier")));
manager.flush();
List<String> uids = new ArrayList<>();
uids.add("eventUid001");
uids.add("eventUid002");
uids.add("eventUid003");
List<String> fetchedUids = programStageInstanceService.getProgramStageInstanceUidsIncludingDeleted(uids);
assertTrue(Sets.difference(new HashSet<>(uids), new HashSet<>(fetchedUids)).isEmpty());
}
Aggregations