Search in sources :

Example 66 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class SchemaController method getSchema.

@RequestMapping(value = "/{type}", method = RequestMethod.GET)
@ResponseBody
public RootNode getSchema(@PathVariable String type) {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add("*");
    }
    Schema schema = getSchemaFromType(type);
    if (schema != null) {
        linkService.generateSchemaLinks(schema);
        CollectionNode collectionNode = fieldFilterService.filter(Schema.class, Collections.singletonList(schema), fields);
        return NodeUtils.createRootNode(collectionNode.getChildren().get(0));
    }
    throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Type " + type + " does not exist.");
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Schema(org.hisp.dhis.schema.Schema) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 67 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class DefaultAclService method canUpdate.

@Override
public boolean canUpdate(User user, IdentifiableObject object) {
    Schema schema = schemaService.getSchema(object.getClass());
    if (schema == null || haveOverrideAuthority(user)) {
        return true;
    }
    List<String> anyAuthorities = schema.getAuthorityByType(AuthorityType.UPDATE);
    if (anyAuthorities.isEmpty()) {
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE));
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PRIVATE));
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PUBLIC));
    }
    if (canAccess(user, anyAuthorities)) {
        if (!schema.isShareable()) {
            return true;
        }
        if (checkSharingAccess(user, object) && (checkUser(user, object) || checkSharingPermission(user, object, AccessStringHelper.Permission.WRITE))) {
            return true;
        }
    } else if (schema.isImplicitPrivateAuthority() && checkUser(user, object) && checkSharingAccess(user, object)) {
        return true;
    }
    return false;
}
Also used : Schema(org.hisp.dhis.schema.Schema)

Example 68 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class DefaultAclService method canDelete.

@Override
public boolean canDelete(User user, IdentifiableObject object) {
    Schema schema = schemaService.getSchema(object.getClass());
    if (schema == null || haveOverrideAuthority(user)) {
        return true;
    }
    List<String> anyAuthorities = schema.getAuthorityByType(AuthorityType.DELETE);
    if (anyAuthorities.isEmpty()) {
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE));
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PRIVATE));
        anyAuthorities.addAll(schema.getAuthorityByType(AuthorityType.CREATE_PUBLIC));
    }
    if (canAccess(user, anyAuthorities)) {
        if (!schema.isShareable()) {
            return true;
        }
        if (checkUser(user, object) || checkSharingPermission(user, object, AccessStringHelper.Permission.WRITE)) {
            return true;
        }
    } else if (schema.isImplicitPrivateAuthority() && checkUser(user, object)) {
        return true;
    }
    return false;
}
Also used : Schema(org.hisp.dhis.schema.Schema)

Example 69 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class ValidationCriteriaSchemaDescriptor method getSchema.

@Override
public Schema getSchema() {
    Schema schema = new Schema(ValidationCriteria.class, SINGULAR, PLURAL);
    schema.setOrder(1460);
    return schema;
}
Also used : Schema(org.hisp.dhis.schema.Schema)

Example 70 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class ValidationRuleGroupSchemaDescriptor method getSchema.

@Override
public Schema getSchema() {
    Schema schema = new Schema(ValidationRuleGroup.class, SINGULAR, PLURAL);
    schema.setRelativeApiEndpoint(API_ENDPOINT);
    schema.setOrder(1400);
    schema.getAuthorities().add(new Authority(AuthorityType.CREATE, Lists.newArrayList("F_VALIDATIONRULEGROUP_PUBLIC_ADD")));
    schema.getAuthorities().add(new Authority(AuthorityType.UPDATE, Lists.newArrayList("F_VALIDATIONRULEGROUP_PRIVATE_ADD")));
    schema.getAuthorities().add(new Authority(AuthorityType.DELETE, Lists.newArrayList("F_VALIDATIONRULEGROUP_DELETE")));
    return schema;
}
Also used : Authority(org.hisp.dhis.security.Authority) Schema(org.hisp.dhis.schema.Schema)

Aggregations

Schema (org.hisp.dhis.schema.Schema)149 Authority (org.hisp.dhis.security.Authority)65 Property (org.hisp.dhis.schema.Property)29 ArrayList (java.util.ArrayList)20 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)20 Test (org.junit.Test)16 Collection (java.util.Collection)14 List (java.util.List)13 HashMap (java.util.HashMap)12 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)12 Map (java.util.Map)10 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)10 User (org.hisp.dhis.user.User)10 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)9 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)9 UserCredentials (org.hisp.dhis.user.UserCredentials)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Log (org.apache.commons.logging.Log)8