use of io.crnk.core.engine.registry.RegistryEntry 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.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ApprovalManager method requestApproval.
public <T> T requestApproval(T entity, HttpMethod method) {
RegistryEntry entry = moduleRegistry.getResourceRegistry().getEntry(entity.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
Object id = resourceInformation.getId(entity);
ApprovalProcessInstance resource = newApprovalProcessInstance(entity.getClass());
resource.setResourceType(resourceInformation.getResourceType());
resource.setResourceId(id.toString());
resource.setNewValues(approvalMapper.mapValues(entity));
T currentEntity = entity;
if (method != HttpMethod.POST) {
// you may need additional logic here, like detaching entities from an entity manager
// in case of entities, like detaching from entity manager
currentEntity = (T) get(entry, id.toString());
PreconditionUtil.assertFalse("posted resource must not be managed", currentEntity == entity);
if (currentEntity != null) {
resource.setPreviousValues(approvalMapper.mapValues(currentEntity));
}
}
Map<String, Object> processVariables = resourceMapper.mapToVariables(resource);
runtimeService.startProcessInstanceByKey("scheduleChange", processVariables);
return currentEntity;
}
use of io.crnk.core.engine.registry.RegistryEntry 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.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class CrnkFeature method registerActionRepositories.
/**
* All repositories with JAX-RS action need to be registered with JAX-RS as singletons.
*
* @param context of jaxrs
* @param boot of crnk
*/
private void registerActionRepositories(FeatureContext context, CrnkBoot boot) {
ResourceRegistry resourceRegistry = boot.getResourceRegistry();
Collection<RegistryEntry> registryEntries = resourceRegistry.getResources();
for (RegistryEntry registryEntry : registryEntries) {
ResourceRepositoryInformation repositoryInformation = registryEntry.getRepositoryInformation();
if (repositoryInformation != null && !repositoryInformation.getActions().isEmpty()) {
ResourceRepositoryAdapter<?, Serializable> repositoryAdapter = registryEntry.getResourceRepository(null);
Object resourceRepository = repositoryAdapter.getResourceRepository();
context.register(resourceRepository);
}
}
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class SecurityModule method toType.
private <T> String toType(Class<T> resourceClass) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntryForClass(resourceClass);
if (entry == null) {
throw new ResourceNotFoundException("resource type not found: " + resourceClass.getName());
}
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
Aggregations