8c7dfb6eecb3e3a7d29567fae333e5c7c4c865df
[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 org.onap.observations.Observation;
24 import org.onap.optf.cmso.optimizer.clients.ticketmgt.models.ActiveTicketsResponse;
25 import org.onap.optf.cmso.optimizer.common.LogMessages;
26 import org.onap.optf.cmso.optimizer.model.Request;
27 import org.onap.optf.cmso.optimizer.model.Ticket;
28 import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
29 import org.onap.optf.cmso.optimizer.model.dao.TicketDao;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.core.env.Environment;
32 import org.springframework.stereotype.Component;
33
34 /**
35  * Ticket Mgt request manager.
36  *
37  * @author jf9860
38  *
39  */
40 @Component
41 public class TicketMgtRequestManager {
42
43     @Autowired
44     Environment env;
45
46     @Autowired
47     RequestDao requestDao;
48
49     @Autowired
50     TicketDao ticketDao;
51
52     @Autowired
53     TicketMgtClient ticketmgtClient;
54
55     /**
56      * Creates the topology request.
57      *
58      * @param requestRow the uuid
59      * @return the active tickets response
60      */
61     public ActiveTicketsResponse createTicketsRequest(Request requestRow) {
62         try {
63             Ticket row = null;
64             Optional<Ticket> rowOpt = ticketDao.findById(requestRow.getUuid());
65             if (rowOpt.isPresent()) {
66                 row = rowOpt.get();
67
68             }
69             if (row == null) {
70                 row = new Ticket();
71                 row.setUuid(requestRow.getUuid());
72                 row.setTicketsRetries(0);
73             }
74             ActiveTicketsResponse apiResponse = ticketmgtClient.makeRequest(requestRow, row);
75             switch (apiResponse.getStatus()) {
76                 case COMPLETED:
77                     break;
78                 case FAILED:
79                     break;
80                 case IN_PROGRESS:
81                     break;
82                 default:
83                     break;
84             }
85             return apiResponse;
86         } catch (Exception e) {
87             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
88         }
89         return null;
90
91     }
92
93 }