@Override protected Response getPaginatedResults( Tag[] tags, int start, int size, String sortBy, String sortOrder) { org.wso2.carbon.registry.core.Tag[] paginatedTags; String[] tagNames = new String[tags.length]; if (size == 0 && start == 0) { for (int i = 0; i < tags.length; i++) { tagNames[i] = tags[i].getTagName(); } TagModel tagModel = new TagModel(); tagModel.setTags(tagNames); return Response.ok(tagModel).build(); } if (tags.length < start) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (tags.length < start + size) { paginatedTags = new org.wso2.carbon.registry.core.Tag[tags.length - start]; System.arraycopy(tags, start, paginatedTags, 0, tags.length - start); } else { paginatedTags = new org.wso2.carbon.registry.core.Tag[size]; System.arraycopy(tags, start, paginatedTags, 0, size); } String[] paginatedTagNames = new String[paginatedTags.length]; for (int i = 0; i < paginatedTags.length; i++) { paginatedTagNames[i] = paginatedTags[i].getTagName(); } TagModel paginatedTagModel = new TagModel(); paginatedTagModel.setTags(paginatedTagNames); return Response.ok(paginatedTagModel).build(); }
/** * This method add array of tags to the specified resource * * @param resourcePath - Resource path * @param tags - eg:{"tags":[<array of tag names>]} * @return HTTP 204 No Content ,if success. */ @POST @Consumes("application/json") @Produces("application/json") @ApiOperation( value = "Add an array of tags to a resource", httpMethod = "POST", notes = "Add an array of tags to a resource") @ApiResponses( value = { @ApiResponse(code = 204, message = "Resource tagged successfully"), @ApiResponse(code = 401, message = "Invalid credentials provided"), @ApiResponse(code = 404, message = "Specified resource not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response addTags( @QueryParam("path") String resourcePath, TagModel tags, @HeaderParam("X-JWT-Assertion") String JWTToken) { RestAPIAuthContext authContext = RestAPISecurityUtils.getAuthContext( PrivilegedCarbonContext.getThreadLocalCarbonContext(), JWTToken); if (!authContext.isAuthorized()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } try { Registry registry = getUserRegistry(authContext.getUserName(), authContext.getTenantId()); if (!registry.resourceExists(resourcePath)) { return Response.status(Response.Status.NOT_FOUND) .entity(RestAPIConstants.RESOURCE_NOT_FOUND) .build(); } String[] tagsOnResource = tags.getTags(); for (String aTagsOnResource : tagsOnResource) { registry.applyTag(resourcePath, aTagsOnResource); } return Response.status(Response.Status.NO_CONTENT).build(); } catch (RegistryException e) { log.error("user doesn't have permission to put the tags for the given resource", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } }