use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class DefaultGmlImportService method importGml.
// -------------------------------------------------------------------------
// GmlImportService implementation
// -------------------------------------------------------------------------
@Transactional
@Override
public ImportReport importGml(InputStream inputStream, MetadataImportParams importParams) {
ImportReport importReport = new ImportReport();
if (!importParams.getImportStrategy().isUpdate()) {
importParams.setImportStrategy(ImportStrategy.UPDATE);
log.warn("Changed GML import strategy to update. Only updates are supported.");
}
PreProcessingResult preProcessed = preProcessGml(inputStream);
if (preProcessed.isSuccess && preProcessed.metaData != null) {
importParams.addMetadata(schemaService.getMetadataSchemas(), preProcessed.metaData);
importReport = importService.importMetadata(importParams);
} else {
Throwable throwable = preProcessed.throwable;
notifier.notify(importParams.getId(), NotificationLevel.ERROR, createNotifierErrorMessage(throwable), false);
importReport.setStatus(Status.ERROR);
ObjectReport objectReport = new ObjectReport(getClass(), 0);
objectReport.addErrorReport(new ErrorReport(getClass(), new ErrorMessage(ErrorCode.E7010, createNotifierErrorMessage(throwable))));
TypeReport typeReport = new TypeReport(getClass());
typeReport.addObjectReport(objectReport);
importReport.addTypeReport(typeReport);
log.error("GML import failed: ", throwable);
}
return importReport;
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class DefaultMetadataWorkflowService method acceptAdd.
private ImportReport acceptAdd(MetadataProposal proposal, ObjectBundleMode mode) {
Class<? extends IdentifiableObject> objType = proposal.getTarget().getType();
IdentifiableObject obj = mapJsonChangeToObject(proposal.getChange(), objType);
if (obj == null) {
return createJsonErrorReport(proposal);
}
MetadataImportParams params = createImportParams(mode, ImportStrategy.CREATE, obj);
ImportReport report = importService.importMetadata(params);
if (report.getStatus() == Status.OK) {
TypeReport typeReport = report.getTypeReport(objType);
ObjectReport objectReport = new ObjectReport(obj, object -> 0);
typeReport.addObjectReport(objectReport);
}
return report;
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class AbstractCrudController method deleteObject.
// --------------------------------------------------------------------------
// DELETE
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{uid}")
@ResponseBody
public WebMessage deleteObject(@PathVariable("uid") String pvUid, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
if (!aclService.canDelete(currentUser, objects.get(0))) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
preDeleteEntity(objects.get(0));
MetadataImportParams params = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setUser(currentUser).setImportStrategy(ImportStrategy.DELETE).addObject(objects.get(0));
ImportReport importReport = importService.importMetadata(params);
postDeleteEntity(pvUid);
return objectReport(importReport);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class AbstractCrudController method bulkSharing.
@ResponseBody
@PatchMapping(path = "/sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws Exception {
final BulkJsonPatch bulkJsonPatch = jsonMapper.readValue(request.getInputStream(), BulkJsonPatch.class);
BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatch(bulkJsonPatch, patchParams);
if (patchedObjects.isEmpty() || (atomic && patchParams.hasErrorReports())) {
ImportReport importReport = new ImportReport();
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(Status.ERROR);
return importReport(importReport);
}
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).addObjects(patchedObjects);
ImportReport importReport = importService.importMetadata(params);
if (patchParams.hasErrorReports()) {
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(importReport.getStatus() == Status.OK ? Status.WARNING : importReport.getStatus());
}
return importReport(importReport);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class AbstractCrudController method patchObject.
// --------------------------------------------------------------------------
// PATCH
// --------------------------------------------------------------------------
/**
* Adds support for HTTP Patch using JSON Patch (RFC 6902), updated object
* is run through normal metadata importer and internally looks like a
* normal PUT (after the JSON Patch has been applied).
*
* For now we only support the official mimetype
* "application/json-patch+json" but in future releases we might also want
* to support "application/json" after the old patch behavior has been
* removed.
*/
@ResponseBody
@PatchMapping(path = "/{uid}", consumes = "application/json-patch+json")
public WebMessage patchObject(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
WebOptions options = new WebOptions(rpParameters);
List<T> entities = getEntity(pvUid, options);
if (entities.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
final T persistedObject = entities.get(0);
if (!aclService.canUpdate(currentUser, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
manager.resetNonOwnerProperties(persistedObject);
prePatchEntity(persistedObject);
final JsonPatch patch = jsonMapper.readValue(request.getInputStream(), JsonPatch.class);
final T patchedObject = jsonPatchManager.apply(patch, persistedObject);
// we don't allow changing IDs
((BaseIdentifiableObject) patchedObject).setId(persistedObject.getId());
// we don't allow changing UIDs
((BaseIdentifiableObject) patchedObject).setUid(persistedObject.getUid());
// Only supports new Sharing format
((BaseIdentifiableObject) patchedObject).clearLegacySharingCollections();
prePatchEntity(persistedObject, patchedObject);
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
if (!parameterValuesMap.containsKey("importReportMode")) {
parameterValuesMap.put("importReportMode", Collections.singletonList("ERRORS_NOT_OWNER"));
}
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(patchedObject);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postPatchEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
Aggregations