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