Search in sources :

Example 1 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class DefaultCompleteDataSetRegistrationExchangeService method saveCompleteDataSetRegistrations.

private ImportSummary saveCompleteDataSetRegistrations(ImportOptions importOptions, TaskId id, CompleteDataSetRegistrations completeRegistrations) {
    Clock clock = new Clock(log).startClock().logTime("Starting complete data set registration import, options: " + importOptions);
    notifier.clear(id).notify(id, "Process started");
    // Start here so we can access any outer attributes for the configuration
    completeRegistrations.open();
    ImportSummary importSummary = new ImportSummary();
    // ---------------------------------------------------------------------
    // Set up import configuration
    // ---------------------------------------------------------------------
    importOptions = importOptions != null ? importOptions : ImportOptions.getDefaultImportOptions();
    log.info("Import options: " + importOptions);
    ImportConfig cfg = new ImportConfig(completeRegistrations, importOptions);
    // ---------------------------------------------------------------------
    // Set up meta-data
    // ---------------------------------------------------------------------
    MetaDataCaches caches = new MetaDataCaches();
    MetaDataCallables metaDataCallables = new MetaDataCallables(cfg);
    if (importOptions.isPreheatCacheDefaultFalse()) {
        caches.preheat(idObjManager, cfg);
    }
    // ---------------------------------------------------------------------
    // Perform import
    // ---------------------------------------------------------------------
    notifier.notify(id, "Importing complete data set registrations");
    int totalCount = batchImport(completeRegistrations, cfg, importSummary, metaDataCallables, caches);
    notifier.notify(id, NotificationLevel.INFO, "Import done", true).addTaskSummary(id, importSummary);
    ImportCount count = importSummary.getImportCount();
    clock.logTime(String.format("Complete data set registration import done, total: %d, imported: %d, updated: %d, deleted: %d", totalCount, count.getImported(), count.getUpdated(), count.getDeleted()));
    completeRegistrations.close();
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) Clock(org.hisp.dhis.system.util.Clock)

Example 2 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class UserKeyJsonValueController method deleteUserKeyJsonValue.

/**
     * Delete a key.
     */
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.DELETE, produces = "application/json")
public void deleteUserKeyJsonValue(@PathVariable String namespace, @PathVariable String key, HttpServletResponse response) throws WebMessageException {
    UserKeyJsonValue userKeyJsonValue = userKeyJsonValueService.getUserKeyJsonValue(currentUserService.getCurrentUser(), namespace, key);
    if (userKeyJsonValue == null) {
        throw new WebMessageException(WebMessageUtils.notFound("The key '" + key + "' was not found in the namespace '" + namespace + "'."));
    }
    userKeyJsonValueService.deleteUserKeyJsonValue(userKeyJsonValue);
    messageService.sendJson(WebMessageUtils.ok("Key '" + key + "' deleted from the namespace '" + namespace + "'."), response);
}
Also used : UserKeyJsonValue(org.hisp.dhis.userkeyjsonvalue.UserKeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class DefaultAdxDataService method saveDataValueSetInternal.

private ImportSummary saveDataValueSetInternal(InputStream in, ImportOptions importOptions, TaskId id) {
    notifier.clear(id).notify(id, "ADX parsing process started");
    ImportOptions adxImportOptions = ObjectUtils.firstNonNull(importOptions, ImportOptions.getDefaultImportOptions()).instance().setNotificationLevel(NotificationLevel.OFF);
    // Get import options
    IdScheme dataSetIdScheme = importOptions.getIdSchemes().getDataSetIdScheme();
    IdScheme dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme();
    // Create meta-data maps
    CachingMap<String, DataSet> dataSetMap = new CachingMap<>();
    CachingMap<String, DataElement> dataElementMap = new CachingMap<>();
    // Get meta-data maps
    IdentifiableObjectCallable<DataSet> dataSetCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataSet.class, dataSetIdScheme, null);
    IdentifiableObjectCallable<DataElement> dataElementCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataElement.class, dataElementIdScheme, null);
    // Heat cache
    if (importOptions.isPreheatCacheDefaultFalse()) {
        dataSetMap.load(identifiableObjectManager.getAll(DataSet.class), o -> o.getPropertyValue(dataSetIdScheme));
        dataElementMap.load(identifiableObjectManager.getAll(DataElement.class), o -> o.getPropertyValue(dataElementIdScheme));
    }
    XMLReader adxReader = XMLFactory.getXMLReader(in);
    ImportSummary importSummary;
    adxReader.moveToStartElement(AdxDataService.ROOT, AdxDataService.NAMESPACE);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    // Give the DXF import a different notification task ID so it doesn't conflict with notifications from this level.
    TaskId dxfTaskId = new TaskId(TaskCategory.DATAVALUE_IMPORT_INTERNAL, id.getUser());
    int groupCount = 0;
    try (PipedOutputStream pipeOut = new PipedOutputStream()) {
        Future<ImportSummary> futureImportSummary = executor.submit(new AdxPipedImporter(dataValueSetService, adxImportOptions, dxfTaskId, pipeOut, sessionFactory));
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter dxfWriter = factory.createXMLStreamWriter(pipeOut);
        List<ImportConflict> adxConflicts = new LinkedList<>();
        dxfWriter.writeStartDocument("1.0");
        dxfWriter.writeStartElement("dataValueSet");
        dxfWriter.writeDefaultNamespace("http://dhis2.org/schema/dxf/2.0");
        notifier.notify(id, "Starting to import ADX data groups.");
        while (adxReader.moveToStartElement(AdxDataService.GROUP, AdxDataService.NAMESPACE)) {
            notifier.update(id, "Importing ADX data group: " + groupCount);
            // note this returns conflicts which are detected at ADX level
            adxConflicts.addAll(parseAdxGroupToDxf(adxReader, dxfWriter, adxImportOptions, dataSetMap, dataSetCallable, dataElementMap, dataElementCallable));
            groupCount++;
        }
        // end dataValueSet
        dxfWriter.writeEndElement();
        dxfWriter.writeEndDocument();
        pipeOut.flush();
        importSummary = futureImportSummary.get(TOTAL_MINUTES_TO_WAIT, TimeUnit.MINUTES);
        importSummary.getConflicts().addAll(adxConflicts);
        importSummary.getImportCount().incrementIgnored(adxConflicts.size());
    } catch (AdxException ex) {
        importSummary = new ImportSummary();
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setDescription("Data set import failed within group number: " + groupCount);
        importSummary.getConflicts().add(ex.getImportConflict());
        notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
        log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
    } catch (IOException | XMLStreamException | InterruptedException | ExecutionException | TimeoutException ex) {
        importSummary = new ImportSummary();
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setDescription("Data set import failed within group number: " + groupCount);
        notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
        log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
    }
    executor.shutdown();
    notifier.update(id, INFO, "ADX data import done", true).addTaskSummary(id, importSummary);
    ImportCount c = importSummary.getImportCount();
    log.info("ADX data import done, imported: " + c.getImported() + ", updated: " + c.getUpdated() + ", deleted: " + c.getDeleted() + ", ignored: " + c.getIgnored());
    return importSummary;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) TaskId(org.hisp.dhis.scheduling.TaskId) DataSet(org.hisp.dhis.dataset.DataSet) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PipedOutputStream(java.io.PipedOutputStream) DataElement(org.hisp.dhis.dataelement.DataElement) CachingMap(org.hisp.dhis.commons.collection.CachingMap) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ExecutionException(java.util.concurrent.ExecutionException) XMLReader(org.hisp.staxwax.reader.XMLReader) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict) TimeoutException(java.util.concurrent.TimeoutException) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) IdScheme(org.hisp.dhis.common.IdScheme) IOException(java.io.IOException) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) LinkedList(java.util.LinkedList) XMLStreamException(javax.xml.stream.XMLStreamException) ExecutorService(java.util.concurrent.ExecutorService) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 4 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class AbstractEventService method deleteEvent.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@Transactional
@Override
public ImportSummary deleteEvent(String uid) {
    boolean existsEvent = programStageInstanceService.programStageInstanceExists(uid);
    if (existsEvent) {
        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(uid);
        List<String> errors = trackerAccessManager.canDelete(currentUserService.getCurrentUser(), programStageInstance, false);
        if (!errors.isEmpty()) {
            return new ImportSummary(ImportStatus.ERROR, errors.toString()).incrementIgnored();
        }
        programStageInstanceService.deleteProgramStageInstance(programStageInstance);
        if (programStageInstance.getProgramStage().getProgram().isRegistration()) {
            entityInstanceService.updateTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance());
        }
        ImportSummary importSummary = new ImportSummary(ImportStatus.SUCCESS, "Deletion of event " + uid + " was successful").incrementDeleted();
        importSummary.setReference(uid);
        return importSummary;
    } else {
        return new ImportSummary(ImportStatus.SUCCESS, "Event " + uid + " cannot be deleted as it is not present in the system").incrementIgnored();
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DELETED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.

the class AbstractEnrollmentService method deleteEnrollment.

private ImportSummary deleteEnrollment(String uid, Enrollment enrollment, ImportOptions importOptions) {
    ImportSummary importSummary = new ImportSummary();
    importOptions = updateImportOptions(importOptions);
    boolean existsEnrollment = programInstanceService.programInstanceExists(uid);
    if (existsEnrollment) {
        ProgramInstance programInstance = programInstanceService.getProgramInstance(uid);
        if (enrollment != null) {
            importSummary.setReference(uid);
            importSummary.setEvents(handleEvents(enrollment, programInstance, importOptions));
        }
        if (importOptions.getUser() != null) {
            isAllowedToDelete(importOptions.getUser(), programInstance, importSummary);
            if (importSummary.hasConflicts()) {
                importSummary.setStatus(ImportStatus.ERROR);
                importSummary.setReference(programInstance.getUid());
                importSummary.incrementIgnored();
                return importSummary;
            }
        }
        programInstanceService.deleteProgramInstance(programInstance);
        teiService.updateTrackedEntityInstance(programInstance.getEntityInstance());
        importSummary.setReference(uid);
        importSummary.setStatus(ImportStatus.SUCCESS);
        importSummary.setDescription("Deletion of enrollment " + uid + " was successful");
        return importSummary.incrementDeleted();
    } else {
        // If I am here, it means that the item is either already deleted or
        // it is not present in the system at all.
        importSummary.setStatus(ImportStatus.SUCCESS);
        importSummary.setDescription("Enrollment " + uid + " cannot be deleted as it is not present in the system");
        return importSummary.incrementIgnored();
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)26 Test (org.junit.jupiter.api.Test)12 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 IOException (java.io.IOException)5 DhisTest (org.hisp.dhis.DhisTest)5 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)5 Program (org.hisp.dhis.program.Program)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 IdScheme (org.hisp.dhis.common.IdScheme)4 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 Lists (com.google.common.collect.Lists)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3