Search in sources :

Example 31 with RangerServiceResource

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

the class TagREST method updateServiceResourceByGuid.

@PUT
@Path(TagRESTConstants.RESOURCE_RESOURCE + "guid/{guid}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
public RangerServiceResource updateServiceResourceByGuid(@PathParam("guid") String guid, RangerServiceResource resource) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagREST.updateServiceResourceByGuid(" + guid + ", " + resource + ")");
    }
    RangerServiceResource ret;
    try {
        validator.preUpdateServiceResourceByGuid(guid, resource);
        ret = tagStore.updateServiceResource(resource);
    } catch (Exception excp) {
        LOG.error("updateServiceResourceByGuid(" + guid + ", " + resource + ") failed", excp);
        throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagREST.updateServiceResourceByGuid(" + guid + ", " + resource + "): " + ret);
    }
    return ret;
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PUT(javax.ws.rs.PUT)

Example 32 with RangerServiceResource

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

the class RangerServiceResourceService method getTaggedResourcesInServiceId.

public List<RangerServiceResource> getTaggedResourcesInServiceId(Long serviceId) {
    List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
    List<XXServiceResource> xxServiceResources = daoMgr.getXXServiceResource().findByServiceId(serviceId);
    if (CollectionUtils.isNotEmpty(xxServiceResources)) {
        for (XXServiceResource xxServiceResource : xxServiceResources) {
            RangerServiceResource serviceResource = populateViewBean(xxServiceResource);
            ret.add(serviceResource);
        }
    }
    return ret;
}
Also used : XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ArrayList(java.util.ArrayList)

Example 33 with RangerServiceResource

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

the class RangerServiceResourceService method getByServiceAndResourceSignature.

public RangerServiceResource getByServiceAndResourceSignature(Long serviceId, String resourceSignature) {
    RangerServiceResource ret = null;
    XXServiceResource xxServiceResource = daoMgr.getXXServiceResource().findByServiceAndResourceSignature(serviceId, resourceSignature);
    if (xxServiceResource != null) {
        ret = populateViewBean(xxServiceResource);
    }
    return ret;
}
Also used : XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource)

Example 34 with RangerServiceResource

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

the class TagPredicateUtil method addPredicateForResourceId.

private Predicate addPredicateForResourceId(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 RangerServiceResource) {
                RangerServiceResource resource = (RangerServiceResource) object;
                ret = StringUtils.equals(id, resource.getId().toString());
            } else if (object instanceof RangerTagResourceMap) {
                RangerTagResourceMap tagResourceMap = (RangerTagResourceMap) object;
                ret = StringUtils.equals(id, tagResourceMap.getId().toString());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) Predicate(org.apache.commons.collections.Predicate)

Example 35 with RangerServiceResource

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

the class TagPredicateUtil method addPredicateForResourceSignature.

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

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

Aggregations

RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)65 Test (org.junit.Test)42 HashMap (java.util.HashMap)37 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)30 WebApplicationException (javax.ws.rs.WebApplicationException)17 ExpectedException (org.junit.rules.ExpectedException)14 ArrayList (java.util.ArrayList)10 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)7 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)5 Predicate (org.apache.commons.collections.Predicate)4 XXServiceResource (org.apache.ranger.entity.XXServiceResource)4 RangerTag (org.apache.ranger.plugin.model.RangerTag)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 PUT (javax.ws.rs.PUT)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2