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 javax.ws.rs.core.Response;
32 import org.onap.so.db.catalog.data.repository.ServiceRepository;
33 import org.onap.so.rest.catalog.beans.Service;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36 import org.springframework.transaction.annotation.Transactional;
37 import com.google.common.base.Strings;
38 import io.swagger.annotations.ApiOperation;
42 public class ServiceRestImpl {
45 private ServiceRepository serviceRepo;
48 private ServiceMapper serviceMapper;
51 @Path("/services/{modelUUID}")
52 @Produces({MediaType.APPLICATION_JSON})
53 @Transactional(readOnly = true)
54 public Service findService(@PathParam("modelUUID") String modelUUID, @QueryParam("depth") int depth) {
55 org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(modelUUID);
56 return serviceMapper.mapService(service, depth);
61 @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List")
62 @Produces({MediaType.APPLICATION_JSON})
63 @Transactional(readOnly = true)
64 public List<Service> queryServices(@QueryParam("modelName") String modelName,
65 @QueryParam("distributionStatus") String distributionStatus, @QueryParam("depth") int depth) {
66 List<Service> services = new ArrayList<>();
67 List<org.onap.so.db.catalog.beans.Service> serviceFromDB = new ArrayList<>();
68 if (!Strings.isNullOrEmpty(modelName) && !Strings.isNullOrEmpty(distributionStatus)) {
69 serviceFromDB = serviceRepo.findByModelNameAndDistrobutionStatus(modelName, distributionStatus);
70 } else if (!Strings.isNullOrEmpty(modelName)) {
71 serviceFromDB = serviceRepo.findByModelName(modelName);
73 serviceFromDB.stream().forEach(serviceDB -> services.add(serviceMapper.mapService(serviceDB, depth)));