Search in sources :

Example 1 with Transform

use of org.hisp.dhis.schema.annotation.Gist.Transform in project dhis2-core by dhis2.

the class GistValidator method validateField.

private void validateField(Field f, RelativePropertyContext context) {
    String path = f.getPropertyPath();
    if (Field.REFS_PATH.equals(path) || f.isAttribute()) {
        return;
    }
    Property field = context.resolveMandatory(path);
    if (!isNonNestedPath(path)) {
        List<Property> pathElements = context.resolvePath(path);
        Property head = pathElements.get(0);
        if (head.isCollection() && head.isPersisted()) {
            throw createIllegalProperty(field, "Property `%s` computes to many values and therefore cannot be used as a field.");
        }
    }
    Transform transformation = f.getTransformation();
    String transArgs = f.getTransformationArgument();
    if (transformation == Transform.PLUCK && transArgs != null) {
        Property plucked = context.switchedTo(getBaseType(field)).resolveMandatory(transArgs);
        if (!plucked.isPersisted()) {
            throw createIllegalProperty(plucked, "Property `%s` cannot be plucked as it is not a persistent field.");
        }
    }
    if (transformation == Transform.FROM) {
        validateFromTransformation(context, field, transArgs);
    }
    if (!field.isReadable()) {
        throw createNoReadAccess(f, null);
    }
    validateFieldAccess(f, context);
}
Also used : Transform(org.hisp.dhis.schema.annotation.Gist.Transform) Property(org.hisp.dhis.schema.Property)

Example 2 with Transform

use of org.hisp.dhis.schema.annotation.Gist.Transform in project dhis2-core by dhis2.

the class GistBuilder method createCollectionFieldHQL.

private String createCollectionFieldHQL(int index, Field field) {
    String path = field.getPropertyPath();
    Property property = context.resolveMandatory(path);
    String endpointRoot = getSameParentEndpointRoot(path);
    if (endpointRoot != null && query.isReferences()) {
        int idFieldIndex = getSameParentFieldIndex(path, ID_PROPERTY);
        int refIndex = fieldIndexByPath.get(Field.REFS_PATH);
        addTransformer(row -> addEndpointURL(row, refIndex, field, isNullOrEmpty(row[index]) ? null : toEndpointURL(endpointRoot, row[idFieldIndex], property)));
    }
    Transform transform = field.getTransformation();
    switch(transform) {
        default:
        case AUTO:
        case NONE:
            return HQL_NULL;
        case SIZE:
            return createSizeTransformerHQL(index, field, property, "");
        case IS_EMPTY:
            return createSizeTransformerHQL(index, field, property, "=0");
        case IS_NOT_EMPTY:
            return createSizeTransformerHQL(index, field, property, ">0");
        case NOT_MEMBER:
            return createHasMemberTransformerHQL(index, field, property, "=0");
        case MEMBER:
            return createHasMemberTransformerHQL(index, field, property, ">0");
        case ID_OBJECTS:
            addTransformer(row -> row[index] = toIdObjects(row[index]));
            return createIdsTransformerHQL(index, field, property);
        case IDS:
            return createIdsTransformerHQL(index, field, property);
        case PLUCK:
            return createPluckTransformerHQL(index, field, property);
    }
}
Also used : Transform(org.hisp.dhis.schema.annotation.Gist.Transform) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) GistLogic.isAccessProperty(org.hisp.dhis.gist.GistLogic.isAccessProperty) Property(org.hisp.dhis.schema.Property) GistLogic.isHrefProperty(org.hisp.dhis.gist.GistLogic.isHrefProperty)

Aggregations

Property (org.hisp.dhis.schema.Property)2 Transform (org.hisp.dhis.schema.annotation.Gist.Transform)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 GistLogic.isAccessProperty (org.hisp.dhis.gist.GistLogic.isAccessProperty)1 GistLogic.isHrefProperty (org.hisp.dhis.gist.GistLogic.isHrefProperty)1