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