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