Changes to ProtocolReference table insert 87/13587/2
authorRamya Balaji <rb111y@att.com>
Wed, 20 Sep 2017 00:58:45 +0000 (20:58 -0400)
committerRamya Balaji <rb111y@att.com>
Wed, 20 Sep 2017 01:07:43 +0000 (21:07 -0400)
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 <rb111y@att.com>
appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java
appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java

index a619a00..5cc92f3 100644 (file)
@@ -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;
+    }
+
 }
index fec7fbb..5df455a 100644 (file)
@@ -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;