From 161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:14:21 -0800 Subject: Second part of onap rename This is the second commit of the rename. The folder structure is renamed for appc-adapters and appc-config in this commit. Change-Id: Iaa2b8c937ff1ca1b5d1178128961fb115ee65d9b Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../data/services/AppcDataServiceActivator.java | 59 ++ .../data/services/AppcDataServiceConstant.java | 51 ++ .../appc/data/services/db/DGGeneralDBService.java | 446 ++++++++++++ .../appc/data/services/db/GeneralDataService.java | 80 +++ .../data/services/node/ConfigResourceNode.java | 751 +++++++++++++++++++++ .../onap/appc/data/services/utils/EscapeUtils.java | 39 ++ .../data/services/AppcDataServiceActivator.java | 59 -- .../data/services/AppcDataServiceConstant.java | 51 -- .../appc/data/services/db/DGGeneralDBService.java | 446 ------------ .../appc/data/services/db/GeneralDataService.java | 80 --- .../data/services/node/ConfigResourceNode.java | 751 --------------------- .../appc/data/services/utils/EscapeUtils.java | 39 -- .../data/services/db/TestConfigResourceNode.java | 170 +++++ .../data/services/db/TestDGGeneralDBService.java | 210 ++++++ .../appc/data/services/db/TestSQLSaveQuery.java | 140 ++++ .../data/services/db/TestConfigResourceNode.java | 170 ----- .../data/services/db/TestDGGeneralDBService.java | 210 ------ .../appc/data/services/db/TestSQLSaveQuery.java | 140 ---- 18 files changed, 1946 insertions(+), 1946 deletions(-) create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceActivator.java create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/GeneralDataService.java create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java create mode 100644 appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/utils/EscapeUtils.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceActivator.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceConstant.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/DGGeneralDBService.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/GeneralDataService.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/node/ConfigResourceNode.java delete mode 100644 appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/utils/EscapeUtils.java create mode 100644 appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestConfigResourceNode.java create mode 100644 appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java create mode 100644 appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java delete mode 100644 appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java delete mode 100644 appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java delete mode 100644 appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java (limited to 'appc-config/appc-data-services/provider/src') diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceActivator.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceActivator.java new file mode 100644 index 000000000..698924853 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceActivator.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services; + +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.onap.appc.data.services.node.ConfigResourceNode; +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 AppcDataServiceActivator implements BundleActivator { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(AppcDataServiceActivator.class); + private List registrations = new LinkedList(); + + @Override + public void start(BundleContext ctx) throws Exception { + + ConfigResourceNode configResourceNode = new ConfigResourceNode(); + log.info("Registering service-- " + configResourceNode.getClass().getName()); + registrations.add(ctx.registerService(configResourceNode.getClass().getName(), configResourceNode, null)); + + + + + } + + @Override + public void stop(BundleContext arg0) throws Exception { + for (ServiceRegistration registration : registrations) { + registration.unregister(); + registration = null; + } + } +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java new file mode 100644 index 000000000..9add56b5e --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services; + +public class AppcDataServiceConstant { + + + + + public static String INPUT_PARAM_RESPONSE_PREFIX = "responsePrefix"; + public static String OUTPUT_STATUS_SUCCESS = "success"; + public static String OUTPUT_STATUS_FAILURE = "failure"; + public static final String INPUT_PARAM_MESSAGE = "message"; + public static final String INPUT_PARAM_MESSAGE_TYPE = "messageType"; + public static String OUTPUT_PARAM_STATUS = "status"; + public static String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; + public static final String INPUT_PARAM_FILE_CATEGORY = "fileCategory"; + public static final String INPUT_PARAM_VM_INSTANCE = "vmInstance"; + public static final String INPUT_PARAM_SDC_ARTIFACT_IND = "asdcArtifactInd"; + public static final Object INPUT_PARAM_VNF_ID = "vnfId"; + public static final Object INPUT_PARAM_VM_NAME = "vmName"; + + public static final String INPUT_PARAM_FILE_ID = "fileId"; + + public static String INPUT_PARAM_UPLOAD_CONFIG_ID= "uploadConfigId"; + public static String CAPABILITY_VM_LEVEL="vm"; + public enum ACTIONS + { + Start, Stop, Restart; + } + + +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java new file mode 100644 index 000000000..87e5506a2 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java @@ -0,0 +1,446 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.db; + +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DGGeneralDBService { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DGGeneralDBService.class); + private SvcLogicResource serviceLogic; + private static DGGeneralDBService dgGeneralDBService = null; + + public static DGGeneralDBService initialise() { + if (dgGeneralDBService == null) { + dgGeneralDBService = new DGGeneralDBService(); + } + return dgGeneralDBService; + } + + private DGGeneralDBService() { + if (serviceLogic == null) { + serviceLogic = new SqlResource(); + } + } + + public QueryStatus getDeviceProtocolByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * FROM DEVICE_INTERFACE_PROTOCOL WHERE vnf_type = $vnf-type ;"; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getDeviceAuthenticationByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * FROM DEVICE_AUTHENTICATION WHERE vnf_type = $vnf-type ;"; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + + } + return status; + } + + public QueryStatus getConfigFileReferenceByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * FROM CONFIG_FILE_REFERENCE WHERE vnf_type = $vnf-type ;"; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getConfigFileReferenceByFileTypeNVnfType(SvcLogicContext ctx, String prefix, String fileType) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * FROM CONFIG_FILE_REFERENCE WHERE file_type = '" + fileType + + "' and vnf_type = $vnf-type ;"; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplate(SvcLogicContext ctx, String prefix, String fileCategory) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = ( SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type ) ; "; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplateByVnfTypeNAction(SvcLogicContext ctx, String prefix, String fileCategory) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type ) ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplateByVnfType(SvcLogicContext ctx, String prefix, String fileCategory) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND vnf_type = $vnf-type ) ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplateByTemplateName(SvcLogicContext ctx, String prefix, String templateName) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS " + " WHERE artifact_name = '" + templateName + "' ) ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getConfigureActionDGByVnfTypeNAction(SvcLogicContext ctx, String prefix) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * " + " FROM CONFIGURE_ACTION_DG " + + " where vnf_type = $vnf-type and action = $request-action ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getConfigureActionDGByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * " + " FROM CONFIGURE_ACTION_DG " + + " where vnf_type = $vnf-type and action IS NULL ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getMaxConfigFileId(SvcLogicContext ctx, String prefix, String fileCategory) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " + " WHERE file_category = '" + + fileCategory + "'" + " AND vnf_id = $vnf-id AND vm_name = $vm-name ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus saveConfigFiles(SvcLogicContext ctx, String prefix) throws SvcLogicException { + + QueryStatus status = null; + + if (serviceLogic != null && ctx != null) { + String key = "INSERT INTO CONFIGFILES " + " SET data_source = $data-source , " + + " service_instance_id = $service-instance-id ," + " action = $request-action ," + + " vnf_type = $vnf-type ," + " vnfc_type = $vnfc-type ," + + " vnf_id = $vnf-id , " + " vnf_name = $vnf-name ," + + " vm_name = $vm-name ," + " file_category = $file-category ," + + " file_content = $file-content ; "; + + status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); + + } + return status; + + } + + public QueryStatus savePrepareRelationship(SvcLogicContext ctx, String prefix, String fileId, String sdcInd) + throws SvcLogicException { + + QueryStatus status = null; + String key = null; + + if (serviceLogic != null && ctx != null) { + + if ("Y".equals(sdcInd)) + + key = "INSERT INTO PREPARE_FILE_RELATIONSHIP " + " SET service_instance_id = $service-instance-id , " + + " request_id = $request-id , " + " asdc_artifacts_id = " + fileId + " ;"; + else + key = "INSERT INTO PREPARE_FILE_RELATIONSHIP " + " SET service_instance_id = $service-instance-id , " + + " request_id = $request-id , " + " config_file_id = " + fileId + " ;"; + + status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); + + log.info("DGGeneralDBService.savePrepareRelationship()" + ctx.getAttributeKeySet()); + } + return status; + + } + + public void cleanContextPropertyByPrefix(SvcLogicContext ctx, String prefix) { + if (ctx != null && ctx.getAttributeKeySet() != null && StringUtils.isNotBlank(prefix)) { + + Set keySet = ctx.getAttributeKeySet(); + for (String key : keySet) { + if (StringUtils.isNotBlank(key) && key.startsWith(prefix = ".")) { + ctx.getAttributeKeySet().remove(key); + } + } + } + } + + public QueryStatus saveUploadConfig(SvcLogicContext ctx, String prefix) throws SvcLogicException { + + QueryStatus status = null; + + if (serviceLogic != null && ctx != null) { + String key = "INSERT INTO UPLOAD_CONFIG " + " SET request_id = $request-id , " + + " action = $request-action , " + " originator_id = $originator-id , " + " vnf_id = $vnf-id , " + + " vnf_name = $vnf-name , " + " vm_name = $vm-name , " + + " host_ip_address = $vnf-host-ip-address , " + " vnf_type = $vnf-type , " + + " vnfc_type = $vnfc-type , " + " config_indicator = 'Current' , " + + " content = $tmp.escaped.devicerunningconfig ; "; + + status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); + + log.info("DGGeneralDBService.saveUploadConfig()" + ctx.getAttributeKeySet()); + + } + return status; + + } + + /*public QueryStatus getMaxUploadConfigFileId(SvcLogicContext ctx, String prefix) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " + + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + log.info("DGGeneralDBService.getMaxUploadConfigFileId()" + ctx.getAttributeKeySet()); + } + return status; + }*/ + + public QueryStatus updateUploadConfig(SvcLogicContext ctx, String prefix, int maxId) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "UPDATE UPLOAD_CONFIG " + " SET config_indicator = null " + + " WHERE upload_config_id != " + maxId + " AND config_indicator = 'Current' " + + " AND vnf_id = $vnf-id " + " AND vm_name = $vm-name ; "; + + status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); + + log.info("DGGeneralDBService.updateUploadConfig()" + ctx.getAttributeKeySet()); + + } + return status; + + } + + + public QueryStatus getTemplateByArtifactType(SvcLogicContext ctx, String prefix, String fileCategory, String artifactType) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND artifactType = '" + artifactType + "'" + " AND vnf_type = $vnf-type ) ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + + public QueryStatus getConfigFilesByVnfVmNCategory(SvcLogicContext ctx, String prefix, String fileCategory, String vnfId, String vmName) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT file_content , config_file_id " + + " FROM CONFIGFILES " + + " WHERE config_file_id = ( SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " + + " WHERE file_category = '" + fileCategory + "'" + + " AND vnf_id = '" + vnfId + "'" + + " AND vm_name = '" + vmName + "' ) ; "; + + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + + public QueryStatus getDownloadConfigTemplateByVnf(SvcLogicContext ctx, String prefix) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "SELECT * FROM DOWNLOAD_CONFIG_TEMPLATE WHERE vnf_type = $vnf-type ; "; + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + + + public QueryStatus saveConfigTransactionLog(SvcLogicContext ctx, String prefix) throws SvcLogicException { + + 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); + + + + } + return status; + + } + + + public QueryStatus getVnfcReferenceByVnfcTypeNAction(SvcLogicContext ctx, String prefix) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT * " + + " FROM VNFC_REFERENCE " + + " WHERE vnf_type = $vnf-type " + + " AND vnfc_type = $vnfc-type " + + " AND action = $request-action " + + " ORDER BY vm_instance, vnfc_instance ; "; + + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + + public QueryStatus getVnfcReferenceByVnfTypeNAction(SvcLogicContext ctx, String prefix) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT * " + + " FROM VNFC_REFERENCE " + + " WHERE vnf_type = $vnf-type " + + " AND action = $request-action " + + " ORDER BY vm_instance, vnfc_instance ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + + public QueryStatus getUploadConfigInfo(SvcLogicContext ctx, String prefix) + throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP " + + " FROM UPLOAD_CONFIG " + + " WHERE upload_config_id = " + + "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " + + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ) ; "; + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + public String getCapability(SvcLogicContext ctx, String vnf_type) throws SvcLogicException { + + //{"capabilities":{"vnfc":[],"vm":[],"vf-module":[],"vnf":["ConfigureTest","ConfigModify","HealthCheck"]}} + String fn = "getCapability "; + QueryStatus status = null; + SvcLogicContext localContext = new SvcLogicContext(); + localContext.setAttribute("vnf-type", vnf_type); + if (serviceLogic != null) { + String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from ASDC_ARTIFACTS " + + " where artifact_name in (select artifact_name from ASDC_REFERENCE where vnf_type= $vnf-type " + + " and file_category = 'capability' )" ; + + log.info(fn + "Query String : " + queryString); + status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext); + + if(status.toString().equals("FAILURE")) + throw new SvcLogicException("Error - while getting capabilitiesData "); + + String queryString1 = "select artifact_content from ASDC_ARTIFACTS " + + " where artifact_name = $artifactName and internal_version = $maxInternalVersion "; + + log.debug(fn + "Query String : " + queryString1); + status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext); + if (status.toString().equals("NOT_FOUND")) + return null; + + if(status.toString().equals("FAILURE")) + throw new SvcLogicException("Error - while getting capabilitiesData "); + } + + return localContext.getAttribute("artifact-content"); + } + +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/GeneralDataService.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/GeneralDataService.java new file mode 100644 index 000000000..d0b8726ad --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/GeneralDataService.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.db; + +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; + +import org.onap.appc.data.services.AppcDataServiceConstant; +import org.onap.appc.data.services.utils.EscapeUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class GeneralDataService { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(GeneralDataService.class); + + public void saveTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException + { + SvcLogicContext logger = new SvcLogicContext(); + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE); + String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE); + try + { + + String escapedMessage = EscapeUtils.escapeSql(message); + logger.setAttribute("request-id", ctx.getAttribute("request-id")); + logger.setAttribute("log-message-type", messageType); + logger.setAttribute("log-message", escapedMessage); + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + QueryStatus status = db.saveConfigTransactionLog( logger, responsePrefix); + + logger.setAttribute("log-message", null); + logger.setAttribute("log-message-type", null); + logger.setAttribute("request-id", null); + + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to insert into config_transaction_log"); + + + } + catch (Exception e) + { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + throw new SvcLogicException(e.getMessage()); + } + } + +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java new file mode 100644 index 000000000..abdb3e85b --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java @@ -0,0 +1,751 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.node; + +import java.util.Map; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import org.onap.appc.data.services.AppcDataServiceConstant; +import org.onap.appc.data.services.db.DGGeneralDBService; +import org.onap.appc.data.services.utils.EscapeUtils; + +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; + +public class ConfigResourceNode implements SvcLogicJavaPlugin { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class); + + public void getConfigFileReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getConfigFiles call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig", + "device_configuration"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read ConfigFileReference:device-configuration"); + + status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success", + "configuration_success"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read ConfigFileReference:configuration_success"); + + status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure", + "configuration_error"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read ConfigFileReference:configuration_error"); + + status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read ConfigFileReference:configuration_log"); + + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetConfigFileReference Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in GetConfigFileReference " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void getCommonConfigInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getDeviceInfo call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read device_authentication"); + + status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read device_interface_protocol"); + + status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg"); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to Read configure_action_dg"); + + if (status == QueryStatus.NOT_FOUND) { + status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read configure_action_dg"); + } + + + + + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getCommonConfigInfo Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getCommonConfigInfo " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + // fileCategory Can be config_template, parameter_definitions, parameter_yang + public void getTemplate(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getTemplate call with params : " + inParams); + + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); + String templateName = ctx.getAttribute("template-name"); + QueryStatus status = null; + String responsePrefix1 = ""; + + try { + + responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + log.info("RESPONSEPREFIX : " + responsePrefix); + log.info("RESPONSEPREFIX1 : " + responsePrefix1); + + DGGeneralDBService db = DGGeneralDBService.initialise(); + + if (StringUtils.isBlank(templateName)) { + + //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { + + + status = db.getTemplate(ctx, responsePrefix, fileCategory); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to Read " + fileCategory ); + //} + + if (status == QueryStatus.NOT_FOUND) { + + + status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); + + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to Read " + fileCategory ); + + if (status == QueryStatus.NOT_FOUND) { + + //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory); + + //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read " + fileCategory ); + } + } + } else { + + status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read " + fileCategory + " template"); + } + + + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetTemplate Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getTemplate " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void saveConfigFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received saveConfigFiles call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles"); + + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles"); + + status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category")); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles"); + + status = db.savePrepareRelationship(ctx, "tmp.preparerel", + ctx.getAttribute("tmp.configfilesmax.configfileid"), "N"); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to save prepare_relationship"); + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("saveConfigFiles Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in saveConfigFiles " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void updateUploadConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received updateUploadConfig call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + + ctx.setAttribute("tmp.escaped.devicerunningconfig", + EscapeUtils.escapeSql(ctx.getAttribute("device-running-config"))); + + QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig"); + + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to Save configuration in upload_config"); + + /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to get record from upload_config"); + + status = db.updateUploadConfig(ctx, "tmp.uploadConfig", + Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid"))); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to upload upload_config");*/ + + status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo"); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to get record from upload_config"); + + status = db.updateUploadConfig(ctx, "tmp.uploadConfig", + Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID"))); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to upload upload_config"); + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("updateUploadConfig Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in updateUploadConfig " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void savePrepareRelationship(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received savePrepareRelationship call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND); + String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID); + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + + QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to save prepare_relationship"); + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("savePrepareRelationship Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in saveConfigFiles " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void saveConfigBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received saveConfigBlock call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + ctx.setAttribute("tmp.convertconfig.escapeData", + EscapeUtils.escapeSql(ctx.getAttribute("configuration"))); + DGGeneralDBService db = DGGeneralDBService.initialise(); + + if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { + saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"), + ctx.getAttribute("configuration")); + } else { + + saveConfigurationBlock(inParams, ctx); + + ctx.setAttribute("tmp.convertconfig.escapeData", + EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); + saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"), + ctx.getAttribute("tmp.merge.mergedData")); + + saveConfigurationData(inParams, ctx); + } + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("saveConfigBlock Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in saveConfigBlock " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void saveTemplateConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received saveTemplateConfig call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + + if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { + + ctx.setAttribute("tmp.convertconfig.escapeData", + EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content"))); + saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"), + ctx.getAttribute("config-template.file-content")); + + } else { + saveConfigurationData(inParams, ctx); + + ctx.setAttribute("tmp.convertconfig.escapeData", + EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); + saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"), + ctx.getAttribute("tmp.merge.mergedData")); + + } + + QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", + ctx.getAttribute("config-template.config-file-id"), "Y"); + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to save prepare_relationship"); + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("saveTemplateConfig Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in saveTemplateConfig " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + + + public void saveStyleSheetConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + + log.info("Received saveStyleSheet call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + try { + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + ctx.setAttribute("tmp.convertconfig.escapeData", + EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); + saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"), + ctx.getAttribute("tmp.merge.mergedData")); + + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("saveStyleSheet Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage()); + log.error("Failed in saveStyleSheet " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + public void getSmmChainKeyFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + + log.info("Received saveStyleSheet call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + String siteLocation = ctx.getAttribute("site-location"); + + QueryStatus status = null; + + try{ + + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + + + + status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation); + + if ( status == QueryStatus.FAILURE ) + throw new Exception("Unable to Read smm file"); + + + status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation); + + if ( status == QueryStatus.FAILURE ) + throw new Exception("Unable to Read intermediate_ca_chain file"); + + + + + status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key", siteLocation); + + if ( status == QueryStatus.FAILURE ) + throw new Exception("Unable to Read server_certificate_and_key file"); + + + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("saveStyleSheet Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage()); + log.error("Failed in saveStyleSheet " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + public void saveDeviceConfiguration(Map inParams, SvcLogicContext ctx, String dataSource, + String fileContent, String deviceConfig) throws SvcLogicException { + ctx.setAttribute("data-source", dataSource); + ctx.setAttribute("file-content", fileContent); + ctx.setAttribute("file-category", "device_configuration"); + ctx.setAttribute("deviceconfig-file-content", deviceConfig); + + saveConfigFiles(inParams, ctx); + } + + public void saveConfigurationBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + ctx.setAttribute("data-source", "Request"); + ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData")); + ctx.setAttribute("file-category", "configuration_block"); + saveConfigFiles(inParams, ctx); + } + + public void saveConfigurationData(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + ctx.setAttribute("data-source", ctx.getAttribute("originator-id")); + ctx.setAttribute("file-content", ctx.getAttribute("configuration-params")); + ctx.setAttribute("file-category", "config_data"); + saveConfigFiles(inParams, ctx); + } + + + public void getConfigFilesByVnfVmNCategory(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); + String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID); + String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME); + try { + + + DGGeneralDBService db = DGGeneralDBService.initialise(); + + QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles"); + + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS)); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + public void getDownloadConfigTemplateByVnf(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + try { + DGGeneralDBService db = DGGeneralDBService.initialise(); + + QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to get download config template."); + + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS)); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + + public void saveConfigTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE); + String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE); + + try { + + SvcLogicContext logctx = new SvcLogicContext(); + + String escapedMessage = EscapeUtils.escapeSql(message); + + + logctx.setAttribute("request-id", ctx.getAttribute("request-id")); + logctx.setAttribute("log-message-type", messageType); + logctx.setAttribute("log-message", escapedMessage); + + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + DGGeneralDBService db = DGGeneralDBService.initialise(); + QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix); + + logctx.setAttribute("log-message", null); + + if (status == QueryStatus.FAILURE) + throw new Exception("Unable to insert into config_transaction_log"); + + + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + + + throw new SvcLogicException(e.getMessage()); + } + } + + + + public void getVnfcReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + log.info("Received getVnfcReference call with params : " + inParams); + + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + + + QueryStatus status = null; + + try { + + + DGGeneralDBService db = DGGeneralDBService.initialise(); + + if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { + status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix); + + if ( status == QueryStatus.FAILURE) + throw new Exception("Unable to Read vnfc-reference"); + } + //else if (status == QueryStatus.NOT_FOUND ) { + status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); + + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) + throw new Exception("Unable to Read vnfc reference"); + + //} + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getVnfcReference Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getVnfcReference " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public void getCapability(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + log.info("Received getCapability call with params : " + inParams); + String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; + String caplevel = inParams.get("caplevel"); + String findCapability = inParams.get("checkCapability"); + + if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) + { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getCapability Successful - No need for capability check for this action"); + return; + } + try { + DGGeneralDBService db = DGGeneralDBService.initialise(); + String cap = db.getCapability(ctx, inParams.get("vnf-type")); + log.info("getCapability::returned from DB::+cap"); + if (StringUtils.isBlank(cap)) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getCapability Successful - No capability blocks found"); + return; + } + + ObjectMapper mapper = new ObjectMapper(); + JsonNode caps = mapper.readTree(cap); + log.info("From DB = " + caps); + JsonNode capabilities = caps.get("capabilities"); + log.info("capabilities = " + capabilities); + if(caplevel !=null && !caplevel.isEmpty()){ + JsonNode subCapabilities = capabilities.get(caplevel); + log.info("subCapabilities = " + caplevel + " : " + subCapabilities); + if(findCapability !=null && !findCapability.isEmpty()){ + if(subCapabilities != null && subCapabilities.toString().contains(findCapability)) + ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability, + "Supported"); + else + ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability, + "Not-Supported"); + } + else + { + ctx.setAttribute(responsePrefix + "capabilities." + caplevel, + subCapabilities.toString()); + } + + } + else + ctx.setAttribute(responsePrefix + "capabilities", + capabilities.toString()); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("getCapability Successful "); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed in getCapability " + e.getMessage()); + + throw new SvcLogicException(e.getMessage()); + } + } + + public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) { + boolean capabilityCheckNeeded = true; + if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) { + List actionList = new ArrayList( + Arrays.asList(AppcDataServiceConstant.ACTIONS.values())); + for (AppcDataServiceConstant.ACTIONS action : actionList) { + if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) { + capabilityCheckNeeded = false; + break; + } + } + } + return capabilityCheckNeeded; + } + + +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/utils/EscapeUtils.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/utils/EscapeUtils.java new file mode 100644 index 000000000..56e776c7c --- /dev/null +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/utils/EscapeUtils.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.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); + } +} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceActivator.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceActivator.java deleted file mode 100644 index 698924853..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceActivator.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services; - -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.onap.appc.data.services.node.ConfigResourceNode; -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 AppcDataServiceActivator implements BundleActivator { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(AppcDataServiceActivator.class); - private List registrations = new LinkedList(); - - @Override - public void start(BundleContext ctx) throws Exception { - - ConfigResourceNode configResourceNode = new ConfigResourceNode(); - log.info("Registering service-- " + configResourceNode.getClass().getName()); - registrations.add(ctx.registerService(configResourceNode.getClass().getName(), configResourceNode, null)); - - - - - } - - @Override - public void stop(BundleContext arg0) throws Exception { - for (ServiceRegistration registration : registrations) { - registration.unregister(); - registration = null; - } - } -} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceConstant.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceConstant.java deleted file mode 100644 index 9add56b5e..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/AppcDataServiceConstant.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services; - -public class AppcDataServiceConstant { - - - - - public static String INPUT_PARAM_RESPONSE_PREFIX = "responsePrefix"; - public static String OUTPUT_STATUS_SUCCESS = "success"; - public static String OUTPUT_STATUS_FAILURE = "failure"; - public static final String INPUT_PARAM_MESSAGE = "message"; - public static final String INPUT_PARAM_MESSAGE_TYPE = "messageType"; - public static String OUTPUT_PARAM_STATUS = "status"; - public static String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; - public static final String INPUT_PARAM_FILE_CATEGORY = "fileCategory"; - public static final String INPUT_PARAM_VM_INSTANCE = "vmInstance"; - public static final String INPUT_PARAM_SDC_ARTIFACT_IND = "asdcArtifactInd"; - public static final Object INPUT_PARAM_VNF_ID = "vnfId"; - public static final Object INPUT_PARAM_VM_NAME = "vmName"; - - public static final String INPUT_PARAM_FILE_ID = "fileId"; - - public static String INPUT_PARAM_UPLOAD_CONFIG_ID= "uploadConfigId"; - public static String CAPABILITY_VM_LEVEL="vm"; - public enum ACTIONS - { - Start, Stop, Restart; - } - - -} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/DGGeneralDBService.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/DGGeneralDBService.java deleted file mode 100644 index 87e5506a2..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/DGGeneralDBService.java +++ /dev/null @@ -1,446 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services.db; - -import java.util.Set; - -import org.apache.commons.lang3.StringUtils; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; -import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class DGGeneralDBService { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(DGGeneralDBService.class); - private SvcLogicResource serviceLogic; - private static DGGeneralDBService dgGeneralDBService = null; - - public static DGGeneralDBService initialise() { - if (dgGeneralDBService == null) { - dgGeneralDBService = new DGGeneralDBService(); - } - return dgGeneralDBService; - } - - private DGGeneralDBService() { - if (serviceLogic == null) { - serviceLogic = new SqlResource(); - } - } - - public QueryStatus getDeviceProtocolByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * FROM DEVICE_INTERFACE_PROTOCOL WHERE vnf_type = $vnf-type ;"; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getDeviceAuthenticationByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * FROM DEVICE_AUTHENTICATION WHERE vnf_type = $vnf-type ;"; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - - } - return status; - } - - public QueryStatus getConfigFileReferenceByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * FROM CONFIG_FILE_REFERENCE WHERE vnf_type = $vnf-type ;"; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getConfigFileReferenceByFileTypeNVnfType(SvcLogicContext ctx, String prefix, String fileType) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * FROM CONFIG_FILE_REFERENCE WHERE file_type = '" + fileType - + "' and vnf_type = $vnf-type ;"; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getTemplate(SvcLogicContext ctx, String prefix, String fileCategory) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " - + " FROM ASDC_ARTIFACTS " - + " WHERE asdc_artifacts_id = ( SELECT MAX(a.asdc_artifacts_id) configfileid " - + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " - + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " - + " AND vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type ) ; "; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getTemplateByVnfTypeNAction(SvcLogicContext ctx, String prefix, String fileCategory) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " - + " FROM ASDC_ARTIFACTS " - + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " - + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " - + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " - + " AND vnf_type = $vnf-type ) ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getTemplateByVnfType(SvcLogicContext ctx, String prefix, String fileCategory) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " - + " FROM ASDC_ARTIFACTS " - + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " - + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " - + " AND file_category = '" + fileCategory + "'" + " AND vnf_type = $vnf-type ) ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getTemplateByTemplateName(SvcLogicContext ctx, String prefix, String templateName) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " - + " FROM ASDC_ARTIFACTS " - + " WHERE asdc_artifacts_id = (SELECT MAX(asdc_artifacts_id) configfileid " - + " FROM ASDC_ARTIFACTS " + " WHERE artifact_name = '" + templateName + "' ) ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getConfigureActionDGByVnfTypeNAction(SvcLogicContext ctx, String prefix) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * " + " FROM CONFIGURE_ACTION_DG " - + " where vnf_type = $vnf-type and action = $request-action ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getConfigureActionDGByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * " + " FROM CONFIGURE_ACTION_DG " - + " where vnf_type = $vnf-type and action IS NULL ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus getMaxConfigFileId(SvcLogicContext ctx, String prefix, String fileCategory) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " + " WHERE file_category = '" - + fileCategory + "'" + " AND vnf_id = $vnf-id AND vm_name = $vm-name ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - public QueryStatus saveConfigFiles(SvcLogicContext ctx, String prefix) throws SvcLogicException { - - QueryStatus status = null; - - if (serviceLogic != null && ctx != null) { - String key = "INSERT INTO CONFIGFILES " + " SET data_source = $data-source , " - + " service_instance_id = $service-instance-id ," + " action = $request-action ," - + " vnf_type = $vnf-type ," + " vnfc_type = $vnfc-type ," - + " vnf_id = $vnf-id , " + " vnf_name = $vnf-name ," - + " vm_name = $vm-name ," + " file_category = $file-category ," - + " file_content = $file-content ; "; - - status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - - } - return status; - - } - - public QueryStatus savePrepareRelationship(SvcLogicContext ctx, String prefix, String fileId, String sdcInd) - throws SvcLogicException { - - QueryStatus status = null; - String key = null; - - if (serviceLogic != null && ctx != null) { - - if ("Y".equals(sdcInd)) - - key = "INSERT INTO PREPARE_FILE_RELATIONSHIP " + " SET service_instance_id = $service-instance-id , " - + " request_id = $request-id , " + " asdc_artifacts_id = " + fileId + " ;"; - else - key = "INSERT INTO PREPARE_FILE_RELATIONSHIP " + " SET service_instance_id = $service-instance-id , " - + " request_id = $request-id , " + " config_file_id = " + fileId + " ;"; - - status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - - log.info("DGGeneralDBService.savePrepareRelationship()" + ctx.getAttributeKeySet()); - } - return status; - - } - - public void cleanContextPropertyByPrefix(SvcLogicContext ctx, String prefix) { - if (ctx != null && ctx.getAttributeKeySet() != null && StringUtils.isNotBlank(prefix)) { - - Set keySet = ctx.getAttributeKeySet(); - for (String key : keySet) { - if (StringUtils.isNotBlank(key) && key.startsWith(prefix = ".")) { - ctx.getAttributeKeySet().remove(key); - } - } - } - } - - public QueryStatus saveUploadConfig(SvcLogicContext ctx, String prefix) throws SvcLogicException { - - QueryStatus status = null; - - if (serviceLogic != null && ctx != null) { - String key = "INSERT INTO UPLOAD_CONFIG " + " SET request_id = $request-id , " - + " action = $request-action , " + " originator_id = $originator-id , " + " vnf_id = $vnf-id , " - + " vnf_name = $vnf-name , " + " vm_name = $vm-name , " - + " host_ip_address = $vnf-host-ip-address , " + " vnf_type = $vnf-type , " - + " vnfc_type = $vnfc-type , " + " config_indicator = 'Current' , " - + " content = $tmp.escaped.devicerunningconfig ; "; - - status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - - log.info("DGGeneralDBService.saveUploadConfig()" + ctx.getAttributeKeySet()); - - } - return status; - - } - - /*public QueryStatus getMaxUploadConfigFileId(SvcLogicContext ctx, String prefix) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " - + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - log.info("DGGeneralDBService.getMaxUploadConfigFileId()" + ctx.getAttributeKeySet()); - } - return status; - }*/ - - public QueryStatus updateUploadConfig(SvcLogicContext ctx, String prefix, int maxId) throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "UPDATE UPLOAD_CONFIG " + " SET config_indicator = null " - + " WHERE upload_config_id != " + maxId + " AND config_indicator = 'Current' " - + " AND vnf_id = $vnf-id " + " AND vm_name = $vm-name ; "; - - status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - - log.info("DGGeneralDBService.updateUploadConfig()" + ctx.getAttributeKeySet()); - - } - return status; - - } - - - public QueryStatus getTemplateByArtifactType(SvcLogicContext ctx, String prefix, String fileCategory, String artifactType) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " - + " FROM ASDC_ARTIFACTS " - + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " - + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " - + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " - + " AND artifactType = '" + artifactType + "'" + " AND vnf_type = $vnf-type ) ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - - public QueryStatus getConfigFilesByVnfVmNCategory(SvcLogicContext ctx, String prefix, String fileCategory, String vnfId, String vmName) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - - String key = "SELECT file_content , config_file_id " - + " FROM CONFIGFILES " - + " WHERE config_file_id = ( SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " - + " WHERE file_category = '" + fileCategory + "'" - + " AND vnf_id = '" + vnfId + "'" - + " AND vm_name = '" + vmName + "' ) ; "; - - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - - public QueryStatus getDownloadConfigTemplateByVnf(SvcLogicContext ctx, String prefix) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "SELECT * FROM DOWNLOAD_CONFIG_TEMPLATE WHERE vnf_type = $vnf-type ; "; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - - - public QueryStatus saveConfigTransactionLog(SvcLogicContext ctx, String prefix) throws SvcLogicException { - - 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); - - - - } - return status; - - } - - - public QueryStatus getVnfcReferenceByVnfcTypeNAction(SvcLogicContext ctx, String prefix) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - - String key = "SELECT * " - + " FROM VNFC_REFERENCE " - + " WHERE vnf_type = $vnf-type " - + " AND vnfc_type = $vnfc-type " - + " AND action = $request-action " - + " ORDER BY vm_instance, vnfc_instance ; "; - - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - - public QueryStatus getVnfcReferenceByVnfTypeNAction(SvcLogicContext ctx, String prefix) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - - String key = "SELECT * " - + " FROM VNFC_REFERENCE " - + " WHERE vnf_type = $vnf-type " - + " AND action = $request-action " - + " ORDER BY vm_instance, vnfc_instance ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - - - public QueryStatus getUploadConfigInfo(SvcLogicContext ctx, String prefix) - throws SvcLogicException { - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - - String key = "SELECT * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP " - + " FROM UPLOAD_CONFIG " - + " WHERE upload_config_id = " + - "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " - + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ) ; "; - - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - } - return status; - } - public String getCapability(SvcLogicContext ctx, String vnf_type) throws SvcLogicException { - - //{"capabilities":{"vnfc":[],"vm":[],"vf-module":[],"vnf":["ConfigureTest","ConfigModify","HealthCheck"]}} - String fn = "getCapability "; - QueryStatus status = null; - SvcLogicContext localContext = new SvcLogicContext(); - localContext.setAttribute("vnf-type", vnf_type); - if (serviceLogic != null) { - String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from ASDC_ARTIFACTS " + - " where artifact_name in (select artifact_name from ASDC_REFERENCE where vnf_type= $vnf-type " + - " and file_category = 'capability' )" ; - - log.info(fn + "Query String : " + queryString); - status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext); - - if(status.toString().equals("FAILURE")) - throw new SvcLogicException("Error - while getting capabilitiesData "); - - String queryString1 = "select artifact_content from ASDC_ARTIFACTS " + - " where artifact_name = $artifactName and internal_version = $maxInternalVersion "; - - log.debug(fn + "Query String : " + queryString1); - status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext); - if (status.toString().equals("NOT_FOUND")) - return null; - - if(status.toString().equals("FAILURE")) - throw new SvcLogicException("Error - while getting capabilitiesData "); - } - - return localContext.getAttribute("artifact-content"); - } - -} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/GeneralDataService.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/GeneralDataService.java deleted file mode 100644 index d0b8726ad..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/db/GeneralDataService.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services.db; - -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.StringUtils; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; -import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; - -import org.onap.appc.data.services.AppcDataServiceConstant; -import org.onap.appc.data.services.utils.EscapeUtils; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class GeneralDataService { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(GeneralDataService.class); - - public void saveTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException - { - SvcLogicContext logger = new SvcLogicContext(); - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE); - String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE); - try - { - - String escapedMessage = EscapeUtils.escapeSql(message); - logger.setAttribute("request-id", ctx.getAttribute("request-id")); - logger.setAttribute("log-message-type", messageType); - logger.setAttribute("log-message", escapedMessage); - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - QueryStatus status = db.saveConfigTransactionLog( logger, responsePrefix); - - logger.setAttribute("log-message", null); - logger.setAttribute("log-message-type", null); - logger.setAttribute("request-id", null); - - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to insert into config_transaction_log"); - - - } - catch (Exception e) - { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - throw new SvcLogicException(e.getMessage()); - } - } - -} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/node/ConfigResourceNode.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/node/ConfigResourceNode.java deleted file mode 100644 index abdb3e85b..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/node/ConfigResourceNode.java +++ /dev/null @@ -1,751 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services.node; - -import java.util.Map; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import org.onap.appc.data.services.AppcDataServiceConstant; -import org.onap.appc.data.services.db.DGGeneralDBService; -import org.onap.appc.data.services.utils.EscapeUtils; - -import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; - -public class ConfigResourceNode implements SvcLogicJavaPlugin { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class); - - public void getConfigFileReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getConfigFiles call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - QueryStatus status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-deviceconfig", - "device_configuration"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read ConfigFileReference:device-configuration"); - - status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-success", - "configuration_success"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read ConfigFileReference:configuration_success"); - - status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-failure", - "configuration_error"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read ConfigFileReference:configuration_error"); - - status = db.getConfigFileReferenceByFileTypeNVnfType(ctx, "configfilereference-log", "log"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read ConfigFileReference:configuration_log"); - - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("GetConfigFileReference Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in GetConfigFileReference " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void getCommonConfigInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getDeviceInfo call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - QueryStatus status = db.getDeviceAuthenticationByVnfType(ctx, "device-authentication"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read device_authentication"); - - status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read device_interface_protocol"); - - status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg"); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to Read configure_action_dg"); - - if (status == QueryStatus.NOT_FOUND) { - status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read configure_action_dg"); - } - - - - - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getCommonConfigInfo Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getCommonConfigInfo " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - // fileCategory Can be config_template, parameter_definitions, parameter_yang - public void getTemplate(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getTemplate call with params : " + inParams); - - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); - String templateName = ctx.getAttribute("template-name"); - QueryStatus status = null; - String responsePrefix1 = ""; - - try { - - responsePrefix1 = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - log.info("RESPONSEPREFIX : " + responsePrefix); - log.info("RESPONSEPREFIX1 : " + responsePrefix1); - - DGGeneralDBService db = DGGeneralDBService.initialise(); - - if (StringUtils.isBlank(templateName)) { - - //if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { - - - status = db.getTemplate(ctx, responsePrefix, fileCategory); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to Read " + fileCategory ); - //} - - if (status == QueryStatus.NOT_FOUND) { - - - status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); - - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to Read " + fileCategory ); - - if (status == QueryStatus.NOT_FOUND) { - - //status = db.getTemplateByVnfType(ctx, responsePrefix, fileCategory); - - //if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read " + fileCategory ); - } - } - } else { - - status = db.getTemplateByTemplateName(ctx, responsePrefix, templateName); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read " + fileCategory + " template"); - } - - - ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("GetTemplate Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getTemplate " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void saveConfigFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received saveConfigFiles call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles"); - - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles"); - - status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category")); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles"); - - status = db.savePrepareRelationship(ctx, "tmp.preparerel", - ctx.getAttribute("tmp.configfilesmax.configfileid"), "N"); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to save prepare_relationship"); - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("saveConfigFiles Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in saveConfigFiles " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void updateUploadConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received updateUploadConfig call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - - ctx.setAttribute("tmp.escaped.devicerunningconfig", - EscapeUtils.escapeSql(ctx.getAttribute("device-running-config"))); - - QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig"); - - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to Save configuration in upload_config"); - - /*status = db.getMaxUploadConfigFileId(ctx, "tmp.uploadconfigmax"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to get record from upload_config"); - - status = db.updateUploadConfig(ctx, "tmp.uploadConfig", - Integer.parseInt(ctx.getAttribute("tmp.uploadconfigmax.uploadconfigid"))); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to upload upload_config");*/ - - status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo"); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to get record from upload_config"); - - status = db.updateUploadConfig(ctx, "tmp.uploadConfig", - Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID"))); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to upload upload_config"); - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("updateUploadConfig Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in updateUploadConfig " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void savePrepareRelationship(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received savePrepareRelationship call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - String sdcArtifactInd = inParams.get(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND); - String fileId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_ID); - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - - QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to save prepare_relationship"); - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("savePrepareRelationship Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in saveConfigFiles " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void saveConfigBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received saveConfigBlock call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - ctx.setAttribute("tmp.convertconfig.escapeData", - EscapeUtils.escapeSql(ctx.getAttribute("configuration"))); - DGGeneralDBService db = DGGeneralDBService.initialise(); - - if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { - saveDeviceConfiguration(inParams, ctx, "Request", ctx.getAttribute("tmp.convertconfig.escapeData"), - ctx.getAttribute("configuration")); - } else { - - saveConfigurationBlock(inParams, ctx); - - ctx.setAttribute("tmp.convertconfig.escapeData", - EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); - saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"), - ctx.getAttribute("tmp.merge.mergedData")); - - saveConfigurationData(inParams, ctx); - } - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("saveConfigBlock Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in saveConfigBlock " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void saveTemplateConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received saveTemplateConfig call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - - if (StringUtils.isBlank(ctx.getAttribute("configuration-params"))) { - - ctx.setAttribute("tmp.convertconfig.escapeData", - EscapeUtils.escapeSql(ctx.getAttribute("config-template.file-content"))); - saveDeviceConfiguration(inParams, ctx, "Template", ctx.getAttribute("tmp.convertconfig.escapeData"), - ctx.getAttribute("config-template.file-content")); - - } else { - saveConfigurationData(inParams, ctx); - - ctx.setAttribute("tmp.convertconfig.escapeData", - EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); - saveDeviceConfiguration(inParams, ctx, "Configurator", ctx.getAttribute("tmp.convertconfig.escapeData"), - ctx.getAttribute("tmp.merge.mergedData")); - - } - - QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", - ctx.getAttribute("config-template.config-file-id"), "Y"); - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to save prepare_relationship"); - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("saveTemplateConfig Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in saveTemplateConfig " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - - - public void saveStyleSheetConfig(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - - log.info("Received saveStyleSheet call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - try { - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - ctx.setAttribute("tmp.convertconfig.escapeData", - EscapeUtils.escapeSql(ctx.getAttribute("tmp.merge.mergedData"))); - saveDeviceConfiguration(inParams, ctx, "StyleSheet", ctx.getAttribute("tmp.convertconfig.escapeData"), - ctx.getAttribute("tmp.merge.mergedData")); - - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("saveStyleSheet Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage()); - log.error("Failed in saveStyleSheet " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - public void getSmmChainKeyFiles(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - - log.info("Received saveStyleSheet call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - String siteLocation = ctx.getAttribute("site-location"); - - QueryStatus status = null; - - try{ - - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - - - - status = db.getTemplateByArtifactType(ctx, "smm", "smm", siteLocation); - - if ( status == QueryStatus.FAILURE ) - throw new Exception("Unable to Read smm file"); - - - status = db.getTemplateByArtifactType(ctx, "intermediate-ca-chain", "intermediate_ca_chain", siteLocation); - - if ( status == QueryStatus.FAILURE ) - throw new Exception("Unable to Read intermediate_ca_chain file"); - - - - - status = db.getTemplateByArtifactType(ctx, "server-certificate-and-key", "server_certificate_and_key", siteLocation); - - if ( status == QueryStatus.FAILURE ) - throw new Exception("Unable to Read server_certificate_and_key file"); - - - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("saveStyleSheet Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE,e.getMessage()); - log.error("Failed in saveStyleSheet " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - public void saveDeviceConfiguration(Map inParams, SvcLogicContext ctx, String dataSource, - String fileContent, String deviceConfig) throws SvcLogicException { - ctx.setAttribute("data-source", dataSource); - ctx.setAttribute("file-content", fileContent); - ctx.setAttribute("file-category", "device_configuration"); - ctx.setAttribute("deviceconfig-file-content", deviceConfig); - - saveConfigFiles(inParams, ctx); - } - - public void saveConfigurationBlock(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - ctx.setAttribute("data-source", "Request"); - ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData")); - ctx.setAttribute("file-category", "configuration_block"); - saveConfigFiles(inParams, ctx); - } - - public void saveConfigurationData(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - ctx.setAttribute("data-source", ctx.getAttribute("originator-id")); - ctx.setAttribute("file-content", ctx.getAttribute("configuration-params")); - ctx.setAttribute("file-category", "config_data"); - saveConfigFiles(inParams, ctx); - } - - - public void getConfigFilesByVnfVmNCategory(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getConfigFilesByVnfVmNCategory call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); - String vnfId = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VNF_ID); - String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME); - try { - - - DGGeneralDBService db = DGGeneralDBService.initialise(); - - QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles"); - - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getConfigFilesByVnfVmNCategory Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS)); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getConfigFilesByVnfVmNCategory " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - public void getDownloadConfigTemplateByVnf(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getDownloadConfigTemplateByVnfNProtocol call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - try { - DGGeneralDBService db = DGGeneralDBService.initialise(); - - QueryStatus status = db.getDownloadConfigTemplateByVnf(ctx, responsePrefix); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to get download config template."); - - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getDownloadConfigTemplateByVnf Successful " + ctx.getAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS)); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getDownloadConfigTemplateByVnf " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - - public void saveConfigTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - String messageType = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE); - String message = inParams.get(AppcDataServiceConstant.INPUT_PARAM_MESSAGE); - - try { - - SvcLogicContext logctx = new SvcLogicContext(); - - String escapedMessage = EscapeUtils.escapeSql(message); - - - logctx.setAttribute("request-id", ctx.getAttribute("request-id")); - logctx.setAttribute("log-message-type", messageType); - logctx.setAttribute("log-message", escapedMessage); - - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - DGGeneralDBService db = DGGeneralDBService.initialise(); - QueryStatus status = db.saveConfigTransactionLog( logctx, responsePrefix); - - logctx.setAttribute("log-message", null); - - if (status == QueryStatus.FAILURE) - throw new Exception("Unable to insert into config_transaction_log"); - - - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - - - throw new SvcLogicException(e.getMessage()); - } - } - - - - public void getVnfcReference(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - log.info("Received getVnfcReference call with params : " + inParams); - - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - - - QueryStatus status = null; - - try { - - - DGGeneralDBService db = DGGeneralDBService.initialise(); - - if ( !StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { - status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix); - - if ( status == QueryStatus.FAILURE) - throw new Exception("Unable to Read vnfc-reference"); - } - //else if (status == QueryStatus.NOT_FOUND ) { - status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); - - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) - throw new Exception("Unable to Read vnfc reference"); - - //} - - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getVnfcReference Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getVnfcReference " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public void getCapability(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - log.info("Received getCapability call with params : " + inParams); - String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""; - String caplevel = inParams.get("caplevel"); - String findCapability = inParams.get("checkCapability"); - - if (!checkIfCapabilityCheckNeeded(caplevel, findCapability)) - { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getCapability Successful - No need for capability check for this action"); - return; - } - try { - DGGeneralDBService db = DGGeneralDBService.initialise(); - String cap = db.getCapability(ctx, inParams.get("vnf-type")); - log.info("getCapability::returned from DB::+cap"); - if (StringUtils.isBlank(cap)) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getCapability Successful - No capability blocks found"); - return; - } - - ObjectMapper mapper = new ObjectMapper(); - JsonNode caps = mapper.readTree(cap); - log.info("From DB = " + caps); - JsonNode capabilities = caps.get("capabilities"); - log.info("capabilities = " + capabilities); - if(caplevel !=null && !caplevel.isEmpty()){ - JsonNode subCapabilities = capabilities.get(caplevel); - log.info("subCapabilities = " + caplevel + " : " + subCapabilities); - if(findCapability !=null && !findCapability.isEmpty()){ - if(subCapabilities != null && subCapabilities.toString().contains(findCapability)) - ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability, - "Supported"); - else - ctx.setAttribute(responsePrefix + "capabilities." + caplevel + "." + findCapability, - "Not-Supported"); - } - else - { - ctx.setAttribute(responsePrefix + "capabilities." + caplevel, - subCapabilities.toString()); - } - - } - else - ctx.setAttribute(responsePrefix + "capabilities", - capabilities.toString()); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); - log.info("getCapability Successful "); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, - AppcDataServiceConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AppcDataServiceConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed in getCapability " + e.getMessage()); - - throw new SvcLogicException(e.getMessage()); - } - } - - public boolean checkIfCapabilityCheckNeeded(String caplevel, String findCapability) { - boolean capabilityCheckNeeded = true; - if (!StringUtils.equalsIgnoreCase(caplevel, AppcDataServiceConstant.CAPABILITY_VM_LEVEL)) { - List actionList = new ArrayList( - Arrays.asList(AppcDataServiceConstant.ACTIONS.values())); - for (AppcDataServiceConstant.ACTIONS action : actionList) { - if (StringUtils.equalsIgnoreCase(action.toString(), findCapability)) { - capabilityCheckNeeded = false; - break; - } - } - } - return capabilityCheckNeeded; - } - - -} diff --git a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/utils/EscapeUtils.java b/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/utils/EscapeUtils.java deleted file mode 100644 index 56e776c7c..000000000 --- a/appc-config/appc-data-services/provider/src/main/java/org/openecomp/appc/data/services/utils/EscapeUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.data.services.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); - } -} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestConfigResourceNode.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestConfigResourceNode.java new file mode 100644 index 000000000..fb44e8799 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestConfigResourceNode.java @@ -0,0 +1,170 @@ +/*- + * ============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.onap.appc.data.services.db; + +import java.util.HashMap; +import java.util.Map; +import static org.junit.Assert.assertFalse; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.data.services.AppcDataServiceConstant; +import org.onap.appc.data.services.node.ConfigResourceNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public class TestConfigResourceNode { + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetConfigFileReferenc() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + dbService.getConfigFileReference(map, ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetTemplate() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ctx.setAttribute(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "test"); + ctx.setAttribute(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); + ctx.setAttribute("template-name", "test.json"); + + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + dbService.getTemplate(map, ctx); + + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetVnfcReference() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); + dbService.getVnfcReference(map, ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetSmmChainKeyFiles() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ctx.setAttribute("site-location","test/location"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); + dbService.getSmmChainKeyFiles(map, ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetDownloadConfigTemplateByVnf() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); + dbService.getDownloadConfigTemplateByVnf(map, ctx); + + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetCommonConfigInfo() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + dbService.getCommonConfigInfo(map, ctx); + + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testupdateUploadConfigss() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ConfigResourceNode dbService = new ConfigResourceNode(); + Map map = new HashMap(); + dbService.updateUploadConfig(map, ctx); + + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testgetConfigFilesByVnfVmNCategory() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ConfigResourceNode node = new ConfigResourceNode(); + Map inParams = new HashMap(); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "response-prefix"); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "config_template"); + inParams.put((String) AppcDataServiceConstant.INPUT_PARAM_VNF_ID, "test"); + inParams.put((String) AppcDataServiceConstant.INPUT_PARAM_VM_NAME, "test"); + node.getConfigFilesByVnfVmNCategory(inParams, ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testsaveConfigTransactionLog() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ConfigResourceNode node = new ConfigResourceNode(); + Map inParams = new HashMap(); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, "testMessage"); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "response-prefix"); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, "testmessage"); + ctx.setAttribute("request-id", "tets-id"); + node.saveConfigTransactionLog(inParams, ctx); + + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testsaveConfigBlock() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ConfigResourceNode node = new ConfigResourceNode(); + Map inParams = new HashMap(); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp"); + ctx.setAttribute("configuration", "test"); + ctx.setAttribute("tmp.convertconfig.escapeData", "test"); + ctx.setAttribute("tmp.merge.mergedData", "test"); + node.saveConfigBlock(inParams, ctx); + } + + @Test + public void testcheckIfCapabilityCheckNeeded () throws Exception { + ConfigResourceNode node = new ConfigResourceNode(); + String findCapability="Start"; + String capLevel="vnf"; + boolean result=node.checkIfCapabilityCheckNeeded(capLevel,findCapability); + assertFalse(result); + } + +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java new file mode 100644 index 000000000..91f05c1d4 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java @@ -0,0 +1,210 @@ +/*- + * ============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.onap.appc.data.services.db; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.appc.data.services.db.DGGeneralDBService; + +public class TestDGGeneralDBService { + DGGeneralDBService dbService; + private static String STRING_ENCODING = "utf-8"; + + // @Before + public void setUp() { + Properties props = new Properties(); + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); + if (propStr == null) { + System.err.println("src/test/resources/svclogic.properties missing"); + } + try { + props.load(propStr); + propStr.close(); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Could not initialize properties"); + } + // Add properties to global properties + Enumeration propNames = props.keys(); + while (propNames.hasMoreElements()) { + String propName = (String) propNames.nextElement(); + System.setProperty(propName, props.getProperty(propName)); + } + dbService = DGGeneralDBService.initialise(); + } + + @Test(expected = Exception.class) + public void testGetUploadConfig() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-name", "test"); + ctx.setAttribute("vnf-id", "test"); + QueryStatus status = dbService.getUploadConfigInfo(ctx, "test"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetDeviceProtocolByVnfType() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test"); + assertEquals(status, "SUCCESS"); + } + + @Test(expected = Exception.class) + public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetDeviceAuthenticationByVnfType() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetTemplate() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnfc-type", "test"); + ctx.setAttribute("request-action", "Configure"); + QueryStatus status = dbService.getTemplate(ctx, "test", "config_template"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetTemplateByVnfTypeNAction() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + ctx.setAttribute("request-action", "Configure"); + QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetTemplateByTemplateName() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("request-action", "Configure"); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetTemplateByVnfType() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + ctx.setAttribute("request-action", "ConfigModify"); + QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetConfigureActionDGByVnfType() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetMaxConfigFileId() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-id", "test"); + ctx.setAttribute("vm-name", "test"); + QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-id", "test"); + ctx.setAttribute("vm-name", "test"); + QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test", + "ibcx0001vm001"); + assertEquals(status, "SUCCESS"); + + } + + @Test(expected = Exception.class) + public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test"); + QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test"); + assertEquals(status, "SUCCESS"); + } + + @Test(expected = Exception.class) + public void testSaveConfigTxLog() throws SvcLogicException, IOException { + + SvcLogicContext ctx = new SvcLogicContext(); + String message = IOUtils.toString( + TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"), + STRING_ENCODING); + ctx.setAttribute("request-id", "1234"); + String escapedMessage = StringEscapeUtils.escapeSql(message); + ctx.setAttribute("log-message", escapedMessage); + ctx.setAttribute("log-message-type", "request"); + QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test"); + assertEquals(status, "SUCCESS"); + } + +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java new file mode 100644 index 000000000..2a8115336 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java @@ -0,0 +1,140 @@ +/*- + * ============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.onap.appc.data.services.db; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class TestSQLSaveQuery { + + private static final Logger LOG = LoggerFactory.getLogger(TestSQLSaveQuery.class); + private static String CRYPT_KEY = ""; + + @Test + public void testSQLSaveQuery() { + try { + String message = FileUtils.readFileToString(new File("src/test/resources/query/sampledata.txt")); + System.out.println("TestSQLSaveQuery.testSQLSaveQuery()" + message); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("request-id", "1234"); + String escapedMessage = StringEscapeUtils.escapeSql(message); + ctx.setAttribute("log_message", escapedMessage); + String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + + " SET request_id = $request-id , message_type = 'request' , message = $log_message ;"; + String resolvedContext = resolveCtxVars(key, ctx); + ctx.setAttribute("log_message", null); + } catch (IOException e) { + + } + + } + + private String resolveCtxVars(String key, SvcLogicContext ctx) { + if (key == null) { + return (null); + } + if (key.startsWith("'") && key.endsWith("'")) { + key = key.substring(1, key.length() - 1); + LOG.debug("Stripped outer single quotes - key is now [" + key + "]"); + } + String[] keyTerms = key.split("\\s+"); + StringBuffer sqlBuffer = new StringBuffer(); + for (int i = 0; i < keyTerms.length; i++) { + sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); + sqlBuffer.append(" "); + } + return (sqlBuffer.toString()); + } + + private String resolveTerm(String term, SvcLogicContext ctx) { + if (term == null) { + return (null); + } + LOG.debug("resolveTerm: term is " + term); + if (term.startsWith("$") && (ctx != null)) { + // Resolve any index variables. + return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'"); + + } else { + return (term); + } + + } + + private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) { + + if (ctxVarName.indexOf('[') == -1) { + // Ctx variable contains no arrays + if ("CRYPT_KEY".equals(ctxVarName)) { + // Handle crypt key as special case. If it's set as a context + // variable, use it. Otherwise, use + // configured crypt key. + String cryptKey = ctx.getAttribute(ctxVarName); + if ((cryptKey != null) && (cryptKey.length() > 0)) { + return (cryptKey); + } else { + return (CRYPT_KEY); + } + + } + return (ctx.getAttribute(ctxVarName)); + } + // Resolve any array references + StringBuffer sbuff = new StringBuffer(); + String[] ctxVarParts = ctxVarName.split("\\["); + sbuff.append(ctxVarParts[0]); + for (int i = 1; i < ctxVarParts.length; i++) { + if (ctxVarParts[i].startsWith("$")) { + int endBracketLoc = ctxVarParts[i].indexOf("]"); + if (endBracketLoc == -1) { + // Missing end bracket ... give up parsing + LOG.warn("Variable reference " + ctxVarName + " seems to be missing a ']'"); + return (ctx.getAttribute(ctxVarName)); + } + + String idxVarName = ctxVarParts[i].substring(1, endBracketLoc); + String remainder = ctxVarParts[i].substring(endBracketLoc); + sbuff.append("["); + sbuff.append(ctx.getAttribute(idxVarName)); + sbuff.append(remainder); + + } else { + // Index is not a variable reference + sbuff.append("["); + sbuff.append(ctxVarParts[i]); + } + } + return (ctx.getAttribute(sbuff.toString())); + } + +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java deleted file mode 100644 index fb44e8799..000000000 --- a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestConfigResourceNode.java +++ /dev/null @@ -1,170 +0,0 @@ -/*- - * ============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.onap.appc.data.services.db; - -import java.util.HashMap; -import java.util.Map; -import static org.junit.Assert.assertFalse; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.data.services.AppcDataServiceConstant; -import org.onap.appc.data.services.node.ConfigResourceNode; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public class TestConfigResourceNode { - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetConfigFileReferenc() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - dbService.getConfigFileReference(map, ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetTemplate() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ctx.setAttribute(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "test"); - ctx.setAttribute(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); - ctx.setAttribute("template-name", "test.json"); - - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - dbService.getTemplate(map, ctx); - - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetVnfcReference() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); - dbService.getVnfcReference(map, ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetSmmChainKeyFiles() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ctx.setAttribute("site-location","test/location"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); - dbService.getSmmChainKeyFiles(map, ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetDownloadConfigTemplateByVnf() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - map.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp.test"); - dbService.getDownloadConfigTemplateByVnf(map, ctx); - - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetCommonConfigInfo() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - dbService.getCommonConfigInfo(map, ctx); - - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testupdateUploadConfigss() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ConfigResourceNode dbService = new ConfigResourceNode(); - Map map = new HashMap(); - dbService.updateUploadConfig(map, ctx); - - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testgetConfigFilesByVnfVmNCategory() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ConfigResourceNode node = new ConfigResourceNode(); - Map inParams = new HashMap(); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "response-prefix"); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "config_template"); - inParams.put((String) AppcDataServiceConstant.INPUT_PARAM_VNF_ID, "test"); - inParams.put((String) AppcDataServiceConstant.INPUT_PARAM_VM_NAME, "test"); - node.getConfigFilesByVnfVmNCategory(inParams, ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testsaveConfigTransactionLog() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ConfigResourceNode node = new ConfigResourceNode(); - Map inParams = new HashMap(); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, "testMessage"); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "response-prefix"); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, "testmessage"); - ctx.setAttribute("request-id", "tets-id"); - node.saveConfigTransactionLog(inParams, ctx); - - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testsaveConfigBlock() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ConfigResourceNode node = new ConfigResourceNode(); - Map inParams = new HashMap(); - inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "tmp"); - ctx.setAttribute("configuration", "test"); - ctx.setAttribute("tmp.convertconfig.escapeData", "test"); - ctx.setAttribute("tmp.merge.mergedData", "test"); - node.saveConfigBlock(inParams, ctx); - } - - @Test - public void testcheckIfCapabilityCheckNeeded () throws Exception { - ConfigResourceNode node = new ConfigResourceNode(); - String findCapability="Start"; - String capLevel="vnf"; - boolean result=node.checkIfCapabilityCheckNeeded(capLevel,findCapability); - assertFalse(result); - } - -} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java deleted file mode 100644 index 91f05c1d4..000000000 --- a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java +++ /dev/null @@ -1,210 +0,0 @@ -/*- - * ============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.onap.appc.data.services.db; - -import static org.junit.Assert.assertEquals; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Properties; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; -import org.onap.appc.data.services.db.DGGeneralDBService; - -public class TestDGGeneralDBService { - DGGeneralDBService dbService; - private static String STRING_ENCODING = "utf-8"; - - // @Before - public void setUp() { - Properties props = new Properties(); - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - if (propStr == null) { - System.err.println("src/test/resources/svclogic.properties missing"); - } - try { - props.load(propStr); - propStr.close(); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Could not initialize properties"); - } - // Add properties to global properties - Enumeration propNames = props.keys(); - while (propNames.hasMoreElements()) { - String propName = (String) propNames.nextElement(); - System.setProperty(propName, props.getProperty(propName)); - } - dbService = DGGeneralDBService.initialise(); - } - - @Test(expected = Exception.class) - public void testGetUploadConfig() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-name", "test"); - ctx.setAttribute("vnf-id", "test"); - QueryStatus status = dbService.getUploadConfigInfo(ctx, "test"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetDeviceProtocolByVnfType() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); - } - - @Test(expected = Exception.class) - public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetDeviceAuthenticationByVnfType() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetTemplate() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnfc-type", "test"); - ctx.setAttribute("request-action", "Configure"); - QueryStatus status = dbService.getTemplate(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetTemplateByVnfTypeNAction() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - ctx.setAttribute("request-action", "Configure"); - QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetTemplateByTemplateName() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("request-action", "Configure"); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetTemplateByVnfType() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - ctx.setAttribute("request-action", "ConfigModify"); - QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetConfigureActionDGByVnfType() throws SvcLogicException { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetMaxConfigFileId() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-id", "test"); - ctx.setAttribute("vm-name", "test"); - QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-id", "test"); - ctx.setAttribute("vm-name", "test"); - QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test", - "ibcx0001vm001"); - assertEquals(status, "SUCCESS"); - - } - - @Test(expected = Exception.class) - public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException { - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("vnf-type", "test"); - QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test"); - assertEquals(status, "SUCCESS"); - } - - @Test(expected = Exception.class) - public void testSaveConfigTxLog() throws SvcLogicException, IOException { - - SvcLogicContext ctx = new SvcLogicContext(); - String message = IOUtils.toString( - TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"), - STRING_ENCODING); - ctx.setAttribute("request-id", "1234"); - String escapedMessage = StringEscapeUtils.escapeSql(message); - ctx.setAttribute("log-message", escapedMessage); - ctx.setAttribute("log-message-type", "request"); - QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test"); - assertEquals(status, "SUCCESS"); - } - -} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java deleted file mode 100644 index 2a8115336..000000000 --- a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * ============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.onap.appc.data.services.db; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class TestSQLSaveQuery { - - private static final Logger LOG = LoggerFactory.getLogger(TestSQLSaveQuery.class); - private static String CRYPT_KEY = ""; - - @Test - public void testSQLSaveQuery() { - try { - String message = FileUtils.readFileToString(new File("src/test/resources/query/sampledata.txt")); - System.out.println("TestSQLSaveQuery.testSQLSaveQuery()" + message); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("request-id", "1234"); - String escapedMessage = StringEscapeUtils.escapeSql(message); - ctx.setAttribute("log_message", escapedMessage); - String key = "INSERT INTO CONFIG_TRANSACTION_LOG " - + " SET request_id = $request-id , message_type = 'request' , message = $log_message ;"; - String resolvedContext = resolveCtxVars(key, ctx); - ctx.setAttribute("log_message", null); - } catch (IOException e) { - - } - - } - - private String resolveCtxVars(String key, SvcLogicContext ctx) { - if (key == null) { - return (null); - } - if (key.startsWith("'") && key.endsWith("'")) { - key = key.substring(1, key.length() - 1); - LOG.debug("Stripped outer single quotes - key is now [" + key + "]"); - } - String[] keyTerms = key.split("\\s+"); - StringBuffer sqlBuffer = new StringBuffer(); - for (int i = 0; i < keyTerms.length; i++) { - sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); - sqlBuffer.append(" "); - } - return (sqlBuffer.toString()); - } - - private String resolveTerm(String term, SvcLogicContext ctx) { - if (term == null) { - return (null); - } - LOG.debug("resolveTerm: term is " + term); - if (term.startsWith("$") && (ctx != null)) { - // Resolve any index variables. - return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'"); - - } else { - return (term); - } - - } - - private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) { - - if (ctxVarName.indexOf('[') == -1) { - // Ctx variable contains no arrays - if ("CRYPT_KEY".equals(ctxVarName)) { - // Handle crypt key as special case. If it's set as a context - // variable, use it. Otherwise, use - // configured crypt key. - String cryptKey = ctx.getAttribute(ctxVarName); - if ((cryptKey != null) && (cryptKey.length() > 0)) { - return (cryptKey); - } else { - return (CRYPT_KEY); - } - - } - return (ctx.getAttribute(ctxVarName)); - } - // Resolve any array references - StringBuffer sbuff = new StringBuffer(); - String[] ctxVarParts = ctxVarName.split("\\["); - sbuff.append(ctxVarParts[0]); - for (int i = 1; i < ctxVarParts.length; i++) { - if (ctxVarParts[i].startsWith("$")) { - int endBracketLoc = ctxVarParts[i].indexOf("]"); - if (endBracketLoc == -1) { - // Missing end bracket ... give up parsing - LOG.warn("Variable reference " + ctxVarName + " seems to be missing a ']'"); - return (ctx.getAttribute(ctxVarName)); - } - - String idxVarName = ctxVarParts[i].substring(1, endBracketLoc); - String remainder = ctxVarParts[i].substring(endBracketLoc); - sbuff.append("["); - sbuff.append(ctx.getAttribute(idxVarName)); - sbuff.append(remainder); - - } else { - // Index is not a variable reference - sbuff.append("["); - sbuff.append(ctxVarParts[i]); - } - } - return (ctx.getAttribute(sbuff.toString())); - } - -} -- cgit 1.2.3-korg