TagREST { @GET @Path(TagRESTConstants.TAGS_RESOURCE + "type/{type}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") public List<RangerTag> getTagsByType(@PathParam("type") String type) { if(LOG.isDebugEnabled()) { LOG.debug("==> TagREST.getTagsByType(" + type + ")"); } List<RangerTag> ret; try { ret = tagStore.getTagsByType(type); } catch(Exception excp) { LOG.error("getTagsByType(" + type + ") failed", excp); throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true); } if(LOG.isDebugEnabled()) { LOG.debug("<== TagREST.getTagsByType(" + type + "): " + ret); } return ret; } TagREST(); @PostConstruct void initStore(); @POST @Path(TagRESTConstants.TAGDEFS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagDef createTagDef(RangerTagDef tagDef, @DefaultValue("true") @QueryParam("updateIfExists") boolean updateIfExists); @PUT @Path(TagRESTConstants.TAGDEF_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagDef updateTagDef(@PathParam("id") Long id, RangerTagDef tagDef); @DELETE @Path(TagRESTConstants.TAGDEF_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagDef(@PathParam("id") Long id); @DELETE @Path(TagRESTConstants.TAGDEF_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagDefByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.TAGDEF_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagDef getTagDef(@PathParam("id") Long id); @GET @Path(TagRESTConstants.TAGDEF_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagDef getTagDefByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.TAGDEF_RESOURCE + "name/{name}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagDef getTagDefByName(@PathParam("name") String name); @GET @Path(TagRESTConstants.TAGDEFS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerTagDef> getAllTagDefs(); @GET @Path(TagRESTConstants.TAGTYPES_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<String> getTagTypes(); @POST @Path(TagRESTConstants.TAGS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTag createTag(RangerTag tag, @DefaultValue("true") @QueryParam("updateIfExists") boolean updateIfExists); @PUT @Path(TagRESTConstants.TAG_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTag updateTag(@PathParam("id") Long id, RangerTag tag); @PUT @Path(TagRESTConstants.TAG_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTag updateTagByGuid(@PathParam("guid") String guid, RangerTag tag); @DELETE @Path(TagRESTConstants.TAG_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTag(@PathParam("id") Long id); @DELETE @Path(TagRESTConstants.TAG_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.TAG_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTag getTag(@PathParam("id") Long id); @GET @Path(TagRESTConstants.TAG_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTag getTagByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.TAGS_RESOURCE + "type/{type}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerTag> getTagsByType(@PathParam("type") String type); @GET @Path(TagRESTConstants.TAGS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerTag> getAllTags(); @POST @Path(TagRESTConstants.RESOURCES_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource createServiceResource(RangerServiceResource resource, @DefaultValue("true") @QueryParam("updateIfExists") boolean updateIfExists); @PUT @Path(TagRESTConstants.RESOURCE_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource updateServiceResource(@PathParam("id") Long id, RangerServiceResource resource); @PUT @Path(TagRESTConstants.RESOURCE_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource updateServiceResourceByGuid(@PathParam("guid") String guid, RangerServiceResource resource); @DELETE @Path(TagRESTConstants.RESOURCE_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteServiceResource(@PathParam("id") Long id); @DELETE @Path(TagRESTConstants.RESOURCE_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteServiceResourceByGuid(@PathParam("guid") String guid, @DefaultValue("false") @QueryParam("deleteReferences") boolean deleteReferences); @GET @Path(TagRESTConstants.RESOURCE_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource getServiceResource(@PathParam("id") Long id); @GET @Path(TagRESTConstants.RESOURCE_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource getServiceResourceByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.RESOURCES_RESOURCE + "service/{serviceName}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerServiceResource> getServiceResourcesByService(@PathParam("serviceName") String serviceName); @GET @Path(TagRESTConstants.RESOURCE_RESOURCE + "service/{serviceName}/signature/{resourceSignature}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerServiceResource getServiceResourceByServiceAndResourceSignature(@PathParam("serviceName") String serviceName,
                                                                       @PathParam("resourceSignature") String resourceSignature); @GET @Path(TagRESTConstants.RESOURCES_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerServiceResource> getAllServiceResources(); @POST @Path(TagRESTConstants.TAGRESOURCEMAPS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagResourceMap createTagResourceMap(@QueryParam("tag-guid") String tagGuid, @QueryParam("resource-guid") String resourceGuid,
                                                     @DefaultValue("false") @QueryParam("lenient") boolean lenient); @DELETE @Path(TagRESTConstants.TAGRESOURCEMAP_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagResourceMap(@PathParam("id") Long id); @DELETE @Path(TagRESTConstants.TAGRESOURCEMAP_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagResourceMapByGuid(@PathParam("guid") String guid); @DELETE @Path(TagRESTConstants.TAGRESOURCEMAPS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagResourceMap(@QueryParam("tag-guid") String tagGuid, @QueryParam("resource-guid") String resourceGuid); @GET @Path(TagRESTConstants.TAGRESOURCEMAP_RESOURCE + "{id}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagResourceMap getTagResourceMap(@PathParam("id") Long id); @GET @Path(TagRESTConstants.TAGRESOURCEMAP_RESOURCE + "guid/{guid}") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagResourceMap getTagResourceMapByGuid(@PathParam("guid") String guid); @GET @Path(TagRESTConstants.TAGRESOURCEMAP_RESOURCE + "tag-resource-guid") @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") RangerTagResourceMap getTagResourceMap(@QueryParam("tagGuid") String tagGuid, @QueryParam("resourceGuid") String resourceGuid); @GET @Path(TagRESTConstants.TAGRESOURCEMAPS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") List<RangerTagResourceMap> getAllTagResourceMaps(); @PUT @Path(TagRESTConstants.IMPORT_SERVICETAGS_RESOURCE) @Produces({ "application/json", "application/xml" }) @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void importServiceTags(ServiceTags serviceTags); @GET @Path(TagRESTConstants.TAGS_DOWNLOAD + "{serviceName}") @Produces({ "application/json", "application/xml" }) ServiceTags getServiceTagsIfUpdated(@PathParam("serviceName") String serviceName,
                                                   @QueryParam(TagRESTConstants.LAST_KNOWN_TAG_VERSION_PARAM) Long lastKnownVersion,
                                               @DefaultValue("0") @QueryParam(TagRESTConstants.LAST_ACTIVATION_TIME) Long lastActivationTime, @QueryParam("pluginId") String pluginId,
                                               @DefaultValue("false") @QueryParam(RangerRESTUtils.REST_PARAM_SUPPORTS_TAG_DELTAS) Boolean supportsTagDeltas,
                                               @DefaultValue("") @QueryParam(RangerRESTUtils.REST_PARAM_CAPABILITIES) String pluginCapabilities,
                                               @Context HttpServletRequest request); @GET @Path(TagRESTConstants.TAGS_SECURE_DOWNLOAD + "{serviceName}") @Produces({ "application/json", "application/xml" }) ServiceTags getSecureServiceTagsIfUpdated(@PathParam("serviceName") String serviceName,
                                                   @QueryParam(TagRESTConstants.LAST_KNOWN_TAG_VERSION_PARAM) Long lastKnownVersion,
                                                     @DefaultValue("0") @QueryParam(TagRESTConstants.LAST_ACTIVATION_TIME) Long lastActivationTime, @QueryParam("pluginId") String pluginId,
                                                     @DefaultValue("false") @QueryParam(RangerRESTUtils.REST_PARAM_SUPPORTS_TAG_DELTAS) Boolean supportsTagDeltas,
                                                     @DefaultValue("") @QueryParam(RangerRESTUtils.REST_PARAM_CAPABILITIES) String pluginCapabilities,
                                                     @Context HttpServletRequest request); @DELETE @Path("/server/tagdeltas") @PreAuthorize("hasRole('ROLE_SYS_ADMIN')") void deleteTagDeltas(@DefaultValue("3") @QueryParam("days") Integer olderThan, @Context HttpServletRequest request); static final String Allowed_User_List_For_Tag_Download; }
@Test public void test25getTagsByType() { String type = "file"; List<RangerTag> tag = new ArrayList<RangerTag>(); RangerTag rTag = new RangerTag(); rTag.setType(type); tag.add(rTag); try { Mockito.when(tagStore.getTagsByType(type)).thenReturn(tag); } catch (Exception e) { } List<RangerTag> rangerTag = tagREST.getTagsByType(type); Assert.assertEquals(rangerTag.get(0).getType(), tag.get(0).getType()); try { Mockito.verify(tagStore).getTagsByType(type); } catch (Exception e) { } }