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