use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class DefaultDataValueSetService method importDataValueSet.
/**
* There are specific id schemes for data elements and organisation units
* and a generic id scheme for all objects. The specific id schemes will
* take precedence over the generic id scheme. The generic id scheme also
* applies to data set and category option combo.
* <p>
* The id schemes uses the following order of precedence:
* <p>
* <ul>
* <li>Id scheme from the data value set</li>
* <li>Id scheme from the import options</li>
* <li>Default id scheme which is UID</li>
* <ul>
* <p>
* If id scheme is specific in the data value set, any id schemes in the
* import options will be ignored.
*/
private ImportSummary importDataValueSet(ImportOptions options, JobConfiguration id, DataValueSetReader reader) {
DataValueSet dataValueSet = reader.readHeader();
final ImportContext context = createDataValueSetImportContext(options, dataValueSet);
logDataValueSetImportContextInfo(context);
Clock clock = new Clock(log).startClock().logTime("Starting data value import, options: " + context.getImportOptions());
NotificationLevel notificationLevel = context.getImportOptions().getNotificationLevel(INFO);
notifier.clear(id).notify(id, notificationLevel, "Process started");
// ---------------------------------------------------------------------
// Heat caches
// ---------------------------------------------------------------------
preheatCaches(context);
// ---------------------------------------------------------------------
// Get outer meta-data
// ---------------------------------------------------------------------
ImportContext.DataSetContext dataSetContext = createDataSetContext(context, dataValueSet);
if (importValidator.abortDataSetImport(dataValueSet, context, dataSetContext)) {
context.getSummary().setDescription("Import process was aborted");
notifier.notify(id, WARN, "Import process aborted", true).addJobSummary(id, context.getSummary(), ImportSummary.class);
return context.getSummary();
}
Date completeDate = parseDate(dataValueSet.getCompleteDate());
if (dataSetContext.getDataSet() != null && completeDate != null) {
notifier.notify(id, notificationLevel, "Completing data set");
handleComplete(dataSetContext.getDataSet(), completeDate, dataSetContext.getOuterPeriod(), dataSetContext.getOuterOrgUnit(), dataSetContext.getFallbackCategoryOptionCombo(), context.getCurrentUserName(), context.getSummary());
} else {
context.getSummary().setDataSetComplete(Boolean.FALSE.toString());
}
final ImportCount importCount = new ImportCount();
// ---------------------------------------------------------------------
// Data values
// ---------------------------------------------------------------------
Date now = new Date();
clock.logTime("Validated outer meta-data");
notifier.notify(id, notificationLevel, "Importing data values");
List<? extends DataValueEntry> values = dataValueSet.getDataValues();
int index = 0;
if (values != null && !values.isEmpty()) {
for (DataValueEntry dataValue : values) {
importDataValue(context, dataSetContext, importCount, now, index++, dataValue);
}
}
DataValueEntry dataValue = reader.readNext();
while (dataValue != null) {
importDataValue(context, dataSetContext, importCount, now, index++, dataValue);
dataValue = reader.readNext();
}
context.getDataValueBatchHandler().flush();
if (!context.isSkipAudit()) {
context.getAuditBatchHandler().flush();
}
context.getSummary().setImportCount(importCount).setStatus(!context.getSummary().hasConflicts() ? ImportStatus.SUCCESS : ImportStatus.WARNING).setDescription("Import process completed successfully");
clock.logTime("Data value import done, total: " + importCount.getTotalCount() + ", import: " + importCount.getImported() + ", update: " + importCount.getUpdated() + ", delete: " + importCount.getDeleted());
notifier.notify(id, notificationLevel, "Import done", true).addJobSummary(id, notificationLevel, context.getSummary(), ImportSummary.class);
return context.getSummary();
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class EventImportTest method testVerifyEventCanBeUpdatedUsingProgramOnly.
@Test
void testVerifyEventCanBeUpdatedUsingProgramOnly() throws IOException {
// CREATE A NEW EVENT
InputStream is = createEventJsonInputStream(programB.getUid(), programStageB.getUid(), organisationUnitB.getUid(), null, dataElementB, "10");
ImportSummaries importSummaries = eventService.addEventsJson(is, null);
String uid = importSummaries.getImportSummaries().get(0).getReference();
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
// FETCH NEWLY CREATED EVENT
ProgramStageInstance psi = programStageInstanceService.getProgramStageInstance(uid);
// UPDATE EVENT (no actual changes, except for empty data value)
// USE ONLY PROGRAM
Event event = new Event();
event.setEvent(uid);
event.setProgram(programB.getUid());
event.setStatus(EventStatus.COMPLETED);
assertEquals(ImportStatus.SUCCESS, eventService.updateEvent(event, false, ImportOptions.getDefaultImportOptions(), false).getStatus());
cleanSession();
ProgramStageInstance psi2 = programStageInstanceService.getProgramStageInstance(uid);
assertThat(psi.getLastUpdated(), DateMatchers.before(psi2.getLastUpdated()));
assertThat(psi.getCreated(), is(psi2.getCreated()));
assertThat(psi.getProgramInstance().getUid(), is(psi2.getProgramInstance().getUid()));
assertThat(psi.getProgramStage().getUid(), is(psi2.getProgramStage().getUid()));
assertThat(psi.getOrganisationUnit().getUid(), is(psi2.getOrganisationUnit().getUid()));
assertThat(psi.getAttributeOptionCombo().getUid(), is(psi2.getAttributeOptionCombo().getUid()));
assertThat(psi.getStatus().getValue(), is(psi2.getStatus().getValue()));
assertThat(psi.getExecutionDate(), is(psi2.getExecutionDate()));
assertThat(psi.getCompletedDate(), is(psi2.getCompletedDate()));
assertThat(psi.getCompletedBy(), is(psi2.getCompletedBy()));
assertThat(psi.isDeleted(), is(psi2.isDeleted()));
assertThat(psi.getEventDataValues().size(), is(1));
assertThat(psi2.getEventDataValues().size(), is(0));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class EventImportTest method testVerifyEventUncompleteSetsCompletedDateToNull.
@Test
void testVerifyEventUncompleteSetsCompletedDateToNull() throws IOException {
// CREATE A NEW EVENT
InputStream is = createEventJsonInputStream(programB.getUid(), programStageB.getUid(), organisationUnitB.getUid(), null, dataElementB, "10");
ImportSummaries importSummaries = eventService.addEventsJson(is, null);
String uid = importSummaries.getImportSummaries().get(0).getReference();
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
// FETCH NEWLY CREATED EVENT
ProgramStageInstance psi = programStageInstanceService.getProgramStageInstance(uid);
// UPDATE EVENT (no actual changes, except for empty data value and
// status
// change)
Event event = new Event();
event.setEvent(uid);
event.setProgram(programB.getUid());
event.setStatus(EventStatus.ACTIVE);
assertEquals(ImportStatus.SUCCESS, eventService.updateEvent(event, false, ImportOptions.getDefaultImportOptions(), false).getStatus());
cleanSession();
ProgramStageInstance psi2 = programStageInstanceService.getProgramStageInstance(uid);
assertThat(psi.getLastUpdated(), DateMatchers.before(psi2.getLastUpdated()));
assertThat(psi.getCreated(), is(psi2.getCreated()));
assertThat(psi.getProgramInstance().getUid(), is(psi2.getProgramInstance().getUid()));
assertThat(psi.getProgramStage().getUid(), is(psi2.getProgramStage().getUid()));
assertThat(psi.getOrganisationUnit().getUid(), is(psi2.getOrganisationUnit().getUid()));
assertThat(psi.getAttributeOptionCombo().getUid(), is(psi2.getAttributeOptionCombo().getUid()));
assertThat(psi2.getStatus(), is(EventStatus.ACTIVE));
assertThat(psi.getExecutionDate(), is(psi2.getExecutionDate()));
assertThat(psi2.getCompletedDate(), is(nullValue()));
assertThat(psi.getCompletedBy(), is(psi2.getCompletedBy()));
assertThat(psi.isDeleted(), is(psi2.isDeleted()));
assertThat(psi.getEventDataValues().size(), is(1));
assertThat(psi2.getEventDataValues().size(), is(0));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class DataElementGroupController method getOperands.
@GetMapping("/{uid}/operands")
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
Collections.sort(dataElementOperands);
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class EventController method putJsonEventForEventDate.
@PutMapping(value = "/{uid}/eventDate", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonEventForEventDate(HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
return notFound("Event not found for ID " + uid);
}
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Event updatedEvent = renderService.fromJson(inputStream, Event.class);
updatedEvent.setEvent(uid);
eventService.updateEventForEventDate(updatedEvent);
return ok("Event updated " + uid);
}
Aggregations