Search in sources :

Example 36 with UID

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();
}
Also used : ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) Clock(org.hisp.dhis.system.util.Clock) Date(java.util.Date) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate)

Example 37 with UID

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 38 with UID

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 39 with UID

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());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 40 with UID

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);
}
Also used : InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 Event (org.hisp.dhis.dxf2.events.event.Event)39 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)34 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)29 GetMapping (org.springframework.web.bind.annotation.GetMapping)28 User (org.hisp.dhis.user.User)23 Test (org.junit.jupiter.api.Test)21 HashMap (java.util.HashMap)19 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)19 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)19 InputStream (java.io.InputStream)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)18 ArrayList (java.util.ArrayList)17 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 List (java.util.List)16 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)15