Search in sources :

Example 1 with RegistryEntry

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 + "'");
    }
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 2 with RegistryEntry

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;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 3 with RegistryEntry

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 + "'");
    }
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 4 with RegistryEntry

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);
        }
    }
}
Also used : Serializable(java.io.Serializable) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 5 with RegistryEntry

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();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6