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 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.design.dbervices;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.fasterxml.jackson.core.JsonParser;
30 import com.fasterxml.jackson.databind.JsonNode;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.util.ArrayList;
35 import java.util.List;
37 import org.json.JSONObject;
38 import org.onap.appc.design.data.ArtifactInfo;
39 import org.onap.appc.design.data.DesignInfo;
40 import org.onap.appc.design.data.DesignResponse;
41 import org.onap.appc.design.data.StatusInfo;
42 import org.onap.appc.design.services.util.ArtifactHandlerClient;
43 import org.onap.appc.design.services.util.DesignServiceConstants;
44 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
45 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
46 import org.apache.commons.lang.StringUtils;
48 public class DesignDBService {
50 private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class);
51 private static DesignDBService dgGeneralDBService;
53 private static final String SUCCESS_JSON = "{\"update\" : \"success\" } ";
54 private static final String STATUS = "STATUS";
55 private static final String INFO_STR = "Info : ";
56 private static final String DB_OPERATION_ERROR = "Error while DB operation : ";
57 private static final String VNFC_TYPE = "vnfc-type";
58 private static final String QUERY_STR = "Query String :";
59 private static final String USER_ID = "userID";
61 private SvcLogicResource serviceLogic;
62 private DbService dbservice;
63 private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory();
65 public static DesignDBService initialise() {
66 if (dgGeneralDBService == null) {
67 dgGeneralDBService = new DesignDBService();
69 return dgGeneralDBService;
72 private DesignDBService() {
73 if (serviceLogic == null) {
74 serviceLogic = new SqlResource();
78 public String execute(String action, String payload, String requestID) throws Exception {
80 log.info("Received execute request for action : " + action + " with Payload : " + payload);
81 RequestValidator.validate(action, payload);
83 dbservice = new DbService();
85 case DesignServiceConstants.GETDESIGNS:
86 response = getDesigns(payload, requestID);
88 case DesignServiceConstants.GETAPPCTIMESTAMPUTC:
89 response = getAppcTimestampUTC( requestID );
91 case DesignServiceConstants.ADDINCART:
92 response = setInCart(payload, requestID);
94 case DesignServiceConstants.GETARTIFACTREFERENCE:
95 response = getArtifactReference(payload, requestID);
97 case DesignServiceConstants.GETARTIFACT:
98 response = getArtifact(payload, requestID);
100 case DesignServiceConstants.GETGUIREFERENCE:
101 response = getGuiReference(payload, requestID);
103 case DesignServiceConstants.GETSTATUS:
104 response = getStatus(payload, requestID);
106 case DesignServiceConstants.SETSTATUS:
107 response = setStatus(payload, requestID);
109 case DesignServiceConstants.UPLOADARTIFACT:
110 response = uploadArtifact(payload, requestID);
112 case DesignServiceConstants.SETPROTOCOLREFERENCE:
113 response = setProtocolReference(payload, requestID);
115 case DesignServiceConstants.UPLOADADMINARTIFACT:
116 response = uploadAdminArtifact(payload, requestID);
118 case DesignServiceConstants.CHECKVNF:
119 response = checkVNF(payload, requestID);
122 throw new DBException(" Action " + action + " not found while processing request ");
128 private String checkVNF(String payload, String requestId) throws Exception {
130 log.info("Got into Check VNF Request with payload: " + payload);
131 if (StringUtils.isBlank(payload))
132 throw new DBException("Payload in CheckVNF request is null or Blank");
133 if (StringUtils.isBlank(requestId))
134 throw new DBException("requestId in CheckVNF request is null or Blank");
135 ObjectMapper objectMapper = new ObjectMapper();
136 JsonNode payloadObject = objectMapper.readTree(payload);
137 String vnfType = payloadObject.get("vnf-type").textValue();
138 log.info("Check VNF Request with VNF TYPE: " + vnfType);
139 ArrayList<String> argList = new ArrayList<>();
140 argList.add(vnfType);
141 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 ; ";
142 log.info(QUERY_STR + queryString);
143 ResultSet data = dbservice.getDBData(queryString, argList);
146 String dtActionStatusId = null;
147 while (data.next()) {
149 user = data.getString("USER");
150 dtActionStatusId = data.getString("DT_ACTION_STATUS_ID");
152 log.debug("DT_ACTION_STATUS_ID-> " + dtActionStatusId + " user-> " + user);
153 JSONObject jObject = new JSONObject();
155 log.debug("vnf-type does not present in APPC DB, row Count:" + rowCount);
156 jObject.put("result", "No");
158 log.debug("vnf-type present in APPC DB, row Count:" + rowCount);
159 jObject.put("result", "Yes");
160 jObject.put("user", user);
162 log.info("Check VNF result: " + jObject.toString());
164 return jObject.toString();
168 private String uploadAdminArtifact(String payload, String requestId) throws Exception {
170 ObjectMapper objectMapper = new ObjectMapper();
171 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
172 JsonNode payloadObject = objectMapper.readTree(payload);
173 log.info("Got upload Admin Aritfact with requestId : " + requestId + " & Payload" + payloadObject.asText());
175 if (StringUtils.isBlank(requestId)) {
176 throw new DBException("Request-id is missing in the uploadAdminArtifact payload . ");
179 ArtifactHandlerClient ac = new ArtifactHandlerClient();
180 String requestString = ac.createArtifactData(payload, requestId);
181 ac.execute(requestString, "POST");
183 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId);
184 if (sdcArtifactId == 0)
185 throw new DBException(
186 "Error occured while validating/Saving the artifact to SDC_ARTIFACTS or getting SDC_ARTIFACTS_ID .");
187 JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID);
188 if (json == null || json.asText().trim().isEmpty()) {
189 log.info("UserId in Admin Aritfact is null or blank, User Id : " + json.asText());
190 throw new DBException("User Id is null or blank");
193 int sdcReferenceId = 0;
194 createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId);
199 private String getAppcTimestampUTC( String requestID) throws Exception
201 log.info("Starting getAppcTimestampUTC: requestID:" + requestID );
202 java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT");
203 java.text.SimpleDateFormat formatter =
204 new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
205 formatter.setTimeZone( gmtTZ );
206 java.util.Date dateVal= new java.util.Date();
207 log.info("getAppcTimestampUTC: current local Date:[" + dateVal+ "]");
208 String timeStr= formatter.format( dateVal );
209 log.info("getAppcTimestampUTC: returning:[" + timeStr + "]");
213 private String setInCart(String payload, String requestID) throws Exception {
215 ObjectMapper objectMapper = new ObjectMapper();
216 JsonNode payloadObject = objectMapper.readTree(payload);
217 ArrayList<String> argList = new ArrayList<>();
218 argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue());
219 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
221 String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN "
222 + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? ";
224 if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject
225 .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) {
226 queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? ";
227 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
229 queryString = queryString + " ) AND USER = ? ";
231 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
232 log.info(QUERY_STR + queryString);
233 boolean data = dbservice.updateDBData(queryString, argList);
236 throw new DBException("Error while updating ProtocolReference");
241 private String setProtocolReference(String payload, String requestID) throws Exception {
243 ObjectMapper objectMapper = new ObjectMapper();
244 JsonNode payloadObject = objectMapper.readTree(payload);
245 ArrayList<String> argList = new ArrayList<>();
247 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
248 argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue());
249 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
250 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
252 String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? ";
254 log.info("Delete Query String :" + queryString);
257 log.info("Record Deleted");
259 if (payloadObject.get(DesignServiceConstants.TEMPLATE) != null &&
260 !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty()) {
262 argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue());
267 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null &&
268 !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
270 queryString = queryString + " AND VNFC_TYPE = ? )";
272 queryString = queryString + " ) ";
274 log.info(QUERY_STR + queryString);
275 data = dbservice.updateDBData(queryString, argList);
278 throw new DBException("Error while updating ProtocolReference");
283 private String uploadArtifact(String payload, String requestID) throws Exception {
285 ObjectMapper objectMapper = new ObjectMapper();
286 objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
287 JsonNode payloadObject = objectMapper.readTree(payload);
288 log.info("Got upload Aritfact with Payload : " + payloadObject.asText());
290 ArtifactHandlerClient ac = artifactHandlerFactory.ahi();
291 String requestString = ac.createArtifactData(payload, requestID);
292 ac.execute(requestString, "POST");
293 int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID);
294 int sdcReferenceId = getSDCReferenceID(payload);
295 createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId);
296 String status = getDataFromActionStatus(payload, STATUS);
297 if (status == null || status.isEmpty()) {
298 log.info("Action Status is: "+ status);
299 setActionStatus(payload, "Not Tested");
301 linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload);
303 } catch (Exception e) {
304 log.error("An error occured in uploadArtifact", e);
311 private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception {
313 ObjectMapper objectMapper = new ObjectMapper();
314 JsonNode payloadObject = objectMapper.readTree(payload);
315 ArrayList<String> argList = new ArrayList<>();
316 argList.add(String.valueOf(sdcArtifactId));
317 argList.add(String.valueOf(sdcReferenceId));
318 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
319 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
320 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
323 "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " +
324 "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , "
325 + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
327 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
328 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
329 queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )";
331 queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) ";
333 log.info(QUERY_STR + queryString);
334 boolean data = dbservice.updateDBData(queryString, argList);
337 throw new DBException("Error while updating RelationShip table");
342 private int getSDCReferenceID(String payload) throws Exception {
344 ObjectMapper objectMapper = new ObjectMapper();
345 JsonNode payloadObject = objectMapper.readTree(payload);
346 ArrayList<String> argList = new ArrayList<>();
347 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
349 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue());
350 argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue());
352 String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? "
353 + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? ";
355 if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject
356 .get(DesignServiceConstants.ACTION).textValue().isEmpty()) {
357 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
358 queryString = queryString + " AND ACTION = ? ";
360 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
361 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
362 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
363 queryString = queryString + " AND VNFC_TYPE = ? ";
367 log.info(QUERY_STR + queryString);
368 ResultSet data = dbservice.getDBData(queryString, argList);
369 int sdcReferenceId = 0;
370 while (data.next()) {
371 sdcReferenceId = data.getInt("ASDC_REFERENCE_ID");
373 log.info("Got sdcReferenceId= " + sdcReferenceId);
374 return sdcReferenceId;
377 private String getDataFromActionStatus(String payload, String dataValue) throws Exception {
378 String status = null;
379 ObjectMapper objectMapper = new ObjectMapper();
380 JsonNode payloadObject = objectMapper.readTree(payload);
381 ArrayList<String> argList = new ArrayList<>();
382 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
383 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
384 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
386 " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? ";
387 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
388 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
389 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
390 queryString = queryString + " AND VNFC_TYPE = ? ";
392 log.info(QUERY_STR + queryString);
393 ResultSet data = dbservice.getDBData(queryString, argList);
394 while (data.next()) {
395 status = data.getString(STATUS);
397 log.info("DT_ACTION_STATUS Status = " + status);
401 private void setActionStatus(String payload, String status) throws Exception {
402 ObjectMapper objectMapper = new ObjectMapper();
403 JsonNode payloadObject = objectMapper.readTree(payload);
404 ArrayList<String> argList = new ArrayList<>();
405 argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue());
406 argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue());
408 String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); ";
409 if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject
410 .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) {
411 argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
412 log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue());
416 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
417 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
418 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
419 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
425 log.info("QueryString: " + insertQuery);
426 log.info("Arguments List: " + argList);
427 boolean updateStatus = dbservice.updateDBData(insertQuery, argList);
429 throw new DBException("Error while updating Action Status");
432 private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId)
435 ObjectMapper objectMapper = new ObjectMapper();
436 JsonNode payloadObject = objectMapper.readTree(payload);
438 ArrayList<String> argList = new ArrayList<>();
439 argList.add(String.valueOf(sdcArtifactId));
440 argList.add(String.valueOf(sdcReferenceId));
441 argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue());
442 if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject
443 .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) {
444 argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue());
449 if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject
450 .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) {
451 argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue());
456 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' )";
458 log.info(QUERY_STR + queryString);
459 boolean data = dbservice.updateDBData(queryString, argList);
461 throw new DBException("Error Updating DT_ARTIFACT_TRACKING ");
465 private int getSDCArtifactIDbyRequestID(String requestID) throws Exception {
466 log.info("Starting getArtifactIDbyRequestID DB Operation");
469 ArrayList<String> argList = new ArrayList<>();
470 argList.add("TLSUUID" + requestID);
471 String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? ";
472 log.info(QUERY_STR + queryString+ " & UUID or" + "TLSUUID :" + requestID);
473 ResultSet data = dbservice.getDBData(queryString, argList);
474 while (data.next()) {
475 artifactId = data.getInt("ASDC_ARTIFACTS_ID");
477 } catch (Exception e) {
478 log.error("An error occurred in getSDCArtifactIDbyRequestID", e);
481 log.info("Got SDC_ARTIFACTS_ID As :" + artifactId);
486 private String getArtifact(String payload, String requestID) throws Exception {
487 log.info("Starting getArtifact DB Operation");
489 ObjectMapper objectMapper = new ObjectMapper();
490 JsonNode payloadObject = objectMapper.readTree(payload);
491 String artifactName = payloadObject.get("artifact-name").textValue();
492 ArrayList<String> argList = new ArrayList<>();
493 argList.add(artifactName);
494 argList.add(payloadObject.get("artifact-type").textValue());
496 String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where "
497 + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? ";
498 log.info(QUERY_STR + queryString);
499 ResultSet data = dbservice.getDBData(queryString, argList);
500 String artifactContent = null;
502 int hightestVerion = -1;
503 while (data.next()) {
505 int version = data.getInt("INTERNAL_VERSION");
506 if (hightestVerion < version) {
507 artifactContent = data.getString("ARTIFACT_CONTENT");
508 hightestVerion = version;
511 log.debug("No of rows: " + rowCount + " highest Inetrnal Version" + hightestVerion);
513 throw new DBException("Sorry !!!APPC DB doesn't have any artifact Named : " + artifactName);
515 if (artifactContent == null || artifactContent.isEmpty()) {
516 throw new DBException("Sorry !!! Artifact Content is stored blank in APPC DB for " + artifactName
517 + " and Internal version " + hightestVerion);
519 DesignResponse designResponse = new DesignResponse();
520 List<ArtifactInfo> artifactInfoList = new ArrayList<>();
521 ArtifactInfo artifactInfo = new ArtifactInfo();
522 artifactInfo.setArtifact_content(artifactContent);
523 artifactInfoList.add(artifactInfo);
524 designResponse.setArtifactInfo(artifactInfoList);
525 ObjectMapper mapper = new ObjectMapper();
526 String jsonString = mapper.writeValueAsString(designResponse);
527 log.debug("End of getArtifact:" + INFO_STR + jsonString);
529 } catch (Exception e) {
530 log.error(DB_OPERATION_ERROR, e);
535 private String setStatus(String payload, String requestID) throws Exception {
537 log.info("Starting getStatus DB Operation");
539 ObjectMapper objectMapper = new ObjectMapper();
540 JsonNode payloadObject = objectMapper.readTree(payload);
542 ArrayList<String> argList = new ArrayList<>();
543 argList.add(payloadObject.get("artifact_status").textValue());
544 argList.add(payloadObject.get("action_status").textValue());
546 argList.add(payloadObject.get(USER_ID).textValue());
547 argList.add(payloadObject.get("vnf-type").textValue());
550 " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? "
551 + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
552 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
553 + " and DAS.VNF_TYPE = ? ";
555 if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) {
556 argList.add(payloadObject.get(VNFC_TYPE).textValue());
557 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
560 log.info(QUERY_STR + queryString);
562 DesignResponse designResponse = new DesignResponse();
563 designResponse.setUserId(payloadObject.get(USER_ID).textValue());
564 boolean update = dbservice.updateDBData(queryString, argList);
566 throw new DBException("Sorry .....Something went wrong while updating the Status");
569 ObjectMapper mapper = new ObjectMapper();
570 String jsonString = mapper.writeValueAsString(designResponse);
571 log.info(INFO_STR + jsonString);
573 } catch (Exception e) {
574 log.error(DB_OPERATION_ERROR, e);
579 private String getStatus(String payload, String requestID) throws Exception {
580 log.info("Starting getStatus DB Operation");
582 String vnfcType = null;
583 ObjectMapper objectMapper = new ObjectMapper();
584 JsonNode payloadObject = objectMapper.readTree(payload);
585 String userID = payloadObject.get(USER_ID).textValue();
586 String vnfType = payloadObject.get("vnf-type").textValue();
587 if (payloadObject.get(VNFC_TYPE) != null) {
588 vnfcType = payloadObject.get(VNFC_TYPE).textValue();
590 ArrayList<String> argList = new ArrayList<>();
593 argList.add(vnfType);
595 String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS "
596 + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " +
597 " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID "
598 + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? "
599 + " and DAS.VNF_TYPE = ? ";
601 if (vnfcType != null && !vnfcType.isEmpty()) {
602 argList.add(vnfcType);
603 queryString = queryString + " and DAS.VNFC_TYPE = ? ";
606 log.info(QUERY_STR + queryString);
608 DesignResponse designResponse = new DesignResponse();
609 designResponse.setUserId(userID);
610 List<StatusInfo> statusInfoList = new ArrayList<>();
611 ResultSet data = dbservice.getDBData(queryString, argList);
612 while (data.next()) {
613 StatusInfo statusInfo = new StatusInfo();
614 statusInfo.setAction(data.getString("ACTION"));
615 statusInfo.setAction_status(data.getString(STATUS));
616 statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS"));
617 statusInfo.setVnf_type(data.getString("VNF_TYPE"));
618 statusInfo.setVnfc_type(data.getString("VNFC_TYPE"));
619 statusInfoList.add(statusInfo);
622 if (statusInfoList.isEmpty()) {
623 throw new DBException(
624 "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID);
626 designResponse.setStatusInfoList(statusInfoList);
627 ObjectMapper mapper = new ObjectMapper();
628 String jsonString = mapper.writeValueAsString(designResponse);
629 log.info(INFO_STR + jsonString);
631 } catch (SQLException e) {
632 log.error(DB_OPERATION_ERROR, e);
634 } catch (Exception e) {
635 log.error(DB_OPERATION_ERROR + e.getMessage());
636 log.error("Exception : ", e);
641 private String getGuiReference(String payload, String requestID) {
642 // TODO Auto-generated method stub
646 private String getArtifactReference(String payload, String requestID) {
647 // TODO Auto-generated method stub
651 private String getDesigns(String payload, String requestID) throws Exception {
654 log.info("Starting getDesigns DB Operation");
657 ObjectMapper objectMapper = new ObjectMapper();
658 JsonNode payloadObject = objectMapper.readTree(payload);
659 String userID = payloadObject.get(USER_ID).textValue();
660 String filterKey = null;
661 if (payloadObject.hasNonNull("filter")) {
662 filterKey = payloadObject.get("filter").textValue();
664 ArrayList<String> argList = new ArrayList<>();
667 if (filterKey != null) {
669 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
671 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
672 + DesignServiceConstants.DB_SDC_REFERENCE +
673 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%"
674 + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
677 "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from "
679 DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , "
680 + DesignServiceConstants.DB_SDC_REFERENCE +
681 " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME";
683 DesignResponse designResponse = new DesignResponse();
684 designResponse.setUserId(userID);
685 List<DesignInfo> designInfoList = new ArrayList<>();
686 ResultSet data = dbservice.getDBData(queryString, argList);
687 while (data.next()) {
688 DesignInfo designInfo = new DesignInfo();
689 designInfo.setInCart(data.getString("IN_CART"));
690 designInfo.setProtocol(data.getString("PROTOCOL"));
691 designInfo.setVnf_type(data.getString("VNF_TYPE"));
692 designInfo.setVnfc_type(data.getString("VNFC_TYPE"));
693 designInfo.setAction(data.getString("ACTION"));
694 designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE"));
695 designInfo.setArtifact_name(data.getString("ARTIFACT_NAME"));
696 designInfoList.add(designInfo);
698 if (designInfoList.isEmpty()) {
699 throw new DBException(
700 " Welcome to CDT, Looks like you dont have Design Yet... Lets create some....");
702 designResponse.setDesignInfoList(designInfoList);
703 ObjectMapper mapper = new ObjectMapper();
704 String jsonString = mapper.writeValueAsString(designResponse);
705 log.info(INFO_STR + jsonString);
707 } catch (Exception e) {
708 log.error("Error while Starting getDesgins DB operation : ", e);
713 public static class ArtifactHandlerFactory {
715 public ArtifactHandlerClient ahi() throws Exception{
716 return new ArtifactHandlerClient();