diff options
Diffstat (limited to 'appc-inbound/appc-artifact-handler')
2 files changed, 44 insertions, 1 deletions
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; |