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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations