Search in sources :

Example 91 with ImportReport

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);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 92 with ImportReport

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);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) BulkPatchParameters(org.hisp.dhis.jsonpatch.BulkPatchParameters) BulkJsonPatches(org.hisp.dhis.jsonpatch.BulkJsonPatches) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 93 with 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();
}
Also used : MetadataProposal(org.hisp.dhis.metadata.MetadataProposal) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Schema(org.hisp.dhis.schema.Schema) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 94 with ImportReport

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;
}
Also used : RestoreOptions(org.hisp.dhis.security.RestoreOptions) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)87 Test (org.junit.jupiter.api.Test)52 List (java.util.List)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)37 ClassPathResource (org.springframework.core.io.ClassPathResource)37 User (org.hisp.dhis.user.User)34 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)33 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)32 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11 IOException (java.io.IOException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 CsvImportOptions (org.hisp.dhis.dxf2.csv.CsvImportOptions)9 InputStream (java.io.InputStream)8 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 UserService (org.hisp.dhis.user.UserService)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8