2 * ============LICENSE_START==============================================
3 * Copyright (c) 2019 AT&T Intellectual Property.
4 * =======================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain a
7 * copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 * ============LICENSE_END=================================================
20 package org.onap.optf.cmso.optimizer.clients.topology;
22 import java.util.Optional;
23 import java.util.UUID;
24 import org.onap.optf.cmso.optimizer.clients.topology.models.TopologyResponse;
25 import org.onap.optf.cmso.optimizer.model.Request;
26 import org.onap.optf.cmso.optimizer.model.Topology;
27 import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
28 import org.onap.optf.cmso.optimizer.model.dao.TopologyDao;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.core.env.Environment;
31 import org.springframework.stereotype.Component;
34 * The Class TopologyRequestManager.
37 public class TopologyRequestManager {
43 RequestDao requestDao;
46 TopologyDao topologyDao;
49 TopologyClient topologyClient;
52 * Creates the topology request.
54 * @param requestRow the request row
55 * @return the topology response
57 public TopologyResponse createTopologyRequest(Request requestRow) {
58 Topology topology = getExistingTopology(requestRow.getUuid());
59 if (topology == null) {
60 topology = new Topology();
61 topology.setUuid(requestRow.getUuid());
62 topology.setTopologyRetries(0);
64 TopologyResponse topologyResponse = topologyClient.makeRequest(requestRow, topology);
65 topologyDao.save(topology);
66 return topologyResponse;
72 * Gets the existing topology.
74 * @param uuid the uuid
75 * @return the existing topology
77 public Topology getExistingTopology(UUID uuid) {
78 Optional<Topology> topologyOpt = topologyDao.findById(uuid);
79 if (topologyOpt.isPresent()) {
80 return topologyOpt.get();