Search in sources :

Example 31 with RangerTagDef

use of org.apache.ranger.plugin.model.RangerTagDef in project ranger by apache.

the class RangerTagDefService method mapEntityToViewBean.

@Override
protected RangerTagDef mapEntityToViewBean(RangerTagDef vObj, XXTagDef xObj) {
    RangerTagDef ret = super.mapEntityToViewBean(vObj, xObj);
    List<RangerTagDef.RangerTagAttributeDef> attributeDefs = RangerTagDBRetriever.gsonBuilder.fromJson(xObj.getTagAttrDefs(), RangerTagDBRetriever.subsumedDataType);
    ret.setAttributeDefs(attributeDefs);
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef)

Example 32 with RangerTagDef

use of org.apache.ranger.plugin.model.RangerTagDef in project ranger by apache.

the class RangerServiceTagsDeltaUtil method pruneUnusedAttributes.

public static void pruneUnusedAttributes(ServiceTags serviceTags) {
    if (serviceTags != null) {
        serviceTags.setTagUpdateTime(null);
        for (Map.Entry<Long, RangerTagDef> entry : serviceTags.getTagDefinitions().entrySet()) {
            RangerTagDef tagDef = entry.getValue();
            tagDef.setCreatedBy(null);
            tagDef.setCreateTime(null);
            tagDef.setUpdatedBy(null);
            tagDef.setUpdateTime(null);
            tagDef.setGuid(null);
        }
        for (Map.Entry<Long, RangerTag> entry : serviceTags.getTags().entrySet()) {
            RangerTag tag = entry.getValue();
            tag.setCreatedBy(null);
            tag.setCreateTime(null);
            tag.setUpdatedBy(null);
            tag.setUpdateTime(null);
            tag.setGuid(null);
        }
        for (RangerServiceResource serviceResource : serviceTags.getServiceResources()) {
            serviceResource.setCreatedBy(null);
            serviceResource.setCreateTime(null);
            serviceResource.setUpdatedBy(null);
            serviceResource.setUpdateTime(null);
            serviceResource.setGuid(null);
            serviceResource.setServiceName(null);
        }
    }
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerTag(org.apache.ranger.plugin.model.RangerTag) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with RangerTagDef

use of org.apache.ranger.plugin.model.RangerTagDef in project ranger by apache.

the class TagPredicateUtil method addPredicateForTagType.

private Predicate addPredicateForTagType(final String type, List<Predicate> predicates) {
    if (StringUtils.isEmpty(type)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            boolean ret = false;
            if (object == null) {
                return ret;
            }
            if (object instanceof RangerTagDef) {
                RangerTagDef tagDef = (RangerTagDef) object;
                ret = StringUtils.equals(type, tagDef.getName());
            } else if (object instanceof RangerTag) {
                RangerTag tag = (RangerTag) object;
                ret = StringUtils.equals(type, tag.getType());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerTag(org.apache.ranger.plugin.model.RangerTag) Predicate(org.apache.commons.collections.Predicate)

Example 34 with RangerTagDef

use of org.apache.ranger.plugin.model.RangerTagDef in project ranger by apache.

the class TagPredicateUtil method addPredicateForTagDefGuid.

private Predicate addPredicateForTagDefGuid(final String guid, List<Predicate> predicates) {
    if (StringUtils.isEmpty(guid)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            boolean ret = false;
            if (object == null) {
                return ret;
            }
            if (object instanceof RangerTagDef) {
                RangerTagDef tagDef = (RangerTagDef) object;
                ret = StringUtils.equals(guid, tagDef.getGuid());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) Predicate(org.apache.commons.collections.Predicate)

Example 35 with RangerTagDef

use of org.apache.ranger.plugin.model.RangerTagDef in project ranger by apache.

the class TagPredicateUtil method addPredicateForTagDefId.

private Predicate addPredicateForTagDefId(final String id, List<Predicate> predicates) {
    if (StringUtils.isEmpty(id)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            boolean ret = false;
            if (object == null) {
                return ret;
            }
            if (object instanceof RangerTagDef) {
                RangerTagDef tagDef = (RangerTagDef) object;
                ret = StringUtils.equals(id, tagDef.getId().toString());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) Predicate(org.apache.commons.collections.Predicate)

Aggregations

RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)39 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)15 XXTagDef (org.apache.ranger.entity.XXTagDef)14 HashMap (java.util.HashMap)10 RangerTag (org.apache.ranger.plugin.model.RangerTag)10 WebApplicationException (javax.ws.rs.WebApplicationException)9 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)9 ExpectedException (org.junit.rules.ExpectedException)9 XXTagDefDao (org.apache.ranger.db.XXTagDefDao)7 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)6 List (java.util.List)5 Map (java.util.Map)5 XXTagAttributeDef (org.apache.ranger.entity.XXTagAttributeDef)5 Date (java.util.Date)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)4 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)4 TagStore (org.apache.ranger.plugin.store.TagStore)4 Predicate (org.apache.commons.collections.Predicate)3 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)3