use of org.forgerock.util.query.QueryFilter in project OpenAM by OpenRock.
the class ApplicationV1Filter method findOrCreateResourceType.
/**
* Attempts to first find a resource type that has the same set of
* actions and resources. If none is found a new resource type is created.
*
* @param actions
* the map of resource type actions
* @param resources
* the set of resource type patterns
* @param context
* the filter chain context
* @param request
* the create request
*
* @return a resource type that matches the passed actions and resources
*
* @throws EntitlementException
* should some error occur finding or creating a resource type
*/
private ResourceType findOrCreateResourceType(final Map<String, Boolean> actions, Set<String> resources, final Context context, CreateRequest request) throws EntitlementException {
final Subject callingSubject = contextHelper.getSubject(context);
final String realm = contextHelper.getRealm(context);
final Set<QueryFilter<SmsAttribute>> actionFilters = transformSet(actions.entrySet(), new ActionsToQuery());
final Set<QueryFilter<SmsAttribute>> patternFilters = transformSet(resources, new ResourcesToQuery());
final Set<ResourceType> resourceTypes = resourceTypeService.getResourceTypes(QueryFilter.and(QueryFilter.and(actionFilters), QueryFilter.and(patternFilters)), callingSubject, realm);
if (!resourceTypes.isEmpty()) {
// Some matching resource types have been found, return the first one.
return resourceTypes.iterator().next();
}
final String resourceTypeName = generateResourceTypeName(request);
final ResourceType resourceType = ResourceType.builder().setName(resourceTypeName).setActions(actions).setPatterns(resources).setDescription("Generated resource type").generateUUID().build();
// Create and return new resource type.
return resourceTypeService.saveResourceType(callingSubject, realm, resourceType);
}
Aggregations