Add junit coverage to RequestInfoBuilder class
[appc.git] / appc-inbound / appc-design-services / provider / src / main / java / org / onap / appc / design / dbervices / DesignDBService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.appc.design.dbervices;
24
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.fasterxml.jackson.core.JsonParser;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import java.sql.ResultSet;
31 import java.sql.SQLException;
32 import java.util.ArrayList;
33 import java.util.List;
34 import org.onap.appc.design.data.ArtifactInfo;
35 import org.onap.appc.design.data.DesignInfo;
36 import org.onap.appc.design.data.DesignResponse;
37 import org.onap.appc.design.data.StatusInfo;
38 import org.onap.appc.design.services.util.ArtifactHandlerClient;
39 import org.onap.appc.design.services.util.DesignServiceConstants;
40 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
42
43 public class DesignDBService {
44
45     private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class);
46     private static DesignDBService dgGeneralDBService;
47
48     private static final String SUCCESS_JSON = "{\"update\" : \"success\" } ";
49     private static final String STATUS = "STATUS";
50     private static final String INFO_STR = "Info : ";
51     private static final String DB_OPERATION_ERROR = "Error while DB operation : ";
52     private static final String VNFC_TYPE = "vnfc-type";
53     private static final String QUERY_STR = "Query String :";
54     private static final String USER_ID = "userID";
55
56     private SvcLogicResource serviceLogic;
57     private DbService dbservice;
58
59     public static DesignDBService initialise() {
60         if (dgGeneralDBService == null) {
61             dgGeneralDBService = new DesignDBService();
62         }
63         return dgGeneralDBService;
64     }
65
66     private DesignDBService() {
67         if (serviceLogic == null) {
68             serviceLogic = new SqlResource();
69         }
70     }
71
72     public String execute(String action, String payload, String requestID) throws Exception {
73
74         log.info("Received execute request for action : " + action + "  with Payload : " + payload);
75         RequestValidator.validate(action, payload);
76         String response;
77         dbservice = new DbService();
78         switch (action) {
79             case DesignServiceConstants.GETDESIGNS:
80                 response = getDesigns(payload, requestID);
81                 break;
82             case DesignServiceConstants.ADDINCART:
83                 response = setInCart(payload, requestID);
84                 break;
85             case DesignServiceConstants.GETARTIFACTREFERENCE:
86                 response = getArtifactReference(payload, requestID);
87                 break;
88             case DesignServiceConstants.GETARTIFACT:
89                 response = getArtifact(payload, requestID);
90                 break;
91             case DesignServiceConstants.GETGUIREFERENCE:
92                 response = getGuiReference(payload, requestID);
93                 break;
94             case DesignServiceConstants.GETSTATUS:
95                 response = getStatus(payload, requestID);
96                 break;
97             case DesignServiceConstants.SETSTATUS:
98                 response = setStatus(payload, requestID);
99                 break;
100             case DesignServiceConstants.UPLOADARTIFACT:
101                 response = uploadArtifact(payload, requestID);
102                 break;
103             case DesignServiceConstants.SETPROTOCOLREFERENCE:
104                 response = setProtocolReference(payload, requestID);
105                 break;
106             default:
107                 throw new DBException(" Action " + action + " not found while processing request ");
108
109         }
110         return response;
111     }
112
113     private String setInCart(String payload, String requestID) throws Exception {
114
115         ObjectMapper objectMapper = new ObjectMapper();
116         JsonNode payloadObject = objectMapper.readTree(payload);
117         ArrayList<String> argList = new ArrayList<>();
118         argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue());
119         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
120
121         String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID  IN "
122             + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? ";
123
124         if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject
125             .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) {
126             queryString = queryString + "  AND VNFC_TYPE = ? ) AND USER = ? ";
127             argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
128         } else {
129             queryString = queryString + "  ) AND USER = ? ";
130         }
131         argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
132         log.info(QUERY_STR + queryString);
133         boolean data = dbservice.updateDBData(queryString, argList);
134
135         if (!data) {
136             throw new DBException("Error while updating ProtocolReference");
137         }
138         return SUCCESS_JSON;
139     }
140
141     private String setProtocolReference(String payload, String requestID) throws Exception {
142
143         ObjectMapper objectMapper = new ObjectMapper();
144         JsonNode payloadObject = objectMapper.readTree(payload);
145         ArrayList<String> argList = new ArrayList<>();
146
147         argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
148         argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue());
149         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
150         argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
151
152         String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ?  AND PROTOCOL = ? ";
153
154         log.info("Delete Query String :" + queryString);
155         boolean data;
156
157         log.info("Record Deleted");
158
159         if (payloadObject.get(DesignServiceConstants.TEMPLATE) != null &&
160             !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty()) {
161
162             argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue());
163         } else {
164             argList.add("NO");
165         }
166
167         if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null &&
168             !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
169
170             queryString = queryString + " AND  VNFC_TYPE =  ? )";
171         } else {
172             queryString = queryString + " ) ";
173         }
174         log.info(QUERY_STR + queryString);
175         data = dbservice.updateDBData(queryString, argList);
176
177         if (!data) {
178             throw new DBException("Error while updating ProtocolReference");
179         }
180         return SUCCESS_JSON;
181     }
182
183     private String uploadArtifact(String payload, String requestID) throws Exception {
184
185         ObjectMapper objectMapper = new ObjectMapper();
186         objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
187         JsonNode payloadObject = objectMapper.readTree(payload);
188         log.info("Got upload Aritfact with Payload : " + payloadObject.asText());
189         try {
190             ArtifactHandlerClient ac = new ArtifactHandlerClient();
191             String requestString = ac.createArtifactData(payload, requestID);
192             ac.execute(requestString, "POST");
193             int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID);
194             int sdcReferenceId = getSDCReferenceID(payload);
195             createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId);
196             String status = getDataFromActionStatus(payload, STATUS);
197             if (status == null || status.isEmpty()) {
198               log.info("Action Status is: "+ status);
199               setActionStatus(payload, "Not Tested");
200             }
201             linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload);
202
203         } catch (Exception e) {
204             log.error("An error occured in uploadArtifact", e);
205             throw e;
206         }
207         return SUCCESS_JSON;
208
209     }
210
211     private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception {
212
213         ObjectMapper objectMapper = new ObjectMapper();
214         JsonNode payloadObject = objectMapper.readTree(payload);
215         ArrayList<String> argList = new ArrayList<>();
216         argList.add(String.valueOf(sdcArtifactId));
217         argList.add(String.valueOf(sdcReferenceId));
218         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
219         argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
220         argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
221
222         String queryString =
223             "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " +
224                 "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , "
225                 + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE  VNF_TYPE = ? AND ACTION = ?  AND USER = ? ";
226
227         if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
228             .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
229             queryString = queryString + " AND  VNFC_TYPE =  ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )";
230         } else {
231             queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) ";
232         }
233         log.info(QUERY_STR + queryString);
234         boolean data = dbservice.updateDBData(queryString, argList);
235
236         if (!data) {
237             throw new DBException("Error while updating RelationShip table");
238         }
239
240     }
241
242     private int getSDCReferenceID(String payload) throws Exception {
243
244         ObjectMapper objectMapper = new ObjectMapper();
245         JsonNode payloadObject = objectMapper.readTree(payload);
246         ArrayList<String> argList = new ArrayList<>();
247         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
248
249         argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue());
250         argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue());
251
252         String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ?  "
253             + " AND ARTIFACT_TYPE = ?  AND ARTIFACT_NAME = ? ";
254
255         if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject
256             .get(DesignServiceConstants.ACTION).textValue().isEmpty()) {
257             argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
258             queryString = queryString + " AND ACTION = ? ";
259         }
260         if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
261             .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
262             argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
263             queryString = queryString + " AND VNFC_TYPE = ? ";
264
265         }
266
267         log.info(QUERY_STR + queryString);
268         ResultSet data = dbservice.getDBData(queryString, argList);
269         int sdcReferenceId = 0;
270         while (data.next()) {
271             sdcReferenceId = data.getInt("ASDC_REFERENCE_ID");
272         }
273         log.info("Got sdcReferenceId= " + sdcReferenceId);
274         return sdcReferenceId;
275     }
276
277     private String getDataFromActionStatus(String payload, String dataValue) throws Exception {
278         String status = null;
279         ObjectMapper objectMapper = new ObjectMapper();
280         JsonNode payloadObject = objectMapper.readTree(payload);
281         ArrayList<String> argList = new ArrayList<>();
282         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
283         argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
284         argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
285         String queryString =
286             " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
287         if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
288             .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
289             argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
290             queryString = queryString + " AND VNFC_TYPE = ? ";
291         }
292         log.info(QUERY_STR + queryString);
293         ResultSet data = dbservice.getDBData(queryString, argList);
294         while (data.next()) {
295             status = data.getString(STATUS);
296         }
297         log.info("DT_ACTION_STATUS Status = " + status);
298         return status;
299     }
300
301     private void setActionStatus(String payload, String status) throws Exception {
302         ObjectMapper objectMapper = new ObjectMapper();
303         JsonNode payloadObject = objectMapper.readTree(payload);
304         ArrayList<String> argList = new ArrayList<>();
305         argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
306         argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
307
308         String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); ";
309         if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
310             .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
311             argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
312             log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
313         } else {
314             argList.add(null);
315         }
316         argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
317         if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
318             .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
319             argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
320         } else {
321             argList.add(null);
322         }
323         argList.add(status);
324
325         log.info("QueryString: " + insertQuery);
326         log.info("Arguments List: " + argList);
327         boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
328         if (!updateStatus)
329             throw new DBException("Error while updating Action Status");
330     }
331
332     private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
333         throws Exception {
334
335         ObjectMapper objectMapper = new ObjectMapper();
336         JsonNode payloadObject = objectMapper.readTree(payload);
337
338         ArrayList<String> argList = new ArrayList<>();
339         argList.add(String.valueOf(sdcArtifactId));
340         argList.add(String.valueOf(sdcReferenceId));
341         argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
342         if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
343             .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
344             argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
345         } else {
346             argList.add("");
347         }
348
349         if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject
350             .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) {
351             argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
352         } else {
353             argList.add("");
354         }
355
356         String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created',  ? ,'N' )";
357
358         log.info(QUERY_STR + queryString);
359         boolean data = dbservice.updateDBData(queryString, argList);
360         if (!data) {
361             throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
362         }
363     }
364
365     private int getSDCArtifactIDbyRequestID(String requestID) throws Exception {
366         log.info("Starting getArtifactIDbyRequestID DB Operation");
367         int artifactId = 0;
368         try {
369             ArrayList<String> argList = new ArrayList<>();
370             argList.add("TLSUUID" + requestID);
371             String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
372             log.info(QUERY_STR + queryString);
373             ResultSet data = dbservice.getDBData(queryString, argList);
374             while (data.next()) {
375                 artifactId = data.getInt("ASDC_ARTIFACTS_ID");
376             }
377         } catch (Exception e) {
378             log.error("An error occurred in getSDCArtifactIDbyRequestID", e);
379             throw e;
380         }
381         log.info("Got SDC_ARTIFACTS_ID As :" + artifactId);
382         return artifactId;
383     }
384
385
386     private String getArtifact(String payload, String requestID) throws Exception {
387         log.info("Starting getArtifact DB Operation");
388         try {
389             ObjectMapper objectMapper = new ObjectMapper();
390             JsonNode payloadObject = objectMapper.readTree(payload);
391             ArrayList<String> argList = new ArrayList<>();
392             argList.add(payloadObject.get("artifact-name").textValue());
393             argList.add(payloadObject.get("artifact-type").textValue());
394
395             String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " +
396                 " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ?  ";
397
398             log.info(QUERY_STR + queryString);
399             ResultSet data = dbservice.getDBData(queryString, argList);
400             String artifactContent = null;
401             int hightestVerion = -1;
402             while (data.next()) {
403                 int version = data.getInt("INTERNAL_VERSION");
404                 if (hightestVerion < version) {
405                     artifactContent = data.getString("ARTIFACT_CONTENT");
406                 }
407             }
408             if (artifactContent == null || artifactContent.isEmpty()) {
409                 throw new DBException(
410                     "Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue());
411             }
412             DesignResponse designResponse = new DesignResponse();
413             List<ArtifactInfo> artifactInfoList = new ArrayList<>();
414             ArtifactInfo artifactInfo = new ArtifactInfo();
415             artifactInfo.setArtifact_content(artifactContent);
416             artifactInfoList.add(artifactInfo);
417             designResponse.setArtifactInfo(artifactInfoList);
418             ObjectMapper mapper = new ObjectMapper();
419             String jsonString = mapper.writeValueAsString(designResponse);
420             log.info(INFO_STR + jsonString);
421             return jsonString;
422         } catch (Exception e) {
423             log.error(DB_OPERATION_ERROR, e);
424             throw e;
425         }
426     }
427
428     private String setStatus(String payload, String requestID) throws Exception {
429
430         log.info("Starting getStatus DB Operation");
431         try {
432             ObjectMapper objectMapper = new ObjectMapper();
433             JsonNode payloadObject = objectMapper.readTree(payload);
434
435             ArrayList<String> argList = new ArrayList<>();
436             argList.add(payloadObject.get("artifact_status").textValue());
437             argList.add(payloadObject.get("action_status").textValue());
438
439             argList.add(payloadObject.get(USER_ID).textValue());
440             argList.add(payloadObject.get("vnf-type").textValue());
441
442             String queryString =
443                 " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR  SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? "
444                     + " where  DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
445                     + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
446                     + " and  DAS.VNF_TYPE = ? ";
447
448             if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) {
449                 argList.add(payloadObject.get(VNFC_TYPE).textValue());
450                 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
451             }
452
453             log.info(QUERY_STR + queryString);
454
455             DesignResponse designResponse = new DesignResponse();
456             designResponse.setUserId(payloadObject.get(USER_ID).textValue());
457             boolean update = dbservice.updateDBData(queryString, argList);
458             if (!update) {
459                 throw new DBException("Sorry .....Something went wrong while updating the Status");
460             }
461
462             ObjectMapper mapper = new ObjectMapper();
463             String jsonString = mapper.writeValueAsString(designResponse);
464             log.info(INFO_STR + jsonString);
465             return jsonString;
466         } catch (Exception e) {
467             log.error(DB_OPERATION_ERROR, e);
468             throw e;
469         }
470     }
471
472     private String getStatus(String payload, String requestID) throws Exception {
473         log.info("Starting getStatus DB Operation");
474         try {
475             String vnfcType = null;
476             ObjectMapper objectMapper = new ObjectMapper();
477             JsonNode payloadObject = objectMapper.readTree(payload);
478             String userID = payloadObject.get(USER_ID).textValue();
479             String vnfType = payloadObject.get("vnf-type").textValue();
480             if (payloadObject.get(VNFC_TYPE) != null) {
481                 vnfcType = payloadObject.get(VNFC_TYPE).textValue();
482             }
483             ArrayList<String> argList = new ArrayList<>();
484
485             argList.add(userID);
486             argList.add(vnfType);
487
488             String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE,  DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS "
489                 + "from  DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " +
490                 " where  DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
491                 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
492                 + " and  DAS.VNF_TYPE = ? ";
493
494             if (vnfcType != null && !vnfcType.isEmpty()) {
495                 argList.add(vnfcType);
496                 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
497             }
498
499             log.info(QUERY_STR + queryString);
500
501             DesignResponse designResponse = new DesignResponse();
502             designResponse.setUserId(userID);
503             List<StatusInfo> statusInfoList = new ArrayList<>();
504             ResultSet data = dbservice.getDBData(queryString, argList);
505             while (data.next()) {
506                 StatusInfo statusInfo = new StatusInfo();
507                 statusInfo.setAction(data.getString("ACTION"));
508                 statusInfo.setAction_status(data.getString(STATUS));
509                 statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS"));
510                 statusInfo.setVnf_type(data.getString("VNF_TYPE"));
511                 statusInfo.setVnfc_type(data.getString("VNFC_TYPE"));
512                 statusInfoList.add(statusInfo);
513             }
514
515             if (statusInfoList.isEmpty()) {
516                 throw new DBException(
517                     "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
518             }
519             designResponse.setStatusInfoList(statusInfoList);
520             ObjectMapper mapper = new ObjectMapper();
521             String jsonString = mapper.writeValueAsString(designResponse);
522             log.info(INFO_STR + jsonString);
523             return jsonString;
524         } catch (SQLException e) {
525             log.error(DB_OPERATION_ERROR, e);
526             throw e;
527         } catch (Exception e) {
528             log.error(DB_OPERATION_ERROR + e.getMessage());
529             log.error("Exception : ", e);
530             throw e;
531         }
532     }
533
534     private String getGuiReference(String payload, String requestID) {
535         // TODO Auto-generated method stub
536         return null;
537     }
538
539     private String getArtifactReference(String payload, String requestID) {
540         // TODO Auto-generated method stub
541         return null;
542     }
543
544     private String getDesigns(String payload, String requestID) throws Exception {
545
546         String queryString;
547         log.info("Starting getDesigns DB Operation");
548
549         try {
550             ObjectMapper objectMapper = new ObjectMapper();
551             JsonNode payloadObject = objectMapper.readTree(payload);
552             String userID = payloadObject.get(USER_ID).textValue();
553             String filterKey = null;
554             if (payloadObject.hasNonNull("filter")) {
555                 filterKey = payloadObject.get("filter").textValue();
556             }
557             ArrayList<String> argList = new ArrayList<>();
558             argList.add(userID);
559
560             if (filterKey != null) {
561                 queryString =
562                     "SELECT AR.VNF_TYPE, AR.VNFC_TYPE,  DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from  "
563                         +
564                         DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
565                         + DesignServiceConstants.DB_SDC_REFERENCE +
566                         " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID  and DAT.USER = ? and AR.ARTIFACT_NAME like '%"
567                         + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
568             } else {
569                 queryString =
570                     "SELECT AR.VNF_TYPE, AR.VNFC_TYPE,  DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from  "
571                         +
572                         DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
573                         + DesignServiceConstants.DB_SDC_REFERENCE +
574                         " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID  and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
575             }
576             DesignResponse designResponse = new DesignResponse();
577             designResponse.setUserId(userID);
578             List<DesignInfo> designInfoList = new ArrayList<>();
579             ResultSet data = dbservice.getDBData(queryString, argList);
580             while (data.next()) {
581                 DesignInfo designInfo = new DesignInfo();
582                 designInfo.setInCart(data.getString("IN_CART"));
583                 designInfo.setProtocol(data.getString("PROTOCOL"));
584                 designInfo.setVnf_type(data.getString("VNF_TYPE"));
585                 designInfo.setVnfc_type(data.getString("VNFC_TYPE"));
586                 designInfo.setAction(data.getString("ACTION"));
587                 designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE"));
588                 designInfo.setArtifact_name(data.getString("ARTIFACT_NAME"));
589                 designInfoList.add(designInfo);
590             }
591             if (designInfoList.isEmpty()) {
592                 throw new DBException(
593                     " Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
594             }
595             designResponse.setDesignInfoList(designInfoList);
596             ObjectMapper mapper = new ObjectMapper();
597             String jsonString = mapper.writeValueAsString(designResponse);
598             log.info(INFO_STR + jsonString);
599             return jsonString;
600         } catch (Exception e) {
601             log.error("Error while Starting getDesgins DB operation : ", e);
602             throw e;
603         }
604     }
605 }
606
607