Search in sources :

Example 1 with XXServiceResourceElementValue

use of org.apache.ranger.entity.XXServiceResourceElementValue in project ranger by apache.

the class TagDBStore method createResourceForServiceResource.

private void createResourceForServiceResource(Long resourceId, RangerServiceResource serviceResource) {
    String serviceName = serviceResource.getServiceName();
    XXService xService = daoManager.getXXService().findByName(serviceName);
    if (xService == null) {
        throw errorUtil.createRESTException("No Service found with name: " + serviceName, MessageEnums.ERROR_CREATING_OBJECT);
    }
    XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(xService.getType());
    if (xServiceDef == null) {
        throw errorUtil.createRESTException("No Service-Def found with ID: " + xService.getType(), MessageEnums.ERROR_CREATING_OBJECT);
    }
    Map<String, RangerPolicy.RangerPolicyResource> resElements = serviceResource.getResourceElements();
    for (Map.Entry<String, RangerPolicyResource> resElement : resElements.entrySet()) {
        XXResourceDef xResDef = daoManager.getXXResourceDef().findByNameAndServiceDefId(resElement.getKey(), xServiceDef.getId());
        if (xResDef == null) {
            LOG.error("TagDBStore.createResource: ResourceType is not valid [" + resElement.getKey() + "]");
            throw errorUtil.createRESTException("Resource Type is not valid [" + resElement.getKey() + "]", MessageEnums.DATA_NOT_FOUND);
        }
        RangerPolicyResource policyRes = resElement.getValue();
        XXServiceResourceElement resourceElement = new XXServiceResourceElement();
        resourceElement.setIsExcludes(policyRes.getIsExcludes());
        resourceElement.setIsRecursive(policyRes.getIsRecursive());
        resourceElement.setResDefId(xResDef.getId());
        resourceElement.setResourceId(resourceId);
        resourceElement = rangerAuditFields.populateAuditFieldsForCreate(resourceElement);
        resourceElement = daoManager.getXXServiceResourceElement().create(resourceElement);
        int sortOrder = 1;
        for (String resVal : policyRes.getValues()) {
            XXServiceResourceElementValue resourceElementValue = new XXServiceResourceElementValue();
            resourceElementValue.setResElementId(resourceElement.getId());
            resourceElementValue.setValue(resVal);
            resourceElementValue.setSortOrder(sortOrder);
            resourceElementValue = rangerAuditFields.populateAuditFieldsForCreate(resourceElementValue);
            resourceElementValue = daoManager.getXXServiceResourceElementValue().create(resourceElementValue);
            sortOrder++;
        }
    }
}
Also used : XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXService(org.apache.ranger.entity.XXService) HashMap(java.util.HashMap) XXTagResourceMap(org.apache.ranger.entity.XXTagResourceMap) Map(java.util.Map) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Example 2 with XXServiceResourceElementValue

use of org.apache.ranger.entity.XXServiceResourceElementValue in project ranger by apache.

the class TagDBStore method deleteResourceForServiceResource.

private void deleteResourceForServiceResource(Long resourceId) {
    List<XXServiceResourceElement> resElements = daoManager.getXXServiceResourceElement().findByResourceId(resourceId);
    if (CollectionUtils.isNotEmpty(resElements)) {
        for (XXServiceResourceElement resElement : resElements) {
            List<XXServiceResourceElementValue> elementValues = daoManager.getXXServiceResourceElementValue().findByResValueId(resElement.getId());
            if (CollectionUtils.isNotEmpty(elementValues)) {
                for (XXServiceResourceElementValue elementValue : elementValues) {
                    daoManager.getXXServiceResourceElementValue().remove(elementValue.getId());
                }
            }
            daoManager.getXXServiceResourceElement().remove(resElement.getId());
        }
    }
}
Also used : XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Aggregations

XXServiceResourceElement (org.apache.ranger.entity.XXServiceResourceElement)2 XXServiceResourceElementValue (org.apache.ranger.entity.XXServiceResourceElementValue)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XXResourceDef (org.apache.ranger.entity.XXResourceDef)1 XXService (org.apache.ranger.entity.XXService)1 XXServiceDef (org.apache.ranger.entity.XXServiceDef)1 XXTagResourceMap (org.apache.ranger.entity.XXTagResourceMap)1 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)1