use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method buildResourceRepository.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ResourceEntry buildResourceRepository(ResourceInformation resourceInformation) {
resourceRepository.information().setResourceInformation(resourceInformation);
ResourceRepositoryInformation repositoryInformation = resourceRepository.information().build();
Object instance = resourceRepository.instance;
final Object decoratedRepository = decorateRepository(instance);
RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, instance.getClass()) {
@Override
public Object buildRepository() {
return decoratedRepository;
}
};
if (ClassUtils.getAnnotation(decoratedRepository.getClass(), JsonApiResourceRepository.class).isPresent()) {
return new AnnotatedResourceEntry(repositoryInstanceBuilder, repositoryInformation);
} else {
return new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
}
}
use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.
the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.
@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
// GIVEN
ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
Map relRepos = new HashMap<>();
relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
// THEN
expectedException.expect(ResourceFieldNotFoundException.class);
// WHEN
sut.getRelationshipRepository("users", null);
}
use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.
the class JaxrsModuleTest method testActionDetection.
@Test
public void testActionDetection() {
ResourceRepositoryInformation information = (ResourceRepositoryInformation) builder.build(TaskRepository.class, context);
Map<String, RepositoryAction> actions = information.getActions();
Assert.assertEquals(5, actions.size());
RepositoryAction action = actions.get("repositoryAction");
Assert.assertNotNull(actions.get("repositoryPostAction"));
Assert.assertNotNull(actions.get("repositoryDeleteAction"));
Assert.assertNotNull(actions.get("repositoryPutAction"));
Assert.assertNull(actions.get("notAnAction"));
Assert.assertNotNull(action);
Assert.assertEquals("repositoryAction", action.getName());
Assert.assertEquals(RepositoryActionType.REPOSITORY, action.getActionType());
Assert.assertEquals(RepositoryActionType.RESOURCE, actions.get("resourceAction").getActionType());
}
use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.
the class PathBuilderTest method prepare.
@Before
public void prepare() {
CrnkBoot boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
boot.boot();
pathBuilder = new PathBuilder(boot.getResourceRegistry());
RegistryEntry entry = boot.getResourceRegistry().findEntry(Task.class);
ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
repositoryInformation.getActions().put("someRepositoryAction", Mockito.mock(RepositoryAction.class));
repositoryInformation.getActions().put("someResourceAction", Mockito.mock(RepositoryAction.class));
}
use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.
the class ResourceMetaParitition method discoverElements.
@Override
public void discoverElements() {
ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
// enforce setup of meta data
Collection<RegistryEntry> entries = resourceRegistry.getResources();
for (RegistryEntry entry : entries) {
ResourceInformation resourceInformation = entry.getResourceInformation();
MetaResource metaResource = discoverResource(resourceInformation);
ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
ResourceRepositoryAdapter<?, Serializable> resourceRepository = entry.getResourceRepository();
if (resourceRepository != null) {
MetaResourceRepository repository = discoverRepository(repositoryInformation, metaResource, resourceRepository);
context.addElement(repository);
}
}
}
Aggregations