use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class ServiceUtil method toVXPolicy.
public VXPolicy toVXPolicy(RangerPolicy policy, RangerService service) {
if (policy == null || service == null || toAssetType(service.getType()) == null) {
return null;
}
VXPolicy ret = new VXPolicy();
rangerObjectToDataObject(policy, ret);
ret.setPolicyName(StringUtils.trim(policy.getName()));
ret.setDescription(policy.getDescription());
ret.setRepositoryName(policy.getService());
ret.setIsEnabled(policy.getIsEnabled() ? true : false);
ret.setRepositoryType(service.getType());
ret.setIsAuditEnabled(policy.getIsAuditEnabled());
if (policy.getVersion() != null) {
ret.setVersion(policy.getVersion().toString());
} else {
ret.setVersion(version);
}
for (Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) {
RangerPolicy.RangerPolicyResource res = e.getValue();
String resType = e.getKey();
String resString = getResourceString(res.getValues());
if ("path".equalsIgnoreCase(resType)) {
ret.setResourceName(resString);
ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? true : false);
} else if ("table".equalsIgnoreCase(resType)) {
ret.setTables(resString);
ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? toVxPolicyIncExc(RangerCommonEnums.POLICY_EXCLUSION) : toVxPolicyIncExc(RangerCommonEnums.POLICY_INCLUSION));
} else if ("column-family".equalsIgnoreCase(resType)) {
ret.setColumnFamilies(resString);
} else if ("column".equalsIgnoreCase(resType)) {
ret.setColumns(resString);
ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? toVxPolicyIncExc(RangerCommonEnums.POLICY_EXCLUSION) : toVxPolicyIncExc(RangerCommonEnums.POLICY_INCLUSION));
} else if ("database".equalsIgnoreCase(resType)) {
ret.setDatabases(resString);
} else if ("udf".equalsIgnoreCase(resType)) {
ret.setUdfs(resString);
} else if ("topology".equalsIgnoreCase(resType)) {
ret.setTopologies(resString);
} else if ("service".equalsIgnoreCase(resType)) {
ret.setServices(resString);
}
}
updateResourceName(ret);
List<VXPermMap> vXPermMapList = getVXPermMapList(policy);
List<VXPermObj> vXPermObjList = mapPermMapToPermObj(vXPermMapList);
ret.setPermMapList(vXPermObjList);
return ret;
}
Aggregations