Search in sources :

Example 1 with ResourceRepositoryV2

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 + "'");
    }
}
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 ResourceRepositoryV2

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);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 3 with ResourceRepositoryV2

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();
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2)

Example 4 with ResourceRepositoryV2

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 + "'");
    }
}
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 5 with ResourceRepositoryV2

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;
}
Also used : ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) MetaDataObject(io.crnk.meta.model.MetaDataObject) RepositoryAction(io.crnk.core.engine.information.repository.RepositoryAction)

Aggregations

ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)14 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)5 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)4 ResourceRepository (io.crnk.legacy.repository.ResourceRepository)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3 Serializable (java.io.Serializable)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2 ResourceList (io.crnk.core.resource.list.ResourceList)2 ApprovalManager (io.crnk.activiti.example.approval.ApprovalManager)1 ApprovalMapper (io.crnk.activiti.example.approval.ApprovalMapper)1 ActivitiResourceMapper (io.crnk.activiti.mapper.ActivitiResourceMapper)1 DefaultDateTimeMapper (io.crnk.activiti.mapper.DefaultDateTimeMapper)1 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 RepositoryAction (io.crnk.core.engine.information.repository.RepositoryAction)1 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1