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", tags = "model")
44 public class ServiceRestImpl {
47 private ServiceRepository serviceRepo;
50 private ServiceMapper serviceMapper;
55 @Produces({MediaType.APPLICATION_JSON})
56 @Transactional(readOnly = true)
57 public Service findService(@PathParam("modelUUID") String modelUUID, @QueryParam("depth") int depth) {
58 org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(modelUUID);
59 if (service == null) {
60 new CatalogEntityNotFoundException("Unable to find Service " + modelUUID);
62 return serviceMapper.mapService(service, depth);
66 @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List")
67 @Produces({MediaType.APPLICATION_JSON})
68 @Transactional(readOnly = true)
69 public List<Service> queryServices(
70 @ApiParam(value = "modelName", required = false) @QueryParam("modelName") String modelName,
71 @ApiParam(value = "distributionStatus",
72 required = false) @QueryParam("distributionStatus") String distributionStatus,
73 @ApiParam(value = "depth", required = false) @QueryParam("depth") int depth) {
74 List<Service> services = new ArrayList<>();
75 List<org.onap.so.db.catalog.beans.Service> serviceFromDB = new ArrayList<>();
76 if (!Strings.isNullOrEmpty(modelName) && !Strings.isNullOrEmpty(distributionStatus)) {
77 serviceFromDB = serviceRepo.findByModelNameAndDistrobutionStatus(modelName, distributionStatus);
78 } else if (!Strings.isNullOrEmpty(modelName)) {
79 serviceFromDB = serviceRepo.findByModelName(modelName);
81 serviceFromDB = serviceRepo.findAll();
83 serviceFromDB.stream().forEach(serviceDB -> services.add(serviceMapper.mapService(serviceDB, depth)));