use of io.crnk.core.engine.registry.ResourceRegistry 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);
}
}
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ConstraintViolationImplTest method setup.
@Before
public void setup() {
boot = new CrnkBoot();
boot.addModule(ValidationModule.create());
boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.validation.mock.repository"));
boot.boot();
errorData = Mockito.spy(new ErrorDataBuilder().setDetail("testMessage").addMetaField(ConstraintViolationExceptionMapper.META_RESOURCE_TYPE, "tasks").setSourcePointer("name").build());
ResourceRegistry resourceRegistry = boot.getResourceRegistry();
violation = ConstraintViolationImpl.fromError(resourceRegistry, errorData);
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ConstraintViolationExceptionMapper method getResourceId.
/**
* @param resource to get the id from
* @return id of the given resource
*/
protected String getResourceId(Object resource) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
ResourceField idField = resourceInformation.getIdField();
Object id = idField.getAccessor().getValue(resource);
if (id != null) {
return id.toString();
}
return null;
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class OffsetLimitPagingBehaviorTest method testBuild.
@Test
public void testBuild() {
PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
QuerySpec spec = new QuerySpec(Task.class);
QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
querySpecAdapter.setPagingSpec(pagingSpec);
PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
pagedMetaInformation.setTotalResourceCount(30L);
ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
for (int i = 0; i < 30; i++) {
resourceList.add(new Task());
}
PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
assertNull(pagedLinksInformation.getPrev());
assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method setup.
@Before
public void setup() {
requestContextProvider = new HttpRequestContextProvider();
filter = Mockito.mock(ResourceFilter.class);
filters.add(filter);
resourceInformation = Mockito.mock(ResourceInformation.class);
resourceField = Mockito.mock(ResourceField.class);
resourceRegistry = Mockito.mock(ResourceRegistry.class);
directory = new ResourceFilterDirectoryImpl(filters, requestContextProvider, resourceRegistry);
}
Aggregations