use of org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef in project ranger by apache.
the class TagDBStore method createTagAttributeDefs.
private List<XXTagAttributeDef> createTagAttributeDefs(Long tagDefId, List<RangerTagAttributeDef> tagAttrDefList) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagDBStore.createTagAttributeDefs(" + tagDefId + ", attributeDefCount=" + (tagAttrDefList == null ? 0 : tagAttrDefList.size()) + ")");
}
if (tagDefId == null) {
throw errorUtil.createRESTException("TagDBStore.createTagAttributeDefs(): Error creating tag-attr def. tagDefId can not be null.", MessageEnums.ERROR_CREATING_OBJECT);
}
List<XXTagAttributeDef> ret = new ArrayList<XXTagAttributeDef>();
if (CollectionUtils.isNotEmpty(tagAttrDefList)) {
for (RangerTagDef.RangerTagAttributeDef attrDef : tagAttrDefList) {
XXTagAttributeDef xAttrDef = new XXTagAttributeDef();
xAttrDef.setTagDefId(tagDefId);
xAttrDef.setName(attrDef.getName());
xAttrDef.setType(attrDef.getType());
xAttrDef = rangerAuditFields.populateAuditFieldsForCreate(xAttrDef);
xAttrDef = daoManager.getXXTagAttributeDef().create(xAttrDef);
ret.add(xAttrDef);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagDBStore.createTagAttributeDefs(" + tagDefId + ", attributeDefCount=" + (tagAttrDefList == null ? 0 : tagAttrDefList.size()) + "): retCount=" + ret.size());
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTags.
private static Map<String, ServiceTags> buildServiceTags(List<RangerAtlasEntityWithTags> entitiesWithTags) {
Map<String, ServiceTags> ret = new HashMap<>();
for (RangerAtlasEntityWithTags element : entitiesWithTags) {
RangerAtlasEntity entity = element.getEntity();
if (entity != null) {
buildServiceTags(element, ret);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring entity because its State is not ACTIVE: " + element);
}
}
}
// Remove duplicate tag definitions
if (CollectionUtils.isNotEmpty(ret.values())) {
for (ServiceTags serviceTag : ret.values()) {
if (MapUtils.isNotEmpty(serviceTag.getTagDefinitions())) {
Map<String, RangerTagDef> uniqueTagDefs = new HashMap<>();
for (RangerTagDef tagDef : serviceTag.getTagDefinitions().values()) {
RangerTagDef existingTagDef = uniqueTagDefs.get(tagDef.getName());
if (existingTagDef == null) {
uniqueTagDefs.put(tagDef.getName(), tagDef);
} else {
if (CollectionUtils.isNotEmpty(tagDef.getAttributeDefs())) {
for (RangerTagAttributeDef tagAttrDef : tagDef.getAttributeDefs()) {
boolean attrDefExists = false;
if (CollectionUtils.isNotEmpty(existingTagDef.getAttributeDefs())) {
for (RangerTagAttributeDef existingTagAttrDef : existingTagDef.getAttributeDefs()) {
if (StringUtils.equalsIgnoreCase(existingTagAttrDef.getName(), tagAttrDef.getName())) {
attrDefExists = true;
break;
}
}
}
if (!attrDefExists) {
existingTagDef.getAttributeDefs().add(tagAttrDef);
}
}
}
}
}
serviceTag.getTagDefinitions().clear();
for (RangerTagDef tagDef : uniqueTagDefs.values()) {
serviceTag.getTagDefinitions().put(tagDef.getId(), tagDef);
}
}
}
}
if (MapUtils.isNotEmpty(ret)) {
for (Map.Entry<String, ServiceTags> entry : ret.entrySet()) {
ServiceTags serviceTags = entry.getValue();
serviceTags.setOp(ServiceTags.OP_REPLACE);
}
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef in project ranger by apache.
the class AtlasNotificationMapper method getTagDefs.
private static List<RangerTagDef> getTagDefs(RangerAtlasEntityWithTags entityWithTags) {
List<RangerTagDef> ret = new ArrayList<>();
if (entityWithTags != null && CollectionUtils.isNotEmpty(entityWithTags.getTags())) {
Map<String, String> tagNames = new HashMap<>();
for (EntityNotificationWrapper.RangerAtlasClassification tag : entityWithTags.getTags()) {
if (!tagNames.containsKey(tag.getName())) {
tagNames.put(tag.getName(), tag.getName());
RangerTagDef tagDef = new RangerTagDef(tag.getName(), "Atlas");
if (MapUtils.isNotEmpty(tag.getAttributes())) {
for (String attributeName : tag.getAttributes().keySet()) {
tagDef.getAttributeDefs().add(new RangerTagAttributeDef(attributeName, entityWithTags.getTagAttributeType(tag.getName(), attributeName)));
}
}
ret.add(tagDef);
}
}
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef in project ranger by apache.
the class RangerTagDefServiceBase method populateRangerTagAttributeDef.
/**
* @param xObj
* @return
*/
public RangerTagAttributeDef populateRangerTagAttributeDef(XXTagAttributeDef xObj) {
RangerTagAttributeDef attrDef = new RangerTagAttributeDef();
attrDef.setName(xObj.getName());
attrDef.setType(xObj.getType());
return attrDef;
}
use of org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef in project ranger by apache.
the class RangerTagDefServiceBase method getAttributeDefForTagDef.
public List<RangerTagAttributeDef> getAttributeDefForTagDef(XXTagDef xtagDef) {
List<XXTagAttributeDef> tagAttrDefList = daoMgr.getXXTagAttributeDef().findByTagDefId(xtagDef.getId());
List<RangerTagDef.RangerTagAttributeDef> attributeDefList = new ArrayList<RangerTagDef.RangerTagAttributeDef>();
for (XXTagAttributeDef xAttrTag : tagAttrDefList) {
RangerTagAttributeDef attrDef = populateRangerTagAttributeDef(xAttrTag);
attributeDefList.add(attrDef);
}
return attributeDefList;
}
Aggregations