Search in sources :

Example 21 with RegistryEntry

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

the class SetOwnerStrategy method addRelations.

@Override
public void addRelations(T source, Iterable<J> targetIds, String fieldName) {
    RegistryEntry sourceEntry = context.getSourceEntry();
    ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
    ResourceInformation sourceInformation = sourceEntry.getResourceInformation();
    ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
    if (field.hasIdField()) {
        Collection currentIds = (Collection) field.getIdAccessor().getValue(source);
        currentIds.addAll((Collection) targetIds);
    } else {
        RegistryEntry targetEntry = context.getTargetEntry(field);
        Iterable<D> targets = context.findAll(targetEntry, targetIds);
        @SuppressWarnings("unchecked") Collection<D> currentTargets = getOrCreateCollection(source, field);
        for (D target : targets) {
            currentTargets.add(target);
        }
    }
    sourceAdapter.update(source, context.createSaveQueryAdapter(fieldName));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Collection(java.util.Collection) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 22 with RegistryEntry

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

the class SetOwnerStrategy method setRelations.

@Override
public void setRelations(T source, Iterable<J> targetIds, String fieldName) {
    RegistryEntry sourceEntry = context.getSourceEntry();
    ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
    ResourceInformation sourceInformation = sourceEntry.getResourceInformation();
    ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
    if (field.hasIdField()) {
        field.getIdAccessor().setValue(source, targetIds);
    } else {
        RegistryEntry targetEntry = context.getTargetEntry(field);
        Iterable<D> targets = context.findAll(targetEntry, targetIds);
        field.getAccessor().setValue(source, targets);
    }
    sourceAdapter.update(source, context.createSaveQueryAdapter(fieldName));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 23 with RegistryEntry

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

the class SetOwnerStrategy method setRelation.

@Override
public void setRelation(T source, J targetId, String fieldName) {
    RegistryEntry sourceEntry = context.getSourceEntry();
    ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
    ResourceInformation sourceInformation = sourceEntry.getResourceInformation();
    ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
    if (field.hasIdField()) {
        field.getIdAccessor().setValue(source, targetId);
    } else {
        RegistryEntry targetEntry = context.getTargetEntry(field);
        D target = context.findOne(targetEntry, targetId);
        field.getAccessor().setValue(source, target);
    }
    sourceAdapter.update(source, context.createSaveQueryAdapter(fieldName));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 24 with RegistryEntry

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

the class DefaultQuerySpecConverter method getResourceClass.

private Class<?> getResourceClass(String resourceType) {
    RegistryEntry registryEntry = resourceRegistry.getEntry(resourceType);
    if (registryEntry == null) {
        throw new IllegalArgumentException("resourceType " + resourceType + " not found");
    }
    ResourceInformation resourceInformation = registryEntry.getResourceInformation();
    return resourceInformation.getResourceClass();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 25 with RegistryEntry

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

the class MetaFilteringTest method checkTotalResourceFiltering.

@Test
public void checkTotalResourceFiltering() throws IOException {
    RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    Mockito.when(filter.filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
    checkResourceMeta(false, false, false, false);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) HttpMethod(io.crnk.core.engine.http.HttpMethod) Test(org.junit.Test)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6