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));
}
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));
}
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));
}
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();
}
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);
}
Aggregations