2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * Modifications (C) 2019 IBM
11 * =============================================================================
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.design.dbervices;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import com.fasterxml.jackson.core.JsonParser;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import java.sql.ResultSet;
34 import java.sql.SQLException;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.json.JSONObject;
39 import org.onap.appc.design.data.ArtifactInfo;
40 import org.onap.appc.design.data.DesignInfo;
41 import org.onap.appc.design.data.DesignResponse;
42 import org.onap.appc.design.data.StatusInfo;
43 import org.onap.appc.design.services.util.ArtifactHandlerClient;
44 import org.onap.appc.design.services.util.DesignServiceConstants;
45 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
46 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
47 import org.apache.commons.lang.StringUtils;
49 public class DesignDBService {
51 private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class);
52 private static DesignDBService dgGeneralDBService;
54 private static final String SUCCESS_JSON = "{\"update\" : \"success\" } ";
55 private static final String STATUS = "STATUS";
56 private static final String INFO_STR = "Info : ";
57 private static final String DB_OPERATION_ERROR = "Error while DB operation : ";
58 private static final String VNFC_TYPE = "vnfc-type";
59 private static final String QUERY_STR = "Query String :";
60 private static final String USER_ID = "userID";
62 private SvcLogicResource serviceLogic;
63 private DbService dbservice;
64 private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory();
66 public static DesignDBService initialise() {
67 if (dgGeneralDBService == null) {
68 dgGeneralDBService = new DesignDBService();
70 return dgGeneralDBService;
73 private DesignDBService() {
74 if (serviceLogic == null) {
75 serviceLogic = new SqlResource();
79 public String execute(String action, String payload, String requestID) throws Exception {
81 log.info("Received execute request for action : " + action + " with Payload : " + payload);
82 RequestValidator.validate(action, payload);
84 dbservice = new DbService();
86 case DesignServiceConstants.GETDESIGNS:
87 response = getDesigns(payload, requestID);
89 case DesignServiceConstants.GETAPPCTIMESTAMPUTC:
90 response = getAppcTimestampUTC( requestID );
92 case DesignServiceConstants.ADDINCART:
93 response = setInCart(payload, requestID);
95 case DesignServiceConstants.GETARTIFACTREFERENCE:
96 response = getArtifactReference(payload, requestID);
98 case DesignServiceConstants.GETARTIFACT:
99 response = getArtifact(payload, requestID);
101 case DesignServiceConstants.GETGUIREFERENCE:
102 response = getGuiReference(payload, requestID);
104 case DesignServiceConstants.GETSTATUS:
105 response = getStatus(payload, requestID);
107 case DesignServiceConstants.SETSTATUS:
108 response = setStatus(payload, requestID);
110 case DesignServiceConstants.UPLOADARTIFACT:
111 response = uploadArtifact(payload, requestID);
113 case DesignServiceConstants.SETPROTOCOLREFERENCE:
114 response = setProtocolReference(payload, requestID);
116 case DesignServiceConstants.UPLOADADMINARTIFACT:
117 response = uploadAdminArtifact(payload, requestID);
119 case DesignServiceConstants.CHECKVNF:
120 response = checkVNF(payload, requestID);
123 throw new DBException(" Action " + action + " not found while processing request ");
129 private String checkVNF(String payload, String requestId) throws Exception {
131 log.info("Got into Check VNF Request with payload: " + payload);
132 if (StringUtils.isBlank(payload))
133 throw new DBException("Payload in CheckVNF request is null or Blank");
134 if (StringUtils.isBlank(requestId))
135 throw new DBException("requestId in CheckVNF request is null or Blank");
136 ObjectMapper objectMapper = new ObjectMapper();
137 JsonNode payloadObject = objectMapper.readTree(payload);
138 String vnfType = payloadObject.get("vnf-type").textValue();
139 log.info("Check VNF Request with VNF TYPE: " + vnfType);
140 ArrayList<String> argList = new ArrayList<>();
141 argList.add(vnfType);
142 String queryString = "SELECT DT_ACTION_STATUS_ID,USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ? ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1 ; ";
143 log.info(QUERY_STR + queryString);
144 ResultSet data = dbservice.getDBData(queryString, argList);
147 String dtActionStatusId = null;
148 while (data.next()) {
150 user = data.getString("USER");
151 dtActionStatusId = data.getString("DT_ACTION_STATUS_ID");
153 log.debug("DT_ACTION_STATUS_ID-> " + dtActionStatusId + " user-> " + user);
154 JSONObject jObject = new JSONObject();
156 log.debug("vnf-type does not present in APPC DB, row Count:" + rowCount);
157 jObject.put("result", "No");
159 log.debug("vnf-type present in APPC DB, row Count:" + rowCount);
160 jObject.put("result", "Yes");
161 jObject.put("user", user);
163 log.info("Check VNF result: " + jObject.toString());
165 return jObject.toString();
169 private String uploadAdminArtifact(String payload, String requestId) throws Exception {
171 ObjectMapper objectMapper = new ObjectMapper();
172 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
173 JsonNode payloadObject = objectMapper.readTree(payload);
174 log.info("Got upload Admin Aritfact with requestId : " + requestId + " & Payload" + payloadObject.asText());
176 if (StringUtils.isBlank(requestId)) {
177 throw new DBException("Request-id is missing in the uploadAdminArtifact payload . ");
180 ArtifactHandlerClient ac = new ArtifactHandlerClient();
181 String requestString = ac.createArtifactData(payload, requestId);
182 ac.execute(requestString, "POST");
184 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId);
185 if (sdcArtifactId == 0)
186 throw new DBException(
187 "Error occured while validating/Saving the artifact to SDC_ARTIFACTS or getting SDC_ARTIFACTS_ID .");
188 JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID);
190 throw new DBException("User Id is null");
191 } else if (json.asText().trim().isEmpty()) {
192 log.info("UserId in Admin Aritfact is blank, User Id : " + json.asText());
193 throw new DBException("User Id is blank");
196 int sdcReferenceId = 0;
197 createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId);
202 private String getAppcTimestampUTC( String requestID) throws Exception
204 log.info("Starting getAppcTimestampUTC: requestID:" + requestID );
205 java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT");
206 java.text.SimpleDateFormat formatter =
207 new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
208 formatter.setTimeZone( gmtTZ );
209 java.util.Date dateVal= new java.util.Date();
210 log.info("getAppcTimestampUTC: current local Date:[" + dateVal+ "]");
211 String timeStr= formatter.format( dateVal );
212 log.info("getAppcTimestampUTC: returning:[" + timeStr + "]");
216 private String setInCart(String payload, String requestID) throws Exception {
218 ObjectMapper objectMapper = new ObjectMapper();
219 JsonNode payloadObject = objectMapper.readTree(payload);
220 ArrayList<String> argList = new ArrayList<>();
221 argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue());
222 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
224 String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN "
225 + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? ";
227 if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject
228 .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) {
229 queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? ";
230 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
232 queryString = queryString + " ) AND USER = ? ";
234 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
235 log.info(QUERY_STR + queryString);
236 boolean data = dbservice.updateDBData(queryString, argList);
239 throw new DBException("Error while updating ProtocolReference");
244 private String setProtocolReference(String payload, String requestID) throws Exception {
246 ObjectMapper objectMapper = new ObjectMapper();
247 JsonNode payloadObject = objectMapper.readTree(payload);
248 ArrayList<String> argList = new ArrayList<>();
250 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
251 argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue());
252 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
253 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
255 String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? ";
257 log.info("Delete Query String :" + queryString);
260 log.info("Record Deleted");
262 if (payloadObject.get(DesignServiceConstants.TEMPLATE) != null &&
263 !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty()) {
265 argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue());
270 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null &&
271 !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
273 queryString = queryString + " AND VNFC_TYPE = ? )";
275 queryString = queryString + " ) ";
277 log.info(QUERY_STR + queryString);
278 data = dbservice.updateDBData(queryString, argList);
281 throw new DBException("Error while updating ProtocolReference");
286 private String uploadArtifact(String payload, String requestID) throws Exception {
288 ObjectMapper objectMapper = new ObjectMapper();
289 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
290 JsonNode payloadObject = objectMapper.readTree(payload);
291 log.info("Got upload Aritfact with Payload : " + payloadObject.asText());
293 ArtifactHandlerClient ac = artifactHandlerFactory.ahi();
294 String requestString = ac.createArtifactData(payload, requestID);
295 ac.execute(requestString, "POST");
296 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID);
297 int sdcReferenceId = getSDCReferenceID(payload);
298 createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId);
299 String status = getDataFromActionStatus(payload, STATUS);
300 if (status == null || status.isEmpty()) {
301 log.info("Action Status is: "+ status);
302 setActionStatus(payload, "Not Tested");
304 linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload);
306 } catch (Exception e) {
307 log.error("An error occured in uploadArtifact", e);
314 private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception {
316 ObjectMapper objectMapper = new ObjectMapper();
317 JsonNode payloadObject = objectMapper.readTree(payload);
318 ArrayList<String> argList = new ArrayList<>();
319 argList.add(String.valueOf(sdcArtifactId));
320 argList.add(String.valueOf(sdcReferenceId));
321 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
322 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
323 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
326 "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " +
327 "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , "
328 + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
330 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
331 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
332 queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )";
334 queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) ";
336 log.info(QUERY_STR + queryString);
337 boolean data = dbservice.updateDBData(queryString, argList);
340 throw new DBException("Error while updating RelationShip table");
345 private int getSDCReferenceID(String payload) throws Exception {
347 ObjectMapper objectMapper = new ObjectMapper();
348 JsonNode payloadObject = objectMapper.readTree(payload);
349 ArrayList<String> argList = new ArrayList<>();
350 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
352 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue());
353 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue());
355 String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? "
356 + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? ";
358 if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject
359 .get(DesignServiceConstants.ACTION).textValue().isEmpty()) {
360 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
361 queryString = queryString + " AND ACTION = ? ";
363 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
364 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
365 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
366 queryString = queryString + " AND VNFC_TYPE = ? ";
370 log.info(QUERY_STR + queryString);
371 ResultSet data = dbservice.getDBData(queryString, argList);
372 int sdcReferenceId = 0;
373 while (data.next()) {
374 sdcReferenceId = data.getInt("ASDC_REFERENCE_ID");
376 log.info("Got sdcReferenceId= " + sdcReferenceId);
377 return sdcReferenceId;
380 private String getDataFromActionStatus(String payload, String dataValue) throws Exception {
381 String status = null;
382 ObjectMapper objectMapper = new ObjectMapper();
383 JsonNode payloadObject = objectMapper.readTree(payload);
384 ArrayList<String> argList = new ArrayList<>();
385 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
386 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
387 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
389 " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
390 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
391 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
392 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
393 queryString = queryString + " AND VNFC_TYPE = ? ";
395 log.info(QUERY_STR + queryString);
396 ResultSet data = dbservice.getDBData(queryString, argList);
397 while (data.next()) {
398 status = data.getString(STATUS);
400 log.info("DT_ACTION_STATUS Status = " + status);
404 private void setActionStatus(String payload, String status) throws Exception {
405 ObjectMapper objectMapper = new ObjectMapper();
406 JsonNode payloadObject = objectMapper.readTree(payload);
407 ArrayList<String> argList = new ArrayList<>();
408 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
409 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
411 String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); ";
412 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
413 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
414 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
415 log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
419 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
420 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
421 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
422 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
428 log.info("QueryString: " + insertQuery);
429 log.info("Arguments List: " + argList);
430 boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
432 throw new DBException("Error while updating Action Status");
435 private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
438 ObjectMapper objectMapper = new ObjectMapper();
439 JsonNode payloadObject = objectMapper.readTree(payload);
441 ArrayList<String> argList = new ArrayList<>();
442 argList.add(String.valueOf(sdcArtifactId));
443 argList.add(String.valueOf(sdcReferenceId));
444 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
445 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
446 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
447 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
452 if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject
453 .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) {
454 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
459 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' )";
461 log.info(QUERY_STR + queryString);
462 boolean data = dbservice.updateDBData(queryString, argList);
464 throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
468 private int getSDCArtifactIDbyRequestID(String requestID) throws Exception {
469 log.info("Starting getArtifactIDbyRequestID DB Operation");
472 ArrayList<String> argList = new ArrayList<>();
473 argList.add("TLSUUID" + requestID);
474 String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
475 log.info(QUERY_STR + queryString+ " & UUID or" + "TLSUUID :" + requestID);
476 ResultSet data = dbservice.getDBData(queryString, argList);
477 while (data.next()) {
478 artifactId = data.getInt("ASDC_ARTIFACTS_ID");
480 } catch (Exception e) {
481 log.error("An error occurred in getSDCArtifactIDbyRequestID", e);
484 log.info("Got SDC_ARTIFACTS_ID As :" + artifactId);
489 private String getArtifact(String payload, String requestID) throws Exception {
490 log.info("Starting getArtifact DB Operation");
492 ObjectMapper objectMapper = new ObjectMapper();
493 JsonNode payloadObject = objectMapper.readTree(payload);
494 String artifactName = payloadObject.get("artifact-name").textValue();
495 ArrayList<String> argList = new ArrayList<>();
496 argList.add(artifactName);
497 argList.add(payloadObject.get("artifact-type").textValue());
499 String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where "
500 + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
501 log.info(QUERY_STR + queryString);
502 ResultSet data = dbservice.getDBData(queryString, argList);
503 String artifactContent = null;
505 int hightestVerion = -1;
506 while (data.next()) {
508 int version = data.getInt("INTERNAL_VERSION");
509 if (hightestVerion < version) {
510 artifactContent = data.getString("ARTIFACT_CONTENT");
511 hightestVerion = version;
514 log.debug("No of rows: " + rowCount + " highest Inetrnal Version" + hightestVerion);
516 throw new DBException("Sorry !!!APPC DB doesn't have any artifact Named : " + artifactName);
518 if (artifactContent == null || artifactContent.isEmpty()) {
519 throw new DBException("Sorry !!! Artifact Content is stored blank in APPC DB for " + artifactName
520 + " and Internal version " + hightestVerion);
522 DesignResponse designResponse = new DesignResponse();
523 List<ArtifactInfo> artifactInfoList = new ArrayList<>();
524 ArtifactInfo artifactInfo = new ArtifactInfo();
525 artifactInfo.setArtifact_content(artifactContent);
526 artifactInfoList.add(artifactInfo);
527 designResponse.setArtifactInfo(artifactInfoList);
528 ObjectMapper mapper = new ObjectMapper();
529 String jsonString = mapper.writeValueAsString(designResponse);
530 log.debug("End of getArtifact:" + INFO_STR + jsonString);
532 } catch (Exception e) {
533 log.error(DB_OPERATION_ERROR, e);
538 private String setStatus(String payload, String requestID) throws Exception {
540 log.info("Starting getStatus DB Operation");
542 ObjectMapper objectMapper = new ObjectMapper();
543 JsonNode payloadObject = objectMapper.readTree(payload);
545 ArrayList<String> argList = new ArrayList<>();
546 argList.add(payloadObject.get("artifact_status").textValue());
547 argList.add(payloadObject.get("action_status").textValue());
549 argList.add(payloadObject.get(USER_ID).textValue());
550 argList.add(payloadObject.get("vnf-type").textValue());
553 " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? "
554 + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
555 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
556 + " and DAS.VNF_TYPE = ? ";
558 if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) {
559 argList.add(payloadObject.get(VNFC_TYPE).textValue());
560 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
563 log.info(QUERY_STR + queryString);
565 DesignResponse designResponse = new DesignResponse();
566 designResponse.setUserId(payloadObject.get(USER_ID).textValue());
567 boolean update = dbservice.updateDBData(queryString, argList);
569 throw new DBException("Sorry .....Something went wrong while updating the Status");
572 ObjectMapper mapper = new ObjectMapper();
573 String jsonString = mapper.writeValueAsString(designResponse);
574 log.info(INFO_STR + jsonString);
576 } catch (Exception e) {
577 log.error(DB_OPERATION_ERROR, e);
582 private String getStatus(String payload, String requestID) throws Exception {
583 log.info("Starting getStatus DB Operation");
585 String vnfcType = null;
586 ObjectMapper objectMapper = new ObjectMapper();
587 JsonNode payloadObject = objectMapper.readTree(payload);
588 String userID = payloadObject.get(USER_ID).textValue();
589 String vnfType = payloadObject.get("vnf-type").textValue();
590 if (payloadObject.get(VNFC_TYPE) != null) {
591 vnfcType = payloadObject.get(VNFC_TYPE).textValue();
593 ArrayList<String> argList = new ArrayList<>();
596 argList.add(vnfType);
598 String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS "
599 + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " +
600 " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
601 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
602 + " and DAS.VNF_TYPE = ? ";
604 if (vnfcType != null && !vnfcType.isEmpty()) {
605 argList.add(vnfcType);
606 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
609 log.info(QUERY_STR + queryString);
611 DesignResponse designResponse = new DesignResponse();
612 designResponse.setUserId(userID);
613 List<StatusInfo> statusInfoList = new ArrayList<>();
614 ResultSet data = dbservice.getDBData(queryString, argList);
615 while (data.next()) {
616 StatusInfo statusInfo = new StatusInfo();
617 statusInfo.setAction(data.getString("ACTION"));
618 statusInfo.setAction_status(data.getString(STATUS));
619 statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS"));
620 statusInfo.setVnf_type(data.getString("VNF_TYPE"));
621 statusInfo.setVnfc_type(data.getString("VNFC_TYPE"));
622 statusInfoList.add(statusInfo);
625 if (statusInfoList.isEmpty()) {
626 throw new DBException(
627 "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
629 designResponse.setStatusInfoList(statusInfoList);
630 ObjectMapper mapper = new ObjectMapper();
631 String jsonString = mapper.writeValueAsString(designResponse);
632 log.info(INFO_STR + jsonString);
634 } catch (SQLException e) {
635 log.error(DB_OPERATION_ERROR, e);
637 } catch (Exception e) {
638 log.error(DB_OPERATION_ERROR + e.getMessage());
639 log.error("Exception : ", e);
644 private String getGuiReference(String payload, String requestID) {
645 // TODO Auto-generated method stub
649 private String getArtifactReference(String payload, String requestID) {
650 // TODO Auto-generated method stub
654 private String getDesigns(String payload, String requestID) throws Exception {
657 log.info("Starting getDesigns DB Operation");
660 ObjectMapper objectMapper = new ObjectMapper();
661 JsonNode payloadObject = objectMapper.readTree(payload);
662 String userID = payloadObject.get(USER_ID).textValue();
663 String filterKey = null;
664 if (payloadObject.hasNonNull("filter")) {
665 filterKey = payloadObject.get("filter").textValue();
667 ArrayList<String> argList = new ArrayList<>();
670 if (filterKey != null) {
672 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
674 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
675 + DesignServiceConstants.DB_SDC_REFERENCE +
676 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%"
677 + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
680 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
682 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
683 + DesignServiceConstants.DB_SDC_REFERENCE +
684 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
686 DesignResponse designResponse = new DesignResponse();
687 designResponse.setUserId(userID);
688 List<DesignInfo> designInfoList = new ArrayList<>();
689 ResultSet data = dbservice.getDBData(queryString, argList);
690 while (data.next()) {
691 DesignInfo designInfo = new DesignInfo();
692 designInfo.setInCart(data.getString("IN_CART"));
693 designInfo.setProtocol(data.getString("PROTOCOL"));
694 designInfo.setVnf_type(data.getString("VNF_TYPE"));
695 designInfo.setVnfc_type(data.getString("VNFC_TYPE"));
696 designInfo.setAction(data.getString("ACTION"));
697 designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE"));
698 designInfo.setArtifact_name(data.getString("ARTIFACT_NAME"));
699 designInfoList.add(designInfo);
701 if (designInfoList.isEmpty()) {
702 throw new DBException(
703 " Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
705 designResponse.setDesignInfoList(designInfoList);
706 ObjectMapper mapper = new ObjectMapper();
707 String jsonString = mapper.writeValueAsString(designResponse);
708 log.info(INFO_STR + jsonString);
710 } catch (Exception e) {
711 log.error("Error while Starting getDesgins DB operation : ", e);
716 public static class ArtifactHandlerFactory {
718 public ArtifactHandlerClient ahi() throws Exception{
719 return new ArtifactHandlerClient();