use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class AbstractRelationshipService method deleteRelationship.
private ImportSummary deleteRelationship(String uid, ImportOptions importOptions) {
ImportSummary importSummary = new ImportSummary();
importOptions = updateImportOptions(importOptions);
if (uid.isEmpty()) {
importSummary.setStatus(ImportStatus.WARNING);
importSummary.setDescription("Missing required property 'relationship'");
return importSummary.incrementIgnored();
}
org.hisp.dhis.relationship.Relationship daoRelationship = relationshipService.getRelationship(uid);
if (daoRelationship != null) {
importSummary.setReference(uid);
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), daoRelationship);
if (!errors.isEmpty()) {
importSummary.setDescription(errors.toString());
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
relationshipService.deleteRelationship(daoRelationship);
importSummary.setStatus(ImportStatus.SUCCESS);
importSummary.setDescription("Deletion of relationship " + uid + " was successful");
return importSummary.incrementDeleted();
} else {
importSummary.setStatus(ImportStatus.WARNING);
importSummary.setDescription("Relationship " + uid + " cannot be deleted as it is not present in the system");
return importSummary.incrementIgnored();
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class AbstractEnrollmentService method checkForExistingEnrollmentsIncludingDeleted.
private List<String> checkForExistingEnrollmentsIncludingDeleted(List<Enrollment> enrollments, ImportSummaries importSummaries) {
List<String> foundEnrollments = programInstanceService.getProgramInstancesUidsIncludingDeleted(enrollments.stream().map(Enrollment::getEnrollment).collect(toList()));
for (String foundEnrollmentUid : foundEnrollments) {
ImportSummary is = new ImportSummary(ImportStatus.ERROR, "Enrollment " + foundEnrollmentUid + " already exists or was deleted earlier").setReference(foundEnrollmentUid).incrementIgnored();
importSummaries.addImportSummary(is);
}
return foundEnrollments;
}
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, JobConfiguration id) {
notifier.clear(id).notify(id, "ADX parsing process started");
ImportOptions adxImportOptions = firstNonNull(importOptions, ImportOptions.getDefaultImportOptions()).instance().setNotificationLevel(NotificationLevel.OFF);
// Get import options
IdScheme dsScheme = importOptions.getIdSchemes().getDataSetIdScheme();
IdScheme deScheme = 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, dsScheme, null);
IdentifiableObjectCallable<DataElement> dataElementCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataElement.class, deScheme, null);
// Heat cache
if (importOptions.isPreheatCacheDefaultFalse()) {
dataSetMap.load(identifiableObjectManager.getAll(DataSet.class), o -> o.getPropertyValue(dsScheme));
dataElementMap.load(identifiableObjectManager.getAll(DataElement.class), o -> o.getPropertyValue(deScheme));
}
XMLReader adxReader = XMLFactory.getXMLReader(in);
ImportSummary importSummary;
adxReader.moveToStartElement(AdxDataService.ROOT, AdxDataService.NAMESPACE);
ExecutorService executor = Executors.newSingleThreadExecutor();
// For Async runs, give the DXF import a different notification task ID
// so it doesn't conflict with notifications from this level.
JobConfiguration dxfJobId = (id == null) ? null : new JobConfiguration("dxfJob", JobType.DATAVALUE_IMPORT_INTERNAL, id.getUserUid(), true);
int groupCount = 0;
try (PipedOutputStream pipeOut = new PipedOutputStream()) {
Future<ImportSummary> futureImportSummary = executor.submit(new AdxPipedImporter(dataValueSetService, adxImportOptions, dxfJobId, 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 summary = importSummary;
adxConflicts.forEach(conflict -> summary.addConflict(conflict.getObject(), conflict.getValue()));
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.addConflict(ex.getObject(), ex.getMessage());
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).addJobSummary(id, importSummary, ImportSummary.class);
ImportCount c = importSummary.getImportCount();
log.info("ADX data import done, imported: " + c.getImported() + ", updated: " + c.getUpdated() + ", deleted: " + c.getDeleted() + ", ignored: " + c.getIgnored());
return importSummary;
}
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, JobConfiguration 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(this.systemSettingManager, this.categoryService, completeRegistrations, importOptions);
// ---------------------------------------------------------------------
// Set up meta-data
// ---------------------------------------------------------------------
MetadataCaches caches = new MetadataCaches();
MetadataCallables metaDataCallables = new MetadataCallables(cfg, this.idObjManager, this.periodService, this.categoryService);
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).addJobSummary(id, importSummary, ImportSummary.class);
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;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.DELETED in project dhis2-core by dhis2.
the class DataValueController method deleteDataValue.
// ---------------------------------------------------------------------
// DELETE
// ---------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_DELETE')")
@DeleteMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String ds, @RequestParam(required = false) boolean force, @CurrentUser User currentUser, HttpServletResponse response) throws WebMessageException {
FileResourceRetentionStrategy retentionStrategy = systemSettingManager.getSystemSetting(SettingKey.FILE_RESOURCE_RETENTION_STRATEGY, FileResourceRetentionStrategy.class);
// ---------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------
DataElement dataElement = dataValueValidation.getAndValidateDataElement(de);
CategoryOptionCombo categoryOptionCombo = dataValueValidation.getAndValidateCategoryOptionCombo(co, false);
CategoryOptionCombo attributeOptionCombo = dataValueValidation.getAndValidateAttributeOptionCombo(cc, cp);
Period period = dataValueValidation.getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = dataValueValidation.getAndValidateOrganisationUnit(ou);
DataSet dataSet = dataValueValidation.getAndValidateOptionalDataSet(ds, dataElement);
if (!inputUtils.canForceDataInput(currentUser, force)) {
dataValueValidation.validateDataSetNotLocked(currentUser, dataElement, period, dataSet, organisationUnit, attributeOptionCombo);
}
// ---------------------------------------------------------------------
// Period validation
// ---------------------------------------------------------------------
dataValueValidation.validateDataInputPeriodForDataElementAndPeriod(dataElement, dataSet, period);
// ---------------------------------------------------------------------
// Delete data value
// ---------------------------------------------------------------------
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new WebMessageException(conflict("Data value cannot be deleted because it does not exist"));
}
if (dataValue.getDataElement().isFileType() && retentionStrategy == FileResourceRetentionStrategy.NONE) {
fileResourceService.deleteFileResource(dataValue.getValue());
}
dataValueService.deleteDataValue(dataValue);
}
Aggregations