Search in sources :

Example 81 with ResourceField

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);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField)

Example 82 with ResourceField

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;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Inclusion(io.crnk.legacy.queryParams.include.Inclusion) ArrayList(java.util.ArrayList) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams)

Example 83 with ResourceField

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();
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField)

Example 84 with ResourceField

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;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ArrayList(java.util.ArrayList)

Example 85 with ResourceField

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;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Resource(io.crnk.core.engine.document.Resource) HashSet(java.util.HashSet)

Aggregations

ResourceField (io.crnk.core.engine.information.resource.ResourceField)109 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)75 Test (org.junit.Test)41 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)36 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)13 QuerySpec (io.crnk.core.queryspec.QuerySpec)11 ArrayList (java.util.ArrayList)9 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)8 Response (io.crnk.core.engine.dispatcher.Response)8 Resource (io.crnk.core.engine.document.Resource)8 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)8 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 HashSet (java.util.HashSet)8 Document (io.crnk.core.engine.document.Document)7 Task (io.crnk.core.mock.models.Task)7 Serializable (java.io.Serializable)7 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6