Search in sources :

Example 21 with RangerTag

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

the class RangerTagService method getTagsByType.

public List<RangerTag> getTagsByType(String name) {
    List<RangerTag> ret = new ArrayList<RangerTag>();
    List<XXTag> xxTags = daoMgr.getXXTag().findByName(name);
    if (CollectionUtils.isNotEmpty(xxTags)) {
        for (XXTag xxTag : xxTags) {
            RangerTag tag = populateViewBean(xxTag);
            ret.add(tag);
        }
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) XXTag(org.apache.ranger.entity.XXTag)

Example 22 with RangerTag

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

the class RangerTagService method getTagsForResourceId.

public List<RangerTag> getTagsForResourceId(Long resourceId) {
    List<RangerTag> ret = new ArrayList<RangerTag>();
    List<XXTag> xxTags = daoMgr.getXXTag().findForResourceId(resourceId);
    if (CollectionUtils.isNotEmpty(xxTags)) {
        for (XXTag xxTag : xxTags) {
            RangerTag tag = populateViewBean(xxTag);
            ret.add(tag);
        }
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) XXTag(org.apache.ranger.entity.XXTag)

Example 23 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag 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 24 with RangerTag

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

the class TagPredicateUtil method addPredicateForTagGuid.

private Predicate addPredicateForTagGuid(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 RangerTag) {
                RangerTag tag = (RangerTag) object;
                ret = StringUtils.equals(guid, tag.getGuid());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) Predicate(org.apache.commons.collections.Predicate)

Example 25 with RangerTag

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

the class TestTagREST method test23getTag.

@Test
public void test23getTag() {
    RangerTag oldTag = new RangerTag();
    oldTag.setId(id);
    oldTag.setGuid(gId);
    try {
        Mockito.when(tagStore.getTag(id)).thenReturn(oldTag);
    } catch (Exception e) {
    }
    RangerTag rangerTag = tagREST.getTag(id);
    Assert.assertNotNull(oldTag.getId());
    Assert.assertEquals(rangerTag.getId(), oldTag.getId());
    Assert.assertEquals(rangerTag.getGuid(), oldTag.getGuid());
    try {
        Mockito.verify(tagStore).getTag(id);
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerTag (org.apache.ranger.plugin.model.RangerTag)30 WebApplicationException (javax.ws.rs.WebApplicationException)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 ExpectedException (org.junit.rules.ExpectedException)10 XXTag (org.apache.ranger.entity.XXTag)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)4 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)4 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Predicate (org.apache.commons.collections.Predicate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 HashSet (java.util.HashSet)2 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)2