use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags 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.tagsync.source.atlasrest.RangerAtlasEntityWithTags in project ranger by apache.
the class AtlasTagSource method getPrintableEntityNotification.
private static String getPrintableEntityNotification(EntityNotificationWrapper notification) {
StringBuilder sb = new StringBuilder();
sb.append("{ Notification-Type: ").append(notification.getOpType()).append(", ");
RangerAtlasEntityWithTags entityWithTags = new RangerAtlasEntityWithTags(notification);
sb.append(entityWithTags.toString());
sb.append("}");
return sb.toString();
}
Aggregations