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