aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-artifact-handler/provider/src/main/java/org
diff options
context:
space:
mode:
authorSkip Wonnell <kw5258@att.com>2017-08-14 17:47:10 -0500
committerPatrick Brady <pb071s@att.com>2017-08-18 05:46:15 +0000
commitab6c2c0cd441cf40723016e9a82aeeeb933fec7e (patch)
tree10d9de942694ca129cfc78d13cf2269f5c37cfc9 /appc-inbound/appc-artifact-handler/provider/src/main/java/org
parent5166a76913fcb658be58adffed441590979e41cf (diff)
Initial adds artifact handler and design services
asdc-artifact-handler: an interface to receive artifacts distributed by SDC and persist them into the local database. appc-design-services: an interface to manage VNF configuration artifacts, primarily those generated by the configuration design tool. Includes these user stories: APPC-28/85 Change-Id: Ib207070d4593554fa424fc69d9c77a6cd5349fec Signed-off-by: Skip Wonnell <kw5258@att.com> Issue-Id: APPC-9
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/main/java/org')
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java59
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java37
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java213
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/AsdcArtifactHandlerActivator.java59
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java462
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java450
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java184
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/AsdcArtifactHandlerConstants.java93
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java43
9 files changed, 1600 insertions, 0 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java
new file mode 100644
index 000000000..a35ba6821
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.opendaylight.yang.gen.v1.org.openecomp.appc.artifact.handler.provider.impl.rev170321;
+
+import org.openecomp.appc.artifact.handler.ArtifactHandlerProvider;
+
+public class ArtifactHandlerProviderModule extends org.opendaylight.yang.gen.v1.org.openecomp.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModule {
+ public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.openecomp.appc.artifact.handler.provider.impl.rev170321.ArtifactHandlerProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void customValidation() {
+ // add custom validation form module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ final ArtifactHandlerProvider provider = new ArtifactHandlerProvider(getDataBrokerDependency()
+ , getNotificationServiceDependency()
+ , getRpcRegistryDependency());
+
+ return new AutoCloseable() {
+
+ @Override
+ public void close() throws Exception {
+ provider.close();
+ }
+ };
+ }
+
+
+}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java
new file mode 100644
index 000000000..171eada9b
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+/*
+* Generated file
+*
+* Generated from: yang module name: artifact-handler-provider-impl yang module local name: artifact-handler-provider-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Wed Aug 09 09:36:59 EDT 2017
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.org.openecomp.appc.artifact.handler.provider.impl.rev170321;
+public class ArtifactHandlerProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.openecomp.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModuleFactory {
+
+}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java
new file mode 100644
index 000000000..233984f55
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java
@@ -0,0 +1,213 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler;
+
+import java.util.HashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.ArtifactHandlerService;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.UploadartifactInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.UploadartifactInputBuilder;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.UploadartifactOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.UploadartifactOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.uploadartifact.output.ConfigDocumentResponseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.Services;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.ServicesBuilder;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.openecomp.appc.artifact.handler.node.ArtifactHandlerNode;
+import org.openecomp.appc.artifact.handler.utils.ArtifactHandlerProviderUtil;
+import org.openecomp.appc.artifact.handler.utils.AsdcArtifactHandlerConstants;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+
+
+
+public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerService, DataChangeListener {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProvider.class);
+ private final String appName = "ArtifactsHandler";
+ private final ExecutorService executor;
+ protected DataBroker dataBroker;
+ protected NotificationProviderService notificationService;
+ protected RpcProviderRegistry rpcRegistry;
+ private ListenerRegistration<DataChangeListener> dclServices;
+
+ protected BindingAwareBroker.RpcRegistration<ArtifactHandlerService> rpcRegistration;
+
+ public ArtifactHandlerProvider(DataBroker dataBroker2,
+ NotificationProviderService notificationProviderService,
+ RpcProviderRegistry rpcProviderRegistry) {
+ this.log.info("Creating provider for " + appName);
+ executor = Executors.newFixedThreadPool(10);
+ dataBroker = dataBroker2;
+ notificationService = notificationProviderService;
+ rpcRegistry = rpcProviderRegistry;
+ initialize();
+
+ }
+
+ public void initialize() {
+ log.info("Initializing provider for " + appName);
+ // Create the top level containers
+ createContainers();
+ try {
+ ArtifactHandlerProviderUtil.loadProperties();
+ } catch (Exception e) {
+ log.error("Caught Exception while trying to load properties file");
+ }
+ // Listener for changes to Services tree
+
+ rpcRegistration = rpcRegistry.addRpcImplementation(
+ ArtifactHandlerService.class, this);
+
+ log.info("Initialization complete for " + appName);
+ }
+ private void createContainers() {
+ final WriteTransaction t = dataBroker.newReadWriteTransaction();
+ // Create the Services container
+ t.merge(LogicalDatastoreType.CONFIGURATION,InstanceIdentifier.create(Services.class),new ServicesBuilder().build());
+ t.merge(LogicalDatastoreType.OPERATIONAL,InstanceIdentifier.create(Services.class),new ServicesBuilder().build());
+
+ try {
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = t.submit();
+ checkedFuture.get();
+ log.info("Create Containers succeeded!: ");
+
+ } catch (InterruptedException | ExecutionException e) {
+ log.error("Create Containers Failed: " + e);
+ e.printStackTrace();
+ }
+ }
+
+
+ @Override
+ public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+ @Override
+ public void close() throws Exception {
+
+ log.info("Closing provider for " + appName);
+ if(this.executor != null){
+ executor.shutdown();
+ }
+ if(this.rpcRegistration != null){
+ rpcRegistration.close();
+ }
+ log.info("Successfully closed provider for " + appName);
+
+ }
+
+ private RpcResult<UploadartifactOutput> buildResponse1(
+ String svcRequestId,
+ String topic,
+ String code,
+ String message,
+ String finalInd) {
+
+ UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder();
+ ConfigDocumentResponseBuilder configResponseBuilder=new ConfigDocumentResponseBuilder();
+ configResponseBuilder.setRequestId(svcRequestId);
+ configResponseBuilder.setStatus(code);
+ configResponseBuilder.setErrorReason(message);
+ RpcResult<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> status(true)
+ .withResult(responseBuilder.build()).build();
+ return rpcResult;
+ }
+
+ @Override
+ public Future<RpcResult<UploadartifactOutput>> uploadartifact(UploadartifactInput input) {
+
+ if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) {
+ RpcResult<UploadartifactOutput> rpcResult =
+ buildResponse1("N/A", "N/A", "INVALID_INPUT", "Invalid input, null or empty document information" , "Y");
+ return Futures.immediateFuture(rpcResult);
+ }
+ UploadartifactInputBuilder inputBuilder = new UploadartifactInputBuilder(input);
+ ConfigDocumentResponseBuilder configResponseBuilder = new ConfigDocumentResponseBuilder();
+ UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder();
+ log.info("Received input = " + input );
+ ArtifactHandlerProviderUtil designUtil = new ArtifactHandlerProviderUtil(input);
+ configResponseBuilder.setRequestId(input.getRequestInformation().getRequestId());
+ try{
+
+ if(input.getRequestInformation().getSource() !=null){
+ if(input.getRequestInformation().getSource().equalsIgnoreCase(AsdcArtifactHandlerConstants.DESIGN_TOOL)){
+ designUtil.processTemplate(designUtil.createDummyRequestData());
+ configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString());
+ }
+ else
+ {
+ designUtil.processTemplate(designUtil.createRequestData());
+ configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString());
+ }
+ }
+ else
+ {
+ throw new Exception("No Tempalte data found");
+ }
+
+
+ }
+ catch (Exception e) {
+
+ configResponseBuilder.setErrorReason(e.getMessage());
+ configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_ERROR.toString());
+ log.error("Caught exception looking for Artifact Handler", e);
+ log.info("Caught exception looking for Artifact Handler: ");
+ }
+
+ responseBuilder.setConfigDocumentResponse(configResponseBuilder.build());
+ RpcResult<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> status(true).withResult(responseBuilder.build()).build();
+ return Futures.immediateFuture(rpcResult);
+
+ }
+}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/AsdcArtifactHandlerActivator.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/AsdcArtifactHandlerActivator.java
new file mode 100644
index 000000000..4c8e1358f
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/AsdcArtifactHandlerActivator.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.openecomp.appc.artifact.handler.node.ArtifactHandlerNode;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class AsdcArtifactHandlerActivator implements BundleActivator {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(AsdcArtifactHandlerActivator.class);
+ private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
+
+ @Override
+ public void start(BundleContext ctx) throws Exception {
+ ArtifactHandlerNode artifactHandlerNode = new ArtifactHandlerNode();
+ log.info("Registering service-- " + artifactHandlerNode.getClass().getName());
+ registrations.add(ctx.registerService(artifactHandlerNode.getClass().getName(), artifactHandlerNode, null));
+
+ }
+
+ @Override
+ public void stop(BundleContext arg0) throws Exception {
+ for (ServiceRegistration registration : registrations) {
+ registration.unregister();
+ registration = null;
+ }
+ }
+}
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
new file mode 100644
index 000000000..4984ebf43
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java
@@ -0,0 +1,462 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler.dbservices;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+
+import org.openecomp.appc.artifact.handler.utils.AsdcArtifactHandlerConstants;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;
+import org.openecomp.sdnc.sli.resource.sql.SqlResource;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class DBService {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class);
+ private SvcLogicResource serviceLogic;
+ private static DBService dgGeneralDBService = null;
+ public static DBService initialise() {
+ if (dgGeneralDBService == null) {
+ dgGeneralDBService = new DBService();
+ }
+ return dgGeneralDBService;
+ }
+ private DBService() {
+ if (serviceLogic == null) {
+ serviceLogic = new SqlResource();
+ }
+ }
+
+ public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix) throws SvcLogicException {
+ String fn = "DBService.getInternalVersionNumber";
+ QueryStatus status = null;
+ String artifactInternalVersion = null;
+ if (serviceLogic != null && ctx != null) {
+ String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" + artifactName + "'";
+ log.info("Getting internal Versoin :" + key);
+ status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error - getting internal Artifact Number");
+ artifactInternalVersion = ctx.getAttribute("maximum");
+ log.info("Internal Version received as : " + artifactInternalVersion);
+ log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)"));
+ log.info("Internal Version received as1 : " + ctx.getAttribute("max"));
+ log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version"));
+ log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString());
+ }
+ return artifactInternalVersion;
+ }
+ public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException {
+ String fn = "DBService.getArtifactID";
+ QueryStatus status = null;
+ String artifactID = null;
+ if (serviceLogic != null && ctx != null) {
+ String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" + artifactName + "'";
+ log.info("Getting Artifact ID String :" + key);
+ status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error - getting Artifact ID from database");
+ artifactID = ctx.getAttribute("id");
+ log.info("ASDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id"));
+ }
+ return artifactID;
+ }
+ public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException {
+ String fn = "DBService.saveArtifacts";
+ QueryStatus status = null;
+ if (serviceLogic != null && ctx != null) {
+ String key = "INSERT INTO ASDC_ARTIFACTS " +
+ "SET SERVICE_UUID = $service-uuid , " +
+ " DISTRIBUTION_ID = $distribution-id ," +
+ " SERVICE_NAME = $service-name ," +
+ " SERVICE_DESCRIPTION = $service-description ," +
+ " RESOURCE_UUID = $resource-uuid ," +
+ " RESOURCE_INSTANCE_NAME = $resource-instance-name ," +
+ " RESOURCE_NAME = $resource-name ," +
+ " RESOURCE_VERSION = $resource-version ," +
+ " RESOURCE_TYPE = $resource-type ," +
+ " ARTIFACT_UUID = $artifact-uuid ," +
+ " ARTIFACT_TYPE = $artifact-type ," +
+ " ARTIFACT_VERSION = $artifact-version ," +
+ " ARTIFACT_DESCRIPTION = $artifact-description ," +
+ " INTERNAL_VERSION = " + intversion + "," +
+ " ARTIFACT_NAME = $artifact-name ," +
+ " ARTIFACT_CONTENT = $artifact-contents " ;
+
+ status = serviceLogic.save("SQL", false, false, key, null, null, ctx);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing storing Artifact: " +ctx.getAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME));
+ }
+ return status;
+
+ }
+ public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException {
+ String fn = "DBService.saveReferenceData";
+ QueryStatus status = null;
+ if (serviceLogic != null && ctx != null) {
+ String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , "
+ + " message_type = $log-message-type , "
+ + " message = $log-message ;";
+ status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error while loging data");
+
+ }
+ return status;
+ }
+
+ public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) {
+ String fn = "DBService.processConfigureActionDg";
+ log.info("Update Parameter for ASDC Reference " + isUpdate );
+ String key = "";
+ QueryStatus status = null;
+ if(isUpdate);
+
+ }
+
+ public void processAsdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
+ String fn = "DBService.processAsdcReferences";
+ String key = "";
+ QueryStatus status = null;
+
+ if (isUpdate && AsdcArtifactHandlerConstants.FILE_CATEGORY.equals(AsdcArtifactHandlerConstants.CAPABILITY)) {
+ key = "update " + AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE + " set ARTIFACT_NAME = $" + AsdcArtifactHandlerConstants.ARTIFACT_NAME +
+ " where VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " and FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY +
+ " and ACTION = null";
+ }
+ else if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE + " set ARTIFACT_NAME = $" + AsdcArtifactHandlerConstants.ARTIFACT_NAME +
+ " where VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " and FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY +
+ " and ACTION = $" + AsdcArtifactHandlerConstants.ACTION ;
+
+ else {
+ if (AsdcArtifactHandlerConstants.FILE_CATEGORY.equals(AsdcArtifactHandlerConstants.CAPABILITY)) {
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE +
+ " set VNFC_TYPE = null " +
+ " , FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY +
+ " , VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " , ACTION = null " +
+ " , ARTIFACT_TYPE = null " +
+ " , ARTIFACT_NAME = $" + AsdcArtifactHandlerConstants.ARTIFACT_NAME ;
+ }
+ else {
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE +
+ " set VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " , FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY +
+ " , VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " , ACTION = $" + AsdcArtifactHandlerConstants.ACTION +
+ " , ARTIFACT_TYPE = $" + AsdcArtifactHandlerConstants.ARTIFACT_TYPE +
+ " , ARTIFACT_NAME = $" + AsdcArtifactHandlerConstants.ARTIFACT_NAME ;
+ }
+ }
+ if (serviceLogic != null && context != null) {
+ log.info("Insert Key: " + key);
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing asdc_reference table ");
+ }
+ }
+
+ public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException {
+ String fn = "DBService.isArtifactUpdateRequired";
+ log.info("Checking if Update required for this data" );
+
+ log.info("db" + db);
+ log.info("ACTION=" + context.getAttribute(AsdcArtifactHandlerConstants.ACTION));
+ log.info("VNFC_TYPE=" + context.getAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE));
+ log.info("VNFC_INSTANCE=" + context.getAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE));
+ log.info("VM_INSTANCE=" + context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE));
+ log.info("VNF_TYPE=" + context.getAttribute(AsdcArtifactHandlerConstants.VNF_TYPE));
+ String whereClause = "";
+
+ QueryStatus status = null;
+ /* if(context.getAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME) !=null &&
+ context.getAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME).toLowerCase().startsWith(AsdcArtifactHandlerConstants.PD))
+ whereClause = " where artifact_name = $" + AsdcArtifactHandlerConstants.ARTIFACT_NAME
+ + " and vnf_type = 'DummyVnf' ";
+ else*/
+ whereClause = " where VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE;
+
+ if (db !=null && db.equals(AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE) &&
+ context.getAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY).equals(AsdcArtifactHandlerConstants.CAPABILITY) &&
+ context.getAttribute(AsdcArtifactHandlerConstants.ACTION) ==null) {
+ whereClause = whereClause + " and FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY ;
+ }
+
+ else if(db !=null && db.equals(AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE)) {
+ whereClause = whereClause + " and VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE
+ + " and FILE_CATEGORY = $" + AsdcArtifactHandlerConstants.FILE_CATEGORY
+ + " and ACTION = $" + AsdcArtifactHandlerConstants.ACTION;
+ }
+
+ else if(db.equals(AsdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) {
+ whereClause = " where PROTOCOL = $" + AsdcArtifactHandlerConstants.DEVICE_PROTOCOL;
+ }
+ else if(db.equals(AsdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) {
+ whereClause = whereClause + " and ACTION = $" + AsdcArtifactHandlerConstants.ACTION;
+ }
+ else if(db.equals(AsdcArtifactHandlerConstants.DB_VNFC_REFERENCE)){
+ int vm_instance = -1 ;
+ if(context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE) !=null)
+ vm_instance = Integer.parseInt(context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE));
+ int vnfc_instance = -1 ;
+ if(context.getAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE) !=null)
+ vnfc_instance = Integer.parseInt(context.getAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE));
+ whereClause = whereClause + " and ACTION = $" + AsdcArtifactHandlerConstants.ACTION
+ + " and VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE
+ + " and VNFC_INSTANCE = $" + AsdcArtifactHandlerConstants.VNFC_INSTANCE
+ + " and VM_INSTANCE = $" + AsdcArtifactHandlerConstants.VM_INSTANCE ;
+
+ }
+ if (serviceLogic != null && context != null) {
+ String key = "select COUNT(*) from " + db + whereClause ;
+ log.info("SELECT String : " + key);
+ status = serviceLogic.query("SQL", false, null, key, null, null, context);
+ if(status.toString().equals("FAILURE")){
+ throw new SvcLogicException("Error while reading data from " + db );
+ }
+ String count = context.getAttribute("COUNT(*)");
+ log.info("Number of row Returned : " + count + ": " + status + ":");
+ if(count !=null && Integer.parseInt(count) > 0){
+ context.setAttribute(count, null);
+ return true;
+ }
+ else
+ return false;
+ }
+ return false;
+ }
+
+ public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
+ String fn = "DBService.processDeviceInterfaceProtocol";
+ log.info("Starting DB operation for Device Interface Protocol " + isUpdate );
+ String key = "";
+ QueryStatus status = null;
+ if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL +
+ " set PROTOCOL = $" + AsdcArtifactHandlerConstants.DEVICE_PROTOCOL +
+ " , DG_RPC = 'getDeviceRunningConfig' " +
+ " , MODULE = 'APPC' " +
+ " where VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE ;
+ else
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL+
+ " set VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " , PROTOCOL = $" + AsdcArtifactHandlerConstants.DEVICE_PROTOCOL +
+ " , DG_RPC = 'getDeviceRunningConfig' " +
+ " , MODULE = 'APPC' " ;
+
+ if (serviceLogic != null && context != null) {
+
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table ");
+ }
+
+ }
+
+ public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
+ String fn = "DBService.processDeviceAuthentication";
+ log.info(fn + "Starting DB operation for Device Authentication " + isUpdate );
+ String key = "";
+ QueryStatus status = null;
+ if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION +
+ " set USER_NAME = $" + AsdcArtifactHandlerConstants.USER_NAME +
+ " , PASSWORD = 'dummy' " +
+ " , PORT_NUMBER = $" + AsdcArtifactHandlerConstants.PORT_NUMBER +
+ " where VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE ;
+ else
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION+
+ " set VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " , USER_NAME = $" + AsdcArtifactHandlerConstants.USER_NAME +
+ " , PASSWORD = 'dummy' " +
+ " , PORT_NUMBER = $" + AsdcArtifactHandlerConstants.PORT_NUMBER;
+
+ if (serviceLogic != null && context != null) {
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing DEVICE_AUTHENTICATION table ");
+ }
+ }
+
+ public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
+ String fn = "DBService.processVnfcReference";
+ log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate );
+ String key = "";
+ int vm_instance = -1 ;
+ if(context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE) !=null)
+ vm_instance = Integer.parseInt(context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE));
+ int vnfc_instance = -1 ;
+ if(context.getAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE) !=null)
+ vnfc_instance = Integer.parseInt(context.getAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE));
+ QueryStatus status = null;
+ if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_VNFC_REFERENCE +
+ " set VM_INSTANCE = " + vm_instance +
+ " , VNFC_INSTANCE = " + vnfc_instance +
+ " , VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " , VNFC_FUNCTION_CODE = $" + AsdcArtifactHandlerConstants.VNFC_FUNCTION_CODE +
+ " , GROUP_NOTATION_TYPE = $" + AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE +
+ " , GROUP_NOTATION_VALUE = $" + AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE +
+ " , IPADDRESS_V4_OAM_VIP = $" + AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP +
+ " where VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " and ACTION = $" + AsdcArtifactHandlerConstants.ACTION +
+ " and VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " and VNFC_INSTANCE = $" + AsdcArtifactHandlerConstants.VNFC_INSTANCE
+ + " and VM_INSTANCE = $" + AsdcArtifactHandlerConstants.VM_INSTANCE ;
+ else
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_VNFC_REFERENCE+
+ " set VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE +
+ " , ACTION = $" + AsdcArtifactHandlerConstants.ACTION +
+ " , VM_INSTANCE = $" + AsdcArtifactHandlerConstants.VM_INSTANCE +
+ " , VNFC_INSTANCE = $" + AsdcArtifactHandlerConstants.VNFC_INSTANCE +
+ " , VNFC_TYPE = $" + AsdcArtifactHandlerConstants.VNFC_TYPE +
+ " , VNFC_FUNCTION_CODE = $" + AsdcArtifactHandlerConstants.VNFC_FUNCTION_CODE +
+ " , GROUP_NOTATION_TYPE = $" + AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE +
+ " , IPADDRESS_V4_OAM_VIP = $" + AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP +
+ " , GROUP_NOTATION_VALUE = $" + AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE ;
+
+ if (serviceLogic != null && context != null) {
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
+ }
+ }
+
+ public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException, SQLException {
+ String fn = "DBService.processDownloadDgReference";
+ log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate );
+ String key = "";
+ QueryStatus status = null;
+
+ if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE +
+ " set DOWNLOAD_CONFIG_DG = $" + AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE +
+ " where PROTOCOL = $" + AsdcArtifactHandlerConstants.DEVICE_PROTOCOL ;
+ else
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE+
+ " set DOWNLOAD_CONFIG_DG = $" + AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE +
+ " , PROTOCOL = $" + AsdcArtifactHandlerConstants.DEVICE_PROTOCOL ;
+
+ if (serviceLogic != null && context != null)
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table ");
+ }
+ public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException
+ {
+ String fn = "DBService.processConfigActionDg";
+ log.info(fn + "Starting DB operation for Config DG Action " + isUpdate );
+ String key = "";
+ QueryStatus status = null;
+
+ if(context.getAttribute(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null &&
+ context.getAttribute(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0){
+ if(isUpdate)
+ key = "update " + AsdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG +
+ " set DOWNLOAD_CONFIG_DG = $" + AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE +
+ " where ACTION = $" + AsdcArtifactHandlerConstants.ACTION +
+ " and VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE ;
+ else
+ key = "insert into " + AsdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG+
+ " set DOWNLOAD_CONFIG_DG = $" + AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE +
+ " , ACTION = $" + AsdcArtifactHandlerConstants.ACTION +
+ " , VNF_TYPE = $" + AsdcArtifactHandlerConstants.VNF_TYPE ;
+
+ if (serviceLogic != null && context != null)
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing Configure DG Action table ");
+ }
+ else
+ log.info("No Update required for Config DG Action");
+
+ }
+
+ public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException
+ {
+ String fn = "DBService.getVnfData";
+ String key = "";
+ SvcLogicContext con = new SvcLogicContext();
+ HashMap<String, String> modelData = new HashMap<String, String>();
+ QueryStatus status = null;
+ key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where ARTIFACT_NAME = " + artifact_name ;
+
+ if (serviceLogic != null && con != null) {
+ log.info(fn + "select Key: " + key);
+ status = serviceLogic.query("SQL", false, null, key, null, null, con);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table ");
+
+ }
+
+ log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE"));
+
+ return con.getAttribute("VNF_TYPE");
+
+ }
+ public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents) throws SvcLogicException {
+ String fn = "DBService.updateYangContents";
+ log.info(fn + "Starting DB operation for updateYangContents");
+ String key = "";
+ QueryStatus status = null;
+
+ key = "update ASDC_ARTIFACTS " +
+ " set ARTIFACT_CONTENT = '" + yangContents + "'" +
+ " where ASDC_ARTIFACTS_ID = " + artifactId ;
+
+ if (serviceLogic != null && context != null)
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing Configure DG Action table ");
+
+ }
+
+
+ public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, String action_level,
+ String template) throws SvcLogicException {
+ String fn = "DBService.insertProtocolReference";
+ log.info(fn + "Starting DB operation for insertProtocolReference");
+ String key = "";
+ QueryStatus status = null;
+
+ key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)" +
+ " values (" +
+ "'"+action +"', '"+ vnfType+"', '"+protocol+"', now(),'"+template+"', '"+action_level+"')";
+
+ if (serviceLogic != null && context != null)
+ status = serviceLogic.save("SQL", false, false, key, null, null, context);
+ if(status.toString().equals("FAILURE"))
+ throw new SvcLogicException("Error While processing insertProtocolReference ");
+
+ }
+}
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
new file mode 100644
index 000000000..e4cefad48
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java
@@ -0,0 +1,450 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler.node;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.openecomp.appc.artifact.handler.dbservices.DBService;
+import org.openecomp.appc.artifact.handler.utils.ArtifactHandlerProviderUtil;
+import org.openecomp.appc.artifact.handler.utils.AsdcArtifactHandlerConstants;
+import org.openecomp.appc.yang.YANGGenerator;
+import org.openecomp.appc.yang.impl.YANGGeneratorFactory;
+import org.openecomp.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+
+public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class);
+ public void processArtifact(Map<String, String> inParams, SvcLogicContext ctx) throws Exception
+ {
+ String responsePrefix = inParams.get("response_prefix");
+ try{
+ if(inParams != null && !inParams.isEmpty() && inParams.get("postData") !=null ){
+ log.info("Received request for process Artifact with params: " + inParams.toString());
+ String postData = inParams.get("postData");
+ JSONObject input = new JSONObject(postData).getJSONObject("input");
+ responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
+ storeUpdateAsdcArtifacts(input);
+ }
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ private boolean storeUpdateAsdcArtifacts(JSONObject postDataJson) throws Exception {
+ log.info("Starting processing of ASDC Artifacs into Handler with Data : " + postDataJson.toString());
+ try{
+ JSONObject request_information = (JSONObject)postDataJson.get(AsdcArtifactHandlerConstants.REQUEST_INFORMATION);
+ JSONObject document_information =(JSONObject)postDataJson.get(AsdcArtifactHandlerConstants.DOCUMENT_PARAMETERS);
+ String artifact_name = document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME);
+ if(artifact_name !=null){
+ updateStoreArtifacts(request_information, document_information );
+ if(artifact_name.toLowerCase().startsWith(AsdcArtifactHandlerConstants.REFERENCE))
+ return storeReferenceData(request_information, document_information );
+ else if (artifact_name.toLowerCase().startsWith(AsdcArtifactHandlerConstants.PD))
+ return createDataForPD(request_information, document_information );
+
+ }
+ else
+ throw new Exception("Missing Artifact Name for Request : " + request_information.getString(AsdcArtifactHandlerConstants.REQUETS_ID));
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ throw new Exception("Error while processing Request ID : " + ((JSONObject)postDataJson.get(AsdcArtifactHandlerConstants.REQUEST_INFORMATION)).getString(AsdcArtifactHandlerConstants.REQUETS_ID) + e.getMessage());
+ }
+ return false;
+
+ }
+ private boolean createDataForPD(JSONObject request_information, JSONObject document_information) throws Exception {
+
+ String fn = "ArtifactHandlerNode.createReferenceDataForPD";
+ String artifact_name = document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME);
+ log.info(fn + "Received PD File Name: " + artifact_name + " and suffix lenght " + AsdcArtifactHandlerConstants.PD.length());
+ try {
+
+ String suffix = artifact_name.substring(AsdcArtifactHandlerConstants.PD.length());
+ createArtifactRecords(request_information, document_information, suffix);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Error while createing PD data records " + e.getMessage());
+ }
+ return true;
+ }
+
+ private void createArtifactRecords(JSONObject request_information, JSONObject document_information, String suffix) throws Exception {
+
+ log.info("Creating Tosca Records and storing into ASDC Artifacs");
+ String [] docs = {"Tosca", "Yang"};
+ ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
+ String PDFileContents = document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS);
+
+ //Tosca generation
+ OutputStream toscaStream = new ByteArrayOutputStream();
+ String toscaContents = null;
+ ArtifactProcessorImpl toscaGenerator = new ArtifactProcessorImpl();
+ toscaGenerator.generateArtifact(PDFileContents,toscaStream);
+ if(toscaStream != null)
+ toscaContents = toscaStream.toString();
+ log.info("Generated Tosca File : " + toscaContents);
+
+ //Yang generation
+ //String yangContents = "Dummay Yang, Yang contents will be available after IST Integration";
+
+ String yangContents = "YANG generation is in Progress";
+ String yangName = null;
+
+ for(String doc : docs){
+ document_information.put(AsdcArtifactHandlerConstants.ARTIFACT_TYPE, doc.concat("Type"));
+ document_information.put(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, doc.concat("Model"));
+ if(doc.equals("Tosca"))
+ document_information.put(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS, ahpUtil.escapeSql(toscaContents));
+ else if (doc.equals("Yang"))
+ document_information.put(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS, ahpUtil.escapeSql(yangContents));
+ document_information.put(AsdcArtifactHandlerConstants.ARTIFACT_NAME, doc.concat(suffix));
+ yangName = doc.concat(suffix);
+ updateStoreArtifacts(request_information, document_information);
+ }
+
+ String artifactId = getArtifactID(yangName);
+ OutputStream yangStream = new ByteArrayOutputStream();
+ YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator();
+ yangGenerator.generateYANG(artifactId , toscaContents, yangStream);
+ if(yangStream != null)
+ yangContents = yangStream.toString();
+
+ if(yangContents !=null ){
+ updateYangContents(artifactId, ahpUtil.escapeSql(yangContents));
+ }
+
+ }
+
+ private void updateYangContents(String artifactId, String yangContents) throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ DBService dbservice = DBService.initialise();
+ dbservice.updateYangContents(context, artifactId, yangContents);
+ }
+
+ private String getArtifactID(String yangName) throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ DBService dbservice = DBService.initialise();
+ return dbservice.getArtifactID(context, yangName);
+ }
+
+ private boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information ) throws Exception {
+ log.info("UpdateStoreArtifactsStarted storing of ASDC Artifacs ");
+
+ SvcLogicContext context = new SvcLogicContext();
+ DBService dbservice = DBService.initialise();
+ ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
+ int intversion = 0;
+ context.setAttribute("artifact_name",document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME));
+ String internal_version = dbservice.getInternalVersionNumber(context, document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME), null);
+ log.info("Internal Version number received from Database : " + internal_version);
+ if(internal_version != null){
+ intversion = Integer.parseInt(internal_version);
+ intversion++ ;
+ }
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_UUID, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.DISTRIBUTION_ID, document_information.getString(AsdcArtifactHandlerConstants.DISTRIBUTION_ID));
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_NAME, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_NAME));
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_UUID, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME,document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_TYPE, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_TYPE));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_UUID, document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_TYPE,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_TYPE));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS,ahpUtil.escapeSql(document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS)));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME));
+ dbservice.saveArtifacts(context, intversion);
+ return true;
+
+ }
+
+ public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) throws Exception {
+ log.info("Started storing of ASDC Artifacs into Handler" );
+ try{
+ boolean updateRequired = false;
+ boolean pdFile = false;
+ String suffix = null;
+ String categorySuffix = null;
+ DBService dbservice = DBService.initialise();
+ ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
+ String contentString = ahpUtil.escapeSql(document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS)) ;
+ String artifactName=ahpUtil.escapeSql(document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME));
+ String capabilityArtifactName=StringUtils.replace(artifactName,AsdcArtifactHandlerConstants.ARTIFACT_NAME_REFERENCE,AsdcArtifactHandlerConstants.ARTIFACT_NAME_CAPABILITY);
+ JSONObject capabilities = new JSONObject();
+ JSONArray vnfActionList = new JSONArray();
+ JSONArray vfModuleActionList = new JSONArray();
+ JSONArray vnfcActionList = new JSONArray();
+ JSONArray vmActionList = new JSONArray();
+ String vnfType=null;
+ JSONObject contentObject = new JSONObject(contentString);
+ JSONArray contentArray= contentObject.getJSONArray("reference_data");
+ for(int a=0; a<contentArray.length() ; a++){
+
+ JSONObject content = (JSONObject) contentArray.get(a);
+ log.info("contentString =" + content.toString());
+ JSONObject scope = content.getJSONObject("scope");
+ log.info("scope :" + scope);
+ SvcLogicContext context = new SvcLogicContext();
+ vnfType=scope.getString(AsdcArtifactHandlerConstants.VNF_TYPE);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNF_TYPE, scope.getString(AsdcArtifactHandlerConstants.VNF_TYPE));
+ context.setAttribute(AsdcArtifactHandlerConstants.ACTION, content.getString(AsdcArtifactHandlerConstants.ACTION));
+ String actionLevel=content.getString(AsdcArtifactHandlerConstants.ACTION_LEVEL);
+ context.setAttribute(AsdcArtifactHandlerConstants.ACTION_LEVEL, content.getString(AsdcArtifactHandlerConstants.ACTION_LEVEL));
+ if ((null != actionLevel) && actionLevel.equalsIgnoreCase(AsdcArtifactHandlerConstants.ACTION_LEVEL_VNFC)) {
+ vnfcActionList.put(content.getString(AsdcArtifactHandlerConstants.ACTION));
+ }
+ if (null != actionLevel && actionLevel.equalsIgnoreCase(AsdcArtifactHandlerConstants.ACTION_LEVEL_VF_MODULE)) {
+ vfModuleActionList.put(content.getString(AsdcArtifactHandlerConstants.ACTION));
+ }
+ if (null != actionLevel && actionLevel.equalsIgnoreCase(AsdcArtifactHandlerConstants.ACTION_LEVEL_VNF)) {
+ vnfActionList.put(content.getString(AsdcArtifactHandlerConstants.ACTION));
+ }
+ if (null != actionLevel && actionLevel.equalsIgnoreCase(AsdcArtifactHandlerConstants.ACTION_LEVEL_VM)) {
+ vmActionList.put(content.getString(AsdcArtifactHandlerConstants.ACTION));
+ }
+ if(scope.has(AsdcArtifactHandlerConstants.VNFC_TYPE) && !scope.isNull(AsdcArtifactHandlerConstants.VNFC_TYPE) )
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE, scope.getString(AsdcArtifactHandlerConstants.VNFC_TYPE));
+ else
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE,null);
+ if (content.has(AsdcArtifactHandlerConstants.DEVICE_PROTOCOL))
+ context.setAttribute(AsdcArtifactHandlerConstants.DEVICE_PROTOCOL, content.getString(AsdcArtifactHandlerConstants.DEVICE_PROTOCOL));
+ if (content.has(AsdcArtifactHandlerConstants.USER_NAME))
+ context.setAttribute(AsdcArtifactHandlerConstants.USER_NAME, content.getString(AsdcArtifactHandlerConstants.USER_NAME));
+ if (content.has(AsdcArtifactHandlerConstants.PORT_NUMBER))
+ context.setAttribute(AsdcArtifactHandlerConstants.PORT_NUMBER, content.getString(AsdcArtifactHandlerConstants.PORT_NUMBER));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_TYPE, "");
+ if(content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray){
+ JSONArray artifactLists = (JSONArray)content.get("artifact-list");
+ for(int i=0;i<artifactLists.length();i++){
+ JSONObject artifact=(JSONObject)artifactLists.get(i);
+ log.info("artifact is " + artifact);
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME, artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME));
+ context.setAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY, artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_TYPE));
+
+ if(artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME) !=null &&
+ artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME).toLowerCase().startsWith(AsdcArtifactHandlerConstants.PD))
+ {
+ suffix = artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_NAME).substring(AsdcArtifactHandlerConstants.PD.length());
+ categorySuffix = artifact.getString(AsdcArtifactHandlerConstants.ARTIFACT_TYPE).substring(AsdcArtifactHandlerConstants.PD.length());
+ pdFile = true;
+ }
+
+ dbservice.processAsdcReferences(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE));
+
+ cleanArtifactInstanceData(context);
+ }
+
+ if(pdFile)
+ {
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME, "Tosca".concat(suffix));
+ context.setAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY, AsdcArtifactHandlerConstants.TOSCA_MODEL);
+ dbservice.processAsdcReferences(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME, "Yang".concat(suffix));
+ context.setAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY, AsdcArtifactHandlerConstants.PARAMETER_YANG);
+ dbservice.processAsdcReferences(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE));
+ }
+ }
+ if (content.getString(AsdcArtifactHandlerConstants.ACTION).equals("Configure")) {
+ if(content.has(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) && content.getString(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0){
+ context.setAttribute(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, content.getString(AsdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE));
+ dbservice.processDownloadDgReference(context, dbservice.isArtifactUpdateRequired(context,AsdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE));
+ }
+
+ dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG));
+ dbservice.processDeviceInterfaceProtocol(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL));
+ dbservice.processDeviceAuthentication(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION));
+
+ }
+
+
+ populateProtocolReference(dbservice, content);
+
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE, null);
+
+ if( content.has(AsdcArtifactHandlerConstants.VM) && content.get(AsdcArtifactHandlerConstants.VM) instanceof JSONArray){
+ JSONArray vmList = (JSONArray)content.get(AsdcArtifactHandlerConstants.VM);
+ for(int i=0;i<vmList.length();i++){
+ JSONObject vmInstance=(JSONObject)vmList.get(i);
+ context.setAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE, String.valueOf(vmInstance.getInt(AsdcArtifactHandlerConstants.VM_INSTANCE)));
+ log.info("VALUE = " + context.getAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE));
+ if(vmInstance.get(AsdcArtifactHandlerConstants.VNFC) instanceof JSONArray){
+ JSONArray vnfcInstanceList = (JSONArray)vmInstance.get(AsdcArtifactHandlerConstants.VNFC);
+ for(int k=0;k<vnfcInstanceList.length();k++){
+ JSONObject vnfcInstance = (JSONObject)vnfcInstanceList.get(k);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE, String.valueOf(vnfcInstance.getInt(AsdcArtifactHandlerConstants.VNFC_INSTANCE)));
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE, vnfcInstance.getString(AsdcArtifactHandlerConstants.VNFC_TYPE));
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, vnfcInstance.getString(AsdcArtifactHandlerConstants.VNFC_FUNCTION_CODE));
+ if(vnfcInstance.has(AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP))
+ context.setAttribute(AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, vnfcInstance.getString(AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP));
+ if(vnfcInstance.has(AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE))
+ context.setAttribute(AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, vnfcInstance.getString(AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE));
+ if(vnfcInstance.has(AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE))
+ context.setAttribute(AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, vnfcInstance.getString(AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE));
+ dbservice.processVnfcReference(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_VNFC_REFERENCE));
+ cleanVnfcInstance(context);
+ }
+ context.setAttribute(AsdcArtifactHandlerConstants.VM_INSTANCE,null);
+ }
+ }
+ }
+
+
+ }
+ capabilities.put("vnf",vnfActionList );
+ capabilities.put("vf-module", vfModuleActionList);
+ capabilities.put("vnfc", vnfcActionList);
+ capabilities.put("vm", vmActionList);
+ processAndStoreCapablitiesArtifact(dbservice, document_information, capabilities,capabilityArtifactName,vnfType );
+
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ throw new Exception("Error While Storing : " + e.getMessage());
+ }
+
+ return true;
+ }
+
+
+
+
+
+ private void cleanArtifactInstanceData(SvcLogicContext context)
+ {
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY, null);
+ }
+
+ private void cleanVnfcInstance(SvcLogicContext context) {
+
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_INSTANCE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, null);
+
+ }
+
+ private void processAndStoreCapablitiesArtifact (DBService dbservice , JSONObject document_information,
+ JSONObject capabilities, String capabilityArtifactName, String vnfType) throws Exception {
+ log.info("Begin-->processAndStoreCapablitiesArtifact ");
+
+ try {
+
+ JSONObject newCapabilitiesObject=new JSONObject();
+ newCapabilitiesObject.put("capabilities", capabilities);
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME,capabilityArtifactName);
+ context.setAttribute(AsdcArtifactHandlerConstants.FILE_CATEGORY, AsdcArtifactHandlerConstants.CAPABILITY);
+ context.setAttribute(AsdcArtifactHandlerConstants.ACTION, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNFC_TYPE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_TYPE, null);
+ context.setAttribute(AsdcArtifactHandlerConstants.VNF_TYPE,vnfType);
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_CONTENTS,newCapabilitiesObject.toString());
+ dbservice.processAsdcReferences(context, dbservice.isArtifactUpdateRequired(context, AsdcArtifactHandlerConstants.DB_ASDC_REFERENCE));
+ int intversion = 0;
+
+ String internal_version = dbservice.getInternalVersionNumber(context, context.getAttribute(AsdcArtifactHandlerConstants.ARTIFACT_NAME), null);
+ log.info("Internal Version number received from Database : " + internal_version);
+ if(internal_version != null){
+ intversion = Integer.parseInt(internal_version);
+ intversion++ ;
+ }
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_UUID, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.DISTRIBUTION_ID, document_information.getString(AsdcArtifactHandlerConstants.DISTRIBUTION_ID));
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_NAME, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_NAME));
+ context.setAttribute(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION, document_information.getString(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_UUID, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME,document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN));
+ context.setAttribute(AsdcArtifactHandlerConstants.RESOURCE_TYPE, document_information.getString(AsdcArtifactHandlerConstants.RESOURCE_TYPE));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_UUID, document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_UUID));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN));
+ context.setAttribute(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION,document_information.getString(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION));
+
+
+ dbservice.saveArtifacts(context, intversion);
+ return ;
+ }
+ catch (Exception e) {
+ log.error("Error saving capabilities artifact to DB: "+ e.toString());
+ throw e;
+ }
+ finally {
+ log.info("End-->processAndStoreCapablitiesArtifact ");
+ }
+
+ }
+
+
+ private void populateProtocolReference(DBService dbservice, JSONObject content) throws Exception{
+ log.info("Begin-->populateProtocolReference ");
+ try {
+ SvcLogicContext context = new SvcLogicContext();
+ JSONObject scope = content.getJSONObject("scope");
+ String vnfType=null,protocol=null,action=null,actionLevel=null,template=null;
+ if(scope.has(AsdcArtifactHandlerConstants.VNF_TYPE) && !scope.isNull(AsdcArtifactHandlerConstants.VNF_TYPE))
+ vnfType=scope.getString(AsdcArtifactHandlerConstants.VNF_TYPE);
+ if (content.has(AsdcArtifactHandlerConstants.DEVICE_PROTOCOL))
+ protocol=content.getString(AsdcArtifactHandlerConstants.DEVICE_PROTOCOL);
+ if (content.has(AsdcArtifactHandlerConstants.ACTION))
+ action= content.getString(AsdcArtifactHandlerConstants.ACTION);
+ if (content.has(AsdcArtifactHandlerConstants.ACTION_LEVEL))
+ actionLevel=content.getString(AsdcArtifactHandlerConstants.ACTION_LEVEL);
+ if (content.has(AsdcArtifactHandlerConstants.TEMPLATE) && !content.isNull(AsdcArtifactHandlerConstants.TEMPLATE))
+ template=content.getString(AsdcArtifactHandlerConstants.TEMPLATE);
+ dbservice.insertProtocolReference(context, vnfType,protocol,action,actionLevel,template);
+ }
+ catch (Exception e) {
+ log.error("Error inserting record into protocolReference: "+e.toString());
+ throw e;
+ }
+ finally {
+ log.info("End-->populateProtocolReference ");
+ }
+ }
+
+ }
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java
new file mode 100644
index 000000000..91b6e88b0
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java
@@ -0,0 +1,184 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler.utils;
+
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.HashMap;
+
+import org.apache.commons.lang3.StringUtils;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.artifacthandler.rev170321.UploadartifactInput;
+import org.openecomp.appc.artifact.handler.node.ArtifactHandlerNode;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ArtifactHandlerProviderUtil {
+
+ public UploadartifactInput templateData ;
+ SvcLogicContext context = null;
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProviderUtil.class);
+ public static void loadProperties() {
+ // TODO Auto-generated method stub
+
+ }
+ public enum DistributionStatusEnum {
+ DOWNLOAD_OK,
+ DOWNLOAD_ERROR,
+ ALREADY_DOWNLOADED,
+ DEPLOY_OK,
+ DEPLOY_ERROR,
+ ALREADY_DEPLOYED;
+ }
+
+ public ArtifactHandlerProviderUtil(){};
+
+ public ArtifactHandlerProviderUtil(UploadartifactInput input) {
+ this.templateData = input;
+ log.info("templateData " + this.templateData);
+ }
+
+ public void processTemplate(String requestInfo) throws Exception {
+ if(context == null)
+ context = new SvcLogicContext();
+
+ ArtifactHandlerNode node = new ArtifactHandlerNode();
+ try {
+
+ HashMap<String, String> processdata = new HashMap<String, String>();
+ processdata.put("postData", requestInfo);
+ log.info("Post data = " + requestInfo);
+ node.processArtifact(processdata, context);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("Error: " + e.getMessage());
+ e.printStackTrace();
+ throw e;
+ }
+
+ }
+ public String createDummyRequestData() throws JSONException, IOException{
+
+
+ JSONObject info = new JSONObject(this.templateData);
+ log.info("INFO = " + info);
+ String artifact_name = templateData.getDocumentParameters().getArtifactName();
+ String artifact_version = templateData.getDocumentParameters().getArtifactVersion();
+
+ JSONObject json = new JSONObject();
+ JSONObject requestInfo = new JSONObject();
+ String random = getRandom();
+
+ requestInfo.put(AsdcArtifactHandlerConstants.REQUETS_ID, "TLRID-" + random);
+ requestInfo.put(AsdcArtifactHandlerConstants.REQUEST_ACTION, "StoreAsdcDocumentRequest");
+ requestInfo.put(AsdcArtifactHandlerConstants.SOURCE, "TemplateLoader");
+
+ JSONObject docParams = new JSONObject();
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_UUID, "TLSUUID" + templateData.getRequestInformation().getRequestId());
+ docParams.put(AsdcArtifactHandlerConstants.DISTRIBUTION_ID, "TLDID" + random);
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_NAME, "TLServiceName");
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "Template Loader Test");
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_ARTIFACTS, "[]");
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_UUID, "TLRUID" + random);
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "TLRIName");
+ docParams.put(AsdcArtifactHandlerConstants.REOURCE_NAME, "TLResourceName");
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN, "TLResourceVersion");
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_TYPE, "TLResourceType");
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random);
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_TYPE, "APPC-CONFIG");
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "AsdcTestDescription");
+ // String data = IOUtils.toString(TestartifactHandlerNode.class.getClassLoader().getResourceAsStream("template_msrp_msc_a_template.json"), "utf-8");
+ // String data = IOUtils.toString(TemplateProcessor.class.getClassLoader().getResourceAsStream("referenceData.json"), "utf-8");
+
+ // this.templateData = this.templateData.substring(this.templateData.indexOf("}") + 1);
+ docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents());
+
+ json.put(AsdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
+ json.put(AsdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams);
+ System.out.println("Final data =" + this.templateData);
+ return String.format("{\"input\": %s}", json.toString());
+ }
+
+ private String getRandom() {
+ SecureRandom random = new SecureRandom();
+ int num = random.nextInt(100000);
+ String formatted = String.format("%05d", num);
+ return formatted;
+ }
+
+ public String escapeSql(String str) {
+ if (str == null) {
+ return null;
+ }
+ String searchList[] = new String[]{"'","\\"};
+ String replacementList[] = new String[]{ "''","\\\\"};
+ return StringUtils.replaceEach(str,searchList, replacementList);
+ }
+ public String createRequestData() throws JSONException, IOException{
+
+
+ JSONObject info = new JSONObject(this.templateData);
+ log.info("INFO = " + info);
+
+ JSONObject json = new JSONObject();
+ JSONObject requestInfo = new JSONObject();
+ String random = getRandom();
+
+ requestInfo.put(AsdcArtifactHandlerConstants.REQUETS_ID, templateData.getRequestInformation().getRequestId());
+ requestInfo.put(AsdcArtifactHandlerConstants.REQUEST_ACTION, "StoreAsdcDocumentRequest");
+ requestInfo.put(AsdcArtifactHandlerConstants.SOURCE, templateData.getRequestInformation().getSource());
+
+ JSONObject docParams = new JSONObject();
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_UUID, templateData.getDocumentParameters().getResourceUuid());
+ docParams.put(AsdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId());
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_NAME, templateData.getDocumentParameters().getServiceName());
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_DESCRIPTION, templateData.getDocumentParameters().getServiceDescription());
+ docParams.put(AsdcArtifactHandlerConstants.SERVICE_ARTIFACTS, templateData.getDocumentParameters().getServiceArtifacts());
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid());
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, templateData.getDocumentParameters().getResourceInstanceName());
+ docParams.put(AsdcArtifactHandlerConstants.REOURCE_NAME, templateData.getDocumentParameters().getResourceName());
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_VERSOIN, templateData.getDocumentParameters().getResourceVersion());
+ docParams.put(AsdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion());
+ docParams.put(AsdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, templateData.getDocumentParameters().getArtifactDescription());
+
+ docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents());
+
+ json.put(AsdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
+ json.put(AsdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams);
+ System.out.println("Final data =" + this.templateData);
+ return String.format("{\"input\": %s}", json.toString());
+ }
+
+
+}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/AsdcArtifactHandlerConstants.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/AsdcArtifactHandlerConstants.java
new file mode 100644
index 000000000..cfcb250ee
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/AsdcArtifactHandlerConstants.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler.utils;
+
+public class AsdcArtifactHandlerConstants {
+
+ public static final String DOCUMENT_PARAMETERS = "document-parameters";
+ public static final String SERVICE_UUID = "service-uuid";
+ public static final String DISTRIBUTION_ID = "distribution-id";
+ public static final String REQUETS_ID = "request-id";
+ public static final String REQUEST_ACTION = "request-action";
+ public static final String SOURCE = "source";
+ public static final String SERVICE_NAME = "service-name";
+ public static final String SERVICE_DESCRIPTION ="service-description";
+ public static final String SERVICE_ARTIFACTS = "service-artifacts";
+ public static final String RESOURCE_UUID ="resource-uuid";
+ public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name";
+ public static final String REOURCE_NAME = "resource-name";
+ public static final String RESOURCE_VERSOIN ="resource-version";
+ public static final String RESOURCE_TYPE= "resource-type";
+ public static final String ARTIFACT_UUID ="artifact-uuid";
+ public static final String ARTIFACT_NAME = "artifact-name";
+ public static final String ARTIFACT_TYPE = "artifact-type";
+ public static final String ARTIFACT_VERSOIN = "artifact-version";
+ public static final String ARTIFACT_DESRIPTION = "artifact-description";
+ public static final String ARTIFACT_CONTENTS = "artifact-contents";
+ public static final String REQUEST_INFORMATION = "request-information";
+ public static final String INTERNAL_VERSION = "internal-versoin";
+ public static final String FILE_CATEGORY = "file-category";
+ public static final String VNF_TYPE = "vnf-type";
+ public static final String ACTION = "action";
+ public static final String ACTION_LEVEL = "action-level";
+ public static final String VNFC_TYPE = "vnfc-type";
+ public static final String VM_INSTANCE = "vm-instance";
+ public static final String VM = "vm";
+ public static final String VNFC = "vnfc";
+ public static final String VNFC_FUNCTION_CODE = "vnfc-function-code";
+ public static final String GROUP_NOTATION = "group-notation";
+ public static final String IPADDRESS_V4_OAM_VIP = "ipaddress-v4-oam-vip";
+ public static final String GROUP_NOTATION_TYPE = "group-notation-type";
+ public static final String GROUP_NOTATION_VALUE = "group-notation-value";
+ public static final String REFERENCE = "reference";
+ public static final String VNFC_INSTANCE = "vnfc-instance";
+ public static final String DEVICE_PROTOCOL = "device-protocol";
+ public static final String DG_RPC = "dg-rpc";
+ public static final String MODULE = "module";
+ public static final String USER_NAME = "user-name";
+ public static final String PORT_NUMBER = "port-number";
+ public static final String DOWNLOAD_DG_REFERENCE = "download-dg-reference";
+
+
+ public static final String DB_DOWNLOAD_DG_REFERENCE = "DOWNLOAD_DG_REFERENCE";
+ public static final String DB_ASDC_REFERENCE = "ASDC_REFERENCE";
+ public static final String DB_DEVICE_INTERFACE_PROTOCOL = "DEVICE_INTERFACE_PROTOCOL";
+ public static final String DB_DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION";
+ public static final String DB_VNFC_REFERENCE = "VNFC_REFERENCE";
+ public static final String DB_CONFIG_ACTION_DG = "CONFIGURE_ACTION_DG";
+ public static final String PD = "pd";
+ public static final String PARAMETER_YANG = "parameter_yang";
+ public static final String TOSCA_MODEL = "tosca_model";
+ public static final String DESIGN_TOOL = "Design-tool";
+ public static final String ACTION_LEVEL_VNFC = "VNFC";
+ public static final String ACTION_LEVEL_VF_MODULE ="VF-MODULE";
+ public static final String ACTION_LEVEL_VNF = "VNF";
+ public static final String ACTION_LEVEL_VM = "VM";
+ public static final String CAPABILITY = "capability";
+ public static final String TEMPLATE = "template";
+ public static final String ARTIFACT_NAME_REFERENCE = "reference";
+ public static final String ARTIFACT_NAME_CAPABILITY = "capability";
+}
+
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java
new file mode 100644
index 000000000..a5a338198
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.artifact.handler.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class EscapeUtils {
+
+ public EscapeUtils() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public static String escapeSql(String str) {
+ if (str == null) {
+ return null;
+ }
+ String searchList[] = new String[]{"'","\\"};
+ String replacementList[] = new String[]{ "''","\\\\"};
+ return StringUtils.replaceEach(str,searchList, replacementList);
+ }
+}