852080975cf7fbfb56ae14d61f1f2cb5787aa1fc
[optf/cmso.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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=================================================
17  *
18  */
19
20 package org.onap.optf.cmso.optimizer.clients.ticketmgt;
21
22 import java.util.Optional;
23 import java.util.UUID;
24 import org.onap.observations.Observation;
25 import org.onap.optf.cmso.optimizer.clients.ticketmgt.models.ActiveTicketsResponse;
26 import org.onap.optf.cmso.optimizer.common.LogMessages;
27 import org.onap.optf.cmso.optimizer.model.Request;
28 import org.onap.optf.cmso.optimizer.model.Ticket;
29 import org.onap.optf.cmso.optimizer.model.Topology;
30 import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
31 import org.onap.optf.cmso.optimizer.model.dao.TicketDao;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.core.env.Environment;
34 import org.springframework.stereotype.Component;
35
36 /**
37  * Ticket Mgt request manager.
38  *
39  * @author jf9860
40  *
41  */
42 @Component
43 public class TicketMgtRequestManager {
44
45     @Autowired
46     Environment env;
47
48     @Autowired
49     RequestDao requestDao;
50
51     @Autowired
52     TicketDao ticketDao;
53
54     @Autowired
55     TicketMgtClient ticketmgtClient;
56
57     /**
58      * Creates the tickets request.
59      *
60      * @param requestRow the uuid
61      * @return the active tickets response
62      */
63     public ActiveTicketsResponse createTicketsRequest(Request requestRow) {
64             Ticket row = null;
65             Optional<Ticket> rowOpt = ticketDao.findById(requestRow.getUuid());
66             if (rowOpt.isPresent()) {
67                 row = rowOpt.get();
68
69             }
70             if (row == null) {
71                 row = new Ticket();
72                 row.setUuid(requestRow.getUuid());
73                 row.setTicketsRetries(0);
74             }
75             ActiveTicketsResponse apiResponse = ticketmgtClient.makeRequest(requestRow, row);
76             ticketDao.save(row);
77             return apiResponse;
78             }
79     /**
80      * Gets the existing tickets.
81      *
82      * @param uuid the uuid
83      * @return the existing tickets
84      */
85     public Ticket getExistingTickets(UUID uuid) {
86         Optional<Ticket> opt = ticketDao.findById(uuid);
87         if (opt.isPresent()) {
88             return opt.get();
89         }
90         return null;
91     }
92
93 }