From 598e7357e2ef9e12e2aeed6a9e63fd1272b69c12 Mon Sep 17 00:00:00 2001 From: Ramya Balaji Date: Tue, 19 Sep 2017 20:58:45 -0400 Subject: Changes to ProtocolReference table insert Added Code to check if record exists previously in table. If so, make an update else insert. Issue-ID:APPC-220 Change-Id: I3825128d8381a4f0c7e62926be6ecec9ab178194 Signed-off-by: Ramya Balaji --- .../artifact/handler/dbservices/DBService.java | 39 ++++++++++++++++++++++ .../artifact/handler/node/ArtifactHandlerNode.java | 6 +++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'appc-inbound/appc-artifact-handler/provider') diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java index a619a00a8..5cc92f3e1 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java @@ -443,5 +443,44 @@ public class DBService { status = serviceLogic.save("SQL", false, false, key, null, null, context); if ((status == null) || status.toString().equals("FAILURE")) throw new SvcLogicException("Error While processing insertProtocolReference "); + } + + public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol, + String action, String action_level, String template) throws SvcLogicException { + SvcLogicContext localContext = new SvcLogicContext(); + String fn = "DBService.isProtocolReferenceUpdateRequired"; + log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); + String key = ""; + QueryStatus status = null; + + key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level + + "' and VNF_TYPE='" + vnfType + "'"; + status = serviceLogic.query("SQL", false, null, key, null, null, localContext); + String countStr = localContext.getAttribute("COUNT(*)"); + int count = Integer.parseInt(countStr); + if (count > 0) + return true; + else + return false; + } + + public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, + String action_level, String template) throws SvcLogicException { + + String fn = "DBService.isProtocolReferenceUpdateRequired"; + log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); + String key = ""; + QueryStatus status = null; + + key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action + + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'"; + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status == QueryStatus.FAILURE) { + log.info("updateProtocolReference:: Error updating protocol reference"); + throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference"); + } + return; + } + } diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java index fec7fbbb6..5df455a8e 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java @@ -501,7 +501,11 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { if (content.has(SdcArtifactHandlerConstants.TEMPLATE) && !content.isNull(SdcArtifactHandlerConstants.TEMPLATE)) template = content.getString(SdcArtifactHandlerConstants.TEMPLATE); - dbservice.insertProtocolReference(context, vnfType, protocol, action, actionLevel, template); + boolean isUpdateNeeded=dbservice.isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template); + if (isUpdateNeeded) + dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template); + else + dbservice.insertProtocolReference(context, vnfType,protocol,action,actionLevel,template); } catch (Exception e) { log.error("Error inserting record into protocolReference: " + e.toString()); throw e; -- cgit 1.2.3-korg