2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.design.dbervices;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.fasterxml.jackson.core.JsonParser;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import com.fasterxml.jackson.databind.ObjectMapper;
31 import java.io.IOException;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.util.ArrayList;
35 import java.util.List;
36 import org.onap.appc.design.data.ArtifactInfo;
37 import org.onap.appc.design.data.DesignInfo;
38 import org.onap.appc.design.data.DesignResponse;
39 import org.onap.appc.design.data.StatusInfo;
40 import org.onap.appc.design.services.util.ArtifactHandlerClient;
41 import org.onap.appc.design.services.util.DesignServiceConstants;
42 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
45 public class DesignDBService {
47 private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class);
48 private static DesignDBService dgGeneralDBService;
50 private static final String SUCCESS_JSON = "{\"update\" : \"success\" } ";
51 private static final String STATUS = "STATUS";
52 private static final String INFO_STR = "Info : ";
53 private static final String DB_OPERATION_ERROR = "Error while DB operation : ";
54 private static final String VNFC_TYPE = "vnfc-type";
55 private static final String QUERY_STR = "Query String :";
56 private static final String USER_ID = "userID";
58 private SvcLogicResource serviceLogic;
59 private DbService dbservice;
60 private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory();
62 public static DesignDBService initialise() {
63 if (dgGeneralDBService == null) {
64 dgGeneralDBService = new DesignDBService();
66 return dgGeneralDBService;
69 private DesignDBService() {
70 if (serviceLogic == null) {
71 serviceLogic = new SqlResource();
75 public String execute(String action, String payload, String requestID) throws Exception {
77 log.info("Received execute request for action : " + action + " with Payload : " + payload);
78 RequestValidator.validate(action, payload);
80 dbservice = new DbService();
82 case DesignServiceConstants.GETDESIGNS:
83 response = getDesigns(payload, requestID);
85 case DesignServiceConstants.GETAPPCTIMESTAMPUTC:
86 response = getAppcTimestampUTC( requestID );
88 case DesignServiceConstants.ADDINCART:
89 response = setInCart(payload, requestID);
91 case DesignServiceConstants.GETARTIFACTREFERENCE:
92 response = getArtifactReference(payload, requestID);
94 case DesignServiceConstants.GETARTIFACT:
95 response = getArtifact(payload, requestID);
97 case DesignServiceConstants.GETGUIREFERENCE:
98 response = getGuiReference(payload, requestID);
100 case DesignServiceConstants.GETSTATUS:
101 response = getStatus(payload, requestID);
103 case DesignServiceConstants.SETSTATUS:
104 response = setStatus(payload, requestID);
106 case DesignServiceConstants.UPLOADARTIFACT:
107 response = uploadArtifact(payload, requestID);
109 case DesignServiceConstants.SETPROTOCOLREFERENCE:
110 response = setProtocolReference(payload, requestID);
113 throw new DBException(" Action " + action + " not found while processing request ");
119 private String getAppcTimestampUTC( String requestID) throws Exception
121 log.info("Starting getAppcTimestampUTC: requestID:"+ requestID );
122 java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT");
123 java.text.SimpleDateFormat formatter =
124 new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
125 formatter.setTimeZone( gmtTZ );
126 java.util.Date dateVal= new java.util.Date();
127 log.info("getAppcTimestampUTC: current local Date:["+ dateVal+"]");
128 String timeStr= formatter.format( dateVal );
129 log.info("getAppcTimestampUTC: returning:["+timeStr+"]");
133 private String setInCart(String payload, String requestID) throws Exception {
135 ObjectMapper objectMapper = new ObjectMapper();
136 JsonNode payloadObject = objectMapper.readTree(payload);
137 ArrayList<String> argList = new ArrayList<>();
138 argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue());
139 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
141 String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN "
142 + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? ";
144 if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject
145 .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) {
146 queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? ";
147 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
149 queryString = queryString + " ) AND USER = ? ";
151 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
152 log.info(QUERY_STR + queryString);
153 boolean data = dbservice.updateDBData(queryString, argList);
156 throw new DBException("Error while updating ProtocolReference");
161 private String setProtocolReference(String payload, String requestID) throws Exception {
163 ObjectMapper objectMapper = new ObjectMapper();
164 JsonNode payloadObject = objectMapper.readTree(payload);
165 ArrayList<String> argList = new ArrayList<>();
167 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
168 argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue());
169 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
170 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
172 String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? ";
174 log.info("Delete Query String :" + queryString);
177 log.info("Record Deleted");
179 if (payloadObject.get(DesignServiceConstants.TEMPLATE) != null &&
180 !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty()) {
182 argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue());
187 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null &&
188 !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
190 queryString = queryString + " AND VNFC_TYPE = ? )";
192 queryString = queryString + " ) ";
194 log.info(QUERY_STR + queryString);
195 data = dbservice.updateDBData(queryString, argList);
198 throw new DBException("Error while updating ProtocolReference");
203 private String uploadArtifact(String payload, String requestID) throws Exception {
205 ObjectMapper objectMapper = new ObjectMapper();
206 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
207 JsonNode payloadObject = objectMapper.readTree(payload);
208 log.info("Got upload Aritfact with Payload : " + payloadObject.asText());
210 ArtifactHandlerClient ac = artifactHandlerFactory.ahi();
211 String requestString = ac.createArtifactData(payload, requestID);
212 ac.execute(requestString, "POST");
213 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID);
214 int sdcReferenceId = getSDCReferenceID(payload);
215 createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId);
216 String status = getDataFromActionStatus(payload, STATUS);
217 if (status == null || status.isEmpty()) {
218 log.info("Action Status is: "+ status);
219 setActionStatus(payload, "Not Tested");
221 linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload);
223 } catch (Exception e) {
224 log.error("An error occured in uploadArtifact", e);
231 private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception {
233 ObjectMapper objectMapper = new ObjectMapper();
234 JsonNode payloadObject = objectMapper.readTree(payload);
235 ArrayList<String> argList = new ArrayList<>();
236 argList.add(String.valueOf(sdcArtifactId));
237 argList.add(String.valueOf(sdcReferenceId));
238 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
239 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
240 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
243 "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " +
244 "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , "
245 + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
247 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
248 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
249 queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )";
251 queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) ";
253 log.info(QUERY_STR + queryString);
254 boolean data = dbservice.updateDBData(queryString, argList);
257 throw new DBException("Error while updating RelationShip table");
262 private int getSDCReferenceID(String payload) throws Exception {
264 ObjectMapper objectMapper = new ObjectMapper();
265 JsonNode payloadObject = objectMapper.readTree(payload);
266 ArrayList<String> argList = new ArrayList<>();
267 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
269 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue());
270 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue());
272 String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? "
273 + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? ";
275 if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject
276 .get(DesignServiceConstants.ACTION).textValue().isEmpty()) {
277 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
278 queryString = queryString + " AND ACTION = ? ";
280 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
281 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
282 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
283 queryString = queryString + " AND VNFC_TYPE = ? ";
287 log.info(QUERY_STR + queryString);
288 ResultSet data = dbservice.getDBData(queryString, argList);
289 int sdcReferenceId = 0;
290 while (data.next()) {
291 sdcReferenceId = data.getInt("ASDC_REFERENCE_ID");
293 log.info("Got sdcReferenceId= " + sdcReferenceId);
294 return sdcReferenceId;
297 private String getDataFromActionStatus(String payload, String dataValue) throws Exception {
298 String status = null;
299 ObjectMapper objectMapper = new ObjectMapper();
300 JsonNode payloadObject = objectMapper.readTree(payload);
301 ArrayList<String> argList = new ArrayList<>();
302 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
303 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
304 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
306 " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
307 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
308 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
309 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
310 queryString = queryString + " AND VNFC_TYPE = ? ";
312 log.info(QUERY_STR + queryString);
313 ResultSet data = dbservice.getDBData(queryString, argList);
314 while (data.next()) {
315 status = data.getString(STATUS);
317 log.info("DT_ACTION_STATUS Status = " + status);
321 private void setActionStatus(String payload, String status) throws Exception {
322 ObjectMapper objectMapper = new ObjectMapper();
323 JsonNode payloadObject = objectMapper.readTree(payload);
324 ArrayList<String> argList = new ArrayList<>();
325 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
326 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
328 String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); ";
329 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
330 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
331 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
332 log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
336 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
337 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
338 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
339 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
345 log.info("QueryString: " + insertQuery);
346 log.info("Arguments List: " + argList);
347 boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
349 throw new DBException("Error while updating Action Status");
352 private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
355 ObjectMapper objectMapper = new ObjectMapper();
356 JsonNode payloadObject = objectMapper.readTree(payload);
358 ArrayList<String> argList = new ArrayList<>();
359 argList.add(String.valueOf(sdcArtifactId));
360 argList.add(String.valueOf(sdcReferenceId));
361 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
362 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
363 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
364 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
369 if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject
370 .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) {
371 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
376 String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created', ? ,'N' )";
378 log.info(QUERY_STR + queryString);
379 boolean data = dbservice.updateDBData(queryString, argList);
381 throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
385 private int getSDCArtifactIDbyRequestID(String requestID) throws Exception {
386 log.info("Starting getArtifactIDbyRequestID DB Operation");
389 ArrayList<String> argList = new ArrayList<>();
390 argList.add("TLSUUID" + requestID);
391 String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
392 log.info(QUERY_STR + queryString);
393 ResultSet data = dbservice.getDBData(queryString, argList);
394 while (data.next()) {
395 artifactId = data.getInt("ASDC_ARTIFACTS_ID");
397 } catch (Exception e) {
398 log.error("An error occurred in getSDCArtifactIDbyRequestID", e);
401 log.info("Got SDC_ARTIFACTS_ID As :" + artifactId);
406 private String getArtifact(String payload, String requestID) throws Exception {
407 log.info("Starting getArtifact DB Operation");
409 ObjectMapper objectMapper = new ObjectMapper();
410 JsonNode payloadObject = objectMapper.readTree(payload);
411 ArrayList<String> argList = new ArrayList<>();
412 argList.add(payloadObject.get("artifact-name").textValue());
413 argList.add(payloadObject.get("artifact-type").textValue());
415 String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " +
416 " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
418 log.info(QUERY_STR + queryString);
419 ResultSet data = dbservice.getDBData(queryString, argList);
420 String artifactContent = null;
421 int hightestVerion = -1;
422 while (data.next()) {
423 int version = data.getInt("INTERNAL_VERSION");
424 if (hightestVerion < version) {
425 artifactContent = data.getString("ARTIFACT_CONTENT");
428 if (artifactContent == null || artifactContent.isEmpty()) {
429 throw new DBException(
430 "Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue());
432 DesignResponse designResponse = new DesignResponse();
433 List<ArtifactInfo> artifactInfoList = new ArrayList<>();
434 ArtifactInfo artifactInfo = new ArtifactInfo();
435 artifactInfo.setArtifact_content(artifactContent);
436 artifactInfoList.add(artifactInfo);
437 designResponse.setArtifactInfo(artifactInfoList);
438 ObjectMapper mapper = new ObjectMapper();
439 String jsonString = mapper.writeValueAsString(designResponse);
440 log.info(INFO_STR + jsonString);
442 } catch (Exception e) {
443 log.error(DB_OPERATION_ERROR, e);
448 private String setStatus(String payload, String requestID) throws Exception {
450 log.info("Starting getStatus DB Operation");
452 ObjectMapper objectMapper = new ObjectMapper();
453 JsonNode payloadObject = objectMapper.readTree(payload);
455 ArrayList<String> argList = new ArrayList<>();
456 argList.add(payloadObject.get("artifact_status").textValue());
457 argList.add(payloadObject.get("action_status").textValue());
459 argList.add(payloadObject.get(USER_ID).textValue());
460 argList.add(payloadObject.get("vnf-type").textValue());
463 " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? "
464 + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
465 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
466 + " and DAS.VNF_TYPE = ? ";
468 if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) {
469 argList.add(payloadObject.get(VNFC_TYPE).textValue());
470 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
473 log.info(QUERY_STR + queryString);
475 DesignResponse designResponse = new DesignResponse();
476 designResponse.setUserId(payloadObject.get(USER_ID).textValue());
477 boolean update = dbservice.updateDBData(queryString, argList);
479 throw new DBException("Sorry .....Something went wrong while updating the Status");
482 ObjectMapper mapper = new ObjectMapper();
483 String jsonString = mapper.writeValueAsString(designResponse);
484 log.info(INFO_STR + jsonString);
486 } catch (Exception e) {
487 log.error(DB_OPERATION_ERROR, e);
492 private String getStatus(String payload, String requestID) throws Exception {
493 log.info("Starting getStatus DB Operation");
495 String vnfcType = null;
496 ObjectMapper objectMapper = new ObjectMapper();
497 JsonNode payloadObject = objectMapper.readTree(payload);
498 String userID = payloadObject.get(USER_ID).textValue();
499 String vnfType = payloadObject.get("vnf-type").textValue();
500 if (payloadObject.get(VNFC_TYPE) != null) {
501 vnfcType = payloadObject.get(VNFC_TYPE).textValue();
503 ArrayList<String> argList = new ArrayList<>();
506 argList.add(vnfType);
508 String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS "
509 + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " +
510 " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
511 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
512 + " and DAS.VNF_TYPE = ? ";
514 if (vnfcType != null && !vnfcType.isEmpty()) {
515 argList.add(vnfcType);
516 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
519 log.info(QUERY_STR + queryString);
521 DesignResponse designResponse = new DesignResponse();
522 designResponse.setUserId(userID);
523 List<StatusInfo> statusInfoList = new ArrayList<>();
524 ResultSet data = dbservice.getDBData(queryString, argList);
525 while (data.next()) {
526 StatusInfo statusInfo = new StatusInfo();
527 statusInfo.setAction(data.getString("ACTION"));
528 statusInfo.setAction_status(data.getString(STATUS));
529 statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS"));
530 statusInfo.setVnf_type(data.getString("VNF_TYPE"));
531 statusInfo.setVnfc_type(data.getString("VNFC_TYPE"));
532 statusInfoList.add(statusInfo);
535 if (statusInfoList.isEmpty()) {
536 throw new DBException(
537 "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
539 designResponse.setStatusInfoList(statusInfoList);
540 ObjectMapper mapper = new ObjectMapper();
541 String jsonString = mapper.writeValueAsString(designResponse);
542 log.info(INFO_STR + jsonString);
544 } catch (SQLException e) {
545 log.error(DB_OPERATION_ERROR, e);
547 } catch (Exception e) {
548 log.error(DB_OPERATION_ERROR + e.getMessage());
549 log.error("Exception : ", e);
554 private String getGuiReference(String payload, String requestID) {
555 // TODO Auto-generated method stub
559 private String getArtifactReference(String payload, String requestID) {
560 // TODO Auto-generated method stub
564 private String getDesigns(String payload, String requestID) throws Exception {
567 log.info("Starting getDesigns DB Operation");
570 ObjectMapper objectMapper = new ObjectMapper();
571 JsonNode payloadObject = objectMapper.readTree(payload);
572 String userID = payloadObject.get(USER_ID).textValue();
573 String filterKey = null;
574 if (payloadObject.hasNonNull("filter")) {
575 filterKey = payloadObject.get("filter").textValue();
577 ArrayList<String> argList = new ArrayList<>();
580 if (filterKey != null) {
582 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
584 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
585 + DesignServiceConstants.DB_SDC_REFERENCE +
586 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%"
587 + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
590 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
592 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
593 + DesignServiceConstants.DB_SDC_REFERENCE +
594 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
596 DesignResponse designResponse = new DesignResponse();
597 designResponse.setUserId(userID);
598 List<DesignInfo> designInfoList = new ArrayList<>();
599 ResultSet data = dbservice.getDBData(queryString, argList);
600 while (data.next()) {
601 DesignInfo designInfo = new DesignInfo();
602 designInfo.setInCart(data.getString("IN_CART"));
603 designInfo.setProtocol(data.getString("PROTOCOL"));
604 designInfo.setVnf_type(data.getString("VNF_TYPE"));
605 designInfo.setVnfc_type(data.getString("VNFC_TYPE"));
606 designInfo.setAction(data.getString("ACTION"));
607 designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE"));
608 designInfo.setArtifact_name(data.getString("ARTIFACT_NAME"));
609 designInfoList.add(designInfo);
611 if (designInfoList.isEmpty()) {
612 throw new DBException(
613 " Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
615 designResponse.setDesignInfoList(designInfoList);
616 ObjectMapper mapper = new ObjectMapper();
617 String jsonString = mapper.writeValueAsString(designResponse);
618 log.info(INFO_STR + jsonString);
620 } catch (Exception e) {
621 log.error("Error while Starting getDesgins DB operation : ", e);
627 public static class ArtifactHandlerFactory {
629 public ArtifactHandlerClient ahi() throws Exception{
630 return new ArtifactHandlerClient();