use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class QuerySpecAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
QuerySpec spec = new QuerySpec(Task.class);
spec.includeField(Arrays.asList("test"));
spec.includeRelation(Arrays.asList("relation"));
QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(spec, adapter.getQuerySpec());
TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
Assert.assertEquals(1, includedFieldsParams.getParams().size());
Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
Assert.assertEquals(1, includedRelationsParams.getParams().size());
Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class QuerySpecRepositoryTest method setup.
@Before
public void setup() {
TaskQuerySpecRepository.clear();
ProjectQuerySpecRepository.clear();
ScheduleRepositoryImpl.clear();
super.setup();
RegistryEntry taskEntry = resourceRegistry.getEntry(Task.class);
RegistryEntry projectEntry = resourceRegistry.getEntry(Project.class);
RegistryEntry scheduleEntry = resourceRegistry.getEntry(Schedule.class);
TaskQuerySpecRepository repo = (TaskQuerySpecRepository) taskEntry.getResourceRepository(null).getResourceRepository();
repo = Mockito.spy(repo);
scheduleAdapter = scheduleEntry.getResourceRepository(null);
projectAdapter = projectEntry.getResourceRepository(null);
taskAdapter = taskEntry.getResourceRepository(null);
projectRelAdapter = taskEntry.getRelationshipRepository("projects", null);
tasksRelAdapter = projectEntry.getRelationshipRepository("tasks", null);
}
use of io.crnk.core.engine.registry.RegistryEntry 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);
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ApprovalManager method approved.
public void approved(Execution execution) {
try {
approverThread.set(true);
Map<String, Object> variables = runtimeService.getVariables(execution.getId());
String resourceType = (String) variables.get("resourceType");
RegistryEntry registryEntry = moduleRegistry.getResourceRegistry().getEntry(resourceType);
ResourceInformation resourceInformation = registryEntry.getResourceInformation();
// fetch resource and changes
ApprovalProcessInstance processResource = newApprovalProcessInstance(resourceInformation.getResourceClass());
resourceMapper.mapFromVariables(processResource, variables);
Object resource = get(registryEntry, processResource.getResourceId());
// apply and save changes
approvalMapper.unmapValues(processResource.getNewValues(), resource);
save(registryEntry, resource);
LOGGER.debug("approval accepted: " + execution.getProcessInstanceId());
} finally {
approverThread.remove();
}
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ActivitiModule method getRepository.
private <T> ResourceRepositoryV2<T, String> getRepository(Class<T> resourceClass) {
ResourceRegistry resourceRegistry = moduleContext.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntry(resourceClass);
if (entry == null) {
throw new RepositoryNotFoundException(resourceClass.getName() + " not registered");
}
return entry.getResourceRepositoryFacade();
}
Aggregations