use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class AnyUtils method setValue.
/**
* Sets the value of the given anytype.
*
* @param partition to use to retrieve information
* @param dataObject the anytype for which the value is set.
* @param value the new value
*/
public static void setValue(MetaPartition partition, AnyTypeObject dataObject, Object value) {
MetaDataObject meta = (MetaDataObject) partition.getMeta(dataObject.getClass());
if (value == null) {
for (MetaAttribute attr : meta.getAttributes()) {
attr.setValue(dataObject, null);
}
} else {
boolean found = false;
for (MetaAttribute attr : meta.getAttributes()) {
if (attr.getName().equals(TYPE_ATTRIBUTE)) {
continue;
}
if (attr.getType().getImplementationClass().isAssignableFrom(value.getClass())) {
attr.setValue(dataObject, value);
found = true;
} else {
attr.setValue(dataObject, null);
}
}
if (!found) {
throw new IllegalStateException("cannot assign " + value + " to " + dataObject);
}
}
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class QueryBuilder method applySelectionSpec.
public Map<String, Integer> applySelectionSpec() {
MetaDataObject meta = query.getMeta();
Map<String, Integer> selectionBindings = new HashMap<>();
int index = 1;
List<IncludeFieldSpec> includedFields = query.getIncludedFields();
for (IncludeFieldSpec includedField : includedFields) {
MetaAttributePath path = meta.resolvePath(includedField.getAttributePath(), attributeFinder);
E attr = backend.getAttribute(path);
backend.addSelection(attr, path.toString());
selectionBindings.put(path.toString(), index++);
}
return selectionBindings;
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class QueryBuilder method applyFilterSpec.
protected void applyFilterSpec() {
QueryFilterBuilder<P, F> predicateBuilder = new QueryFilterBuilder<>(backend, attributeFinder);
MetaDataObject meta = query.getMeta();
List<FilterSpec> filters = query.getFilterSpecs();
List<P> predicates = predicateBuilder.filterSpecListToPredicateArray(meta, backend.getRoot(), filters);
if (predicates != null && !predicates.isEmpty()) {
backend.addPredicate(backend.and(predicates));
}
MetaAttribute parentAttr = query.getParentAttr();
if (parentAttr != null) {
MetaDataObject parentMeta = query.getParentMeta();
MetaKey primaryKey = parentMeta.getPrimaryKey();
if (primaryKey == null) {
throw new IllegalStateException("primary key not found for " + parentAttr.getId());
}
MetaAttribute primaryKeyAttr = primaryKey.getUniqueElement();
backend.addParentPredicate(primaryKeyAttr);
}
}
Aggregations