Search in sources :

Example 11 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class OperationsModule method enrichTypeIdInformation.

private void enrichTypeIdInformation(List<Operation> operations) {
    ResourceRegistry resourceRegistry = moduleContext.getResourceRegistry();
    for (Operation operation : operations) {
        if (operation.getOp().equalsIgnoreCase(HttpMethod.DELETE.toString())) {
            String path = OperationParameterUtils.parsePath(operation.getPath());
            JsonPath jsonPath = (new PathBuilder(resourceRegistry)).build(path);
            Resource resource = new Resource();
            resource.setType(jsonPath.getResourceType());
            resource.setId(jsonPath.getIds().getIds().get(0));
            operation.setValue(resource);
        }
    }
}
Also used : PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) Resource(io.crnk.core.engine.document.Resource) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) OrderedOperation(io.crnk.operations.server.order.OrderedOperation) Operation(io.crnk.operations.Operation) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath)

Example 12 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class RepositoryRequestSpecImpl method getResponseResourceInformation.

@Override
public ResourceInformation getResponseResourceInformation() {
    if (relationshipField != null) {
        String oppositeResourceType = relationshipField.getOppositeResourceType();
        ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
        RegistryEntry entry = resourceRegistry.getEntry(oppositeResourceType);
        return entry.getResourceInformation();
    }
    return owningResourceInformation;
}
Also used : ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 13 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class HttpRequestProcessorImpl method getRequestedResource.

private ResourceInformation getRequestedResource(JsonPath jsonPath) {
    ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
    RegistryEntry registryEntry = resourceRegistry.getEntry(jsonPath.getResourceType());
    PreconditionUtil.assertNotNull("repository not found, that should have been catched earlier", registryEntry);
    String elementName = jsonPath.getElementName();
    if (elementName != null && !elementName.equals(jsonPath.getResourceType())) {
        ResourceField relationshipField = registryEntry.getResourceInformation().findRelationshipFieldByName(elementName);
        if (relationshipField == null) {
            throw new ResourceFieldNotFoundException(elementName);
        }
        String oppositeResourceType = relationshipField.getOppositeResourceType();
        return resourceRegistry.getEntry(oppositeResourceType).getResourceInformation();
    } else {
        return registryEntry.getResourceInformation();
    }
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldNotFoundException(io.crnk.core.exception.ResourceFieldNotFoundException) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 14 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class MetaModule method initRefreshListener.

private void initRefreshListener() {
    ResourceRegistry resourceRegistry = context.getResourceRegistry();
    resourceRegistry.addListener(new ResourceRegistryPartAdapter() {

        @Override
        public void onChanged(ResourceRegistryPartEvent event) {
            currentLookup = null;
        }
    });
}
Also used : ResourceRegistryPartEvent(io.crnk.core.engine.registry.ResourceRegistryPartEvent) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceRegistryPartAdapter(io.crnk.core.engine.registry.ResourceRegistryPartAdapter)

Example 15 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class DecoratorTest method testRelationshipRegistryAwareDecoration.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testRelationshipRegistryAwareDecoration() {
    RegistryAwareRelationshipRepository repository = Mockito.mock(RegistryAwareRelationshipRepository.class);
    RelationshipRepositoryDecoratorBase<Schedule, Long, Task, Long> decorator = new RelationshipRepositoryDecoratorBase() {
    };
    decorator.setDecoratedObject(repository);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    decorator.setResourceRegistry(resourceRegistry);
    Mockito.verify(repository, Mockito.times(1)).setResourceRegistry(Mockito.eq(resourceRegistry));
}
Also used : Task(io.crnk.core.mock.models.Task) RelationshipRepositoryDecoratorBase(io.crnk.core.repository.decorate.RelationshipRepositoryDecoratorBase) Schedule(io.crnk.core.mock.models.Schedule) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) Test(org.junit.Test)

Aggregations

ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)48 Test (org.junit.Test)25 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)21 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)19 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)17 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)15 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)10 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)4 ModuleRegistry (io.crnk.core.module.ModuleRegistry)4 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)4 Before (org.junit.Before)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FieldResourceGet (io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet)3 RelationshipsResourceGet (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet)3 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)3 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)2