Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / services / ChangeManagementServiceImpl.java
1 package org.openecomp.vid.services;
2
3 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
4 import org.openecomp.vid.changeManagement.ChangeManagementRequest;
5 import org.openecomp.vid.changeManagement.RequestDetails;
6 import org.openecomp.vid.mso.MsoBusinessLogic;
7 import org.openecomp.vid.mso.MsoResponseWrapper;
8 import org.openecomp.vid.controller.MsoController;
9 import org.openecomp.portalsdk.core.util.SystemProperties;
10 import org.openecomp.vid.scheduler.*;
11
12 import org.springframework.http.HttpStatus;
13 import org.springframework.http.ResponseEntity;
14 import org.openecomp.vid.mso.rest.Request;
15 import org.springframework.stereotype.Service;
16 import org.json.simple.JSONArray;
17 import org.json.simple.parser.JSONParser;
18
19 import java.util.Date;
20 import java.util.List;
21 import java.util.Collection;
22
23
24 @Service
25 public class ChangeManagementServiceImpl implements ChangeManagementService {
26     @Override
27     public Collection<Request> getMSOChangeManagements() {
28         Collection<Request> result = null;
29                 MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogic();
30                 try {
31             result = msoBusinessLogic.getOrchestrationRequestsForDashboard();
32         } catch (Exception e) {
33             e.printStackTrace();
34         }
35
36         return result;
37     }
38
39     private RequestDetails findRequestByVnfName(List<RequestDetails> requests, String vnfName){
40
41         if (requests == null)
42                 return null;
43
44         for(RequestDetails requestDetails: requests){
45                         if(requestDetails.getVnfName().equals(vnfName)){
46                                 return requestDetails;
47                         }
48                 }
49
50                 return null;
51         }
52
53         @Override
54         public ResponseEntity<String> doChangeManagement(ChangeManagementRequest request, String vnfName) {
55                 if (request == null)
56                         return null;
57                 ResponseEntity<String> response = null;
58                 RequestDetails currentRequestDetails = findRequestByVnfName(request.getRequestDetails(), vnfName);
59                 MsoResponseWrapper msoResponseWrapperObject = null;
60                 if(currentRequestDetails != null){
61                         MsoBusinessLogic msoBusinessLogicObject = new MsoBusinessLogic();
62                         String serviceInstanceId = currentRequestDetails.getRelatedInstList().get(0).getRelatedInstance().getInstanceId();
63                         String vnfInstanceId = currentRequestDetails.getVnfInstanceId();
64                         try {
65                                 if (request.getRequestType().equalsIgnoreCase("update")) {
66                                         
67                                          msoResponseWrapperObject = msoBusinessLogicObject.updateVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
68                                 }
69                                 else if (request.getRequestType().equalsIgnoreCase("replace"))
70                                 {
71                                         msoResponseWrapperObject = msoBusinessLogicObject.replaceVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
72 //                                      throw new NotImplementedException();
73                                 }
74                                 response = new ResponseEntity<String>(msoResponseWrapperObject.getResponse(), HttpStatus.OK);
75                                 return response;
76                         } catch (Exception e) {
77                                 e.printStackTrace();
78                         }
79
80                 }
81
82                 // AH:TODO: return ChangeManagementResponse
83                 return null;
84         }
85
86     @Override
87     public JSONArray getSchedulerChangeManagements() {
88         JSONArray result = null;
89         try {
90             String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_SCHEDULES);
91             org.openecomp.vid.scheduler.RestObject<String> restObject = new org.openecomp.vid.scheduler.RestObject<>();
92             SchedulerRestInterfaceIfc restClient = SchedulerRestInterfaceFactory.getInstance();
93
94             String str = new String();
95             restObject.set(str);
96             restClient.Get(str, "", path, restObject);
97             String restCallResult = restObject.get();
98             JSONParser parser = new JSONParser();
99             Object parserResult = parser.parse(restCallResult);
100             result = (JSONArray) parserResult;
101         } catch (Exception e) {
102             e.printStackTrace();
103         }
104
105         return result;
106     }
107
108
109 }