/* * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hawkular.inventory.rest.deprecated; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.hawkular.inventory.rest.RequestUtil.extractPaging; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.hawkular.inventory.api.ResourceTypes; import org.hawkular.inventory.api.model.Resource; import org.hawkular.inventory.api.paging.Page; import org.hawkular.inventory.rest.RestBase; import org.hawkular.inventory.rest.json.ApiError; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; /** * @author Lukas Krejci * @since 0.4.0 */ @Path("/deprecated") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) @Api(value = "/deprecated", description = "Manages associations between resource types and resources", tags = {"Deprecated"}) public class RestResourceTypesResources extends RestBase { @GET @Path("/resourceTypes/{resourceTypeId}/resources") @ApiOperation("Retrieves all resources with given resource types. Accepts paging query parameters.") @ApiResponses({ @ApiResponse(code = 200, message = "the list of resources"), @ApiResponse(code = 404, message = "Tenant or resource type doesn't exist", response = ApiError.class), @ApiResponse(code = 500, message = "Server error", response = ApiError.class) }) public Response getResources(@PathParam("resourceTypeId") String resourceTypeId, @Context UriInfo uriInfo) { String tenantId = getTenantId(); ResourceTypes.Single single = inventory.tenants().get(tenantId).resourceTypes().get(resourceTypeId); single.entity(); // check whether it exists Page<Resource> ret = single.resources().getAll().entities(extractPaging(uriInfo)); return pagedResponse(Response.ok(), uriInfo, ret).build(); } @GET @Path("/feeds/{feedId}/resourceTypes/{resourceTypeId}/resources") @ApiOperation("Retrieves all metric types associated with the resource type. Accepts paging query params.") @ApiResponses({ @ApiResponse(code = 200, message = "the list of metric types associated with the resource type"), @ApiResponse(code = 404, message = "Tenant or resource type doesn't exist", response = ApiError.class), @ApiResponse(code = 500, message = "Server error", response = ApiError.class) }) public Response getResources(@PathParam("feedId") String feedId, @PathParam("resourceTypeId") String resourceTypeId, @Context UriInfo uriInfo) { Page<Resource> ret = inventory.tenants().get(getTenantId()).feeds().get(feedId).resourceTypes() .get(resourceTypeId).resources().getAll().entities(extractPaging(uriInfo)); return pagedResponse(Response.ok(), uriInfo, ret).build(); } }