Search in sources :

Example 81 with Property

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

the class DefaultJpaQueryParser method getProperty.

@Override
public Property getProperty(Schema schema, String path) throws QueryParserException {
    String[] paths = path.split("\\.");
    Schema currentSchema = schema;
    Property currentProperty = null;
    for (int i = 0; i < paths.length; i++) {
        if (!currentSchema.haveProperty(paths[i])) {
            return null;
        }
        currentProperty = currentSchema.getProperty(paths[i]);
        if (currentProperty == null) {
            throw new QueryParserException("Unknown path property: " + paths[i] + " (" + path + ")");
        }
        if ((currentProperty.isSimple() && !currentProperty.isCollection()) && i != (paths.length - 1)) {
            throw new QueryParserException("Simple type was found before finished parsing path expression, please check your path string.");
        }
        if (currentProperty.isCollection()) {
            currentSchema = schemaService.getDynamicSchema(currentProperty.getItemKlass());
        } else {
            currentSchema = schemaService.getDynamicSchema(currentProperty.getKlass());
        }
    }
    return currentProperty;
}
Also used : Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property)

Example 82 with Property

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

the class InMemoryQueryEngine method getValue.

@SuppressWarnings("unchecked")
private Object getValue(Query query, Object object, String path) {
    String[] paths = path.split("\\.");
    Schema currentSchema = query.getSchema();
    if (path.contains("access") && query.getSchema().isIdentifiableObject()) {
        ((BaseIdentifiableObject) object).setAccess(aclService.getAccess((T) object, query.getUser()));
    }
    for (int i = 0; i < paths.length; i++) {
        Property property = currentSchema.getProperty(paths[i]);
        if (property == null) {
            throw new QueryException("No property found for path " + path);
        }
        if (property.isCollection()) {
            currentSchema = schemaService.getDynamicSchema(property.getItemKlass());
        } else {
            currentSchema = schemaService.getDynamicSchema(property.getKlass());
        }
        object = collect(object, property);
        if (path.contains("access") && property.isIdentifiableObject()) {
            if (property.isCollection()) {
                for (Object item : ((Collection<?>) object)) {
                    ((BaseIdentifiableObject) item).setAccess(aclService.getAccess((T) item, query.getUser()));
                }
            } else {
                ((BaseIdentifiableObject) object).setAccess(aclService.getAccess((T) object, query.getUser()));
            }
        }
        if (i == (paths.length - 1)) {
            if (property.isCollection()) {
                return Lists.newArrayList(object);
            }
            return object;
        }
    }
    throw new QueryException("No values found for path " + path);
}
Also used : BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Schema(org.hisp.dhis.schema.Schema) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Property(org.hisp.dhis.schema.Property)

Example 83 with Property

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

the class DefaultJobConfigurationService method getJobParameters.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * Returns a list of job parameters for the given job type.
 *
 * @param jobType the {@link JobType}.
 * @return a list of {@link Property}.
 */
private List<Property> getJobParameters(JobType jobType) {
    List<Property> jobParameters = new ArrayList<>();
    Class<?> paramsType = jobType.getJobParameters();
    if (paramsType == null) {
        return jobParameters;
    }
    final Set<PropertyDescriptor> properties = Stream.of(PropertyUtils.getPropertyDescriptors(paramsType)).filter(pd -> pd.getReadMethod() != null && pd.getWriteMethod() != null).collect(Collectors.toSet());
    for (Field field : paramsType.getDeclaredFields()) {
        PropertyDescriptor descriptor = properties.stream().filter(pd -> pd.getName().equals(field.getName())).findFirst().orElse(null);
        if (isProperty(field, descriptor)) {
            jobParameters.add(getProperty(jobType, paramsType, field));
        }
    }
    return jobParameters;
}
Also used : JobType.values(org.hisp.dhis.scheduling.JobType.values) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) PropertyUtils(org.apache.commons.beanutils.PropertyUtils) EmbeddedObject(org.hisp.dhis.common.EmbeddedObject) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Property(org.hisp.dhis.schema.Property) Maps(com.google.common.collect.Maps) Primitives(com.google.common.primitives.Primitives) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PropertyDescriptor(java.beans.PropertyDescriptor) IdentifiableObjectStore(org.hisp.dhis.common.IdentifiableObjectStore) TextUtils(org.hisp.dhis.commons.util.TextUtils) Transactional(org.springframework.transaction.annotation.Transactional) Field(java.lang.reflect.Field) PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Property(org.hisp.dhis.schema.Property)

Example 84 with Property

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

the class SchemaToDataFetcherTest method createUniqueProperty.

public Property createUniqueProperty(Class<?> klazz, String name, boolean simple, boolean persisted) {
    Property property = createProperty(klazz, name, simple, persisted);
    property.setUnique(true);
    return property;
}
Also used : Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(org.hisp.dhis.schema.Property)

Example 85 with Property

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

the class SchemaToDataFetcherTest method createProperty.

private Property createProperty(Class<?> klazz, String name, boolean simple, boolean persisted) {
    Property property = new Property(klazz);
    property.setName(name);
    property.setFieldName(name);
    property.setSimple(simple);
    property.setOwner(true);
    property.setPersisted(persisted);
    return property;
}
Also used : Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(org.hisp.dhis.schema.Property)

Aggregations

Property (org.hisp.dhis.schema.Property)126 Schema (org.hisp.dhis.schema.Schema)69 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)26 Collection (java.util.Collection)21 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)21 List (java.util.List)20 Map (java.util.Map)16 Test (org.junit.jupiter.api.Test)16 Attribute (org.hisp.dhis.attribute.Attribute)14 ReflectionUtils (org.hisp.dhis.system.util.ReflectionUtils)14 Collectors (java.util.stream.Collectors)13 User (org.hisp.dhis.user.User)13 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)12 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)12 SimpleNode (org.hisp.dhis.node.types.SimpleNode)12 Query (org.hisp.dhis.query.Query)12 SchemaService (org.hisp.dhis.schema.SchemaService)12 Transactional (org.springframework.transaction.annotation.Transactional)12