use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class TaskRelationshipRepository method findOneTarget.
@Override
public T findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
if (relationshipName.equals(fieldName)) {
RegistryEntry taskEntry = resourceRegistry.getEntry(taskClass);
ResourceRepositoryV2 taskRepository = (ResourceRepositoryV2) taskEntry.getResourceRepository(null).getResourceRepository();
QuerySpec processQuerySpec = querySpec.duplicate();
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(PROCESS_INSTANCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(TASK_DEFINITION_KEY_FIELD), FilterOperator.EQ, taskDefinitionId));
ResourceList tasks = taskRepository.findAll(processQuerySpec);
PreconditionUtil.assertTrue("unique result expected", tasks.size() <= 1);
return tasks.isEmpty() ? null : (T) tasks.get(0);
} else {
throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
}
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class ApprovalManager method get.
private Object get(RegistryEntry entry, String idString) {
ResourceInformation resourceInformation = entry.getResourceInformation();
Object id = resourceInformation.parseIdString(idString);
ResourceRepositoryV2 resourceRepository = entry.getResourceRepositoryFacade();
QuerySpec querySpec = new QuerySpec(resourceInformation.getResourceType());
return resourceRepository.findOne((Serializable) id, querySpec);
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class CrnkClient method getRepositoryForType.
/**
* @param resourceClass repository class
* @return stub for the given resourceClass
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T, I extends Serializable> ResourceRepositoryV2<T, I> getRepositoryForType(Class<T> resourceClass) {
init();
RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
ResourceRepositoryAdapter repositoryAdapter = entry.getResourceRepository(null);
return (ResourceRepositoryV2<T, I>) repositoryAdapter.getResourceRepository();
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class ApprovalRelationshipRepository method findOneTarget.
@Override
public P findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
if (relationshipName.equals(fieldName)) {
RegistryEntry resourceEntry = resourceRegistry.getEntry(resourceClass);
RegistryEntry processEntry = resourceRegistry.getEntry(processInfoClass);
String resourceType = resourceEntry.getResourceInformation().getResourceType();
ResourceRepositoryV2 processRepository = (ResourceRepositoryV2) processEntry.getResourceRepository(null).getResourceRepository();
QuerySpec processQuerySpec = querySpec.duplicate();
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_TYPE_FIELD), FilterOperator.EQ, resourceType));
baseFilters.forEach(processQuerySpec::addFilter);
ResourceList list = processRepository.findAll(querySpec);
PreconditionUtil.assertTrue("unique result expected", list.size() <= 1);
return list.isEmpty() ? null : (P) list.get(0);
} else {
throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
}
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class ResourceMetaParitition method discoverRepository.
private MetaResourceRepository discoverRepository(ResourceRepositoryInformation repositoryInformation, MetaResource metaResource, ResourceRepositoryAdapter<?, Serializable> resourceRepository) {
MetaResourceRepository meta = new MetaResourceRepository();
meta.setResourceType(metaResource);
meta.setName(metaResource.getName() + "$repository");
meta.setId(metaResource.getId() + "$repository");
for (RepositoryAction action : repositoryInformation.getActions().values()) {
MetaResourceAction metaAction = new MetaResourceAction();
metaAction.setName(action.getName());
metaAction.setActionType(MetaResourceAction.MetaRepositoryActionType.valueOf(action.getActionType().toString()));
metaAction.setParent(meta, true);
}
// TODO avoid use of ResourceRepositoryAdapter by enriching ResourceRepositoryInformation
Object repository = resourceRepository.getResourceRepository();
if (repository instanceof ResourceRepositoryV2) {
setListInformationTypes(repository, meta);
}
return meta;
}
Aggregations