use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultCollectionService method validateUpdate.
private Property validateUpdate(IdentifiableObject object, String propertyName, String message) throws WebMessageException {
Schema schema = schemaService.getDynamicSchema(HibernateProxyUtils.getRealClass(object));
if (!aclService.canUpdate(currentUserService.getCurrentUser(), object)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
if (!schema.haveProperty(propertyName)) {
throw new WebMessageException(WebMessageUtils.notFound("Property " + propertyName + " does not exist on " + object.getClass().getName()));
}
Property property = schema.getProperty(propertyName);
if (!property.isCollection() || !property.isIdentifiableObject()) {
throw new WebMessageException(conflict(message));
}
return property;
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultCollectionService method delNonOwnedCollectionItems.
private void delNonOwnedCollectionItems(IdentifiableObject object, Property property, Collection<String> itemCodes, TypeReport report) {
Schema owningSchema = schemaService.getDynamicSchema(property.getItemKlass());
Property owningProperty = owningSchema.propertyByRole(property.getOwningRole());
updateCollectionItems(property, itemCodes, report, ErrorCode.E1109, item -> {
Collection<IdentifiableObject> collection = getCollection(item, owningProperty);
if (collection.contains(object)) {
validateAndThrowErrors(() -> schemaValidator.validateProperty(owningProperty, item));
collection.remove(object);
manager.update(item);
report.getStats().incDeleted();
} else {
report.getStats().incIgnored();
}
});
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultCollectionService method replaceCollectionItems.
@Override
@Transactional
public TypeReport replaceCollectionItems(IdentifiableObject object, String propertyName, Collection<? extends IdentifiableObject> objects) throws Exception {
Property property = validateUpdate(object, propertyName, "Only identifiable object collections can be replaced.");
TypeReport deletions = delCollectionItems(object, propertyName, getCollection(object, property));
TypeReport additions = addCollectionItems(object, propertyName, objects);
return deletions.mergeAllowEmpty(additions);
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultJobConfigurationService method getProperty.
private static Property getProperty(JobType jobType, Class<?> paramsType, Field field) {
Class<?> valueType = field.getType();
Property property = new Property(Primitives.wrap(valueType), null, null);
property.setName(field.getName());
property.setFieldName(TextUtils.getPrettyPropertyName(field.getName()));
try {
field.setAccessible(true);
property.setDefaultValue(field.get(jobType.getJobParameters().newInstance()));
} catch (IllegalAccessException | InstantiationException e) {
log.error("Fetching default value for JobParameters properties failed for property: " + field.getName(), e);
}
String relativeApiElements = jobType.getRelativeApiElements() != null ? jobType.getRelativeApiElements().get(field.getName()) : "";
if (relativeApiElements != null && !relativeApiElements.equals("")) {
property.setRelativeApiEndpoint(relativeApiElements);
}
if (Collection.class.isAssignableFrom(valueType)) {
return setPropertyIfCollection(property, field, paramsType);
}
if (valueType.isEnum()) {
property.setConstants(getConstants(valueType));
}
return property;
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class QueryUtils method convertOrderStrings.
/**
* Converts the specified string orders (e.g. <code>name:asc</code>) to
* order objects.
*
* @param orders the order strings that should be converted.
* @param schema the schema that should be used to perform the conversion.
* @return the converted order.
*/
@Nonnull
public static List<Order> convertOrderStrings(@Nullable Collection<String> orders, @Nonnull Schema schema) {
if (orders == null) {
return Collections.emptyList();
}
final Map<String, Order> result = new LinkedHashMap<>();
for (String o : orders) {
String[] split = o.split(":");
String direction = "asc";
if (split.length < 1) {
continue;
} else if (split.length == 2) {
direction = split[1].toLowerCase();
}
String propertyName = split[0];
Property property = schema.getProperty(propertyName);
if (result.containsKey(propertyName) || !schema.haveProperty(propertyName) || !validProperty(property) || !validDirection(direction)) {
continue;
}
result.put(propertyName, Order.from(direction, property));
}
return new ArrayList<>(result.values());
}
Aggregations