use of io.crnk.legacy.internal.QueryParamsAdapter in project crnk-framework by crnk-project.
the class IncludeLookupSetter method setIncludedElements.
public void setIncludedElements(Document document, Object entity, QueryAdapter queryAdapter, DocumentMappingConfig mappingConfig) {
QueryAdapter inclusionQueryAdapter = queryAdapter;
if (!allowPagination && !(queryAdapter instanceof QueryParamsAdapter) && queryAdapter != null) {
// offset/limit cannot properly work for nested inclusions if becomes cyclic
inclusionQueryAdapter = queryAdapter.duplicate();
if (queryAdapter.getResourceInformation().getPagingBehavior() != null) {
inclusionQueryAdapter.setPagingSpec(queryAdapter.getResourceInformation().getPagingBehavior().createEmptyPagingSpec());
}
}
List<Object> entityList = DocumentMapperUtil.toList(entity);
List<Resource> dataList = DocumentMapperUtil.toList(document.getData().get());
Map<ResourceIdentifier, Resource> dataMap = new HashMap<>();
Map<ResourceIdentifier, Object> entityMap = new HashMap<>();
for (int i = 0; i < dataList.size(); i++) {
Resource dataElement = dataList.get(i);
ResourceIdentifier id = dataElement.toIdentifier();
entityMap.put(id, entityList.get(i));
dataMap.put(id, dataElement);
}
Map<ResourceIdentifier, Resource> resourceMap = new HashMap<>();
resourceMap.putAll(dataMap);
Set<ResourceIdentifier> inclusions = new HashSet<>();
PopulatedCache populatedCache = new PopulatedCache();
RepositoryMethodParameterProvider parameterProvider = mappingConfig.getParameterProvider();
Set<String> fieldsWithEnforcedIdSerialization = mappingConfig.getFieldsWithEnforcedIdSerialization();
ResourceMappingConfig resourceMappingConfig = mappingConfig.getResourceMapping();
ArrayList<ResourceField> stack = new ArrayList<>();
populate(dataList, inclusions, resourceMap, entityMap, stack, inclusionQueryAdapter, parameterProvider, fieldsWithEnforcedIdSerialization, populatedCache, resourceMappingConfig);
// no need to include resources included in the data section
inclusions.removeAll(dataMap.keySet());
// setup included section
ArrayList<Resource> included = new ArrayList<>();
for (ResourceIdentifier inclusionId : inclusions) {
Resource includedResource = resourceMap.get(inclusionId);
PreconditionUtil.assertNotNull("resource not found", includedResource);
included.add(includedResource);
}
Collections.sort(included);
LOGGER.debug("Extracted included resources {}", included.toString());
document.setIncluded(included);
}
use of io.crnk.legacy.internal.QueryParamsAdapter in project crnk-framework by crnk-project.
the class QueryParamsAdapterTest method testGetNonExistingResourceClass.
@Test(expected = IllegalStateException.class)
public void testGetNonExistingResourceClass() {
QueryParams params = new QueryParams();
QueryParamsAdapter adapter = new QueryParamsAdapter(params);
adapter.getResourceInformation();
}
use of io.crnk.legacy.internal.QueryParamsAdapter in project crnk-framework by crnk-project.
the class QuerySpecRepositoryTest method testCrudWithQueryParamsInput.
@Test
public void testCrudWithQueryParamsInput() {
Map<String, Set<String>> params = new HashMap<String, Set<String>>();
addParams(params, "sort[tasks][name]", "asc");
QueryParams queryParams = queryParamsBuilder.buildQueryParams(params);
QueryParamsAdapter queryAdapter = new QueryParamsAdapter(resourceRegistry.getEntry(Task.class).getResourceInformation(), queryParams, moduleRegistry);
checkCrud(queryAdapter);
}
use of io.crnk.legacy.internal.QueryParamsAdapter in project crnk-framework by crnk-project.
the class ResourceIdControllerTest method toQueryAdapter.
private QueryAdapter toQueryAdapter(QueryParams requestParams, Class resourceType) {
ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntry(resourceType);
ResourceInformation resourceInformation = entry.getResourceInformation();
return new QueryParamsAdapter(resourceInformation, requestParams, moduleRegistry);
}
use of io.crnk.legacy.internal.QueryParamsAdapter in project crnk-framework by crnk-project.
the class RepositoryAdapterTest method setUp.
@Before
public void setUp() throws Exception {
queryParams = new QueryParams();
queryAdapter = new QueryParamsAdapter(queryParams);
parameterFactory = new ParametersFactory(new NewInstanceRepositoryMethodParameterProvider());
}
Aggregations