Search in sources :

Example 11 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ResourceRepositoryAdapter method findAll.

public JsonApiResponse findAll(QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @SuppressWarnings("rawtypes")
        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Object resources;
            if (isAnnotated) {
                resources = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findAll(queryAdapter);
            } else if (resourceRepository instanceof ResourceRepositoryV2) {
                QuerySpec querySpec = request.getQuerySpec(resourceInformation);
                resources = ((ResourceRepositoryV2) resourceRepository).findAll(querySpec);
            } else {
                resources = ((ResourceRepository) resourceRepository).findAll(request.getQueryParams());
            }
            return getResponse(resourceRepository, resources, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindAll(moduleRegistry, resourceInformation, queryAdapter);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRepository(io.crnk.legacy.repository.ResourceRepository)

Example 12 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ApprovalManagerTest method setup.

@Before
public void setup() {
    runtimeService = Mockito.mock(RuntimeService.class);
    TaskService taskService = Mockito.mock(TaskService.class);
    repositoryFacade = Mockito.mock(ResourceRepositoryV2.class);
    ApprovalMapper approvalMapper = new ApprovalMapper();
    ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());
    ResourceInformation information = Mockito.mock(ResourceInformation.class);
    registryEntry = Mockito.mock(RegistryEntry.class);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
    Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
    Mockito.when(information.getResourceType()).thenReturn("schedule");
    Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
    ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
    Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);
    originalResource = new Schedule();
    originalResource.setId(mockId);
    originalResource.setName("Jane");
    Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class))).thenReturn(originalResource);
    manager = new ApprovalManager();
    manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) TypeParser(io.crnk.core.engine.parser.TypeParser) RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) DefaultDateTimeMapper(io.crnk.activiti.mapper.DefaultDateTimeMapper) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ApprovalManager(io.crnk.activiti.example.approval.ApprovalManager) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec) ApprovalMapper(io.crnk.activiti.example.approval.ApprovalMapper) Before(org.junit.Before)

Example 13 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class ApprovalManager method save.

private void save(RegistryEntry entry, Object resource) {
    ResourceRepositoryV2 resourceRepository = entry.getResourceRepositoryFacade();
    resourceRepository.save(resource);
}
Also used : ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2)

Example 14 with ResourceRepositoryV2

use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.

the class CrnkClient method getRepositoryForInterface.

@SuppressWarnings("unchecked")
public <R extends ResourceRepositoryV2<?, ?>> R getRepositoryForInterface(Class<R> repositoryInterfaceClass) {
    init();
    RepositoryInformationProvider informationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    PreconditionUtil.assertTrue("no a valid repository interface", informationBuilder.accept(repositoryInterfaceClass));
    ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) informationBuilder.build(repositoryInterfaceClass, new DefaultRepositoryInformationProviderContext(moduleRegistry));
    Class<?> resourceClass = repositoryInformation.getResourceInformation().get().getResourceClass();
    Object actionStub = actionStubFactory != null ? actionStubFactory.createStub(repositoryInterfaceClass) : null;
    ResourceRepositoryV2<?, Serializable> repositoryStub = getQuerySpecRepository(resourceClass);
    ClassLoader classLoader = repositoryInterfaceClass.getClassLoader();
    InvocationHandler invocationHandler = new ClientStubInvocationHandler(repositoryInterfaceClass, repositoryStub, actionStub);
    return (R) Proxy.newProxyInstance(classLoader, new Class[] { repositoryInterfaceClass, ResourceRepositoryV2.class }, invocationHandler);
}
Also used : Serializable(java.io.Serializable) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ClientStubInvocationHandler(io.crnk.client.internal.ClientStubInvocationHandler) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider)

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