use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportExportController method postJsonMetadata.
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postJsonMetadata(HttpServletRequest request) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
final Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objects = renderService.fromMetadata(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), RenderFormat.JSON);
params.setObjects(objects);
if (params.hasJobId()) {
return startAsyncMetadata(params);
}
ImportReport importReport = metadataImportService.importMetadata(params);
return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportExportController method bulkSharing.
@ResponseBody
@PatchMapping(value = "sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws IOException {
final BulkJsonPatches bulkJsonPatches = jsonMapper.readValue(request.getInputStream(), BulkJsonPatches.class);
BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatches(bulkJsonPatches, 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 importParams = metadataImportService.getParamsFromMap(parameterValuesMap);
importParams.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).setAtomicMode(atomic ? AtomicMode.ALL : AtomicMode.NONE).addObjects(patchedObjects);
ImportReport importReport = metadataImportService.importMetadata(importParams);
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.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataWorkflowController method acceptProposal.
@PostMapping(value = { "/{uid}/", "/{uid}" }, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage acceptProposal(@PathVariable("uid") String uid) throws NotFoundException {
MetadataProposal proposal = checkProposalExists(uid);
ImportReport report = service.accept(proposal);
if (report.getStatus() != Status.OK) {
return importReport(report);
}
if (proposal.getType() == MetadataProposalType.ADD) {
String objUid = report.getFirstObjectReport().getUid();
Schema schema = schemaService.getSchema(proposal.getTarget().getType());
return created(schema.getSingular() + " created").setLocation(schema.getRelativeApiEndpoint() + "/" + objUid);
}
return ok();
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class UserController method inviteUser.
/**
* Creates a user invitation and invites the user.
*
* @param user user object parsed from the POST request.
*/
private ObjectReport inviteUser(User user, User currentUser, HttpServletRequest request) {
RestoreOptions restoreOptions = user.getUsername() == null || user.getUsername().isEmpty() ? RestoreOptions.INVITE_WITH_USERNAME_CHOICE : RestoreOptions.INVITE_WITH_DEFINED_USERNAME;
securityService.prepareUserForInvite(user);
ImportReport importReport = createUser(user, currentUser);
ObjectReport objectReport = getObjectReport(importReport);
if (importReport.getStatus() == Status.OK && importReport.getStats().getCreated() == 1 && objectReport != null) {
securityService.sendRestoreOrInviteMessage(user, ContextUtils.getContextPath(request), restoreOptions);
log.info(String.format("An invite email was successfully sent to: %s", user.getEmail()));
}
return objectReport;
}
Aggregations