Search in sources :

Example 21 with ObjectReport

use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method checkUniqueness.

private TypeReport checkUniqueness(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> errorReports = new ArrayList<>();
        if (User.class.isInstance(object)) {
            User user = (User) object;
            errorReports.addAll(checkUniqueness(User.class, user, preheat, identifier));
            errorReports.addAll(checkUniqueness(UserCredentials.class, user.getUserCredentials(), preheat, identifier));
        } else {
            errorReports = checkUniqueness(klass, object, preheat, identifier);
        }
        if (!errorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(errorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) User(org.hisp.dhis.user.User) TypeReport(org.hisp.dhis.feedback.TypeReport) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 22 with ObjectReport

use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.

the class AbstractCrudController method postXmlObject.

@RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" })
public void postXmlObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = currentUserService.getCurrentUser();
    if (!aclService.canCreate(user, getEntityClass())) {
        throw new CreateAccessDeniedException("You don't have the proper permissions to create this object.");
    }
    T parsed = deserializeXmlEntity(request, response);
    parsed.getTranslations().clear();
    preCreateEntity(parsed);
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.CREATE).addObject(parsed);
    ImportReport importReport = importService.importMetadata(params);
    ObjectReport objectReport = getObjectReport(importReport);
    WebMessage webMessage = WebMessageUtils.objectReport(objectReport);
    if (objectReport != null && webMessage.getStatus() == Status.OK) {
        String location = contextService.getApiPath() + getSchema().getRelativeApiEndpoint() + "/" + objectReport.getUid();
        webMessage.setHttpStatus(HttpStatus.CREATED);
        response.setHeader(ContextUtils.HEADER_LOCATION, location);
        T entity = manager.get(getEntityClass(), objectReport.getUid());
        postCreateEntity(entity);
    } else {
        webMessage.setStatus(Status.ERROR);
    }
    webMessageService.send(webMessage, response, request);
}
Also used : User(org.hisp.dhis.user.User) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) CreateAccessDeniedException(org.hisp.dhis.hibernate.exception.CreateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ObjectReport

use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.

the class AbstractCrudController method postJsonObject.

//--------------------------------------------------------------------------
// POST
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = currentUserService.getCurrentUser();
    if (!aclService.canCreate(user, getEntityClass())) {
        throw new CreateAccessDeniedException("You don't have the proper permissions to create this object.");
    }
    T parsed = deserializeJsonEntity(request, response);
    parsed.getTranslations().clear();
    preCreateEntity(parsed);
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.CREATE).addObject(parsed);
    ImportReport importReport = importService.importMetadata(params);
    ObjectReport objectReport = getObjectReport(importReport);
    WebMessage webMessage = WebMessageUtils.objectReport(objectReport);
    if (objectReport != null && webMessage.getStatus() == Status.OK) {
        String location = contextService.getApiPath() + getSchema().getRelativeApiEndpoint() + "/" + objectReport.getUid();
        webMessage.setHttpStatus(HttpStatus.CREATED);
        response.setHeader(ContextUtils.HEADER_LOCATION, location);
        T entity = manager.get(getEntityClass(), objectReport.getUid());
        postCreateEntity(entity);
    } else {
        webMessage.setStatus(Status.ERROR);
    }
    webMessageService.send(webMessage, response, request);
}
Also used : User(org.hisp.dhis.user.User) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) CreateAccessDeniedException(org.hisp.dhis.hibernate.exception.CreateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ObjectReport

use of org.hisp.dhis.feedback.ObjectReport 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) throws Exception {
    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) {
        securityService.sendRestoreMessage(user.getUserCredentials(), ContextUtils.getContextPath(request), restoreOptions);
    }
    return objectReport;
}
Also used : RestoreOptions(org.hisp.dhis.security.RestoreOptions) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 25 with ObjectReport

use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.

the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesUnique.

@Test
public void testValidateMetadataAttributeValuesUnique() throws IOException {
    defaultSetupWithAttributes();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_unique_attributes.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    List<ObjectReport> objectReports = validationReport.getObjectReports(DataElement.class);
    assertFalse(objectReports.isEmpty());
    assertEquals(2, validationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E4009).size());
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ObjectReport (org.hisp.dhis.feedback.ObjectReport)27 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)20 ErrorReport (org.hisp.dhis.feedback.ErrorReport)16 TypeReport (org.hisp.dhis.feedback.TypeReport)16 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)13 List (java.util.List)7 User (org.hisp.dhis.user.User)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)6 Test (org.junit.Test)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 ArrayList (java.util.ArrayList)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)3 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HashMap (java.util.HashMap)2 DeletedObjectQuery (org.hisp.dhis.deletedobject.DeletedObjectQuery)2 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 ErrorCode (org.hisp.dhis.feedback.ErrorCode)2 CreateAccessDeniedException (org.hisp.dhis.hibernate.exception.CreateAccessDeniedException)2