use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DocumentMapperUtil method getIdString.
public String getIdString(Object entity, ResourceInformation resourceInformation) {
ResourceField idField = resourceInformation.getIdField();
Object sourceId = idField.getAccessor().getValue(entity);
return resourceInformation.toIdString(sourceId);
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DocumentMapperUtil method computeRequestedFields.
private static List<ResourceField> computeRequestedFields(IncludedFieldsParams includedFields, boolean relation, QueryAdapter queryAdapter, ResourceInformation resourceInformation, List<ResourceField> fields) {
Set<String> includedFieldNames = includedFields.getParams();
if (relation) {
// for relations consider both "include" and "fields"
TypedParams<IncludedRelationsParams> includedRelationsSet = queryAdapter.getIncludedRelations();
IncludedRelationsParams includedRelations = includedRelationsSet != null ? includedRelationsSet.getParams().get(resourceInformation.getResourceType()) : null;
if (includedRelations != null) {
includedFieldNames = new HashSet<>(includedFieldNames);
for (Inclusion include : includedRelations.getParams()) {
includedFieldNames.add(include.getPath());
}
}
}
List<ResourceField> results = new ArrayList<>();
for (ResourceField field : fields) {
if (includedFieldNames.contains(field.getJsonName())) {
results.add(field);
}
}
return results;
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class IncludeLookupUtil method toPath.
private String toPath(List<ResourceField> fieldPath, int offset) {
StringBuilder builder = new StringBuilder();
for (int i = offset; i < fieldPath.size(); i++) {
ResourceField field = fieldPath.get(i);
if (builder.length() > 0) {
builder.append(".");
}
builder.append(field.getJsonName());
}
return builder.toString();
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class IncludeLookupUtil method toPathList.
private List<String> toPathList(List<ResourceField> fieldPath, int offset) {
List<String> builder = new ArrayList<>();
List<String> result = builder;
for (int i = offset; i < fieldPath.size(); i++) {
ResourceField field = fieldPath.get(i);
result.add(field.getJsonName());
}
return result;
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class IncludeLookupUtil method getRelationshipFields.
public Set<ResourceField> getRelationshipFields(Collection<Resource> resources) {
Set<ResourceField> fields = new HashSet<>();
Set<String> processedTypes = new HashSet<>();
for (Resource resource : resources) {
process(resource.getType(), processedTypes, fields);
}
return fields;
}
Aggregations