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