use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class SecurityModule method reconfigure.
/**
* Applies the new configuration to this module.
*/
public void reconfigure(SecurityConfig config) {
this.config = config;
LOGGER.debug("reconfiguring with {} rules", config.getRules().size());
Map<String, Map<String, ResourcePermission>> newPermissions = new HashMap<>();
for (SecurityRule rule : config.getRules()) {
String resourceType = rule.getResourceType();
if (resourceType == null) {
Class<?> resourceClass = rule.getResourceClass();
if (resourceClass != null) {
resourceType = toType(resourceClass);
}
}
if (resourceType == null) {
Collection<RegistryEntry> entries = context.getResourceRegistry().getResources();
for (RegistryEntry entry : entries) {
String entryResourceType = entry.getResourceInformation().getResourceType();
configureRule(newPermissions, entryResourceType, rule.getRole(), rule.getPermission());
}
} else {
configureRule(newPermissions, resourceType, rule.getRole(), rule.getPermission());
}
}
this.permissions = newPermissions;
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class QuerySpecAdapter method getResourceType.
private String getResourceType(QuerySpec spec) {
if (spec.getResourceType() != null) {
return spec.getResourceType();
}
RegistryEntry entry = resourceRegistry.getEntry(spec.getResourceClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class RelationshipRepositoryBase method setRelation.
@Override
public void setRelation(T source, J targetId, String fieldName) {
RegistryEntry sourceEntry = getSourceEntry();
ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
ResourceInformation sourceInformation = getSourceEntry().getResourceInformation();
ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
if (field.hasIdField()) {
field.getIdAccessor().setValue(source, targetId);
} else {
RegistryEntry targetEntry = getTargetEntry(field);
D target = getTarget(targetEntry, targetId);
field.getAccessor().setValue(source, target);
}
sourceAdapter.update(source, getSaveQueryAdapter(fieldName));
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class RelationshipRepositoryBase method addRelations.
@Override
public void addRelations(T source, Iterable<J> targetIds, String fieldName) {
RegistryEntry sourceEntry = getSourceEntry();
ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
ResourceInformation sourceInformation = getSourceEntry().getResourceInformation();
ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
if (field.hasIdField()) {
Collection currentIds = (Collection) field.getIdAccessor().getValue(source);
currentIds.addAll((Collection) targetIds);
} else {
RegistryEntry targetEntry = getTargetEntry(field);
Iterable<D> targets = getTargets(targetEntry, targetIds);
@SuppressWarnings("unchecked") Collection<D> currentTargets = getOrCreateCollection(source, fieldName);
for (D target : targets) {
currentTargets.add(target);
}
}
sourceAdapter.update(source, getSaveQueryAdapter(fieldName));
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class RelationshipRepositoryBase method findTargets.
@SuppressWarnings("unchecked")
public MultivaluedMap<I, D> findTargets(Iterable<I> sourceIds, String fieldName, QuerySpec querySpec) {
RegistryEntry sourceEntry = resourceRegistry.findEntry(sourceResourceClass);
ResourceInformation sourceInformation = sourceEntry.getResourceInformation();
ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
RegistryEntry targetEntry = getTargetEntry(field);
String oppositeName = getOppositeName(fieldName);
QuerySpec idQuerySpec = querySpec.duplicate();
idQuerySpec.addFilter(new FilterSpec(Arrays.asList(oppositeName, sourceInformation.getIdField().getUnderlyingName()), FilterOperator.EQ, sourceIds));
idQuerySpec.includeRelation(Arrays.asList(oppositeName));
ResourceRepositoryAdapter<D, J> targetAdapter = targetEntry.getResourceRepository();
JsonApiResponse response = targetAdapter.findAll(new QuerySpecAdapter(idQuerySpec, resourceRegistry));
List<D> results = (List<D>) response.getEntity();
MultivaluedMap<I, D> bulkResult = new MultivaluedMap<I, D>() {
@Override
protected List<D> newList() {
return new DefaultResourceList<>();
}
};
Set<I> sourceIdSet = new HashSet<>();
for (I sourceId : sourceIds) {
sourceIdSet.add(sourceId);
}
for (D result : results) {
handleTarget(bulkResult, result, sourceIdSet, oppositeName, sourceInformation);
}
return bulkResult;
}
Aggregations