2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.catalogdb.rest;
23 import java.util.ArrayList;
24 import java.util.List;
25 import javax.ws.rs.GET;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.QueryParam;
30 import javax.ws.rs.core.MediaType;
31 import org.onap.so.db.catalog.data.repository.ServiceRepository;
32 import org.onap.so.rest.catalog.beans.Service;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35 import org.springframework.transaction.annotation.Transactional;
36 import com.google.common.base.Strings;
37 import io.swagger.annotations.Api;
38 import io.swagger.annotations.ApiOperation;
39 import io.swagger.annotations.ApiParam;
41 @Api(value = "/v1/services", tags = "model")
44 public class ServiceRestImpl {
47 private ServiceRepository serviceRepo;
50 private ServiceMapper serviceMapper;
54 @Produces({MediaType.APPLICATION_JSON})
55 @Transactional(readOnly = true)
56 public Service findService(@PathParam("modelUUID") String modelUUID, @QueryParam("depth") int depth) {
57 org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(modelUUID);
58 return serviceMapper.mapService(service, depth);
62 @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List",
63 notes = "If no query parameters are sent an empty list will be returned")
64 @Produces({MediaType.APPLICATION_JSON})
65 @Transactional(readOnly = true)
66 public List<Service> queryServices(
67 @ApiParam(value = "modelName", required = false) @QueryParam("modelName") String modelName,
68 @ApiParam(value = "distributionStatus",
69 required = false) @QueryParam("distributionStatus") String distributionStatus,
70 @ApiParam(value = "depth", required = false) @QueryParam("depth") int depth) {
71 List<Service> services = new ArrayList<>();
72 List<org.onap.so.db.catalog.beans.Service> serviceFromDB = new ArrayList<>();
73 if (!Strings.isNullOrEmpty(modelName) && !Strings.isNullOrEmpty(distributionStatus)) {
74 serviceFromDB = serviceRepo.findByModelNameAndDistrobutionStatus(modelName, distributionStatus);
75 } else if (!Strings.isNullOrEmpty(modelName)) {
76 serviceFromDB = serviceRepo.findByModelName(modelName);
78 serviceFromDB.stream().forEach(serviceDB -> services.add(serviceMapper.mapService(serviceDB, depth)));