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;
30 import java.sql.ResultSet;
31 import java.sql.SQLException;
32 import java.util.ArrayList;
33 import java.util.List;
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.adaptors.resource.sql.SqlResource;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
43 public class DesignDBService {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class);
46 private static DesignDBService dgGeneralDBService;
48 private static final String SUCCESS_JSON = "{\"update\" : \"success\" } ";
49 private static final String STATUS = "STATUS";
50 private static final String INFO_STR = "Info : ";
51 private static final String DB_OPERATION_ERROR = "Error while DB operation : ";
52 private static final String VNFC_TYPE = "vnfc-type";
53 private static final String QUERY_STR = "Query String :";
54 private static final String USER_ID = "userID";
56 private SvcLogicResource serviceLogic;
57 private DbService dbservice;
59 public static DesignDBService initialise() {
60 if (dgGeneralDBService == null) {
61 dgGeneralDBService = new DesignDBService();
63 return dgGeneralDBService;
66 private DesignDBService() {
67 if (serviceLogic == null) {
68 serviceLogic = new SqlResource();
72 public String execute(String action, String payload, String requestID) throws Exception {
74 log.info("Received execute request for action : " + action + " with Payload : " + payload);
75 RequestValidator.validate(action, payload);
77 dbservice = new DbService();
79 case DesignServiceConstants.GETDESIGNS:
80 response = getDesigns(payload, requestID);
82 case DesignServiceConstants.GETAPPCTIMESTAMPUTC:
83 response = getAppcTimestampUTC( requestID );
85 case DesignServiceConstants.ADDINCART:
86 response = setInCart(payload, requestID);
88 case DesignServiceConstants.GETARTIFACTREFERENCE:
89 response = getArtifactReference(payload, requestID);
91 case DesignServiceConstants.GETARTIFACT:
92 response = getArtifact(payload, requestID);
94 case DesignServiceConstants.GETGUIREFERENCE:
95 response = getGuiReference(payload, requestID);
97 case DesignServiceConstants.GETSTATUS:
98 response = getStatus(payload, requestID);
100 case DesignServiceConstants.SETSTATUS:
101 response = setStatus(payload, requestID);
103 case DesignServiceConstants.UPLOADARTIFACT:
104 response = uploadArtifact(payload, requestID);
106 case DesignServiceConstants.SETPROTOCOLREFERENCE:
107 response = setProtocolReference(payload, requestID);
110 throw new DBException(" Action " + action + " not found while processing request ");
116 private String getAppcTimestampUTC( String requestID) throws Exception
118 log.info("Starting getAppcTimestampUTC: requestID:"+ requestID );
119 java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT");
120 java.text.SimpleDateFormat formatter =
121 new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
122 formatter.setTimeZone( gmtTZ );
123 java.util.Date dateVal= new java.util.Date();
124 log.info("getAppcTimestampUTC: current local Date:["+ dateVal+"]");
125 String timeStr= formatter.format( dateVal );
126 log.info("getAppcTimestampUTC: returning:["+timeStr+"]");
130 private String setInCart(String payload, String requestID) throws Exception {
132 ObjectMapper objectMapper = new ObjectMapper();
133 JsonNode payloadObject = objectMapper.readTree(payload);
134 ArrayList<String> argList = new ArrayList<>();
135 argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue());
136 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
138 String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN "
139 + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? ";
141 if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject
142 .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) {
143 queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? ";
144 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
146 queryString = queryString + " ) AND USER = ? ";
148 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
149 log.info(QUERY_STR + queryString);
150 boolean data = dbservice.updateDBData(queryString, argList);
153 throw new DBException("Error while updating ProtocolReference");
158 private String setProtocolReference(String payload, String requestID) throws Exception {
160 ObjectMapper objectMapper = new ObjectMapper();
161 JsonNode payloadObject = objectMapper.readTree(payload);
162 ArrayList<String> argList = new ArrayList<>();
164 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
165 argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue());
166 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
167 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
169 String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? ";
171 log.info("Delete Query String :" + queryString);
174 log.info("Record Deleted");
176 if (payloadObject.get(DesignServiceConstants.TEMPLATE) != null &&
177 !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty()) {
179 argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue());
184 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null &&
185 !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
187 queryString = queryString + " AND VNFC_TYPE = ? )";
189 queryString = queryString + " ) ";
191 log.info(QUERY_STR + queryString);
192 data = dbservice.updateDBData(queryString, argList);
195 throw new DBException("Error while updating ProtocolReference");
200 private String uploadArtifact(String payload, String requestID) throws Exception {
202 ObjectMapper objectMapper = new ObjectMapper();
203 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
204 JsonNode payloadObject = objectMapper.readTree(payload);
205 log.info("Got upload Aritfact with Payload : " + payloadObject.asText());
207 ArtifactHandlerClient ac = new ArtifactHandlerClient();
208 String requestString = ac.createArtifactData(payload, requestID);
209 ac.execute(requestString, "POST");
210 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID);
211 int sdcReferenceId = getSDCReferenceID(payload);
212 createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId);
213 String status = getDataFromActionStatus(payload, STATUS);
214 if (status == null || status.isEmpty()) {
215 log.info("Action Status is: "+ status);
216 setActionStatus(payload, "Not Tested");
218 linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload);
220 } catch (Exception e) {
221 log.error("An error occured in uploadArtifact", e);
228 private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception {
230 ObjectMapper objectMapper = new ObjectMapper();
231 JsonNode payloadObject = objectMapper.readTree(payload);
232 ArrayList<String> argList = new ArrayList<>();
233 argList.add(String.valueOf(sdcArtifactId));
234 argList.add(String.valueOf(sdcReferenceId));
235 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
236 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
237 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
240 "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " +
241 "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , "
242 + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
244 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
245 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
246 queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )";
248 queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) ";
250 log.info(QUERY_STR + queryString);
251 boolean data = dbservice.updateDBData(queryString, argList);
254 throw new DBException("Error while updating RelationShip table");
259 private int getSDCReferenceID(String payload) throws Exception {
261 ObjectMapper objectMapper = new ObjectMapper();
262 JsonNode payloadObject = objectMapper.readTree(payload);
263 ArrayList<String> argList = new ArrayList<>();
264 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
266 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue());
267 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue());
269 String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? "
270 + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? ";
272 if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject
273 .get(DesignServiceConstants.ACTION).textValue().isEmpty()) {
274 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
275 queryString = queryString + " AND ACTION = ? ";
277 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
278 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
279 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
280 queryString = queryString + " AND VNFC_TYPE = ? ";
284 log.info(QUERY_STR + queryString);
285 ResultSet data = dbservice.getDBData(queryString, argList);
286 int sdcReferenceId = 0;
287 while (data.next()) {
288 sdcReferenceId = data.getInt("ASDC_REFERENCE_ID");
290 log.info("Got sdcReferenceId= " + sdcReferenceId);
291 return sdcReferenceId;
294 private String getDataFromActionStatus(String payload, String dataValue) throws Exception {
295 String status = null;
296 ObjectMapper objectMapper = new ObjectMapper();
297 JsonNode payloadObject = objectMapper.readTree(payload);
298 ArrayList<String> argList = new ArrayList<>();
299 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
300 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
301 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
303 " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
304 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
305 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
306 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
307 queryString = queryString + " AND VNFC_TYPE = ? ";
309 log.info(QUERY_STR + queryString);
310 ResultSet data = dbservice.getDBData(queryString, argList);
311 while (data.next()) {
312 status = data.getString(STATUS);
314 log.info("DT_ACTION_STATUS Status = " + status);
318 private void setActionStatus(String payload, String status) throws Exception {
319 ObjectMapper objectMapper = new ObjectMapper();
320 JsonNode payloadObject = objectMapper.readTree(payload);
321 ArrayList<String> argList = new ArrayList<>();
322 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
323 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
325 String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); ";
326 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
327 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
328 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
329 log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
333 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
334 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
335 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
336 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
342 log.info("QueryString: " + insertQuery);
343 log.info("Arguments List: " + argList);
344 boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
346 throw new DBException("Error while updating Action Status");
349 private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
352 ObjectMapper objectMapper = new ObjectMapper();
353 JsonNode payloadObject = objectMapper.readTree(payload);
355 ArrayList<String> argList = new ArrayList<>();
356 argList.add(String.valueOf(sdcArtifactId));
357 argList.add(String.valueOf(sdcReferenceId));
358 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
359 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
360 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
361 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
366 if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject
367 .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) {
368 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
373 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' )";
375 log.info(QUERY_STR + queryString);
376 boolean data = dbservice.updateDBData(queryString, argList);
378 throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
382 private int getSDCArtifactIDbyRequestID(String requestID) throws Exception {
383 log.info("Starting getArtifactIDbyRequestID DB Operation");
386 ArrayList<String> argList = new ArrayList<>();
387 argList.add("TLSUUID" + requestID);
388 String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
389 log.info(QUERY_STR + queryString);
390 ResultSet data = dbservice.getDBData(queryString, argList);
391 while (data.next()) {
392 artifactId = data.getInt("ASDC_ARTIFACTS_ID");
394 } catch (Exception e) {
395 log.error("An error occurred in getSDCArtifactIDbyRequestID", e);
398 log.info("Got SDC_ARTIFACTS_ID As :" + artifactId);
403 private String getArtifact(String payload, String requestID) throws Exception {
404 log.info("Starting getArtifact DB Operation");
406 ObjectMapper objectMapper = new ObjectMapper();
407 JsonNode payloadObject = objectMapper.readTree(payload);
408 ArrayList<String> argList = new ArrayList<>();
409 argList.add(payloadObject.get("artifact-name").textValue());
410 argList.add(payloadObject.get("artifact-type").textValue());
412 String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " +
413 " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
415 log.info(QUERY_STR + queryString);
416 ResultSet data = dbservice.getDBData(queryString, argList);
417 String artifactContent = null;
418 int hightestVerion = -1;
419 while (data.next()) {
420 int version = data.getInt("INTERNAL_VERSION");
421 if (hightestVerion < version) {
422 artifactContent = data.getString("ARTIFACT_CONTENT");
425 if (artifactContent == null || artifactContent.isEmpty()) {
426 throw new DBException(
427 "Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue());
429 DesignResponse designResponse = new DesignResponse();
430 List<ArtifactInfo> artifactInfoList = new ArrayList<>();
431 ArtifactInfo artifactInfo = new ArtifactInfo();
432 artifactInfo.setArtifact_content(artifactContent);
433 artifactInfoList.add(artifactInfo);
434 designResponse.setArtifactInfo(artifactInfoList);
435 ObjectMapper mapper = new ObjectMapper();
436 String jsonString = mapper.writeValueAsString(designResponse);
437 log.info(INFO_STR + jsonString);
439 } catch (Exception e) {
440 log.error(DB_OPERATION_ERROR, e);
445 private String setStatus(String payload, String requestID) throws Exception {
447 log.info("Starting getStatus DB Operation");
449 ObjectMapper objectMapper = new ObjectMapper();
450 JsonNode payloadObject = objectMapper.readTree(payload);
452 ArrayList<String> argList = new ArrayList<>();
453 argList.add(payloadObject.get("artifact_status").textValue());
454 argList.add(payloadObject.get("action_status").textValue());
456 argList.add(payloadObject.get(USER_ID).textValue());
457 argList.add(payloadObject.get("vnf-type").textValue());
460 " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? "
461 + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
462 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
463 + " and DAS.VNF_TYPE = ? ";
465 if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) {
466 argList.add(payloadObject.get(VNFC_TYPE).textValue());
467 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
470 log.info(QUERY_STR + queryString);
472 DesignResponse designResponse = new DesignResponse();
473 designResponse.setUserId(payloadObject.get(USER_ID).textValue());
474 boolean update = dbservice.updateDBData(queryString, argList);
476 throw new DBException("Sorry .....Something went wrong while updating the Status");
479 ObjectMapper mapper = new ObjectMapper();
480 String jsonString = mapper.writeValueAsString(designResponse);
481 log.info(INFO_STR + jsonString);
483 } catch (Exception e) {
484 log.error(DB_OPERATION_ERROR, e);
489 private String getStatus(String payload, String requestID) throws Exception {
490 log.info("Starting getStatus DB Operation");
492 String vnfcType = null;
493 ObjectMapper objectMapper = new ObjectMapper();
494 JsonNode payloadObject = objectMapper.readTree(payload);
495 String userID = payloadObject.get(USER_ID).textValue();
496 String vnfType = payloadObject.get("vnf-type").textValue();
497 if (payloadObject.get(VNFC_TYPE) != null) {
498 vnfcType = payloadObject.get(VNFC_TYPE).textValue();
500 ArrayList<String> argList = new ArrayList<>();
503 argList.add(vnfType);
505 String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS "
506 + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " +
507 " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
508 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
509 + " and DAS.VNF_TYPE = ? ";
511 if (vnfcType != null && !vnfcType.isEmpty()) {
512 argList.add(vnfcType);
513 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
516 log.info(QUERY_STR + queryString);
518 DesignResponse designResponse = new DesignResponse();
519 designResponse.setUserId(userID);
520 List<StatusInfo> statusInfoList = new ArrayList<>();
521 ResultSet data = dbservice.getDBData(queryString, argList);
522 while (data.next()) {
523 StatusInfo statusInfo = new StatusInfo();
524 statusInfo.setAction(data.getString("ACTION"));
525 statusInfo.setAction_status(data.getString(STATUS));
526 statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS"));
527 statusInfo.setVnf_type(data.getString("VNF_TYPE"));
528 statusInfo.setVnfc_type(data.getString("VNFC_TYPE"));
529 statusInfoList.add(statusInfo);
532 if (statusInfoList.isEmpty()) {
533 throw new DBException(
534 "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
536 designResponse.setStatusInfoList(statusInfoList);
537 ObjectMapper mapper = new ObjectMapper();
538 String jsonString = mapper.writeValueAsString(designResponse);
539 log.info(INFO_STR + jsonString);
541 } catch (SQLException e) {
542 log.error(DB_OPERATION_ERROR, e);
544 } catch (Exception e) {
545 log.error(DB_OPERATION_ERROR + e.getMessage());
546 log.error("Exception : ", e);
551 private String getGuiReference(String payload, String requestID) {
552 // TODO Auto-generated method stub
556 private String getArtifactReference(String payload, String requestID) {
557 // TODO Auto-generated method stub
561 private String getDesigns(String payload, String requestID) throws Exception {
564 log.info("Starting getDesigns DB Operation");
567 ObjectMapper objectMapper = new ObjectMapper();
568 JsonNode payloadObject = objectMapper.readTree(payload);
569 String userID = payloadObject.get(USER_ID).textValue();
570 String filterKey = null;
571 if (payloadObject.hasNonNull("filter")) {
572 filterKey = payloadObject.get("filter").textValue();
574 ArrayList<String> argList = new ArrayList<>();
577 if (filterKey != null) {
579 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
581 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
582 + DesignServiceConstants.DB_SDC_REFERENCE +
583 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%"
584 + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
587 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
589 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
590 + DesignServiceConstants.DB_SDC_REFERENCE +
591 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
593 DesignResponse designResponse = new DesignResponse();
594 designResponse.setUserId(userID);
595 List<DesignInfo> designInfoList = new ArrayList<>();
596 ResultSet data = dbservice.getDBData(queryString, argList);
597 while (data.next()) {
598 DesignInfo designInfo = new DesignInfo();
599 designInfo.setInCart(data.getString("IN_CART"));
600 designInfo.setProtocol(data.getString("PROTOCOL"));
601 designInfo.setVnf_type(data.getString("VNF_TYPE"));
602 designInfo.setVnfc_type(data.getString("VNFC_TYPE"));
603 designInfo.setAction(data.getString("ACTION"));
604 designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE"));
605 designInfo.setArtifact_name(data.getString("ARTIFACT_NAME"));
606 designInfoList.add(designInfo);
608 if (designInfoList.isEmpty()) {
609 throw new DBException(
610 " Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
612 designResponse.setDesignInfoList(designInfoList);
613 ObjectMapper mapper = new ObjectMapper();
614 String jsonString = mapper.writeValueAsString(designResponse);
615 log.info(INFO_STR + jsonString);
617 } catch (Exception e) {
618 log.error("Error while Starting getDesgins DB operation : ", e);