Search in sources :

Example 1 with RangerTagAttributeDef

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;
}
Also used : RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList)

Example 2 with RangerTagAttributeDef

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;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) RangerAtlasEntityWithTags(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags) HashMap(java.util.HashMap) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RangerTagAttributeDef

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;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)

Example 4 with RangerTagAttributeDef

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;
}
Also used : RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)

Example 5 with RangerTagAttributeDef

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;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagAttributeDef(org.apache.ranger.entity.XXTagAttributeDef) ArrayList(java.util.ArrayList) RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)

Aggregations

RangerTagAttributeDef (org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)5 ArrayList (java.util.ArrayList)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)3 HashMap (java.util.HashMap)2 XXTagAttributeDef (org.apache.ranger.entity.XXTagAttributeDef)2 Map (java.util.Map)1 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)1 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)1 RangerAtlasEntityWithTags (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags)1