From 280a0f6c73ab1c1aed9ee87fbd053d01d3838d70 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 12 Sep 2018 16:26:03 -0400 Subject: Controller Blueprints Nitrogen to Oxygen Migration Changing package structure from org.onap.ccsdk.config to org.onap.ccsdk.features Change-Id: I7d52b498f11ed892d547220cc4354298b6182c77 Issue-ID: CCSDK-560 Signed-off-by: Singal, Kapil (ks220y) --- .../adaptors/data-adaptor-provider/pom.xml | 10 +- .../data/adaptor/ConfigDataAdaptorException.java | 50 --- .../config/data/adaptor/DataAdaptorConstants.java | 76 ---- .../data/adaptor/dao/ConfigPropertyMapDao.java | 33 -- .../data/adaptor/dao/ConfigPropertyMapDaoImpl.java | 74 ---- .../config/data/adaptor/dao/ConfigResourceDao.java | 58 --- .../data/adaptor/dao/ConfigResourceDaoImpl.java | 415 --------------------- .../data/adaptor/dao/NamedQueryExecutorDao.java | 57 --- .../adaptor/dao/NamedQueryExecutorDaoImpl.java | 56 --- .../config/data/adaptor/dao/QueryExecutorDao.java | 54 --- .../data/adaptor/dao/QueryExecutorDaoImpl.java | 53 --- .../config/data/adaptor/dao/TransactionLogDao.java | 61 --- .../data/adaptor/dao/TransactionLogDaoImpl.java | 90 ----- .../config/data/adaptor/db/DataSourceWrap.java | 91 ----- .../data/adaptor/domain/ConfigPropertyMapData.java | 49 --- .../config/data/adaptor/domain/ConfigResource.java | 171 --------- .../adaptor/domain/ResourceAssignmentData.java | 157 -------- .../config/data/adaptor/domain/TransactionLog.java | 98 ----- .../data/adaptor/service/ConfigResourceNode.java | 61 --- .../adaptor/service/ConfigResourceService.java | 152 -------- .../adaptor/service/ConfigResourceServiceImpl.java | 113 ------ .../data/adaptor/ConfigDataAdaptorException.java | 50 +++ .../data/adaptor/DataAdaptorConstants.java | 76 ++++ .../data/adaptor/dao/ConfigPropertyMapDao.java | 33 ++ .../data/adaptor/dao/ConfigPropertyMapDaoImpl.java | 74 ++++ .../data/adaptor/dao/ConfigResourceDao.java | 59 +++ .../data/adaptor/dao/ConfigResourceDaoImpl.java | 415 +++++++++++++++++++++ .../data/adaptor/dao/NamedQueryExecutorDao.java | 57 +++ .../adaptor/dao/NamedQueryExecutorDaoImpl.java | 56 +++ .../data/adaptor/dao/QueryExecutorDao.java | 54 +++ .../data/adaptor/dao/QueryExecutorDaoImpl.java | 53 +++ .../data/adaptor/dao/TransactionLogDao.java | 62 +++ .../data/adaptor/dao/TransactionLogDaoImpl.java | 90 +++++ .../features/data/adaptor/db/DataSourceWrap.java | 91 +++++ .../data/adaptor/domain/ConfigPropertyMapData.java | 49 +++ .../data/adaptor/domain/ConfigResource.java | 171 +++++++++ .../adaptor/domain/ResourceAssignmentData.java | 157 ++++++++ .../data/adaptor/domain/TransactionLog.java | 98 +++++ .../data/adaptor/service/ConfigResourceNode.java | 61 +++ .../adaptor/service/ConfigResourceService.java | 153 ++++++++ .../adaptor/service/ConfigResourceServiceImpl.java | 114 ++++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 16 +- .../data/adaptor/dao/ConfigPropertyMapDaoTest.java | 51 --- .../data/adaptor/dao/ConfigResourceDaoTest.java | 125 ------- .../adaptor/dao/ConfigTransactionLogDaoTest.java | 79 ---- .../data/adaptor/dao/QueryExecutorDaoTest.java | 81 ---- .../adaptor/service/ConfigResourceNodeTest.java | 86 ----- .../adaptor/service/ConfigResourceServiceTest.java | 192 ---------- .../data/adaptor/dao/ConfigPropertyMapDaoTest.java | 53 +++ .../data/adaptor/dao/ConfigResourceDaoTest.java | 126 +++++++ .../adaptor/dao/ConfigTransactionLogDaoTest.java | 81 ++++ .../data/adaptor/dao/QueryExecutorDaoTest.java | 82 ++++ .../adaptor/service/ConfigResourceNodeTest.java | 89 +++++ .../adaptor/service/ConfigResourceServiceTest.java | 194 ++++++++++ .../src/test/resources/test-context-h2db.xml | 12 +- .../src/test/resources/test-context.xml | 14 +- .../adaptors/rest-adaptor-provider/pom.xml | 8 +- .../rest/adaptor/ConfigRestAdaptorConstants.java | 69 ---- .../rest/adaptor/ConfigRestAdaptorException.java | 50 --- .../config/rest/adaptor/data/RestResponse.java | 76 ---- .../service/AbstractConfigRestClientAdapter.java | 274 -------------- .../adaptor/service/ConfigRestAdaptorService.java | 92 ----- .../service/ConfigRestAdaptorServiceImpl.java | 145 ------- .../service/ConfigRestClientServiceAdapter.java | 38 -- .../service/GenericRestClientAdapterImpl.java | 139 ------- .../adaptor/service/SSLRestClientAdapterImpl.java | 130 ------- .../utils/BasicAuthorizationInterceptor.java | 56 --- .../adaptor/utils/LoggingRequestInterceptor.java | 71 ---- .../rest/adaptor/ConfigRestAdaptorConstants.java | 69 ++++ .../rest/adaptor/ConfigRestAdaptorException.java | 50 +++ .../features/rest/adaptor/data/RestResponse.java | 76 ++++ .../service/AbstractConfigRestClientAdapter.java | 274 ++++++++++++++ .../adaptor/service/ConfigRestAdaptorService.java | 92 +++++ .../service/ConfigRestAdaptorServiceImpl.java | 146 ++++++++ .../service/ConfigRestClientServiceAdapter.java | 38 ++ .../service/GenericRestClientAdapterImpl.java | 139 +++++++ .../adaptor/service/SSLRestClientAdapterImpl.java | 131 +++++++ .../utils/BasicAuthorizationInterceptor.java | 56 +++ .../adaptor/utils/LoggingRequestInterceptor.java | 71 ++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 4 +- .../AbstractConfigRestClientAdapterTest.java | 56 --- .../service/GenericRestClientServiceTest.java | 118 ------ .../rest/adaptor/service/SSLClientServiceTest.java | 118 ------ .../adaptor/utils/RestTemplateFactoryTest.java | 49 --- .../AbstractConfigRestClientAdapterTest.java | 59 +++ .../service/GenericRestClientServiceTest.java | 121 ++++++ .../rest/adaptor/service/SSLClientServiceTest.java | 121 ++++++ .../adaptor/utils/RestTemplateFactoryTest.java | 49 +++ .../test/resources/config-rest-adaptor.properties | 38 +- 89 files changed, 4141 insertions(+), 4115 deletions(-) delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/ConfigDataAdaptorException.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/DataAdaptorConstants.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDao.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDao.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDao.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDaoImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDao.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDao.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDaoImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/db/DataSourceWrap.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigPropertyMapData.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigResource.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ResourceAssignmentData.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/TransactionLog.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNode.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceService.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/ConfigDataAdaptorException.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/DataAdaptorConstants.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDao.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDao.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDao.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDaoImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDao.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDao.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDaoImpl.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/db/DataSourceWrap.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigPropertyMapData.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigResource.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ResourceAssignmentData.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/TransactionLog.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNode.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceService.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceImpl.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoTest.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoTest.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigTransactionLogDaoTest.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoTest.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNodeTest.java delete mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigTransactionLogDaoTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNodeTest.java create mode 100644 blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorConstants.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorException.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/data/RestResponse.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapter.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorService.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestClientServiceAdapter.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/SSLRestClientAdapterImpl.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/BasicAuthorizationInterceptor.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/LoggingRequestInterceptor.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorConstants.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorException.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/data/RestResponse.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapter.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorService.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestClientServiceAdapter.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientAdapterImpl.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/SSLRestClientAdapterImpl.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/BasicAuthorizationInterceptor.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/LoggingRequestInterceptor.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java (limited to 'blueprints-processor/adaptors') diff --git a/blueprints-processor/adaptors/data-adaptor-provider/pom.xml b/blueprints-processor/adaptors/data-adaptor-provider/pom.xml index f328ea954..0de0bab0a 100644 --- a/blueprints-processor/adaptors/data-adaptor-provider/pom.xml +++ b/blueprints-processor/adaptors/data-adaptor-provider/pom.xml @@ -111,11 +111,11 @@ ${project.artifactId} ${project.groupId}.${project.artifactId} - org.onap.ccsdk.config.data.adaptor, - org.onap.ccsdk.config.data.adaptor.dao, - org.onap.ccsdk.config.data.adaptor.db, - org.onap.ccsdk.config.data.adaptor.domain, - org.onap.ccsdk.config.data.adaptor.service + org.onap.ccsdk.features.data.adaptor, + org.onap.ccsdk.features.data.adaptor.dao, + org.onap.ccsdk.features.data.adaptor.db, + org.onap.ccsdk.features.data.adaptor.domain, + org.onap.ccsdk.features.data.adaptor.service diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/ConfigDataAdaptorException.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/ConfigDataAdaptorException.java deleted file mode 100644 index cd4ac277a..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/ConfigDataAdaptorException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor; - -/** - * ConfigDataAdaptorException.java Purpose: Provide Configuration Data Adaptor Exception - * - * @version 1.0 - */ -public class ConfigDataAdaptorException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * This is a ConfigDataAdaptorException constructor - * - * @param message - */ - public ConfigDataAdaptorException(String message) { - super(message); - } - - /** - * This is a ConfigDataAdaptorException constructor - * - * @param message - */ - public ConfigDataAdaptorException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/DataAdaptorConstants.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/DataAdaptorConstants.java deleted file mode 100644 index 6a61370ea..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/DataAdaptorConstants.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor; - -@SuppressWarnings("squid:S1118") -public class DataAdaptorConstants { - - public static final String OUTPUT_STATUS_SUCCESS = "success"; - public static final String OUTPUT_STATUS_FAILURE = "failure"; - - public static final String PROPERTY_ENV_TYPE = "org.onap.ccsdk.config.rest.adaptors.envtype"; - public static final String PROPERTY_ENV_PROD = "field"; - public static final String PROPERTY_ENV_SOLO = "solo"; - - public static final String INPUT_PARAM_TAGS = "tags"; - public static final String INPUT_PARAM_CAPABILITY_NAME = "capabilityName"; - public static final String INPUT_PARAM_MESSAGE = "message"; - public static final String INPUT_PARAM_MESSAGE_TYPE = "messageType"; - public static final String OUTPUT_PARAM_STATUS = "status"; - public static final 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_ASDC_ARTIFACT_IND = "asdcArtifactInd"; - public static final Object INPUT_PARAM_VNF_ID = "vnfId"; - public static final Object INPUT_PARAM_VM_NAME = "vmName"; - - public static final Object INPUT_PARAM_CONFIG_CONTENT_TYPE = "configContentType"; - - public static final Object INPUT_PARAM_CONFIG_CONTENT = "configContent"; - public static final Object INPUT_PARAM_CONFIG_INDICATOR = "configIndicator"; - - public static final Object CONFIG_CONTENT_TYPE_CONFIGURATION = "Configuration"; - public static final Object CONFIG_CONTENT_TYPE_PARAMETERS = "Parameters"; - public static final Object CONFIG_INDICATOR_PREPARE = "Prepare"; - public static final Object CONFIG_INDICATOR_ACTIVE = "Active"; - - public static final String INPUT_PARAM_RESPONSE_PRIFIX = "response-prefix"; - public static final String INPUT_PARAM_VNF_TYPE = "vnfType"; - public static final String INPUT_PARAM_VNFC_TYPE = "vnfcType"; - public static final String INPUT_PARAM_ACTION = "action"; - public static final String INPUT_PARAM_API_VERSION = "apiVersion"; - - public static final String INPUT_PARAM_FILE_ID = "fileId"; - public static final String INPUT_PARAM_UPLOAD_CONFIG_ID = "uploadConfigId"; - public static final String FILE_CATEGORY_SERVICE_TEMPLATE = "service_template"; - - public static final String ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL"; - - public static final String LOG_MESSAGE_TYPE_LOG = "Log"; - public static final String LOG_MESSAGE_TYPE_COMPONENT = "Component"; - public static final String LOG_MESSAGE_TYPE_REQUEST = "Request"; - public static final String LOG_MESSAGE_TYPE_MODEL = "Model"; - public static final String LOG_MESSAGE_TYPE_DATA = "Data"; - public static final String LOG_MESSAGE_TYPE_CONFIG = "Config"; - - public static final String SELF_SERVICE_STATUS_RECEIVED = "Received"; - public static final String SELF_SERVICE_STATUS_ACKNOWLEDGED = "Acknowledged"; - public static final String SELF_SERVICE_STATUS_REPLIED = "Replied"; - public static final String SELF_SERVICE_STATUS_FAILED = "Failed"; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDao.java deleted file mode 100644 index 2bf9682de..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ConfigPropertyMapDao { - - /** - * Query ConcurrentHashMap having CONFIG_PROPERTY_MAP table data for given key. - * - * @param key key mapped to a value - * @return the result string, containing mapped string value - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if fails - */ - public String getConfigPropertyByKey(String key) throws SvcLogicException; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoImpl.java deleted file mode 100644 index 65e241e7d..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.CannotGetJdbcConnectionException; -import org.springframework.jdbc.core.JdbcTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.Preconditions; - -public class ConfigPropertyMapDaoImpl implements ConfigPropertyMapDao { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPropertyMapDaoImpl.class); - - private JdbcTemplate jdbcTemplate; - private Map configPropertyMap = new ConcurrentHashMap<>(); - - public ConfigPropertyMapDaoImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - initializeMap(); - - String envType = configPropertyMap.get(DataAdaptorConstants.PROPERTY_ENV_TYPE); - if (!(DataAdaptorConstants.PROPERTY_ENV_PROD.equalsIgnoreCase(envType) - || DataAdaptorConstants.PROPERTY_ENV_SOLO.equalsIgnoreCase(envType))) { - ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); - Runnable task = this::initializeMap; - executor.scheduleWithFixedDelay(task, 60, 15, TimeUnit.MINUTES); - } - } - - private void initializeMap() { - try { - String getPropQuery = "SELECT * FROM CONFIG_PROPERTY_MAP"; - jdbcTemplate.queryForList(getPropQuery).forEach(rows -> { - String key = StringUtils.trimToEmpty((String) rows.get("reference_key")); - String value = StringUtils.trimToEmpty((String) rows.get("reference_value")); - configPropertyMap.put(key, value); - }); - logger.trace("loaded configPropertyMap : ({})", configPropertyMap); - } catch (CannotGetJdbcConnectionException e) { - // WHAT TO DO? - } - } - - @Override - public String getConfigPropertyByKey(String key) throws SvcLogicException { - Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing property key"); - return configPropertyMap.get(key); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDao.java deleted file mode 100644 index 63628864c..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDao.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ConfigResourceDao { - - /** - * Issue a single SQL Insert operation for CONFIG_RESOURCE table via a prepared statement, binding - * the given arguments. - * - * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert - */ - public ConfigResource save(ConfigResource configResourceInput) throws SvcLogicException; - - /** - * Issue a single SQL Delete operation for CONFIG_RESOURCE table via a prepared statement, binding - * the given arguments. - * - * @param configResource arguments to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert - */ - public void deleteByConfigResource(ConfigResource configResourceInput) throws SvcLogicException; - - /** - * Query CONFIG_RESOURCE table for given input param to create a prepared statement to bind to the - * query, mapping each row to a Java object via a ConfigResource RowMapper. - * - * @param configResource argument to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List findByConfigResource(ConfigResource configResourceInput) throws SvcLogicException; - - public ConfigResource getConfigResource(ConfigResource configResource) throws SvcLogicException; -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoImpl.java deleted file mode 100644 index 42cbbd1b0..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoImpl.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.RowMapperResultSetExtractor; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigResourceDaoImpl implements ConfigResourceDao { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceDaoImpl.class); - - private JdbcTemplate jdbcTemplate; - - public ConfigResourceDaoImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Override - public ConfigResource save(ConfigResource configResource) throws SvcLogicException { - - ConfigResource dbConfigResource = checkConfigResource(configResource); - - if (dbConfigResource != null && StringUtils.isNotBlank(dbConfigResource.getConfigResourceId())) { - configResource.setConfigResourceId(dbConfigResource.getConfigResourceId()); - - validateConfigResource(configResource); - - update(configResource); - - saveConfigResourceAssignmentData(configResource); - } else { - String addQuery = "INSERT INTO CONFIG_RESOURCE " - + "( config_resource_id, resource_id, resource_type, service_template_name, service_template_version," - + "template_name, recipe_name, request_id, resource_data, mask_data, status, created_date, updated_by ) " - + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; - - configResource.setConfigResourceId(configResource.getUniqueId()); - - validateConfigResource(configResource); - - logger.info("saving config resource ({}) ...", configResource); - jdbcTemplate.update(addQuery, configResource.getConfigResourceId(), configResource.getResourceId(), - configResource.getResourceType(), configResource.getServiceTemplateName(), - configResource.getServiceTemplateVersion(), configResource.getTemplateName(), - configResource.getRecipeName(), configResource.getRequestId(), configResource.getResourceData(), - configResource.getMaskData(), configResource.getStatus(), configResource.getCreatedDate(), - configResource.getUpdatedBy()); - - saveConfigResourceAssignmentData(configResource); - } - dbConfigResource = getConfigResource(configResource); - return dbConfigResource; - } - - private void update(ConfigResource configResource) throws SvcLogicException { - if (StringUtils.isNotBlank(configResource.getConfigResourceId())) { - logger.info("updating config resource ({}) ...", configResource); - // Added service_template_name and version in update query to update with 1802 data. - String updateQuery = "UPDATE CONFIG_RESOURCE SET " - + "resource_data = ?, mask_data = ?, created_date = ?, updated_by = ? ,service_template_name = ?, service_template_version = ? " - + "where config_resource_id = ?"; - - jdbcTemplate.update(updateQuery, configResource.getResourceData(), configResource.getMaskData(), - configResource.getCreatedDate(), configResource.getUpdatedBy(), - configResource.getServiceTemplateName(), configResource.getServiceTemplateVersion(), - configResource.getConfigResourceId()); - } else { - throw new SvcLogicException("missing config resource id to update."); - } - } - - private void saveConfigResourceAssignmentData(ConfigResource configResource) { - if (configResource != null && StringUtils.isNotBlank(configResource.getConfigResourceId())) { - List listOfArguments = new ArrayList<>(); - String deleteQuery = "DELETE FROM CONFIG_RESOURCE_ASSIGNMENT_DATA WHERE config_resource_id = ? "; - listOfArguments.add(configResource.getConfigResourceId()); - this.jdbcTemplate.update(deleteQuery, listOfArguments.toArray()); - logger.info("config resource assignment data deleted successfully for the config_resource_id ({})", - configResource.getConfigResourceId()); - - if (configResource.getResourceAssignments() != null) { - List resourceAssignments = configResource.getResourceAssignments(); - for (ResourceAssignmentData resourceAssignmentData : resourceAssignments) { - if (resourceAssignmentData != null) { - resourceAssignmentData.setConfigResourceId(configResource.getConfigResourceId()); - saveResourceAssignmentData(resourceAssignmentData); - } - } - } - } - } - - private ResourceAssignmentData saveResourceAssignmentData(ResourceAssignmentData resourceAssignmentData) { - String addQuery = "INSERT INTO CONFIG_RESOURCE_ASSIGNMENT_DATA " - + "( config_resource_assignment_data_id, config_resource_id, version, updated_by, template_key_name, " - + "resource_name, data_type, entry_schema, resource_value, source, status, message ) " - + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; - - logger.debug("saving config resource assignment data ({}) ... ", resourceAssignmentData); - jdbcTemplate.update(addQuery, resourceAssignmentData.getId(), resourceAssignmentData.getConfigResourceId(), - resourceAssignmentData.getVersion(), resourceAssignmentData.getUpdatedBy(), - resourceAssignmentData.getTemplateKeyName(), resourceAssignmentData.getResourceName(), - resourceAssignmentData.getDataType(), resourceAssignmentData.getEntrySchema(), - resourceAssignmentData.getResourceValue(), resourceAssignmentData.getSource(), - resourceAssignmentData.getStatus(), resourceAssignmentData.getMessage()); - - return resourceAssignmentData; - } - - @Override - public void deleteByConfigResource(ConfigResource configResourceInput) throws SvcLogicException { - StringBuilder selectArtifactBuffer = new StringBuilder(); - List listOfArguments = new ArrayList<>(); - - selectArtifactBuffer.append("DELETE FROM CONFIG_RESOURCE WHERE config_resource_id = ? "); - listOfArguments.add(configResourceInput.getConfigResourceId()); - - String queryString = selectArtifactBuffer.toString(); - this.jdbcTemplate.update(queryString, listOfArguments.toArray()); - logger.info("config resource ({}) deleted successfully ", configResourceInput); - } - - @SuppressWarnings("squid:S3776") - @Override - public List findByConfigResource(ConfigResource configResourceInput) throws SvcLogicException { - StringBuilder selectArtifactBuffer = new StringBuilder(); - List listOfArguments = new ArrayList<>(); - - selectArtifactBuffer.append("SELECT * FROM CONFIG_RESOURCE WHERE "); - - StringBuilder whereClauseRemaining = new StringBuilder(); - - if (configResourceInput.getServiceTemplateName() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("service_template_name = ? "); - listOfArguments.add(configResourceInput.getServiceTemplateName()); - } - - if (configResourceInput.getServiceTemplateVersion() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("service_template_version = ? "); - listOfArguments.add(configResourceInput.getServiceTemplateVersion()); - } - - if (configResourceInput.getResourceId() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("resource_id = ? "); - listOfArguments.add(configResourceInput.getResourceId()); - } - - if (configResourceInput.getResourceType() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("resource_type = ? "); - listOfArguments.add(configResourceInput.getResourceType()); - } - - if (configResourceInput.getRequestId() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("request_id = ? "); - listOfArguments.add(configResourceInput.getRequestId()); - } - - if (configResourceInput.getTemplateName() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("template_name = ? "); - listOfArguments.add(configResourceInput.getTemplateName()); - } - - if (configResourceInput.getRecipeName() != null) { - if (whereClauseRemaining.length() != 0) { - whereClauseRemaining.append("AND "); - } - whereClauseRemaining.append("recipe_name = ? "); - listOfArguments.add(configResourceInput.getRecipeName()); - } - - String queryString = selectArtifactBuffer.toString() + whereClauseRemaining.toString(); - logger.info("config resource queryString ({})", queryString); - List configResources = - this.jdbcTemplate.query(queryString, listOfArguments.toArray(), new ConfigResourceMapper()); - - List returnConfigResources = new ArrayList<>(); - - if (configResources != null) { - for (ConfigResource configResource : configResources) { - if (configResource != null) { - returnConfigResources.add(getConfigResource(configResource)); - } - } - } - return returnConfigResources; - } - - public ConfigResource checkConfigResource(ConfigResource configResource) { - StringBuilder selectBuffer = new StringBuilder(); - List listOfArguments = new ArrayList<>(); - - selectBuffer.append( - "SELECT * FROM CONFIG_RESOURCE WHERE resource_id = ? AND resource_type = ? AND template_name = ? "); - listOfArguments.add(configResource.getResourceId()); - listOfArguments.add(configResource.getResourceType()); - listOfArguments.add(configResource.getTemplateName()); - return queryOneForObject(selectBuffer.toString(), listOfArguments.toArray(), new ConfigResourceMapper()); - } - - @Override - public ConfigResource getConfigResource(ConfigResource configResource) throws SvcLogicException { - ConfigResource dbConfigResource = checkConfigResource(configResource); - if (dbConfigResource != null && StringUtils.isNotBlank(dbConfigResource.getConfigResourceId())) { - List resourceAssignments = - getResourceAssignmentdata(dbConfigResource.getConfigResourceId()); - configResource.setResourceAssignments(resourceAssignments); - } - return configResource; - } - - private List getResourceAssignmentdata(String configResourceId) { - List listOfArguments = new ArrayList<>(); - String queryString = "SELECT * FROM CONFIG_RESOURCE_ASSIGNMENT_DATA WHERE config_resource_id = ? "; - logger.info("getResourceAssignmentdata queryString ({}), query inputs ({})", queryString, configResourceId); - listOfArguments.add(configResourceId); - return this.jdbcTemplate.query(queryString, listOfArguments.toArray(), new ResourceAssignmentDataMapper()); - } - - @SuppressWarnings("squid:S3776") - private boolean validateConfigResource(ConfigResource configResource) throws SvcLogicException { - if (configResource == null) { - throw new SvcLogicException("config resource information is missing."); - } - - if (StringUtils.isBlank(configResource.getConfigResourceId())) { - throw new SvcLogicException("config resource id is missing."); - } - - if (StringUtils.isBlank(configResource.getResourceType())) { - throw new SvcLogicException("config resource type is missing."); - } - if (StringUtils.isBlank(configResource.getResourceId())) { - throw new SvcLogicException("config resource resource id is missing."); - } - - if (StringUtils.isBlank(configResource.getRecipeName())) { - throw new SvcLogicException("config resource action name is missing."); - } - - if (StringUtils.isBlank(configResource.getTemplateName())) { - throw new SvcLogicException("config resource template name is missing."); - } - - if (configResource.getResourceAssignments() != null) { - List resourceAssignments = configResource.getResourceAssignments(); - for (ResourceAssignmentData resourceAssignmentData : resourceAssignments) { - if (resourceAssignmentData != null) { - resourceAssignmentData.setConfigResourceId(configResource.getConfigResourceId()); - if (StringUtils.isBlank(resourceAssignmentData.getId())) { - resourceAssignmentData.setId(resourceAssignmentData.getUniqueId()); - } - if (resourceAssignmentData.getVersion() == null || resourceAssignmentData.getVersion() == 0) { - resourceAssignmentData.setVersion(1); - } - if (StringUtils.isBlank(resourceAssignmentData.getUpdatedBy())) { - resourceAssignmentData.setUpdatedBy("System"); - } - if (resourceAssignmentData.getStatus() == null) { - logger.warn("{} status is missing and setting to undefined", resourceAssignmentData); - resourceAssignmentData.setStatus("undefined"); - } - if (resourceAssignmentData.getMessage() == null) { - resourceAssignmentData.setMessage(""); - } - if (resourceAssignmentData.getResourceValue() == null) { - resourceAssignmentData.setResourceValue(""); - } - - validateResourceAssignmentData(resourceAssignmentData); - } - } - } - - return true; - } - - private boolean validateResourceAssignmentData(ResourceAssignmentData resourceAssignmentData) - throws SvcLogicException { - if (resourceAssignmentData == null) { - throw new SvcLogicException("resource assignment data information is missing."); - } - if (StringUtils.isBlank(resourceAssignmentData.getConfigResourceId())) { - throw new SvcLogicException("resource assignment data config resource id is missing."); - } - if (resourceAssignmentData.getVersion() == null) { - throw new SvcLogicException( - String.format("resource assignment data (%s) version is missing", resourceAssignmentData)); - } - if (StringUtils.isBlank(resourceAssignmentData.getTemplateKeyName())) { - throw new SvcLogicException(String.format("resource assignment data (%s) template key name is missing", - resourceAssignmentData)); - } - if (StringUtils.isBlank(resourceAssignmentData.getResourceName())) { - throw new SvcLogicException( - String.format("resource assignment data (%s) resource name is missing", resourceAssignmentData)); - } - if (resourceAssignmentData.getResourceValue() == null) { - throw new SvcLogicException( - String.format("resource assignment data (%s) resource value is missing", resourceAssignmentData)); - } - if (StringUtils.isBlank(resourceAssignmentData.getSource())) { - throw new SvcLogicException( - String.format("resource assignment data (%s) source is missing", resourceAssignmentData)); - } - if (StringUtils.isBlank(resourceAssignmentData.getDataType())) { - throw new SvcLogicException( - String.format("resource assignment data (%s) data type is missing", resourceAssignmentData)); - } - if (StringUtils.isBlank(resourceAssignmentData.getStatus())) { - throw new SvcLogicException( - String.format("resource assignment data (%s) status is missing", resourceAssignmentData)); - } - if (resourceAssignmentData.getMessage() == null) { - throw new SvcLogicException( - String.format("resource assignment data (%s) message is missing", resourceAssignmentData)); - } - return true; - } - - private T queryOneForObject(String sql, Object[] args, RowMapper rowMapper) { - List results = this.jdbcTemplate.query(sql, args, new RowMapperResultSetExtractor(rowMapper, 1)); - if (results != null && !results.isEmpty()) { - return results.get(0); - } else { - return null; - } - } - - class ConfigResourceMapper implements RowMapper { - @Override - public ConfigResource mapRow(ResultSet rs, int rowNum) throws SQLException { - ConfigResource configResource = new ConfigResource(); - configResource.setConfigResourceId(rs.getString("config_resource_id")); - configResource.setResourceId(rs.getString("resource_id")); - configResource.setResourceType(rs.getString("resource_type")); - configResource.setServiceTemplateName(rs.getString("service_template_name")); - configResource.setServiceTemplateVersion(rs.getString("service_template_version")); - configResource.setTemplateName(rs.getString("template_name")); - configResource.setRecipeName(rs.getString("recipe_name")); - configResource.setRequestId(rs.getString("request_id")); - configResource.setResourceData(rs.getString("resource_data")); - configResource.setMaskData(rs.getString("mask_data")); - configResource.setStatus(rs.getString("status")); - configResource.setCreatedDate(rs.getDate("created_date")); - configResource.setUpdatedBy(rs.getString("updated_by")); - return configResource; - } - } - - class ResourceAssignmentDataMapper implements RowMapper { - @Override - public ResourceAssignmentData mapRow(ResultSet rs, int rowNum) throws SQLException { - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setConfigResourceId(rs.getString("config_resource_id")); - resourceAssignmentData.setDataType(rs.getString("data_type")); - resourceAssignmentData.setEntrySchema(rs.getString("entry_schema")); - resourceAssignmentData.setId(rs.getString("config_resource_assignment_data_id")); - resourceAssignmentData.setMessage(rs.getString("message")); - resourceAssignmentData.setResourceName(rs.getString("resource_name")); - resourceAssignmentData.setResourceValue(rs.getString("resource_value")); - resourceAssignmentData.setSource(rs.getString("source")); - resourceAssignmentData.setStatus(rs.getString("status")); - resourceAssignmentData.setTemplateKeyName(rs.getString("template_key_name")); - resourceAssignmentData.setUpdatedBy(rs.getString("updated_by")); - resourceAssignmentData.setUpdatedDate(rs.getTimestamp("updated_date")); - resourceAssignmentData.setVersion(rs.getInt("version")); - return resourceAssignmentData; - } - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDao.java deleted file mode 100644 index 4cebb3081..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDao.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; - -public interface NamedQueryExecutorDao { - /** - * Return NamedParameterJdbcTemplate object. - */ - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException; - - /** - * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the - * query, expecting a result list. - *

- * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, - * using the column name as the key). - * - * @param sql SQL query to execute - * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return a List that contains a Map per row - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List> query(String sql, Map parameters) throws SvcLogicException; - - /** - * Issue an update via a prepared statement, binding the given arguments. - * - * @param sql SQL containing named parameters - * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return the number of rows affected - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update - */ - public int update(String sql, Map parameters) throws SvcLogicException; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDaoImpl.java deleted file mode 100644 index bcfe6b649..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/NamedQueryExecutorDaoImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class NamedQueryExecutorDaoImpl implements NamedQueryExecutorDao { - private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoImpl.class); - private static final String CLASS_NAME = "NamedQueryExecutorDaoImpl"; - - @Autowired(required = true) - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; - - public NamedQueryExecutorDaoImpl(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { - this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; - logger.info("{} Constructor initialised..", CLASS_NAME); - } - - @Override - public List> query(String sql, Map parameters) throws SvcLogicException { - logger.debug("Query ({}) with parameters ({})", sql, parameters); - return namedParameterJdbcTemplate.queryForList(sql, parameters); - } - - @Override - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { - return namedParameterJdbcTemplate; - } - - @Override - public int update(String sql, Map parameters) throws SvcLogicException { - logger.debug("update ({}) with parameters ({})", sql, parameters); - return namedParameterJdbcTemplate.update(sql, parameters); - } -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDao.java deleted file mode 100644 index 0c39524cf..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDao.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface QueryExecutorDao { - - /** - * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the - * query, expecting a result list. - *

- * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, - * using the column name as the key). Each element in the list will be of the form returned by this - * interface's queryForMap() methods. - * - * @param sql SQL query to execute - * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return a List that contains a Map per row - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List> query(String sql, Object[] data) throws SvcLogicException; - - /** - * Issue a single SQL update operation (such as an insert, update or delete statement) via a - * prepared statement, binding the given arguments. - * - * @param sql SQL containing bind parameters - * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return the number of rows affected - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update - */ - public int update(String sql, Object[] data) throws SvcLogicException; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoImpl.java deleted file mode 100644 index 076ec1d0f..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class QueryExecutorDaoImpl implements QueryExecutorDao { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoImpl.class); - private static final String CLASS_NAME = "QueryExecutorDaoImpl"; - - @Autowired(required = true) - private JdbcTemplate jdbcTemplate; - - public QueryExecutorDaoImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - logger.info("{} Constructor initialised..", CLASS_NAME); - } - - @Override - public List> query(String sql, Object[] data) throws SvcLogicException { - logger.debug("Query ({}) with data ({})", sql, data); - return jdbcTemplate.queryForList(sql, data); - } - - @Override - public int update(String sql, Object[] data) throws SvcLogicException { - logger.debug("Query ({}) with data ({})", sql, data); - return jdbcTemplate.update(sql, data); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDao.java deleted file mode 100644 index c4747e236..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDao.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.List; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface TransactionLogDao { - - /** - * Issue a single SQL Insert operation for CONFIG_TRANSACTION_LOG table via a prepared statement, - * binding the given arguments. - * - * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert - */ - public void save(TransactionLog transactionLog) throws SvcLogicException; - - /** - * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a - * TransactionLog RowMapper. - * - * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List getTransactionsByRequestId(String requestId) throws SvcLogicException; - - /** - * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a - * TransactionLog RowMapper. - * - * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @param messageType argument to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List getTransactionsByRequestId(String requestId, String messageType) - throws SvcLogicException; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDaoImpl.java deleted file mode 100644 index fd3d810e7..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/dao/TransactionLogDaoImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class TransactionLogDaoImpl implements TransactionLogDao { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(TransactionLogDaoImpl.class); - - private JdbcTemplate jdbcTemplate; - - public TransactionLogDaoImpl(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Override - public void save(TransactionLog transactionLog) throws SvcLogicException { - if (transactionLog != null && StringUtils.isNotBlank(transactionLog.getRequestId())) { - String addSql = - "INSERT INTO CONFIG_TRANSACTION_LOG ( config_transaction_log_id, request_id, message_type, message ) VALUES (?, ?, ?, ?) "; - jdbcTemplate.update(addSql, transactionLog.getUniqueId(), transactionLog.getRequestId(), - transactionLog.getMessageType(), transactionLog.getMessage()); - logger.trace("TransactionLog Updated Successfully for message_type {}", transactionLog.getMessageType()); - } - - } - - @Override - public List getTransactionsByRequestId(String requestId) throws SvcLogicException { - if (StringUtils.isNotBlank(requestId)) { - String selectByRequestIdSql = - "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? ORDER BY creation_date DESC"; - return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId}, new TransactionLogMapper()); - } else { - throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing "); - } - } - - @Override - public List getTransactionsByRequestId(String requestId, String messageType) - throws SvcLogicException { - if (StringUtils.isNotBlank(requestId)) { - String selectByRequestIdSql = - "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? and message_type = ? ORDER BY creation_date DESC"; - return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId, messageType}, - new TransactionLogMapper()); - } else { - throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing "); - } - } - - private static final class TransactionLogMapper implements RowMapper { - @Override - public TransactionLog mapRow(ResultSet rs, int rowNum) throws SQLException { - TransactionLog transactionLog = new TransactionLog(); - transactionLog.setCreationDate(rs.getDate("creation_date")); - transactionLog.setMessage(rs.getString("message")); - transactionLog.setMessageType(rs.getString("message_type")); - transactionLog.setRequestId(rs.getString("request_id")); - transactionLog.setTransactionLogId(rs.getString("config_transaction_log_id")); - return transactionLog; - } - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/db/DataSourceWrap.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/db/DataSourceWrap.java deleted file mode 100644 index 18ca9453c..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/db/DataSourceWrap.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.db; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import javax.sql.DataSource; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class DataSourceWrap implements DataSource { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DataSourceWrap.class); - - private DataSource dataSource; - - public DataSourceWrap(DataSource dataSource) { - logger.info("Setting Data Source {} ", dataSource); - this.dataSource = dataSource; - } - - @Override - public PrintWriter getLogWriter() throws SQLException { - return dataSource.getLogWriter(); - } - - @Override - public void setLogWriter(PrintWriter out) throws SQLException { - dataSource.setLogWriter(out); - } - - @Override - public void setLoginTimeout(int seconds) throws SQLException { - dataSource.setLoginTimeout(seconds); - } - - @Override - public int getLoginTimeout() throws SQLException { - return dataSource.getLoginTimeout(); - } - - @Override - public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { - return dataSource.getParentLogger(); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return dataSource.unwrap(iface); - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return dataSource.isWrapperFor(iface); - } - - @SuppressWarnings("squid:S2095") - @Override - public Connection getConnection() throws SQLException { - Connection c = dataSource.getConnection(); - logger.trace("getConnection: ({})", c.getClass().getName()); - c.setAutoCommit(true); - return c; - } - - @SuppressWarnings("squid:S2095") - @Override - public Connection getConnection(String username, String pass) throws SQLException { - Connection c = dataSource.getConnection(username, pass); - c.setAutoCommit(true); - return c; - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigPropertyMapData.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigPropertyMapData.java deleted file mode 100644 index 7d6bff98b..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigPropertyMapData.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.domain; - -import java.io.Serializable; - -public class ConfigPropertyMapData implements Serializable { - private static final long serialVersionUID = 1L; - - private String referenceKey; - private String referenceValue; - - public String getReferenceKey() { - return referenceKey; - } - - public void setReferenceKey(String referenceKey) { - this.referenceKey = referenceKey; - } - - public String getReferenceValue() { - return referenceValue; - } - - public void setReferenceValue(String referenceValue) { - this.referenceValue = referenceValue; - } - - @Override - public String toString() { - return "ConfigPropertyMapData [referenceKey=" + referenceKey + ", referenceValue=" + referenceValue + "]"; - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigResource.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigResource.java deleted file mode 100644 index c8394a74d..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ConfigResource.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.domain; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -public class ConfigResource implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - private String configResourceId; - private String resourceId; - private String resourceType; - private String serviceTemplateName; - private String serviceTemplateVersion; - private String templateName; - private String recipeName; - private String requestId; - private String resourceData; - private String maskData; - private Date createdDate = new Date(); - private String status; - private String updatedBy; - private List resourceAssignments; - - public String getConfigResourceId() { - return configResourceId; - } - - public void setConfigResourceId(String configResourceId) { - this.configResourceId = configResourceId; - } - - public String getResourceId() { - return resourceId; - } - - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getServiceTemplateName() { - return serviceTemplateName; - } - - public void setServiceTemplateName(String serviceTemplateName) { - this.serviceTemplateName = serviceTemplateName; - } - - public String getServiceTemplateVersion() { - return serviceTemplateVersion; - } - - public void setServiceTemplateVersion(String serviceTemplateVersion) { - this.serviceTemplateVersion = serviceTemplateVersion; - } - - public String getTemplateName() { - return templateName; - } - - public void setTemplateName(String templateName) { - this.templateName = templateName; - } - - public String getRecipeName() { - return recipeName; - } - - public void setRecipeName(String recipeName) { - this.recipeName = recipeName; - } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResourceData() { - return resourceData; - } - - public void setResourceData(String resourceData) { - this.resourceData = resourceData; - } - - public String getMaskData() { - return maskData; - } - - public void setMaskData(String maskData) { - this.maskData = maskData; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public List getResourceAssignments() { - return resourceAssignments; - } - - public void setResourceAssignments(List resourceAssignments) { - this.resourceAssignments = resourceAssignments; - } - - @Override - public String toString() { - return "ConfigResource [configResourceId=" + configResourceId + ", resourceId=" + resourceId - + ", serviceTemplateName=" + serviceTemplateName + ", serviceTemplateVersion=" + serviceTemplateVersion - + ", resourceType=" + resourceType + ", templateName=" + templateName + ", recipeName=" + recipeName - + ", requestId=" + requestId + ", resourceData= ******** , maskData=" + maskData + ", createdDate=" - + createdDate + ", updatedBy=" + updatedBy + "]"; - } - - public String getUniqueId() { - return UUID.randomUUID().toString(); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ResourceAssignmentData.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ResourceAssignmentData.java deleted file mode 100644 index 75c1a4957..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/ResourceAssignmentData.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.domain; - -import java.io.Serializable; -import java.util.Date; -import java.util.UUID; - -public class ResourceAssignmentData implements Serializable { - - private static final long serialVersionUID = 1L; - private String id; - private String configResourceId; - private Integer version; - private Date updatedDate = new Date(); - private String updatedBy; - private String templateKeyName; - private String resourceName; - private String dataType; - private String entrySchema; - private String resourceValue; - private String source; - private String status; - private String message; - - public String getUniqueId() { - return UUID.randomUUID().toString(); - } - - @Override - public String toString() { - return "ResourceAssignmentData [id=" + id + ", configResourceId=" + configResourceId + ", version=" + version - + ", updatedDate=" + updatedDate + ", updatedBy=" + updatedBy + ", templateKeyName=" + templateKeyName - + ", resourceName=" + resourceName + ", dataType=" + dataType + ", source=" + source + ", status=" - + status + "]"; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getConfigResourceId() { - return configResourceId; - } - - public void setConfigResourceId(String configResourceId) { - this.configResourceId = configResourceId; - } - - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public Date getUpdatedDate() { - return updatedDate; - } - - public void setUpdatedDate(Date updatedDate) { - this.updatedDate = updatedDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTemplateKeyName() { - return templateKeyName; - } - - public void setTemplateKeyName(String templateKeyName) { - this.templateKeyName = templateKeyName; - } - - public String getResourceName() { - return resourceName; - } - - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - public String getDataType() { - return dataType; - } - - public void setDataType(String dataType) { - this.dataType = dataType; - } - - public String getEntrySchema() { - return entrySchema; - } - - public void setEntrySchema(String entrySchema) { - this.entrySchema = entrySchema; - } - - public String getResourceValue() { - return resourceValue; - } - - public void setResourceValue(String resourceValue) { - this.resourceValue = resourceValue; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/TransactionLog.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/TransactionLog.java deleted file mode 100644 index 77235d137..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/domain/TransactionLog.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.domain; - -import java.io.Serializable; -import java.util.Date; -import java.util.UUID; - -public class TransactionLog implements Serializable { - private static final long serialVersionUID = 1L; - - private String transactionLogId; - private String requestId; - private String messageType; - private Date creationDate; - private String message; - - public TransactionLog() { - - } - - public TransactionLog(String requestId, String messageType, String message) { - this.requestId = requestId; - this.messageType = messageType; - this.message = message; - } - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append("transactionLogId =" + transactionLogId); - buffer.append(", requestId =" + requestId); - buffer.append(", messageType =" + messageType); - buffer.append(", creationDate =" + creationDate); - buffer.append("]"); - return buffer.toString(); - } - - public String getTransactionLogId() { - return transactionLogId; - } - - public void setTransactionLogId(String transactionLogId) { - this.transactionLogId = transactionLogId; - } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getMessageType() { - return messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getUniqueId() { - return UUID.randomUUID().toString(); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNode.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNode.java deleted file mode 100644 index f85da143b..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNode.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.service; - -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -public class ConfigResourceNode implements SvcLogicJavaPlugin { - - private ConfigResourceService configResourceService; - - public ConfigResourceNode(ConfigResourceService configResourceService) { - this.configResourceService = configResourceService; - } - - public void saveConfigTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - String responsePrefix = inParams.get(DataAdaptorConstants.INPUT_PARAM_RESPONSE_PRIFIX); - try { - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; - - String messageType = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE); - String message = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE); - String requestId = ctx.getAttribute("request-id"); - - TransactionLog transactionLog = new TransactionLog(); - - transactionLog.setMessage(message); - transactionLog.setMessageType(messageType); - transactionLog.setRequestId(requestId); - - configResourceService.save(transactionLog); - - } catch (Exception e) { - ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_STATUS, - DataAdaptorConstants.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - throw new SvcLogicException("Failed in saveConfigTransactionLog :" + e.getMessage()); - } - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceService.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceService.java deleted file mode 100644 index b99b74f87..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceService.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.service; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; - -public interface ConfigResourceService { - - /** - * Return NamedParameterJdbcTemplate object. - */ - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException; - - /** - * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the - * query, expecting a result list. - *

- * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, - * using the column name as the key). - * - * @param sql SQL query to execute - * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return a List that contains a Map per row - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List> query(String sql, Map param) throws SvcLogicException; - - /** - * Issue an update via a prepared statement, binding the given arguments. - * - * @param sql SQL containing named parameters - * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return the number of rows affected - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update - */ - public int update(String sql, Map param) throws SvcLogicException; - - /** - * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the - * query, expecting a result list. - *

- * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, - * using the column name as the key). - * - * @param sql SQL query to execute - * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return a List that contains a Map per row - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List> query(String sql, Object[] data) throws SvcLogicException; - - /** - * Issue a single SQL update operation (such as an insert, update or delete statement) via a - * prepared statement, binding the given arguments. - * - * @param sql SQL containing bind parameters - * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return the number of rows affected - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update - */ - public int update(String sql, Object[] data) throws SvcLogicException; - - /** - * Issue a single SQL Insert operation for CONFIG_TRANSACTION_LOG table via a prepared statement, - * binding the given arguments. - * - * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert - */ - public void save(TransactionLog transactionLog) throws SvcLogicException; - - /** - * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a - * TransactionLog RowMapper. - * - * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List getTransactionsByRequestId(String requestId) throws SvcLogicException; - - /** - * Query CONFIG_RESOURCE table for given input param to create a prepared statement to bind to the - * query, mapping each row to a Java object via a ConfigResource RowMapper. - * - * @param configResource argument to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List getConfigResource(ConfigResource configResource) throws SvcLogicException; - - /** - * Issue a single SQL update operation (insert or update statement) for CONFIG_RESOURCE table via a - * prepared statement, binding the given arguments. - * - * @param configResource arguments to bind to the query (mapping it to the PreparedStatement to the - * corresponding SQL type) - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert - */ - public ConfigResource saveConfigResource(ConfigResource configResource) throws SvcLogicException; - - /** - * Query ConcurrentHashMap having CONFIG_PROPERTY_MAP table data for given key. - * - * @param key key mapped to a value - * @return the result string, containing mapped string value - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if fails - */ - public String getConfigPropertyByKey(String key) throws SvcLogicException; - - /** - * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a - * TransactionLog RowMapper. - * - * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the - * corresponding SQL type) - * @param messageType argument to bind to the query (leaving it to the PreparedStatement to guess - * the corresponding SQL type) - * @return the result List, containing mapped objects - * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails - */ - public List getTransactionsByRequestId(String requestId, String messageType) - throws SvcLogicException; - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceImpl.java deleted file mode 100644 index c8803092a..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.service; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigPropertyMapDao; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigResourceDao; -import org.onap.ccsdk.config.data.adaptor.dao.NamedQueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.QueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.TransactionLogDao; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigResourceServiceImpl implements ConfigResourceService { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceServiceImpl.class); - private static final String CLASS_NAME = "ConfigResourceServiceImpl"; - - private TransactionLogDao transactionLogDao; - private ConfigResourceDao configResourceDao; - private QueryExecutorDao queryExecutorDao; - private NamedQueryExecutorDao namedQueryExecutorDao; - private ConfigPropertyMapDao configPropertyMapDao; - - @SuppressWarnings("squid:S00107") - public ConfigResourceServiceImpl(TransactionLogDao transactionLogDao, ConfigResourceDao configResourceDao, - QueryExecutorDao queryExecutorDao, NamedQueryExecutorDao namedQueryExecutorDao, - ConfigPropertyMapDao configPropertyMapDao) { - - logger.info("{} Constuctor Initated...", CLASS_NAME); - this.transactionLogDao = transactionLogDao; - this.configResourceDao = configResourceDao; - this.queryExecutorDao = queryExecutorDao; - this.namedQueryExecutorDao = namedQueryExecutorDao; - this.configPropertyMapDao = configPropertyMapDao; - } - - @Override - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException { - return namedQueryExecutorDao.getNamedParameterJdbcTemplate(); - } - - @Override - public List> query(String sql, Map parameters) throws SvcLogicException { - return namedQueryExecutorDao.query(sql, parameters); - } - - @Override - public int update(String sql, Map parameters) throws SvcLogicException { - return namedQueryExecutorDao.update(sql, parameters); - } - - @Override - public List> query(String sql, Object[] data) throws SvcLogicException { - return queryExecutorDao.query(sql, data); - } - - @Override - public int update(String sql, Object[] data) throws SvcLogicException { - return queryExecutorDao.update(sql, data); - } - - @Override - public void save(TransactionLog transactionLog) throws SvcLogicException { - transactionLogDao.save(transactionLog); - } - - @Override - public List getTransactionsByRequestId(String requestId) throws SvcLogicException { - return transactionLogDao.getTransactionsByRequestId(requestId); - } - - @Override - public List getTransactionsByRequestId(String requestId, String messageType) - throws SvcLogicException { - return transactionLogDao.getTransactionsByRequestId(requestId, messageType); - } - - @Override - public List getConfigResource(ConfigResource configResource) throws SvcLogicException { - return configResourceDao.findByConfigResource(configResource); - } - - @Override - public ConfigResource saveConfigResource(ConfigResource configResource) throws SvcLogicException { - return configResourceDao.save(configResource); - } - - @Override - public String getConfigPropertyByKey(String key) throws SvcLogicException { - return configPropertyMapDao.getConfigPropertyByKey(key); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/ConfigDataAdaptorException.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/ConfigDataAdaptorException.java new file mode 100644 index 000000000..d76ee4ef9 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/ConfigDataAdaptorException.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor; + +/** + * ConfigDataAdaptorException.java Purpose: Provide Configuration Data Adaptor Exception + * + * @version 1.0 + */ +public class ConfigDataAdaptorException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * This is a ConfigDataAdaptorException constructor + * + * @param message + */ + public ConfigDataAdaptorException(String message) { + super(message); + } + + /** + * This is a ConfigDataAdaptorException constructor + * + * @param message + */ + public ConfigDataAdaptorException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/DataAdaptorConstants.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/DataAdaptorConstants.java new file mode 100644 index 000000000..df4912cf0 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/DataAdaptorConstants.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor; + +@SuppressWarnings("squid:S1118") +public class DataAdaptorConstants { + + public static final String OUTPUT_STATUS_SUCCESS = "success"; + public static final String OUTPUT_STATUS_FAILURE = "failure"; + + public static final String PROPERTY_ENV_TYPE = "org.onap.ccsdk.features.rest.adaptors.envtype"; + public static final String PROPERTY_ENV_PROD = "field"; + public static final String PROPERTY_ENV_SOLO = "solo"; + + public static final String INPUT_PARAM_TAGS = "tags"; + public static final String INPUT_PARAM_CAPABILITY_NAME = "capabilityName"; + public static final String INPUT_PARAM_MESSAGE = "message"; + public static final String INPUT_PARAM_MESSAGE_TYPE = "messageType"; + public static final String OUTPUT_PARAM_STATUS = "status"; + public static final 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_ASDC_ARTIFACT_IND = "asdcArtifactInd"; + public static final Object INPUT_PARAM_VNF_ID = "vnfId"; + public static final Object INPUT_PARAM_VM_NAME = "vmName"; + + public static final Object INPUT_PARAM_CONFIG_CONTENT_TYPE = "configContentType"; + + public static final Object INPUT_PARAM_CONFIG_CONTENT = "configContent"; + public static final Object INPUT_PARAM_CONFIG_INDICATOR = "configIndicator"; + + public static final Object CONFIG_CONTENT_TYPE_CONFIGURATION = "Configuration"; + public static final Object CONFIG_CONTENT_TYPE_PARAMETERS = "Parameters"; + public static final Object CONFIG_INDICATOR_PREPARE = "Prepare"; + public static final Object CONFIG_INDICATOR_ACTIVE = "Active"; + + public static final String INPUT_PARAM_RESPONSE_PRIFIX = "response-prefix"; + public static final String INPUT_PARAM_VNF_TYPE = "vnfType"; + public static final String INPUT_PARAM_VNFC_TYPE = "vnfcType"; + public static final String INPUT_PARAM_ACTION = "action"; + public static final String INPUT_PARAM_API_VERSION = "apiVersion"; + + public static final String INPUT_PARAM_FILE_ID = "fileId"; + public static final String INPUT_PARAM_UPLOAD_CONFIG_ID = "uploadConfigId"; + public static final String FILE_CATEGORY_SERVICE_TEMPLATE = "service_template"; + + public static final String ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL"; + + public static final String LOG_MESSAGE_TYPE_LOG = "Log"; + public static final String LOG_MESSAGE_TYPE_COMPONENT = "Component"; + public static final String LOG_MESSAGE_TYPE_REQUEST = "Request"; + public static final String LOG_MESSAGE_TYPE_MODEL = "Model"; + public static final String LOG_MESSAGE_TYPE_DATA = "Data"; + public static final String LOG_MESSAGE_TYPE_CONFIG = "Config"; + + public static final String SELF_SERVICE_STATUS_RECEIVED = "Received"; + public static final String SELF_SERVICE_STATUS_ACKNOWLEDGED = "Acknowledged"; + public static final String SELF_SERVICE_STATUS_REPLIED = "Replied"; + public static final String SELF_SERVICE_STATUS_FAILED = "Failed"; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDao.java new file mode 100644 index 000000000..4a77f7f05 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDao.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ConfigPropertyMapDao { + + /** + * Query ConcurrentHashMap having CONFIG_PROPERTY_MAP table data for given key. + * + * @param key key mapped to a value + * @return the result string, containing mapped string value + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if fails + */ + public String getConfigPropertyByKey(String key) throws SvcLogicException; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoImpl.java new file mode 100644 index 000000000..a5248d2a6 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.CannotGetJdbcConnectionException; +import org.springframework.jdbc.core.JdbcTemplate; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.Preconditions; + +public class ConfigPropertyMapDaoImpl implements ConfigPropertyMapDao { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPropertyMapDaoImpl.class); + + private JdbcTemplate jdbcTemplate; + private Map configPropertyMap = new ConcurrentHashMap<>(); + + public ConfigPropertyMapDaoImpl(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + initializeMap(); + + String envType = configPropertyMap.get(DataAdaptorConstants.PROPERTY_ENV_TYPE); + if (!(DataAdaptorConstants.PROPERTY_ENV_PROD.equalsIgnoreCase(envType) + || DataAdaptorConstants.PROPERTY_ENV_SOLO.equalsIgnoreCase(envType))) { + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + Runnable task = this::initializeMap; + executor.scheduleWithFixedDelay(task, 60, 15, TimeUnit.MINUTES); + } + } + + private void initializeMap() { + try { + String getPropQuery = "SELECT * FROM CONFIG_PROPERTY_MAP"; + jdbcTemplate.queryForList(getPropQuery).forEach(rows -> { + String key = StringUtils.trimToEmpty((String) rows.get("reference_key")); + String value = StringUtils.trimToEmpty((String) rows.get("reference_value")); + configPropertyMap.put(key, value); + }); + logger.trace("loaded configPropertyMap : ({})", configPropertyMap); + } catch (CannotGetJdbcConnectionException e) { + // WHAT TO DO? + } + } + + @Override + public String getConfigPropertyByKey(String key) throws SvcLogicException { + Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing property key"); + return configPropertyMap.get(key); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDao.java new file mode 100644 index 000000000..5e50d6f5f --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDao.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; + +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ConfigResourceDao { + + /** + * Issue a single SQL Insert operation for CONFIG_RESOURCE table via a prepared statement, binding + * the given arguments. + * + * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert + */ + public ConfigResource save(ConfigResource configResourceInput) throws SvcLogicException; + + /** + * Issue a single SQL Delete operation for CONFIG_RESOURCE table via a prepared statement, binding + * the given arguments. + * + * @param configResource arguments to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert + */ + public void deleteByConfigResource(ConfigResource configResourceInput) throws SvcLogicException; + + /** + * Query CONFIG_RESOURCE table for given input param to create a prepared statement to bind to the + * query, mapping each row to a Java object via a ConfigResource RowMapper. + * + * @param configResource argument to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List findByConfigResource(ConfigResource configResourceInput) throws SvcLogicException; + + public ConfigResource getConfigResource(ConfigResource configResource) throws SvcLogicException; +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoImpl.java new file mode 100644 index 000000000..7661e96ee --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoImpl.java @@ -0,0 +1,415 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.ResourceAssignmentData; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.RowMapperResultSetExtractor; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigResourceDaoImpl implements ConfigResourceDao { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceDaoImpl.class); + + private JdbcTemplate jdbcTemplate; + + public ConfigResourceDaoImpl(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public ConfigResource save(ConfigResource configResource) throws SvcLogicException { + + ConfigResource dbConfigResource = checkConfigResource(configResource); + + if (dbConfigResource != null && StringUtils.isNotBlank(dbConfigResource.getConfigResourceId())) { + configResource.setConfigResourceId(dbConfigResource.getConfigResourceId()); + + validateConfigResource(configResource); + + update(configResource); + + saveConfigResourceAssignmentData(configResource); + } else { + String addQuery = "INSERT INTO CONFIG_RESOURCE " + + "( config_resource_id, resource_id, resource_type, service_template_name, service_template_version," + + "template_name, recipe_name, request_id, resource_data, mask_data, status, created_date, updated_by ) " + + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + + configResource.setConfigResourceId(configResource.getUniqueId()); + + validateConfigResource(configResource); + + logger.info("saving config resource ({}) ...", configResource); + jdbcTemplate.update(addQuery, configResource.getConfigResourceId(), configResource.getResourceId(), + configResource.getResourceType(), configResource.getServiceTemplateName(), + configResource.getServiceTemplateVersion(), configResource.getTemplateName(), + configResource.getRecipeName(), configResource.getRequestId(), configResource.getResourceData(), + configResource.getMaskData(), configResource.getStatus(), configResource.getCreatedDate(), + configResource.getUpdatedBy()); + + saveConfigResourceAssignmentData(configResource); + } + dbConfigResource = getConfigResource(configResource); + return dbConfigResource; + } + + private void update(ConfigResource configResource) throws SvcLogicException { + if (StringUtils.isNotBlank(configResource.getConfigResourceId())) { + logger.info("updating config resource ({}) ...", configResource); + // Added service_template_name and version in update query to update with 1802 data. + String updateQuery = "UPDATE CONFIG_RESOURCE SET " + + "resource_data = ?, mask_data = ?, created_date = ?, updated_by = ? ,service_template_name = ?, service_template_version = ? " + + "where config_resource_id = ?"; + + jdbcTemplate.update(updateQuery, configResource.getResourceData(), configResource.getMaskData(), + configResource.getCreatedDate(), configResource.getUpdatedBy(), + configResource.getServiceTemplateName(), configResource.getServiceTemplateVersion(), + configResource.getConfigResourceId()); + } else { + throw new SvcLogicException("missing config resource id to update."); + } + } + + private void saveConfigResourceAssignmentData(ConfigResource configResource) { + if (configResource != null && StringUtils.isNotBlank(configResource.getConfigResourceId())) { + List listOfArguments = new ArrayList<>(); + String deleteQuery = "DELETE FROM CONFIG_RESOURCE_ASSIGNMENT_DATA WHERE config_resource_id = ? "; + listOfArguments.add(configResource.getConfigResourceId()); + this.jdbcTemplate.update(deleteQuery, listOfArguments.toArray()); + logger.info("config resource assignment data deleted successfully for the config_resource_id ({})", + configResource.getConfigResourceId()); + + if (configResource.getResourceAssignments() != null) { + List resourceAssignments = configResource.getResourceAssignments(); + for (ResourceAssignmentData resourceAssignmentData : resourceAssignments) { + if (resourceAssignmentData != null) { + resourceAssignmentData.setConfigResourceId(configResource.getConfigResourceId()); + saveResourceAssignmentData(resourceAssignmentData); + } + } + } + } + } + + private ResourceAssignmentData saveResourceAssignmentData(ResourceAssignmentData resourceAssignmentData) { + String addQuery = "INSERT INTO CONFIG_RESOURCE_ASSIGNMENT_DATA " + + "( config_resource_assignment_data_id, config_resource_id, version, updated_by, template_key_name, " + + "resource_name, data_type, entry_schema, resource_value, source, status, message ) " + + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + + logger.debug("saving config resource assignment data ({}) ... ", resourceAssignmentData); + jdbcTemplate.update(addQuery, resourceAssignmentData.getId(), resourceAssignmentData.getConfigResourceId(), + resourceAssignmentData.getVersion(), resourceAssignmentData.getUpdatedBy(), + resourceAssignmentData.getTemplateKeyName(), resourceAssignmentData.getResourceName(), + resourceAssignmentData.getDataType(), resourceAssignmentData.getEntrySchema(), + resourceAssignmentData.getResourceValue(), resourceAssignmentData.getSource(), + resourceAssignmentData.getStatus(), resourceAssignmentData.getMessage()); + + return resourceAssignmentData; + } + + @Override + public void deleteByConfigResource(ConfigResource configResourceInput) throws SvcLogicException { + StringBuilder selectArtifactBuffer = new StringBuilder(); + List listOfArguments = new ArrayList<>(); + + selectArtifactBuffer.append("DELETE FROM CONFIG_RESOURCE WHERE config_resource_id = ? "); + listOfArguments.add(configResourceInput.getConfigResourceId()); + + String queryString = selectArtifactBuffer.toString(); + this.jdbcTemplate.update(queryString, listOfArguments.toArray()); + logger.info("config resource ({}) deleted successfully ", configResourceInput); + } + + @SuppressWarnings("squid:S3776") + @Override + public List findByConfigResource(ConfigResource configResourceInput) throws SvcLogicException { + StringBuilder selectArtifactBuffer = new StringBuilder(); + List listOfArguments = new ArrayList<>(); + + selectArtifactBuffer.append("SELECT * FROM CONFIG_RESOURCE WHERE "); + + StringBuilder whereClauseRemaining = new StringBuilder(); + + if (configResourceInput.getServiceTemplateName() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("service_template_name = ? "); + listOfArguments.add(configResourceInput.getServiceTemplateName()); + } + + if (configResourceInput.getServiceTemplateVersion() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("service_template_version = ? "); + listOfArguments.add(configResourceInput.getServiceTemplateVersion()); + } + + if (configResourceInput.getResourceId() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("resource_id = ? "); + listOfArguments.add(configResourceInput.getResourceId()); + } + + if (configResourceInput.getResourceType() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("resource_type = ? "); + listOfArguments.add(configResourceInput.getResourceType()); + } + + if (configResourceInput.getRequestId() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("request_id = ? "); + listOfArguments.add(configResourceInput.getRequestId()); + } + + if (configResourceInput.getTemplateName() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("template_name = ? "); + listOfArguments.add(configResourceInput.getTemplateName()); + } + + if (configResourceInput.getRecipeName() != null) { + if (whereClauseRemaining.length() != 0) { + whereClauseRemaining.append("AND "); + } + whereClauseRemaining.append("recipe_name = ? "); + listOfArguments.add(configResourceInput.getRecipeName()); + } + + String queryString = selectArtifactBuffer.toString() + whereClauseRemaining.toString(); + logger.info("config resource queryString ({})", queryString); + List configResources = + this.jdbcTemplate.query(queryString, listOfArguments.toArray(), new ConfigResourceMapper()); + + List returnConfigResources = new ArrayList<>(); + + if (configResources != null) { + for (ConfigResource configResource : configResources) { + if (configResource != null) { + returnConfigResources.add(getConfigResource(configResource)); + } + } + } + return returnConfigResources; + } + + public ConfigResource checkConfigResource(ConfigResource configResource) { + StringBuilder selectBuffer = new StringBuilder(); + List listOfArguments = new ArrayList<>(); + + selectBuffer.append( + "SELECT * FROM CONFIG_RESOURCE WHERE resource_id = ? AND resource_type = ? AND template_name = ? "); + listOfArguments.add(configResource.getResourceId()); + listOfArguments.add(configResource.getResourceType()); + listOfArguments.add(configResource.getTemplateName()); + return queryOneForObject(selectBuffer.toString(), listOfArguments.toArray(), new ConfigResourceMapper()); + } + + @Override + public ConfigResource getConfigResource(ConfigResource configResource) throws SvcLogicException { + ConfigResource dbConfigResource = checkConfigResource(configResource); + if (dbConfigResource != null && StringUtils.isNotBlank(dbConfigResource.getConfigResourceId())) { + List resourceAssignments = + getResourceAssignmentdata(dbConfigResource.getConfigResourceId()); + configResource.setResourceAssignments(resourceAssignments); + } + return configResource; + } + + private List getResourceAssignmentdata(String configResourceId) { + List listOfArguments = new ArrayList<>(); + String queryString = "SELECT * FROM CONFIG_RESOURCE_ASSIGNMENT_DATA WHERE config_resource_id = ? "; + logger.info("getResourceAssignmentdata queryString ({}), query inputs ({})", queryString, configResourceId); + listOfArguments.add(configResourceId); + return this.jdbcTemplate.query(queryString, listOfArguments.toArray(), new ResourceAssignmentDataMapper()); + } + + @SuppressWarnings("squid:S3776") + private boolean validateConfigResource(ConfigResource configResource) throws SvcLogicException { + if (configResource == null) { + throw new SvcLogicException("config resource information is missing."); + } + + if (StringUtils.isBlank(configResource.getConfigResourceId())) { + throw new SvcLogicException("config resource id is missing."); + } + + if (StringUtils.isBlank(configResource.getResourceType())) { + throw new SvcLogicException("config resource type is missing."); + } + if (StringUtils.isBlank(configResource.getResourceId())) { + throw new SvcLogicException("config resource resource id is missing."); + } + + if (StringUtils.isBlank(configResource.getRecipeName())) { + throw new SvcLogicException("config resource action name is missing."); + } + + if (StringUtils.isBlank(configResource.getTemplateName())) { + throw new SvcLogicException("config resource template name is missing."); + } + + if (configResource.getResourceAssignments() != null) { + List resourceAssignments = configResource.getResourceAssignments(); + for (ResourceAssignmentData resourceAssignmentData : resourceAssignments) { + if (resourceAssignmentData != null) { + resourceAssignmentData.setConfigResourceId(configResource.getConfigResourceId()); + if (StringUtils.isBlank(resourceAssignmentData.getId())) { + resourceAssignmentData.setId(resourceAssignmentData.getUniqueId()); + } + if (resourceAssignmentData.getVersion() == null || resourceAssignmentData.getVersion() == 0) { + resourceAssignmentData.setVersion(1); + } + if (StringUtils.isBlank(resourceAssignmentData.getUpdatedBy())) { + resourceAssignmentData.setUpdatedBy("System"); + } + if (resourceAssignmentData.getStatus() == null) { + logger.warn("{} status is missing and setting to undefined", resourceAssignmentData); + resourceAssignmentData.setStatus("undefined"); + } + if (resourceAssignmentData.getMessage() == null) { + resourceAssignmentData.setMessage(""); + } + if (resourceAssignmentData.getResourceValue() == null) { + resourceAssignmentData.setResourceValue(""); + } + + validateResourceAssignmentData(resourceAssignmentData); + } + } + } + + return true; + } + + private boolean validateResourceAssignmentData(ResourceAssignmentData resourceAssignmentData) + throws SvcLogicException { + if (resourceAssignmentData == null) { + throw new SvcLogicException("resource assignment data information is missing."); + } + if (StringUtils.isBlank(resourceAssignmentData.getConfigResourceId())) { + throw new SvcLogicException("resource assignment data config resource id is missing."); + } + if (resourceAssignmentData.getVersion() == null) { + throw new SvcLogicException( + String.format("resource assignment data (%s) version is missing", resourceAssignmentData)); + } + if (StringUtils.isBlank(resourceAssignmentData.getTemplateKeyName())) { + throw new SvcLogicException(String.format("resource assignment data (%s) template key name is missing", + resourceAssignmentData)); + } + if (StringUtils.isBlank(resourceAssignmentData.getResourceName())) { + throw new SvcLogicException( + String.format("resource assignment data (%s) resource name is missing", resourceAssignmentData)); + } + if (resourceAssignmentData.getResourceValue() == null) { + throw new SvcLogicException( + String.format("resource assignment data (%s) resource value is missing", resourceAssignmentData)); + } + if (StringUtils.isBlank(resourceAssignmentData.getSource())) { + throw new SvcLogicException( + String.format("resource assignment data (%s) source is missing", resourceAssignmentData)); + } + if (StringUtils.isBlank(resourceAssignmentData.getDataType())) { + throw new SvcLogicException( + String.format("resource assignment data (%s) data type is missing", resourceAssignmentData)); + } + if (StringUtils.isBlank(resourceAssignmentData.getStatus())) { + throw new SvcLogicException( + String.format("resource assignment data (%s) status is missing", resourceAssignmentData)); + } + if (resourceAssignmentData.getMessage() == null) { + throw new SvcLogicException( + String.format("resource assignment data (%s) message is missing", resourceAssignmentData)); + } + return true; + } + + private T queryOneForObject(String sql, Object[] args, RowMapper rowMapper) { + List results = this.jdbcTemplate.query(sql, args, new RowMapperResultSetExtractor(rowMapper, 1)); + if (results != null && !results.isEmpty()) { + return results.get(0); + } else { + return null; + } + } + + class ConfigResourceMapper implements RowMapper { + @Override + public ConfigResource mapRow(ResultSet rs, int rowNum) throws SQLException { + ConfigResource configResource = new ConfigResource(); + configResource.setConfigResourceId(rs.getString("config_resource_id")); + configResource.setResourceId(rs.getString("resource_id")); + configResource.setResourceType(rs.getString("resource_type")); + configResource.setServiceTemplateName(rs.getString("service_template_name")); + configResource.setServiceTemplateVersion(rs.getString("service_template_version")); + configResource.setTemplateName(rs.getString("template_name")); + configResource.setRecipeName(rs.getString("recipe_name")); + configResource.setRequestId(rs.getString("request_id")); + configResource.setResourceData(rs.getString("resource_data")); + configResource.setMaskData(rs.getString("mask_data")); + configResource.setStatus(rs.getString("status")); + configResource.setCreatedDate(rs.getDate("created_date")); + configResource.setUpdatedBy(rs.getString("updated_by")); + return configResource; + } + } + + class ResourceAssignmentDataMapper implements RowMapper { + @Override + public ResourceAssignmentData mapRow(ResultSet rs, int rowNum) throws SQLException { + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setConfigResourceId(rs.getString("config_resource_id")); + resourceAssignmentData.setDataType(rs.getString("data_type")); + resourceAssignmentData.setEntrySchema(rs.getString("entry_schema")); + resourceAssignmentData.setId(rs.getString("config_resource_assignment_data_id")); + resourceAssignmentData.setMessage(rs.getString("message")); + resourceAssignmentData.setResourceName(rs.getString("resource_name")); + resourceAssignmentData.setResourceValue(rs.getString("resource_value")); + resourceAssignmentData.setSource(rs.getString("source")); + resourceAssignmentData.setStatus(rs.getString("status")); + resourceAssignmentData.setTemplateKeyName(rs.getString("template_key_name")); + resourceAssignmentData.setUpdatedBy(rs.getString("updated_by")); + resourceAssignmentData.setUpdatedDate(rs.getTimestamp("updated_date")); + resourceAssignmentData.setVersion(rs.getInt("version")); + return resourceAssignmentData; + } + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDao.java new file mode 100644 index 000000000..7a06e234a --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDao.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +public interface NamedQueryExecutorDao { + /** + * Return NamedParameterJdbcTemplate object. + */ + public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException; + + /** + * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the + * query, expecting a result list. + *

+ * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, + * using the column name as the key). + * + * @param sql SQL query to execute + * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return a List that contains a Map per row + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List> query(String sql, Map parameters) throws SvcLogicException; + + /** + * Issue an update via a prepared statement, binding the given arguments. + * + * @param sql SQL containing named parameters + * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return the number of rows affected + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update + */ + public int update(String sql, Map parameters) throws SvcLogicException; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDaoImpl.java new file mode 100644 index 000000000..ac59c5149 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/NamedQueryExecutorDaoImpl.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class NamedQueryExecutorDaoImpl implements NamedQueryExecutorDao { + private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoImpl.class); + private static final String CLASS_NAME = "NamedQueryExecutorDaoImpl"; + + @Autowired(required = true) + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + + public NamedQueryExecutorDaoImpl(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { + this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; + logger.info("{} Constructor initialised..", CLASS_NAME); + } + + @Override + public List> query(String sql, Map parameters) throws SvcLogicException { + logger.debug("Query ({}) with parameters ({})", sql, parameters); + return namedParameterJdbcTemplate.queryForList(sql, parameters); + } + + @Override + public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { + return namedParameterJdbcTemplate; + } + + @Override + public int update(String sql, Map parameters) throws SvcLogicException { + logger.debug("update ({}) with parameters ({})", sql, parameters); + return namedParameterJdbcTemplate.update(sql, parameters); + } +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDao.java new file mode 100644 index 000000000..9077d09f7 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDao.java @@ -0,0 +1,54 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface QueryExecutorDao { + + /** + * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the + * query, expecting a result list. + *

+ * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, + * using the column name as the key). Each element in the list will be of the form returned by this + * interface's queryForMap() methods. + * + * @param sql SQL query to execute + * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return a List that contains a Map per row + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List> query(String sql, Object[] data) throws SvcLogicException; + + /** + * Issue a single SQL update operation (such as an insert, update or delete statement) via a + * prepared statement, binding the given arguments. + * + * @param sql SQL containing bind parameters + * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return the number of rows affected + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update + */ + public int update(String sql, Object[] data) throws SvcLogicException; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoImpl.java new file mode 100644 index 000000000..f52c4c50f --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class QueryExecutorDaoImpl implements QueryExecutorDao { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoImpl.class); + private static final String CLASS_NAME = "QueryExecutorDaoImpl"; + + @Autowired(required = true) + private JdbcTemplate jdbcTemplate; + + public QueryExecutorDaoImpl(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + logger.info("{} Constructor initialised..", CLASS_NAME); + } + + @Override + public List> query(String sql, Object[] data) throws SvcLogicException { + logger.debug("Query ({}) with data ({})", sql, data); + return jdbcTemplate.queryForList(sql, data); + } + + @Override + public int update(String sql, Object[] data) throws SvcLogicException { + logger.debug("Query ({}) with data ({})", sql, data); + return jdbcTemplate.update(sql, data); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDao.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDao.java new file mode 100644 index 000000000..c9c5f8a73 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDao.java @@ -0,0 +1,62 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.List; + +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface TransactionLogDao { + + /** + * Issue a single SQL Insert operation for CONFIG_TRANSACTION_LOG table via a prepared statement, + * binding the given arguments. + * + * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert + */ + public void save(TransactionLog transactionLog) throws SvcLogicException; + + /** + * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a + * TransactionLog RowMapper. + * + * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List getTransactionsByRequestId(String requestId) throws SvcLogicException; + + /** + * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a + * TransactionLog RowMapper. + * + * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @param messageType argument to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List getTransactionsByRequestId(String requestId, String messageType) + throws SvcLogicException; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDaoImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDaoImpl.java new file mode 100644 index 000000000..ea6567e1e --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/dao/TransactionLogDaoImpl.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class TransactionLogDaoImpl implements TransactionLogDao { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(TransactionLogDaoImpl.class); + + private JdbcTemplate jdbcTemplate; + + public TransactionLogDaoImpl(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public void save(TransactionLog transactionLog) throws SvcLogicException { + if (transactionLog != null && StringUtils.isNotBlank(transactionLog.getRequestId())) { + String addSql = + "INSERT INTO CONFIG_TRANSACTION_LOG ( config_transaction_log_id, request_id, message_type, message ) VALUES (?, ?, ?, ?) "; + jdbcTemplate.update(addSql, transactionLog.getUniqueId(), transactionLog.getRequestId(), + transactionLog.getMessageType(), transactionLog.getMessage()); + logger.trace("TransactionLog Updated Successfully for message_type {}", transactionLog.getMessageType()); + } + + } + + @Override + public List getTransactionsByRequestId(String requestId) throws SvcLogicException { + if (StringUtils.isNotBlank(requestId)) { + String selectByRequestIdSql = + "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? ORDER BY creation_date DESC"; + return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId}, new TransactionLogMapper()); + } else { + throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing "); + } + } + + @Override + public List getTransactionsByRequestId(String requestId, String messageType) + throws SvcLogicException { + if (StringUtils.isNotBlank(requestId)) { + String selectByRequestIdSql = + "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? and message_type = ? ORDER BY creation_date DESC"; + return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId, messageType}, + new TransactionLogMapper()); + } else { + throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing "); + } + } + + private static final class TransactionLogMapper implements RowMapper { + @Override + public TransactionLog mapRow(ResultSet rs, int rowNum) throws SQLException { + TransactionLog transactionLog = new TransactionLog(); + transactionLog.setCreationDate(rs.getDate("creation_date")); + transactionLog.setMessage(rs.getString("message")); + transactionLog.setMessageType(rs.getString("message_type")); + transactionLog.setRequestId(rs.getString("request_id")); + transactionLog.setTransactionLogId(rs.getString("config_transaction_log_id")); + return transactionLog; + } + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/db/DataSourceWrap.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/db/DataSourceWrap.java new file mode 100644 index 000000000..5ec3eddca --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/db/DataSourceWrap.java @@ -0,0 +1,91 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.db; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import javax.sql.DataSource; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DataSourceWrap implements DataSource { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DataSourceWrap.class); + + private DataSource dataSource; + + public DataSourceWrap(DataSource dataSource) { + logger.info("Setting Data Source {} ", dataSource); + this.dataSource = dataSource; + } + + @Override + public PrintWriter getLogWriter() throws SQLException { + return dataSource.getLogWriter(); + } + + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + dataSource.setLogWriter(out); + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException { + dataSource.setLoginTimeout(seconds); + } + + @Override + public int getLoginTimeout() throws SQLException { + return dataSource.getLoginTimeout(); + } + + @Override + public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { + return dataSource.getParentLogger(); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return dataSource.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return dataSource.isWrapperFor(iface); + } + + @SuppressWarnings("squid:S2095") + @Override + public Connection getConnection() throws SQLException { + Connection c = dataSource.getConnection(); + logger.trace("getConnection: ({})", c.getClass().getName()); + c.setAutoCommit(true); + return c; + } + + @SuppressWarnings("squid:S2095") + @Override + public Connection getConnection(String username, String pass) throws SQLException { + Connection c = dataSource.getConnection(username, pass); + c.setAutoCommit(true); + return c; + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigPropertyMapData.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigPropertyMapData.java new file mode 100644 index 000000000..d9503b3be --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigPropertyMapData.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.domain; + +import java.io.Serializable; + +public class ConfigPropertyMapData implements Serializable { + private static final long serialVersionUID = 1L; + + private String referenceKey; + private String referenceValue; + + public String getReferenceKey() { + return referenceKey; + } + + public void setReferenceKey(String referenceKey) { + this.referenceKey = referenceKey; + } + + public String getReferenceValue() { + return referenceValue; + } + + public void setReferenceValue(String referenceValue) { + this.referenceValue = referenceValue; + } + + @Override + public String toString() { + return "ConfigPropertyMapData [referenceKey=" + referenceKey + ", referenceValue=" + referenceValue + "]"; + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigResource.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigResource.java new file mode 100644 index 000000000..501027021 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ConfigResource.java @@ -0,0 +1,171 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +public class ConfigResource implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + private String configResourceId; + private String resourceId; + private String resourceType; + private String serviceTemplateName; + private String serviceTemplateVersion; + private String templateName; + private String recipeName; + private String requestId; + private String resourceData; + private String maskData; + private Date createdDate = new Date(); + private String status; + private String updatedBy; + private List resourceAssignments; + + public String getConfigResourceId() { + return configResourceId; + } + + public void setConfigResourceId(String configResourceId) { + this.configResourceId = configResourceId; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getServiceTemplateName() { + return serviceTemplateName; + } + + public void setServiceTemplateName(String serviceTemplateName) { + this.serviceTemplateName = serviceTemplateName; + } + + public String getServiceTemplateVersion() { + return serviceTemplateVersion; + } + + public void setServiceTemplateVersion(String serviceTemplateVersion) { + this.serviceTemplateVersion = serviceTemplateVersion; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public String getRecipeName() { + return recipeName; + } + + public void setRecipeName(String recipeName) { + this.recipeName = recipeName; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getResourceData() { + return resourceData; + } + + public void setResourceData(String resourceData) { + this.resourceData = resourceData; + } + + public String getMaskData() { + return maskData; + } + + public void setMaskData(String maskData) { + this.maskData = maskData; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public List getResourceAssignments() { + return resourceAssignments; + } + + public void setResourceAssignments(List resourceAssignments) { + this.resourceAssignments = resourceAssignments; + } + + @Override + public String toString() { + return "ConfigResource [configResourceId=" + configResourceId + ", resourceId=" + resourceId + + ", serviceTemplateName=" + serviceTemplateName + ", serviceTemplateVersion=" + serviceTemplateVersion + + ", resourceType=" + resourceType + ", templateName=" + templateName + ", recipeName=" + recipeName + + ", requestId=" + requestId + ", resourceData= ******** , maskData=" + maskData + ", createdDate=" + + createdDate + ", updatedBy=" + updatedBy + "]"; + } + + public String getUniqueId() { + return UUID.randomUUID().toString(); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ResourceAssignmentData.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ResourceAssignmentData.java new file mode 100644 index 000000000..45e83c27e --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/ResourceAssignmentData.java @@ -0,0 +1,157 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.UUID; + +public class ResourceAssignmentData implements Serializable { + + private static final long serialVersionUID = 1L; + private String id; + private String configResourceId; + private Integer version; + private Date updatedDate = new Date(); + private String updatedBy; + private String templateKeyName; + private String resourceName; + private String dataType; + private String entrySchema; + private String resourceValue; + private String source; + private String status; + private String message; + + public String getUniqueId() { + return UUID.randomUUID().toString(); + } + + @Override + public String toString() { + return "ResourceAssignmentData [id=" + id + ", configResourceId=" + configResourceId + ", version=" + version + + ", updatedDate=" + updatedDate + ", updatedBy=" + updatedBy + ", templateKeyName=" + templateKeyName + + ", resourceName=" + resourceName + ", dataType=" + dataType + ", source=" + source + ", status=" + + status + "]"; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getConfigResourceId() { + return configResourceId; + } + + public void setConfigResourceId(String configResourceId) { + this.configResourceId = configResourceId; + } + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTemplateKeyName() { + return templateKeyName; + } + + public void setTemplateKeyName(String templateKeyName) { + this.templateKeyName = templateKeyName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getEntrySchema() { + return entrySchema; + } + + public void setEntrySchema(String entrySchema) { + this.entrySchema = entrySchema; + } + + public String getResourceValue() { + return resourceValue; + } + + public void setResourceValue(String resourceValue) { + this.resourceValue = resourceValue; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/TransactionLog.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/TransactionLog.java new file mode 100644 index 000000000..f45fdc64c --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/domain/TransactionLog.java @@ -0,0 +1,98 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.UUID; + +public class TransactionLog implements Serializable { + private static final long serialVersionUID = 1L; + + private String transactionLogId; + private String requestId; + private String messageType; + private Date creationDate; + private String message; + + public TransactionLog() { + + } + + public TransactionLog(String requestId, String messageType, String message) { + this.requestId = requestId; + this.messageType = messageType; + this.message = message; + } + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append("transactionLogId =" + transactionLogId); + buffer.append(", requestId =" + requestId); + buffer.append(", messageType =" + messageType); + buffer.append(", creationDate =" + creationDate); + buffer.append("]"); + return buffer.toString(); + } + + public String getTransactionLogId() { + return transactionLogId; + } + + public void setTransactionLogId(String transactionLogId) { + this.transactionLogId = transactionLogId; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getUniqueId() { + return UUID.randomUUID().toString(); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNode.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNode.java new file mode 100644 index 000000000..2eca20731 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNode.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.service; + +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +public class ConfigResourceNode implements SvcLogicJavaPlugin { + + private ConfigResourceService configResourceService; + + public ConfigResourceNode(ConfigResourceService configResourceService) { + this.configResourceService = configResourceService; + } + + public void saveConfigTransactionLog(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + String responsePrefix = inParams.get(DataAdaptorConstants.INPUT_PARAM_RESPONSE_PRIFIX); + try { + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; + + String messageType = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE); + String message = inParams.get(DataAdaptorConstants.INPUT_PARAM_MESSAGE); + String requestId = ctx.getAttribute("request-id"); + + TransactionLog transactionLog = new TransactionLog(); + + transactionLog.setMessage(message); + transactionLog.setMessageType(messageType); + transactionLog.setRequestId(requestId); + + configResourceService.save(transactionLog); + + } catch (Exception e) { + ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_STATUS, + DataAdaptorConstants.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + DataAdaptorConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + throw new SvcLogicException("Failed in saveConfigTransactionLog :" + e.getMessage()); + } + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceService.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceService.java new file mode 100644 index 000000000..2f01749a3 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceService.java @@ -0,0 +1,153 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.service; + +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +public interface ConfigResourceService { + + /** + * Return NamedParameterJdbcTemplate object. + */ + public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException; + + /** + * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the + * query, expecting a result list. + *

+ * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, + * using the column name as the key). + * + * @param sql SQL query to execute + * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return a List that contains a Map per row + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List> query(String sql, Map param) throws SvcLogicException; + + /** + * Issue an update via a prepared statement, binding the given arguments. + * + * @param sql SQL containing named parameters + * @param param map of parameters to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return the number of rows affected + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update + */ + public int update(String sql, Map param) throws SvcLogicException; + + /** + * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the + * query, expecting a result list. + *

+ * The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, + * using the column name as the key). + * + * @param sql SQL query to execute + * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return a List that contains a Map per row + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List> query(String sql, Object[] data) throws SvcLogicException; + + /** + * Issue a single SQL update operation (such as an insert, update or delete statement) via a + * prepared statement, binding the given arguments. + * + * @param sql SQL containing bind parameters + * @param data arguments to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return the number of rows affected + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the update + */ + public int update(String sql, Object[] data) throws SvcLogicException; + + /** + * Issue a single SQL Insert operation for CONFIG_TRANSACTION_LOG table via a prepared statement, + * binding the given arguments. + * + * @param transactionLog arguments to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert + */ + public void save(TransactionLog transactionLog) throws SvcLogicException; + + /** + * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a + * TransactionLog RowMapper. + * + * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List getTransactionsByRequestId(String requestId) throws SvcLogicException; + + /** + * Query CONFIG_RESOURCE table for given input param to create a prepared statement to bind to the + * query, mapping each row to a Java object via a ConfigResource RowMapper. + * + * @param configResource argument to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List getConfigResource(ConfigResource configResource) throws SvcLogicException; + + /** + * Issue a single SQL update operation (insert or update statement) for CONFIG_RESOURCE table via a + * prepared statement, binding the given arguments. + * + * @param configResource arguments to bind to the query (mapping it to the PreparedStatement to the + * corresponding SQL type) + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if there is any problem issuing the insert + */ + public ConfigResource saveConfigResource(ConfigResource configResource) throws SvcLogicException; + + /** + * Query ConcurrentHashMap having CONFIG_PROPERTY_MAP table data for given key. + * + * @param key key mapped to a value + * @return the result string, containing mapped string value + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if fails + */ + public String getConfigPropertyByKey(String key) throws SvcLogicException; + + /** + * Query CONFIG_TRANSACTION_LOG table for given request_id, mapping each row to a Java object via a + * TransactionLog RowMapper. + * + * @param requestId argument to bind to the query (leaving it to the PreparedStatement to guess the + * corresponding SQL type) + * @param messageType argument to bind to the query (leaving it to the PreparedStatement to guess + * the corresponding SQL type) + * @return the result List, containing mapped objects + * @throws org.onap.ccsdk.sli.core.sli.SvcLogicException if the query fails + */ + public List getTransactionsByRequestId(String requestId, String messageType) + throws SvcLogicException; + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceImpl.java b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceImpl.java new file mode 100644 index 000000000..bf1990377 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.service; + +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDao; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDao; +import org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDao; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigResourceServiceImpl implements ConfigResourceService { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceServiceImpl.class); + private static final String CLASS_NAME = "ConfigResourceServiceImpl"; + + private TransactionLogDao transactionLogDao; + private ConfigResourceDao configResourceDao; + private QueryExecutorDao queryExecutorDao; + private NamedQueryExecutorDao namedQueryExecutorDao; + private ConfigPropertyMapDao configPropertyMapDao; + + @SuppressWarnings("squid:S00107") + public ConfigResourceServiceImpl(TransactionLogDao transactionLogDao, ConfigResourceDao configResourceDao, + QueryExecutorDao queryExecutorDao, NamedQueryExecutorDao namedQueryExecutorDao, + ConfigPropertyMapDao configPropertyMapDao) { + + logger.info("{} Constuctor Initated...", CLASS_NAME); + this.transactionLogDao = transactionLogDao; + this.configResourceDao = configResourceDao; + this.queryExecutorDao = queryExecutorDao; + this.namedQueryExecutorDao = namedQueryExecutorDao; + this.configPropertyMapDao = configPropertyMapDao; + } + + @Override + public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() throws SvcLogicException { + return namedQueryExecutorDao.getNamedParameterJdbcTemplate(); + } + + @Override + public List> query(String sql, Map parameters) throws SvcLogicException { + return namedQueryExecutorDao.query(sql, parameters); + } + + @Override + public int update(String sql, Map parameters) throws SvcLogicException { + return namedQueryExecutorDao.update(sql, parameters); + } + + @Override + public List> query(String sql, Object[] data) throws SvcLogicException { + return queryExecutorDao.query(sql, data); + } + + @Override + public int update(String sql, Object[] data) throws SvcLogicException { + return queryExecutorDao.update(sql, data); + } + + @Override + public void save(TransactionLog transactionLog) throws SvcLogicException { + transactionLogDao.save(transactionLog); + } + + @Override + public List getTransactionsByRequestId(String requestId) throws SvcLogicException { + return transactionLogDao.getTransactionsByRequestId(requestId); + } + + @Override + public List getTransactionsByRequestId(String requestId, String messageType) + throws SvcLogicException { + return transactionLogDao.getTransactionsByRequestId(requestId, messageType); + } + + @Override + public List getConfigResource(ConfigResource configResource) throws SvcLogicException { + return configResourceDao.findByConfigResource(configResource); + } + + @Override + public ConfigResource saveConfigResource(ConfigResource configResource) throws SvcLogicException { + return configResourceDao.save(configResource); + } + + @Override + public String getConfigPropertyByKey(String key) throws SvcLogicException { + return configPropertyMapDao.getConfigPropertyByKey(key); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/adaptors/data-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 644fd77f4..e38bcd3ce 100644 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -27,7 +27,7 @@ + class="org.onap.ccsdk.features.data.adaptor.db.DataSourceWrap"> @@ -43,34 +43,34 @@ + class="org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.service.ConfigResourceServiceImpl"> @@ -79,6 +79,6 @@ + interface="org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService" /> diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoTest.java deleted file mode 100644 index 28736386c..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigPropertyMapDaoTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ConfigPropertyMapDaoTest { - - @Autowired - private ConfigPropertyMapDao configPropertyMapDao; - - @Autowired - private QueryExecutorDao queryExecutorDao; - - @Test - public void testConfigResourcesData() throws Exception { - String sql = "INSERT INTO CONFIG_PROPERTY_MAP (reference_key, reference_value) VALUES ( ?, ?)"; - Object[] data = new Object[] {"dummy123", "username123"}; - int result = queryExecutorDao.update(sql, data); - Assert.assertNotNull("Failed to get Query Result", result); - - String propKeyValye = configPropertyMapDao.getConfigPropertyByKey("org.onap.ccsdk.config.rest.adaptors.test"); - Assert.assertNull("propKeyValue is null", propKeyValye); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoTest.java deleted file mode 100644 index 0e57d3b5f..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigResourceDaoTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ConfigResourceDaoTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceDaoTest.class); - - @Autowired - private ConfigResourceDao configResourceDao; - - @Before - public void initialise() { - - } - - @Test - public void testAssignmentResourceData() throws Exception { - ConfigResource configResource = new ConfigResource(); - String resourceData = IOUtils.toString( - ConfigResourceDaoTest.class.getClassLoader().getResourceAsStream("reference/resource_data.json"), - Charset.defaultCharset()); - - logger.trace("resourceData = " + resourceData); - configResource.setResourceData(resourceData); - configResource.setServiceTemplateName("sample-name"); - configResource.setServiceTemplateVersion("1.0.0"); - configResource.setResourceId("123456"); - configResource.setResourceType("vUSP - vDBE-IPX HUB"); - configResource.setRequestId("123456"); - configResource.setRecipeName("activate-action"); - configResource.setTemplateName("vrr-service-template"); - configResource.setMaskData(null); - configResource.setStatus("success"); - configResource.setCreatedDate(new Date(System.currentTimeMillis())); - configResource.setUpdatedBy("an188a"); - - List resourceAssignments = new ArrayList<>(); - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setDataType("string"); - resourceAssignmentData.setStatus("success"); - resourceAssignmentData.setMessage("success"); - resourceAssignmentData.setTemplateKeyName("sample"); - resourceAssignmentData.setResourceName("sample"); - // resourceAssignmentData.setResourceValue("sample123"); - resourceAssignmentData.setSource("input"); - resourceAssignments.add(resourceAssignmentData); - configResource.setResourceAssignments(resourceAssignments); - - ConfigResource dbConfigResource = configResourceDao.save(configResource); - logger.info("Saved sucessfully : " + dbConfigResource.toString()); - Assert.assertNotNull("ConfigResource is null", dbConfigResource); - Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); - Assert.assertEquals("Resource Assignment Data count missmatch", true, - dbConfigResource.getResourceAssignments().size() > 0); - } - - @Test - public void testConfigResourcesData() throws Exception { - ConfigResource configResourceInput = new ConfigResource(); - configResourceInput.setResourceId("123456"); - List dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); - Assert.assertNotNull("ConfigResources is null", dbConfigResources); - Assert.assertEquals("ConfigResources size missmatch", true, dbConfigResources.size() > 0); - - for (ConfigResource configResource : dbConfigResources) { - Assert.assertNotNull("ConfigResources Assignments is null", configResource.getResourceAssignments()); - Assert.assertTrue("ConfigResources Assignments size miss mathch ", - configResource.getResourceAssignments().size() > 0); - logger.trace("ResourceAssignments = " + configResource.getResourceAssignments()); - } - } - - @Test - public void testDeleteByConfigResource() throws Exception { - ConfigResource configResourceInput = new ConfigResource(); - configResourceInput.setResourceId("123456"); - - List dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); - Assert.assertTrue("ConfigResources is null", !dbConfigResources.isEmpty()); - - configResourceInput.setConfigResourceId(dbConfigResources.get(0).getConfigResourceId()); - configResourceDao.deleteByConfigResource(configResourceInput); - - dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); - Assert.assertTrue("ConfigResources is not null", dbConfigResources.isEmpty()); - } -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigTransactionLogDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigTransactionLogDaoTest.java deleted file mode 100644 index ba150d510..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/ConfigTransactionLogDaoTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ConfigTransactionLogDaoTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigTransactionLogDaoTest.class); - - @Autowired - private TransactionLogDao transactionLogDao; - - @Autowired - private NamedQueryExecutorDao namedQueryExecutorDao; - - @Before - public void initialise() { - - } - - @Test - public void testQueryExecution() throws Exception { - String requestId = "12345"; - - transactionLogDao - .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, "Received Request")); - - List result = transactionLogDao.getTransactionsByRequestId(requestId); - logger.info("DB ArtifactReference :" + result); - Assert.assertNotNull("Failed to get Query Result", result); - - List result2 = - transactionLogDao.getTransactionsByRequestId(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG); - logger.info("DB ArtifactReference :" + result2); - Assert.assertNotNull("Failed to get Query Result", result2); - - String namedsql = "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = :request_id"; - Map parameters = new HashMap<>(); - parameters.put("request_id", "12345"); - List> namedresult = namedQueryExecutorDao.query(namedsql, parameters); - logger.info("DB ArtifactReference :" + namedresult); - Assert.assertNotNull("Failed to get Query Result", namedresult); - - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoTest.java deleted file mode 100644 index 257bc3183..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/dao/QueryExecutorDaoTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.dao; - -import java.util.Date; -import org.junit.Assert; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class QueryExecutorDaoTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoTest.class); - - @Autowired - private QueryExecutorDao queryExecutorDao; - - @Before - public void initialise() { - - } - - @Test - public void testInsertQueryExecution() throws Exception { - - String sql = "INSERT INTO CONFIG_RESOURCE" - + "(config_resource_id, resource_id, resource_type, template_name, recipe_name, request_id, resource_data, mask_data, created_date, updated_by) " - + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; - Object[] data = - new Object[] {"12345", "vUSP - vDBE-IPX HUB", "1234567", "activate-action", "vrr-service-template", - "resource-data", "mask-data", null, new Date(System.currentTimeMillis()), "ab1234"}; - int result = queryExecutorDao.update(sql, data); - logger.info("Updated successfully rows :" + result); - Assert.assertNotNull("Failed to get Query Result", result); - } - - @Test - public void testUpdateQueryExecution() throws Exception { - - String sql = "UPDATE CONFIG_RESOURCE set recipe_name=? where config_resource_id=?"; - Object[] data = new Object[] {"vce-service-template", "12345"}; - int result = queryExecutorDao.update(sql, data); - logger.info("Updated successfully rows :" + result); - Assert.assertNotNull("Failed to get Query Result", result); - } - - @Test - public void testDeleteQueryExecution() throws Exception { - - String sql = "DELETE FROM CONFIG_RESOURCE where config_resource_id=?"; - Object[] data = new Object[] {"12345"}; - int result = queryExecutorDao.update(sql, data); - logger.info("Updated successfully rows :" + result); - Assert.assertNotNull("Failed to get Query Result", result); - } - -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNodeTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNodeTest.java deleted file mode 100644 index b2f24bf60..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceNodeTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.service; - -import java.util.HashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigPropertyMapDao; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigResourceDao; -import org.onap.ccsdk.config.data.adaptor.dao.NamedQueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.QueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.TransactionLogDao; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -public class ConfigResourceNodeTest { - - ConfigResourceNode configResourceNode; - - ConfigResourceService configResourceService; - - @Autowired - TransactionLogDao transactionLogDao; - - @Autowired - ConfigResourceDao configResourceDao; - - @Autowired - QueryExecutorDao queryExecutorDao; - - @Autowired - NamedQueryExecutorDao namedQueryExecutorDao; - - @Autowired - ConfigPropertyMapDao configPropertyMapDao; - - @Before - public void before() { - configResourceService = new ConfigResourceServiceImpl(transactionLogDao, configResourceDao, queryExecutorDao, - namedQueryExecutorDao, configPropertyMapDao); - configResourceNode = new ConfigResourceNode(configResourceService); - } - - @Test - public void testSaveConfigTransactionLog() throws Exception { - Map inParams = new HashMap<>(); - inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE, "messageType"); - inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE, "message"); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("request-id", "requestId12345"); - - configResourceNode.saveConfigTransactionLog(inParams, ctx); - - Assert.assertTrue(!transactionLogDao.getTransactionsByRequestId("requestId12345").isEmpty()); - } - - @Test(expected = SvcLogicException.class) - public void testSaveConfigTransactionLogException() throws Exception { - configResourceNode = new ConfigResourceNode(null); - configResourceNode.saveConfigTransactionLog(new HashMap<>(), new SvcLogicContext()); - } -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceTest.java deleted file mode 100644 index 6f861a3be..000000000 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/config/data/adaptor/service/ConfigResourceServiceTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.data.adaptor.service; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigPropertyMapDao; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigResourceDao; -import org.onap.ccsdk.config.data.adaptor.dao.ConfigResourceDaoTest; -import org.onap.ccsdk.config.data.adaptor.dao.NamedQueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.QueryExecutorDao; -import org.onap.ccsdk.config.data.adaptor.dao.TransactionLogDao; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) -public class ConfigResourceServiceTest { - - ConfigResourceService configResourceService; - - @Autowired - TransactionLogDao transactionLogDao; - - @Autowired - ConfigResourceDao configResourceDao; - - @Autowired - QueryExecutorDao queryExecutorDao; - - @Autowired - NamedQueryExecutorDao namedQueryExecutorDao; - - @Autowired - ConfigPropertyMapDao configPropertyMapDao; - - @Before - public void before() { - configResourceService = new ConfigResourceServiceImpl(transactionLogDao, configResourceDao, queryExecutorDao, - namedQueryExecutorDao, configPropertyMapDao); - } - - @Test - public void testUpdate() throws Exception { - String sql = "INSERT INTO CONFIG_RESOURCE" - + "(config_resource_id, resource_id, resource_type, template_name, recipe_name, request_id, resource_data, mask_data, created_date, updated_by) " - + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; - Object[] data = - new Object[] {"54321", "vUSP - vDBE-IPX HUB", "1234567", "activate-action", "vrr-service-template", - "resource-data", "mask-data", null, new Date(System.currentTimeMillis()), "ab1234"}; - int result = configResourceService.update(sql, data); - Assert.assertTrue(result == 1); - - sql = "SELECT * FROM CONFIG_RESOURCE WHERE config_resource_id = ?"; - data = new Object[] {"54321"}; - List> queryResult = configResourceService.query(sql, data); - Assert.assertTrue(queryResult.size() == 1); - } - - @Test - public void testSaveAndGetConfigResource() throws Exception { - ConfigResource configResource = new ConfigResource(); - String resourceData = IOUtils.toString( - ConfigResourceDaoTest.class.getClassLoader().getResourceAsStream("reference/resource_data.json"), - Charset.defaultCharset()); - - configResource.setResourceData(resourceData); - configResource.setServiceTemplateName("sample-name"); - configResource.setServiceTemplateVersion("1.0.0"); - configResource.setResourceId("123456"); - configResource.setResourceType("vUSP - vDBE-IPX HUB"); - configResource.setRequestId("123456"); - configResource.setRecipeName("activate-action"); - configResource.setTemplateName("vrr-service-template"); - configResource.setMaskData(null); - configResource.setStatus("success"); - configResource.setCreatedDate(new Date(System.currentTimeMillis())); - configResource.setUpdatedBy("an188a"); - - List resourceAssignments = new ArrayList<>(); - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setDataType("string"); - resourceAssignmentData.setStatus("success"); - resourceAssignmentData.setMessage("success"); - resourceAssignmentData.setTemplateKeyName("sample"); - resourceAssignmentData.setResourceName("sample"); - // resourceAssignmentData.setResourceValue("sample123"); - resourceAssignmentData.setSource("input"); - resourceAssignments.add(resourceAssignmentData); - configResource.setResourceAssignments(resourceAssignments); - - // save - ConfigResource dbConfigResource = configResourceService.saveConfigResource(configResource); - Assert.assertNotNull("ConfigResource is null", dbConfigResource); - Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); - Assert.assertEquals("Resource Assignment Data count missmatch", true, - dbConfigResource.getResourceAssignments().size() > 0); - Assert.assertEquals(configResource.getServiceTemplateVersion(), dbConfigResource.getServiceTemplateVersion()); - - // update - configResource.setServiceTemplateVersion("1.0.1"); - dbConfigResource = configResourceService.saveConfigResource(configResource); - Assert.assertNotNull("ConfigResource is null", dbConfigResource); - Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); - Assert.assertEquals("Resource Assignment Data count missmatch", true, - dbConfigResource.getResourceAssignments().size() > 0); - Assert.assertEquals(configResource.getServiceTemplateVersion(), dbConfigResource.getServiceTemplateVersion()); - - // find - ConfigResource configResourceInput = new ConfigResource(); - configResourceInput.setResourceId(configResource.getResourceId()); - configResourceInput.setTemplateName(configResource.getTemplateName()); - configResourceInput.setServiceTemplateName(configResource.getServiceTemplateName()); - configResourceInput.setServiceTemplateVersion(configResource.getServiceTemplateVersion()); - configResourceInput.setRequestId(configResource.getRequestId()); - configResourceInput.setRecipeName(configResource.getRecipeName()); - configResourceInput.setResourceType(configResource.getResourceType()); - List dbConfigResources = configResourceService.getConfigResource(configResourceInput); - Assert.assertNotNull("ConfigResources is null", dbConfigResources); - Assert.assertEquals("ConfigResources size missmatch", true, dbConfigResources.size() > 0); - - for (ConfigResource dbConfigResouce : dbConfigResources) { - Assert.assertNotNull("ConfigResources Assignments is null", dbConfigResouce.getResourceAssignments()); - Assert.assertTrue("ConfigResources Assignments size miss mathch ", - dbConfigResouce.getResourceAssignments().size() > 0); - } - } - - @Test - public void testSaveAndGetTransactionLog() throws Exception { - TransactionLog transactionLog = new TransactionLog(); - transactionLog.setMessage("message"); - transactionLog.setMessageType("messageType"); - transactionLog.setRequestId("requestId"); - - configResourceService.save(transactionLog); - - List transactions = - configResourceService.getTransactionsByRequestId(transactionLog.getRequestId()); - Assert.assertTrue(transactions.size() == 1); - transactions = configResourceService.getTransactionsByRequestId(transactionLog.getRequestId(), - transactionLog.getMessageType()); - Assert.assertTrue(transactions.size() == 1); - } - - @Test - public void testNamedQueryExecutorUpdateNQuery() throws Exception { - Map parameters = new HashMap<>(); - parameters.put("config_transaction_log_id", UUID.randomUUID().toString()); - parameters.put("request_id", "requestId123"); - parameters.put("message_type", "messageType"); - parameters.put("message", "message"); - configResourceService.update( - "INSERT INTO CONFIG_TRANSACTION_LOG ( config_transaction_log_id, request_id, message_type, message ) VALUES (:config_transaction_log_id, :request_id, :message_type, :message) ", - parameters); - - List> result = configResourceService - .query("SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = :request_id", parameters); - - Assert.assertTrue(!result.isEmpty()); - Assert.assertNotNull(configResourceService.getNamedParameterJdbcTemplate()); - } -} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoTest.java new file mode 100644 index 000000000..1915017a6 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigPropertyMapDaoTest.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDao; +import org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConfigPropertyMapDaoTest { + + @Autowired + private ConfigPropertyMapDao configPropertyMapDao; + + @Autowired + private QueryExecutorDao queryExecutorDao; + + @Test + public void testConfigResourcesData() throws Exception { + String sql = "INSERT INTO CONFIG_PROPERTY_MAP (reference_key, reference_value) VALUES ( ?, ?)"; + Object[] data = new Object[] {"dummy123", "username123"}; + int result = queryExecutorDao.update(sql, data); + Assert.assertNotNull("Failed to get Query Result", result); + + String propKeyValye = configPropertyMapDao.getConfigPropertyByKey("org.onap.ccsdk.features.rest.adaptors.test"); + Assert.assertNull("propKeyValue is null", propKeyValye); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoTest.java new file mode 100644 index 000000000..7bc9189c9 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigResourceDaoTest.java @@ -0,0 +1,126 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDao; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.ResourceAssignmentData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConfigResourceDaoTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceDaoTest.class); + + @Autowired + private ConfigResourceDao configResourceDao; + + @Before + public void initialise() { + + } + + @Test + public void testAssignmentResourceData() throws Exception { + ConfigResource configResource = new ConfigResource(); + String resourceData = IOUtils.toString( + ConfigResourceDaoTest.class.getClassLoader().getResourceAsStream("reference/resource_data.json"), + Charset.defaultCharset()); + + logger.trace("resourceData = " + resourceData); + configResource.setResourceData(resourceData); + configResource.setServiceTemplateName("sample-name"); + configResource.setServiceTemplateVersion("1.0.0"); + configResource.setResourceId("123456"); + configResource.setResourceType("vUSP - vDBE-IPX HUB"); + configResource.setRequestId("123456"); + configResource.setRecipeName("activate-action"); + configResource.setTemplateName("vrr-service-template"); + configResource.setMaskData(null); + configResource.setStatus("success"); + configResource.setCreatedDate(new Date(System.currentTimeMillis())); + configResource.setUpdatedBy("an188a"); + + List resourceAssignments = new ArrayList<>(); + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setDataType("string"); + resourceAssignmentData.setStatus("success"); + resourceAssignmentData.setMessage("success"); + resourceAssignmentData.setTemplateKeyName("sample"); + resourceAssignmentData.setResourceName("sample"); + // resourceAssignmentData.setResourceValue("sample123"); + resourceAssignmentData.setSource("input"); + resourceAssignments.add(resourceAssignmentData); + configResource.setResourceAssignments(resourceAssignments); + + ConfigResource dbConfigResource = configResourceDao.save(configResource); + logger.info("Saved sucessfully : " + dbConfigResource.toString()); + Assert.assertNotNull("ConfigResource is null", dbConfigResource); + Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); + Assert.assertEquals("Resource Assignment Data count missmatch", true, + dbConfigResource.getResourceAssignments().size() > 0); + } + + @Test + public void testConfigResourcesData() throws Exception { + ConfigResource configResourceInput = new ConfigResource(); + configResourceInput.setResourceId("123456"); + List dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); + Assert.assertNotNull("ConfigResources is null", dbConfigResources); + Assert.assertEquals("ConfigResources size missmatch", true, dbConfigResources.size() > 0); + + for (ConfigResource configResource : dbConfigResources) { + Assert.assertNotNull("ConfigResources Assignments is null", configResource.getResourceAssignments()); + Assert.assertTrue("ConfigResources Assignments size miss mathch ", + configResource.getResourceAssignments().size() > 0); + logger.trace("ResourceAssignments = " + configResource.getResourceAssignments()); + } + } + + @Test + public void testDeleteByConfigResource() throws Exception { + ConfigResource configResourceInput = new ConfigResource(); + configResourceInput.setResourceId("123456"); + + List dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); + Assert.assertTrue("ConfigResources is null", !dbConfigResources.isEmpty()); + + configResourceInput.setConfigResourceId(dbConfigResources.get(0).getConfigResourceId()); + configResourceDao.deleteByConfigResource(configResourceInput); + + dbConfigResources = configResourceDao.findByConfigResource(configResourceInput); + Assert.assertTrue("ConfigResources is not null", dbConfigResources.isEmpty()); + } +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigTransactionLogDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigTransactionLogDaoTest.java new file mode 100644 index 000000000..22e9be9b7 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/ConfigTransactionLogDaoTest.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDao; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConfigTransactionLogDaoTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigTransactionLogDaoTest.class); + + @Autowired + private TransactionLogDao transactionLogDao; + + @Autowired + private NamedQueryExecutorDao namedQueryExecutorDao; + + @Before + public void initialise() { + + } + + @Test + public void testQueryExecution() throws Exception { + String requestId = "12345"; + + transactionLogDao + .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, "Received Request")); + + List result = transactionLogDao.getTransactionsByRequestId(requestId); + logger.info("DB ArtifactReference :" + result); + Assert.assertNotNull("Failed to get Query Result", result); + + List result2 = + transactionLogDao.getTransactionsByRequestId(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG); + logger.info("DB ArtifactReference :" + result2); + Assert.assertNotNull("Failed to get Query Result", result2); + + String namedsql = "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = :request_id"; + Map parameters = new HashMap<>(); + parameters.put("request_id", "12345"); + List> namedresult = namedQueryExecutorDao.query(namedsql, parameters); + logger.info("DB ArtifactReference :" + namedresult); + Assert.assertNotNull("Failed to get Query Result", namedresult); + + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoTest.java new file mode 100644 index 000000000..ee7029f0d --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/dao/QueryExecutorDaoTest.java @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.dao; + +import java.util.Date; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class QueryExecutorDaoTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoTest.class); + + @Autowired + private QueryExecutorDao queryExecutorDao; + + @Before + public void initialise() { + + } + + @Test + public void testInsertQueryExecution() throws Exception { + + String sql = "INSERT INTO CONFIG_RESOURCE" + + "(config_resource_id, resource_id, resource_type, template_name, recipe_name, request_id, resource_data, mask_data, created_date, updated_by) " + + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + Object[] data = + new Object[] {"12345", "vUSP - vDBE-IPX HUB", "1234567", "activate-action", "vrr-service-template", + "resource-data", "mask-data", null, new Date(System.currentTimeMillis()), "ab1234"}; + int result = queryExecutorDao.update(sql, data); + logger.info("Updated successfully rows :" + result); + Assert.assertNotNull("Failed to get Query Result", result); + } + + @Test + public void testUpdateQueryExecution() throws Exception { + + String sql = "UPDATE CONFIG_RESOURCE set recipe_name=? where config_resource_id=?"; + Object[] data = new Object[] {"vce-service-template", "12345"}; + int result = queryExecutorDao.update(sql, data); + logger.info("Updated successfully rows :" + result); + Assert.assertNotNull("Failed to get Query Result", result); + } + + @Test + public void testDeleteQueryExecution() throws Exception { + + String sql = "DELETE FROM CONFIG_RESOURCE where config_resource_id=?"; + Object[] data = new Object[] {"12345"}; + int result = queryExecutorDao.update(sql, data); + logger.info("Updated successfully rows :" + result); + Assert.assertNotNull("Failed to get Query Result", result); + } + +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNodeTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNodeTest.java new file mode 100644 index 000000000..53724c5c9 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceNodeTest.java @@ -0,0 +1,89 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.service; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDao; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDao; +import org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDao; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceNode; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceServiceImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +public class ConfigResourceNodeTest { + + ConfigResourceNode configResourceNode; + + ConfigResourceService configResourceService; + + @Autowired + TransactionLogDao transactionLogDao; + + @Autowired + ConfigResourceDao configResourceDao; + + @Autowired + QueryExecutorDao queryExecutorDao; + + @Autowired + NamedQueryExecutorDao namedQueryExecutorDao; + + @Autowired + ConfigPropertyMapDao configPropertyMapDao; + + @Before + public void before() { + configResourceService = new ConfigResourceServiceImpl(transactionLogDao, configResourceDao, queryExecutorDao, + namedQueryExecutorDao, configPropertyMapDao); + configResourceNode = new ConfigResourceNode(configResourceService); + } + + @Test + public void testSaveConfigTransactionLog() throws Exception { + Map inParams = new HashMap<>(); + inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE, "messageType"); + inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE, "message"); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("request-id", "requestId12345"); + + configResourceNode.saveConfigTransactionLog(inParams, ctx); + + Assert.assertTrue(!transactionLogDao.getTransactionsByRequestId("requestId12345").isEmpty()); + } + + @Test(expected = SvcLogicException.class) + public void testSaveConfigTransactionLogException() throws Exception { + configResourceNode = new ConfigResourceNode(null); + configResourceNode.saveConfigTransactionLog(new HashMap<>(), new SvcLogicContext()); + } +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceTest.java b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceTest.java new file mode 100644 index 000000000..2d599e2f1 --- /dev/null +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/java/org/onap/ccsdk/features/data/adaptor/service/ConfigResourceServiceTest.java @@ -0,0 +1,194 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.data.adaptor.service; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDao; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDao; +import org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDaoTest; +import org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDao; +import org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDao; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.ResourceAssignmentData; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:test-context-h2db.xml"}) +public class ConfigResourceServiceTest { + + ConfigResourceService configResourceService; + + @Autowired + TransactionLogDao transactionLogDao; + + @Autowired + ConfigResourceDao configResourceDao; + + @Autowired + QueryExecutorDao queryExecutorDao; + + @Autowired + NamedQueryExecutorDao namedQueryExecutorDao; + + @Autowired + ConfigPropertyMapDao configPropertyMapDao; + + @Before + public void before() { + configResourceService = new ConfigResourceServiceImpl(transactionLogDao, configResourceDao, queryExecutorDao, + namedQueryExecutorDao, configPropertyMapDao); + } + + @Test + public void testUpdate() throws Exception { + String sql = "INSERT INTO CONFIG_RESOURCE" + + "(config_resource_id, resource_id, resource_type, template_name, recipe_name, request_id, resource_data, mask_data, created_date, updated_by) " + + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + Object[] data = + new Object[] {"54321", "vUSP - vDBE-IPX HUB", "1234567", "activate-action", "vrr-service-template", + "resource-data", "mask-data", null, new Date(System.currentTimeMillis()), "ab1234"}; + int result = configResourceService.update(sql, data); + Assert.assertTrue(result == 1); + + sql = "SELECT * FROM CONFIG_RESOURCE WHERE config_resource_id = ?"; + data = new Object[] {"54321"}; + List> queryResult = configResourceService.query(sql, data); + Assert.assertTrue(queryResult.size() == 1); + } + + @Test + public void testSaveAndGetConfigResource() throws Exception { + ConfigResource configResource = new ConfigResource(); + String resourceData = IOUtils.toString( + ConfigResourceDaoTest.class.getClassLoader().getResourceAsStream("reference/resource_data.json"), + Charset.defaultCharset()); + + configResource.setResourceData(resourceData); + configResource.setServiceTemplateName("sample-name"); + configResource.setServiceTemplateVersion("1.0.0"); + configResource.setResourceId("123456"); + configResource.setResourceType("vUSP - vDBE-IPX HUB"); + configResource.setRequestId("123456"); + configResource.setRecipeName("activate-action"); + configResource.setTemplateName("vrr-service-template"); + configResource.setMaskData(null); + configResource.setStatus("success"); + configResource.setCreatedDate(new Date(System.currentTimeMillis())); + configResource.setUpdatedBy("an188a"); + + List resourceAssignments = new ArrayList<>(); + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setDataType("string"); + resourceAssignmentData.setStatus("success"); + resourceAssignmentData.setMessage("success"); + resourceAssignmentData.setTemplateKeyName("sample"); + resourceAssignmentData.setResourceName("sample"); + // resourceAssignmentData.setResourceValue("sample123"); + resourceAssignmentData.setSource("input"); + resourceAssignments.add(resourceAssignmentData); + configResource.setResourceAssignments(resourceAssignments); + + // save + ConfigResource dbConfigResource = configResourceService.saveConfigResource(configResource); + Assert.assertNotNull("ConfigResource is null", dbConfigResource); + Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); + Assert.assertEquals("Resource Assignment Data count missmatch", true, + dbConfigResource.getResourceAssignments().size() > 0); + Assert.assertEquals(configResource.getServiceTemplateVersion(), dbConfigResource.getServiceTemplateVersion()); + + // update + configResource.setServiceTemplateVersion("1.0.1"); + dbConfigResource = configResourceService.saveConfigResource(configResource); + Assert.assertNotNull("ConfigResource is null", dbConfigResource); + Assert.assertNotNull("Resource Assignment Data is null", dbConfigResource.getResourceAssignments()); + Assert.assertEquals("Resource Assignment Data count missmatch", true, + dbConfigResource.getResourceAssignments().size() > 0); + Assert.assertEquals(configResource.getServiceTemplateVersion(), dbConfigResource.getServiceTemplateVersion()); + + // find + ConfigResource configResourceInput = new ConfigResource(); + configResourceInput.setResourceId(configResource.getResourceId()); + configResourceInput.setTemplateName(configResource.getTemplateName()); + configResourceInput.setServiceTemplateName(configResource.getServiceTemplateName()); + configResourceInput.setServiceTemplateVersion(configResource.getServiceTemplateVersion()); + configResourceInput.setRequestId(configResource.getRequestId()); + configResourceInput.setRecipeName(configResource.getRecipeName()); + configResourceInput.setResourceType(configResource.getResourceType()); + List dbConfigResources = configResourceService.getConfigResource(configResourceInput); + Assert.assertNotNull("ConfigResources is null", dbConfigResources); + Assert.assertEquals("ConfigResources size missmatch", true, dbConfigResources.size() > 0); + + for (ConfigResource dbConfigResouce : dbConfigResources) { + Assert.assertNotNull("ConfigResources Assignments is null", dbConfigResouce.getResourceAssignments()); + Assert.assertTrue("ConfigResources Assignments size miss mathch ", + dbConfigResouce.getResourceAssignments().size() > 0); + } + } + + @Test + public void testSaveAndGetTransactionLog() throws Exception { + TransactionLog transactionLog = new TransactionLog(); + transactionLog.setMessage("message"); + transactionLog.setMessageType("messageType"); + transactionLog.setRequestId("requestId"); + + configResourceService.save(transactionLog); + + List transactions = + configResourceService.getTransactionsByRequestId(transactionLog.getRequestId()); + Assert.assertTrue(transactions.size() == 1); + transactions = configResourceService.getTransactionsByRequestId(transactionLog.getRequestId(), + transactionLog.getMessageType()); + Assert.assertTrue(transactions.size() == 1); + } + + @Test + public void testNamedQueryExecutorUpdateNQuery() throws Exception { + Map parameters = new HashMap<>(); + parameters.put("config_transaction_log_id", UUID.randomUUID().toString()); + parameters.put("request_id", "requestId123"); + parameters.put("message_type", "messageType"); + parameters.put("message", "message"); + configResourceService.update( + "INSERT INTO CONFIG_TRANSACTION_LOG ( config_transaction_log_id, request_id, message_type, message ) VALUES (:config_transaction_log_id, :request_id, :message_type, :message) ", + parameters); + + List> result = configResourceService + .query("SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = :request_id", parameters); + + Assert.assertTrue(!result.isEmpty()); + Assert.assertNotNull(configResourceService.getNamedParameterJdbcTemplate()); + } +} diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context-h2db.xml b/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context-h2db.xml index f0a50f440..baffb54e6 100644 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context-h2db.xml +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context-h2db.xml @@ -53,31 +53,31 @@ + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDaoImpl"> + base-package="org.onap.ccsdk.features.data.adaptor" /> diff --git a/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context.xml b/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context.xml index 17189f2f2..ee3d33120 100644 --- a/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context.xml +++ b/blueprints-processor/adaptors/data-adaptor-provider/src/test/resources/test-context.xml @@ -53,10 +53,10 @@ - + - + @@ -71,26 +71,26 @@ + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigResourceDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.ConfigPropertyMapDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.QueryExecutorDaoImpl"> + class="org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDaoImpl"> + base-package="org.onap.ccsdk.features.data.adaptor" /> diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/pom.xml b/blueprints-processor/adaptors/rest-adaptor-provider/pom.xml index ee5f9f675..0bf0d73d7 100644 --- a/blueprints-processor/adaptors/rest-adaptor-provider/pom.xml +++ b/blueprints-processor/adaptors/rest-adaptor-provider/pom.xml @@ -97,10 +97,10 @@ ${project.artifactId} ${project.groupId}.${project.artifactId} - org.onap.ccsdk.config.rest.adaptor, - org.onap.ccsdk.config.rest.adaptor.data, - org.onap.ccsdk.config.rest.adaptor.service, - org.onap.ccsdk.config.rest.adaptor.utils + org.onap.ccsdk.features.rest.adaptor, + org.onap.ccsdk.features.rest.adaptor.data, + org.onap.ccsdk.features.rest.adaptor.service, + org.onap.ccsdk.features.rest.adaptor.utils diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorConstants.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorConstants.java deleted file mode 100644 index af6b9f2b8..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorConstants.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor; - -public class ConfigRestAdaptorConstants { - private ConfigRestAdaptorConstants() { - - } - - public static final String SDNC_ROOT_DIR_ENV_VAR_KEY = "SDNC_CONFIG_DIR"; - public static final String REST_ADAPTOR_PROPERTIES_FILE_NAME = "config-rest-adaptor.properties"; - public static final String PROXY_URL_KEY = "proxyUrl"; - public static final String PROXY_URLS_VALUE_SEPARATOR = ","; - public static final String AAF_USERNAME_KEY = "aafUserName"; - public static final String AAF_PSSWD_KEY = "aafPassword"; - public static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion"; - - public static final String PROPERTY_ENV_PROD = "field"; - public static final String PROPERTY_ENV_SOLO = "solo"; - - public static final String REST_ADAPTOR_BASE_PROPERTY = "org.onap.ccsdk.config.rest.adaptors."; - public static final String REST_ADAPTOR_ENV_TYPE = "envtype"; - public static final String REST_ADAPTOR_TYPE_GENERIC = "generic"; - public static final String REST_ADAPTOR_TYPE_SSL = "ssl"; - - public static final String SSL_SERVICE_BASEURL = ".url"; - public static final String SSL_SERVICE_APP = ".application"; - public static final String SSL_SERVICE_TRUST = ".ssl.trust"; - public static final String SSL_SERVICE_TRUST_PSSWD = ".ssl.trust.psswd"; - public static final String SSL_SERVICE_KEY = ".ssl.key"; - public static final String SSL_SERVICE_KEY_PSSWD = ".ssl.key.psswd"; - - public static final String SERVICE_TYPE_PROPERTY = ".type"; - public static final String SERVICE_EANABLED_PROPERTY = ".enable"; - public static final String SERVICE_ENV_PROPERTY = ".env"; - public static final String SERVICE_BASEURL_PROPERTY = ".url"; - public static final String SERVICE_PROPERTYFILE = ".propertyfile"; - public static final String SERVICE_USER_PROPERTY = ".user"; - public static final String SERVICE_APPID_PROPERTY = ".appId"; - public static final String SERVICE_PSSWD_PROPERTY = ".passwd"; - public static final String SERVICE_CLIENTAUTH_PROPERTY = ".clientAuth"; - public static final String SERVICE_AUTHORIZATION_PROPERTY = ".authorization"; - - public static final String SELECTOR_AAI = "aai"; - public static final String SELECTOR_ALTS = "alts"; - public static final String SELECTOR_EIPAM = "eipam"; - public static final String SELECTOR_COSMS = "cosms"; - public static final String SELECTOR_RESTCONF = "restconf"; - public static final String SELECTOR_MODEL_SERVICE = "modelservice"; - public static final String SELECTOR_POLICY_MANAGER = "policymanager"; - public static final String SELECTOR_NRD = "networkresourcediscovery"; - public static final String SELECTOR_NSM = "nsm"; - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorException.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorException.java deleted file mode 100644 index c6593f128..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/ConfigRestAdaptorException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor; - -/** - * ConfigRestAdaptorException.java Purpose: Provide Configuration Rest Adaptor Exception - * - * @version 1.0 - */ -public class ConfigRestAdaptorException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * This is a ConfigRestAdaptorException constructor - * - * @param message - */ - public ConfigRestAdaptorException(String message) { - super(message); - } - - /** - * This is a ConfigRestAdaptorException constructor - * - * @param message - */ - public ConfigRestAdaptorException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/data/RestResponse.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/data/RestResponse.java deleted file mode 100644 index d31aa7e8a..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/data/RestResponse.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.data; - -import java.util.Map; - -public class RestResponse { - - private String statusCode; - private String body; - private Map parameters; - private Map responseHeaders; - private Map requestHeaders; - - public String getStatusCode() { - return statusCode; - } - - public void setStatusCode(String statusCode) { - this.statusCode = statusCode; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public Map getResponseHeaders() { - return responseHeaders; - } - - public void setResponseHeaders(Map responseHeaders) { - this.responseHeaders = responseHeaders; - } - - public Map getRequestHeaders() { - return requestHeaders; - } - - public void setRequestHeaders(Map requestHeaders) { - this.requestHeaders = requestHeaders; - } - - @Override - public String toString() { - return "RestResponse [statusCode=" + statusCode + ", body=" + body + ", parameters=" + parameters - + ", responseHeaders=" + responseHeaders + ", requestHeaders=" + requestHeaders + "]"; - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapter.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapter.java deleted file mode 100644 index 7829ee6a8..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapter.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import javax.net.ssl.SSLContext; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContextBuilder; -import org.apache.http.ssl.TrustStrategy; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; -import org.onap.ccsdk.config.rest.adaptor.utils.BasicAuthorizationInterceptor; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.http.converter.ByteArrayHttpMessageConverter; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.ResourceHttpMessageConverter; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.http.converter.xml.SourceHttpMessageConverter; -import org.springframework.util.ResourceUtils; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -abstract class AbstractConfigRestClientAdapter implements ConfigRestClientServiceAdapter { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(AbstractConfigRestClientAdapter.class); - private static final String MS_INIT_FAIL = "Failed to initialise microservice client restTemplate."; - - protected boolean isRestClientServiceAdapaterEnabled = false; - protected boolean isSSLServiceAdapaterEnabled = true; - - protected Map properties = new ConcurrentHashMap<>(); - protected String serviceSelector; - - protected RestTemplate restTemplate; - - protected AbstractConfigRestClientAdapter(Map properties, String serviceSelector) { - this.properties = properties; - this.serviceSelector = serviceSelector; - setRestClientServiceAdapaterEnabled(); - } - - private void setRestClientServiceAdapaterEnabled() { - String isEnabledProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_EANABLED_PROPERTY; - String isRestClientServiceAdapaterEnabledStr = properties.get(isEnabledProperty); - logger.info("Service selector ({}) enable status ({}) ", serviceSelector, - isRestClientServiceAdapaterEnabledStr); - if (StringUtils.isNotBlank(isRestClientServiceAdapaterEnabledStr) - && Boolean.parseBoolean(isRestClientServiceAdapaterEnabledStr)) { - isRestClientServiceAdapaterEnabled = true; - } - } - - private List> getMessageConverters() { - List> converters = new ArrayList<>(); - converters.add(new ByteArrayHttpMessageConverter()); - converters.add(new StringHttpMessageConverter()); - converters.add(new ResourceHttpMessageConverter()); - converters.add(new SourceHttpMessageConverter()); - converters.add(new MappingJackson2HttpMessageConverter()); - return converters; - } - - public void initialise(String user, String pass) { - logger.trace("Config rest template factory user ({}) ", user); - - CloseableHttpClient httpClient = - HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); - HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); - requestFactory.setHttpClient(httpClient); - - restTemplate = new RestTemplate(getMessageConverters()); - restTemplate.setRequestFactory(requestFactory); - if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) { - restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(user, pass)); - } - } - - public void initialiseSSL(String keyStorePath, String trustStorePath, String keyPass, String trustPass) - throws ConfigRestAdaptorException { - logger.trace("SSL rest template factory"); - - TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; - SSLContext sslContext = null; - - try (InputStream keyInput = new FileInputStream(keyStorePath)) { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - keyStore.load(keyInput, keyPass.toCharArray()); - - logger.info("key loaded successfully"); - sslContext = SSLContextBuilder.create().loadKeyMaterial(keyStore, keyPass.toCharArray()).loadTrustMaterial( - ResourceUtils.getFile(trustStorePath), trustPass.toCharArray(), acceptingTrustStrategy).build(); - } catch (Exception e) { - throw new ConfigRestAdaptorException(e.getMessage()); - } - - SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); - CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); - HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); - - restTemplate = new RestTemplate(getMessageConverters()); - restTemplate.setRequestFactory(requestFactory); - } - - public T getResource(HttpHeaders headers, String url, Class responseType) throws ConfigRestAdaptorException { - ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.GET, null, responseType); - return processResponse(response, url, HttpMethod.GET); - } - - public T postResource(HttpHeaders headers, String url, Object request, Class responseType) - throws ConfigRestAdaptorException { - ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.POST, request, responseType); - return processResponse(response, url, HttpMethod.POST); - } - - public T exchangeResource(HttpHeaders headers, String url, Object request, Class responseType, String method) - throws ConfigRestAdaptorException { - ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.valueOf(method), request, responseType); - return processResponse(response, url, HttpMethod.valueOf(method)); - } - - public RestResponse getResource(HttpHeaders headers, String url) throws ConfigRestAdaptorException { - return exchangeForEntity(headers, url, HttpMethod.GET, null); - } - - public RestResponse postResource(HttpHeaders headers, String url, Object request) - throws ConfigRestAdaptorException { - return exchangeForEntity(headers, url, HttpMethod.POST, request); - } - - public RestResponse exchangeResource(HttpHeaders headers, String url, Object request, String method) - throws ConfigRestAdaptorException { - return exchangeForEntity(headers, url, HttpMethod.valueOf(method), request); - } - - private RestResponse exchangeForEntity(HttpHeaders headers, String url, HttpMethod httpMethod, Object request) - throws ConfigRestAdaptorException { - RestResponse restResponse = new RestResponse(); - restResponse.setRequestHeaders(headers.toSingleValueMap()); - ResponseEntity response = null; - - try { - if (restTemplate == null) { - logger.error(MS_INIT_FAIL); - } else { - logger.debug("Rest Operation: {}", httpMethod); - logger.debug("url : ({})", url); - logger.debug("headers: ({})", headers); - logger.debug("request: ({})", request); - - if (HttpMethod.GET == httpMethod) { - HttpEntity entity = new HttpEntity<>("parameters", headers); - response = restTemplate.exchange(url, httpMethod, entity, String.class); - } else { - HttpEntity entity = new HttpEntity<>(request, headers); - response = restTemplate.exchange(url, httpMethod, entity, String.class); - } - logger.debug("response: ({})", response); - - if (response != null) { - logger.debug("response status code: ({})", response.getStatusCode()); - restResponse.setBody(response.getBody()); - restResponse.setStatusCode(response.getStatusCode().toString()); - restResponse.setResponseHeaders( - response.getHeaders() != null ? response.getHeaders().toSingleValueMap() : null); - return restResponse; - } - throw new ConfigRestAdaptorException("Rest exchangeForEntity failed to perform "); - } - } catch (HttpClientErrorException clientError) { - logger.debug("clientError: ({})", clientError); - restResponse.setBody(StringUtils.isBlank(clientError.getResponseBodyAsString()) ? clientError.getMessage() - : clientError.getResponseBodyAsString()); - restResponse.setStatusCode(clientError.getStatusCode().toString()); - } catch (Exception e) { - throw new ConfigRestAdaptorException( - String.format("httpMethod (%s) for url (%s) resulted in Exception (%s)", httpMethod, url, e)); - } - return restResponse; - } - - private ResponseEntity exchangeForEntity(HttpHeaders headers, String url, HttpMethod httpMethod, - Object request, Class responseType) throws ConfigRestAdaptorException { - ResponseEntity response = null; - - try { - if (restTemplate == null) { - logger.error(MS_INIT_FAIL); - } else { - logger.debug("Rest Operation: {}", httpMethod); - logger.debug("url : ({})", url); - logger.debug("headers: ({})", headers); - logger.debug("request: ({})", request); - - if (HttpMethod.GET == httpMethod) { - HttpEntity entity = new HttpEntity<>("parameters", headers); - response = restTemplate.exchange(url, httpMethod, entity, responseType); - } else { - HttpEntity entity = new HttpEntity<>(request, headers); - response = restTemplate.exchange(url, httpMethod, entity, responseType); - } - logger.debug("response: ({})", response); - - if (response != null) { - logger.debug("response status code: ({})", response.getStatusCode()); - } else { - throw new ConfigRestAdaptorException("exchangeForEntity failed to perform "); - } - } - } catch (Exception e) { - throw new ConfigRestAdaptorException( - String.format("httpMethod (%s) for url (%s) resulted in Exception (%s)", httpMethod, url, e)); - } - return response; - } - - protected synchronized T processResponse(ResponseEntity response, String url, HttpMethod httpMethod) - throws ConfigRestAdaptorException { - if (response != null) { - if ((HttpMethod.DELETE == httpMethod && (response.getStatusCode() == HttpStatus.NO_CONTENT - || response.getStatusCode() == HttpStatus.NOT_FOUND)) - || ((HttpMethod.GET == httpMethod || HttpMethod.PUT == httpMethod || HttpMethod.POST == httpMethod) - && (response.getStatusCode() == HttpStatus.OK - || response.getStatusCode() == HttpStatus.CREATED))) { - return response.getBody(); - } - throw new ConfigRestAdaptorException( - String.format("Rest Operation is failed with response-code (%s) for the URL (%s)", - response.getStatusCode(), url)); - } - throw new ConfigRestAdaptorException(String.format("Rest Operation is failed for the URL (%s)", url)); - } - - protected synchronized String constructUrl(String baseUrl, String path) { - if (StringUtils.isNotBlank(path)) { - return baseUrl + path; - } else { - return baseUrl; - } - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorService.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorService.java deleted file mode 100644 index 98c598acb..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorService.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; - -public interface ConfigRestAdaptorService { - - /** - * Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in - * defined responseType. - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - * @param responseType the type of the return value - */ - public T getResource(String selectorName, String path, Class responseType) throws ConfigRestAdaptorException; - - /** - * Create a new resource by POSTing the given object to the URI template, and returns the response - * as defined responseType - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - * @param request the Object to be POSTed, may be {@code null} - * @param responseType the type of the return value - */ - public T postResource(String selectorName, String path, Object request, Class responseType) - throws ConfigRestAdaptorException; - - /** - * Execute the HTTP method to the given URI template, writing the given request entity to the - * request, and returns the response as defined responseType - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - * @param request the Object to be POSTed, may be {@code null} - * @param responseType the type of the return value - * @param method the HTTP method (GET, POST, etc) - */ - public T exchangeResource(String selectorName, String path, Object request, Class responseType, - String method) throws ConfigRestAdaptorException; - - /** - * Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in - * defined responseType. - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - */ - public RestResponse getResource(String selectorName, String path) throws ConfigRestAdaptorException; - - /** - * Create a new resource by POSTing the given object to the URI template, and returns the response - * as defined responseType - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - * @param request the Object to be POSTed, may be {@code null} - */ - public RestResponse postResource(String selectorName, String path, Object request) - throws ConfigRestAdaptorException; - - /** - * Execute the HTTP method to the given URI template, writing the given request entity to the - * request, and returns the response as defined responseType - * - * @param selectorName the property selector - * @param path the URI path which will append in baseURL mentioned in selector property - * @param request the Object to be POSTed, may be {@code null} - * @param method the HTTP method (GET, POST, etc) - */ - public RestResponse exchangeResource(String selectorName, String path, Object request, String method) - throws ConfigRestAdaptorException; - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java deleted file mode 100644 index 65b9defd3..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import java.io.File; -import java.io.FileInputStream; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigRestAdaptorServiceImpl implements ConfigRestAdaptorService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigRestAdaptorServiceImpl.class); - private Map restProperties = new ConcurrentHashMap<>(); - - public ConfigRestAdaptorServiceImpl(String propertyPath) { - initializeProperties(propertyPath); - try { - String envType = restProperties.get(ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY - + ConfigRestAdaptorConstants.REST_ADAPTOR_ENV_TYPE); - - if (!(ConfigRestAdaptorConstants.PROPERTY_ENV_PROD.equalsIgnoreCase(envType) - || ConfigRestAdaptorConstants.PROPERTY_ENV_SOLO.equalsIgnoreCase(envType))) { - ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); - Runnable task = () -> { - initializeProperties(propertyPath); - }; - executor.scheduleWithFixedDelay(task, 60, 15, TimeUnit.MINUTES); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - private void initializeProperties(String propertyPath) { - logger.trace("Initialising Config rest adaptor Service with property directory ({})", propertyPath); - try { - if (StringUtils.isBlank(propertyPath)) { - propertyPath = System.getProperty(ConfigRestAdaptorConstants.SDNC_ROOT_DIR_ENV_VAR_KEY); - } - - if (StringUtils.isBlank(propertyPath)) { - throw new ConfigRestAdaptorException( - String.format("Failed to get the property directory (%s)", propertyPath)); - } - - // Loading Default config-rest-adaptor.properties - String propertyFile = - propertyPath + File.separator + ConfigRestAdaptorConstants.REST_ADAPTOR_PROPERTIES_FILE_NAME; - - Properties properties = new Properties(); - properties.load(new FileInputStream(propertyFile)); - - logger.trace("Initializing properties details for property file ({}) properties ({})", propertyFile, - properties); - restProperties.putAll(properties.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); - - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - @Override - public T getResource(String serviceSelector, String path, Class responseType) - throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).getResource(path, responseType); - } - - @Override - public T postResource(String serviceSelector, String path, Object request, Class responseType) - throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).postResource(path, request, responseType); - } - - @Override - public T exchangeResource(String serviceSelector, String path, Object request, Class responseType, - String method) throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).exchangeResource(path, request, responseType, - method); - } - - @Override - public RestResponse getResource(String serviceSelector, String path) throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).getResource(path); - } - - @Override - public RestResponse postResource(String serviceSelector, String path, Object request) - throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).postResource(path, request); - } - - @Override - public RestResponse exchangeResource(String serviceSelector, String path, Object request, String method) - throws ConfigRestAdaptorException { - return getRestClientAdapterBySelectorName(serviceSelector).exchangeResource(path, request, method); - } - - private ConfigRestClientServiceAdapter getRestClientAdapterBySelectorName(String serviceSelector) - throws ConfigRestAdaptorException { - String adoptorType = restProperties.get(ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_TYPE_PROPERTY); - if (StringUtils.isNotBlank(adoptorType)) { - if (ConfigRestAdaptorConstants.REST_ADAPTOR_TYPE_GENERIC.equalsIgnoreCase(adoptorType)) { - return new GenericRestClientAdapterImpl(restProperties, serviceSelector); - } else if (ConfigRestAdaptorConstants.REST_ADAPTOR_TYPE_SSL.equalsIgnoreCase(adoptorType)) { - return new SSLRestClientAdapterImpl(restProperties, serviceSelector); - } else { - throw new ConfigRestAdaptorException( - String.format("no implementation for rest adoptor type (%s) for the selector (%s).", - adoptorType, serviceSelector)); - } - } else { - throw new ConfigRestAdaptorException( - String.format("couldn't get rest adoptor type for the selector (%s)", serviceSelector)); - } - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestClientServiceAdapter.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestClientServiceAdapter.java deleted file mode 100644 index 46e954fb6..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/ConfigRestClientServiceAdapter.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; - -interface ConfigRestClientServiceAdapter { - - public T getResource(String path, Class responseType) throws ConfigRestAdaptorException; - - public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException; - - public T exchangeResource(String path, Object request, Class responseType, String method) - throws ConfigRestAdaptorException; - - public RestResponse getResource(String path) throws ConfigRestAdaptorException; - - public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException; - - public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException; - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java deleted file mode 100644 index 8cb5e9bea..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import java.util.Map; -import java.util.UUID; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapter { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(GenericRestClientAdapterImpl.class); - private String baseUrl = ""; - - public GenericRestClientAdapterImpl(Map properties, String serviceSelector) - throws ConfigRestAdaptorException { - super(properties, serviceSelector); - init(serviceSelector); - } - - private void init(String serviceSelector) throws ConfigRestAdaptorException { - try { - if (isRestClientServiceAdapaterEnabled) { - String baseUrlProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_BASEURL_PROPERTY; - String userProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_USER_PROPERTY; - String passProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_PSSWD_PROPERTY; - - baseUrl = properties.get(baseUrlProperty); - String userId = properties.get(userProperty); - String pass = properties.get(passProperty); - - initialise(userId, pass); - logger.info("Initialised restconf adaptor service for selector ({})", serviceSelector); - if (restTemplate == null) { - throw new ConfigRestAdaptorException("couldn't initialise rest selector (" + serviceSelector + ")"); - } - } else { - throw new ConfigRestAdaptorException("rest selector (" + serviceSelector + ") is not enabled"); - } - - } catch (Exception e) { - throw new ConfigRestAdaptorException("GenericRestClientServiceAdapter : " + e.getMessage(), e); - } - } - - @Override - public T getResource(String path, Class responseType) throws ConfigRestAdaptorException { - return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType); - } - - @Override - public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException { - return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType); - } - - @Override - public T exchangeResource(String path, Object request, Class responseType, String method) - throws ConfigRestAdaptorException { - return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method); - } - - @Override - public RestResponse getResource(String path) throws ConfigRestAdaptorException { - return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path)); - } - - @Override - public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException { - return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request); - } - - @Override - public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException { - return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method); - } - - private HttpHeaders formHttpHeaders() { - - HttpHeaders headers = new HttpHeaders(); - - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); - headers.add("X-TransactionId", generateUUID()); - headers.add("X-ECOMP-RequestID", headers.getFirst("X-TransactionId")); - - String appIDPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_APPID_PROPERTY; - String environmentPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_ENV_PROPERTY; - String clientAuthPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_CLIENTAUTH_PROPERTY; - String authorizationPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SERVICE_AUTHORIZATION_PROPERTY; - - if (StringUtils.isNotBlank(properties.get(appIDPath))) { - headers.add("X-FromAppId", properties.get(appIDPath)); - } - if (StringUtils.isNotBlank(properties.get(clientAuthPath))) { - headers.add("ClientAuth", properties.get(clientAuthPath)); - } - if (StringUtils.isNotBlank(properties.get(authorizationPath))) { - headers.add("Authorization", properties.get(authorizationPath)); - } - if (StringUtils.isNotBlank(properties.get(environmentPath))) { - headers.add("Environment", properties.get(environmentPath)); - } - - return headers; - } - - private synchronized String generateUUID() { - return UUID.randomUUID().toString(); - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/SSLRestClientAdapterImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/SSLRestClientAdapterImpl.java deleted file mode 100644 index e444d9f17..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/SSLRestClientAdapterImpl.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import java.util.Map; -import java.util.UUID; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.data.RestResponse; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class SSLRestClientAdapterImpl extends AbstractConfigRestClientAdapter { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(SSLRestClientAdapterImpl.class); - private String baseUrl = ""; - private String application = ""; - - public SSLRestClientAdapterImpl(Map properties, String serviceSelector) - throws ConfigRestAdaptorException { - super(properties, serviceSelector); - init(serviceSelector); - } - - private void init(String serviceSelector) throws ConfigRestAdaptorException { - try { - if (isSSLServiceAdapaterEnabled) { - - logger.info("Initializing SSL client for selector ({}), properties ({})", serviceSelector, properties); - - String baseUrlProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_BASEURL; - String applicationProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_APP; - String keyStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_KEY; - String keyStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_KEY_PSSWD; - String trustStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST; - String trustStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector - + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST_PSSWD; - - baseUrl = properties.get(baseUrlProp); - application = properties.get(applicationProp); - - String keyStorePath = properties.get(keyStorePathProp); - String trustStorePath = properties.get(trustStorePathProp); - String keyStorePass = properties.get(keyStorePassProp); - String trustStorePass = properties.get(trustStorePassProp); - - initialiseSSL(keyStorePath, trustStorePath, keyStorePass, trustStorePass); - logger.info("Initialised SSL Client Service adaptor service for selector ({})", serviceSelector); - if (restTemplate == null) { - throw new ConfigRestAdaptorException( - "couldn't initialise SSL Client selector (" + serviceSelector + ")"); - } - } else { - throw new ConfigRestAdaptorException("SSL Client selector (" + serviceSelector + ") is not enabled"); - } - - } catch (Exception e) { - throw new ConfigRestAdaptorException("SSLRestClientAdapterImpl : " + e.getMessage(), e); - } - } - - @Override - public T getResource(String path, Class responseType) throws ConfigRestAdaptorException { - return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType); - } - - @Override - public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException { - return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType); - } - - @Override - public T exchangeResource(String path, Object request, Class responseType, String method) - throws ConfigRestAdaptorException { - return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method); - } - - @Override - public RestResponse getResource(String path) throws ConfigRestAdaptorException { - return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path)); - } - - @Override - public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException { - return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request); - } - - @Override - public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException { - return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method); - } - - private HttpHeaders formHttpHeaders() { - - HttpHeaders headers = new HttpHeaders(); - - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); - headers.add("X-FromAppId", application); - headers.add("X-TransactionId", generateUUID()); - - return headers; - } - - private synchronized String generateUUID() { - return UUID.randomUUID().toString(); - } -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/BasicAuthorizationInterceptor.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/BasicAuthorizationInterceptor.java deleted file mode 100644 index b28c2c1a1..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/BasicAuthorizationInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.utils; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Base64; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.Assert; - -public class BasicAuthorizationInterceptor implements ClientHttpRequestInterceptor { - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - private final String username; - - private final String pass; - - /** - * Create a new interceptor which adds a BASIC authorization header for the given username and pass. - * - * @param username the username to use - * @param pass the password to use - */ - public BasicAuthorizationInterceptor(String username, String pass) { - Assert.hasLength(username, "Username must not be empty"); - this.username = username; - this.pass = (pass != null ? pass : ""); - } - - @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) - throws IOException { - - String token = Base64.getEncoder().encodeToString((this.username + ":" + this.pass).getBytes(UTF_8)); - request.getHeaders().add("Authorization", "Basic " + token); - return execution.execute(request, body); - } -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/LoggingRequestInterceptor.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/LoggingRequestInterceptor.java deleted file mode 100644 index 4095d62fe..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/utils/LoggingRequestInterceptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class LoggingRequestInterceptor implements ClientHttpRequestInterceptor { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(LoggingRequestInterceptor.class); - - @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) - throws IOException { - traceRequest(request, body); - ClientHttpResponse response = execution.execute(request, body); - traceResponse(response); - return response; - } - - @SuppressWarnings({"squid:S2629", "squid:S3457"}) - private void traceRequest(HttpRequest request, byte[] body) throws IOException { - logger.info("===========================request begin================================================"); - logger.info("URI : {}", request.getURI()); - logger.info("Method : {}", request.getMethod()); - logger.info("Headers : {}", request.getHeaders()); - logger.info("Request body: {}", new String(body, "UTF-8")); - logger.debug("==========================request end================================================"); - } - - @SuppressWarnings({"squid:S2629", "squid:S3457"}) - private void traceResponse(ClientHttpResponse response) throws IOException { - StringBuilder inputStringBuilder = new StringBuilder(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), "UTF-8")); - String line = bufferedReader.readLine(); - while (line != null) { - inputStringBuilder.append(line); - inputStringBuilder.append('\n'); - line = bufferedReader.readLine(); - } - logger.info("============================response begin=========================================="); - logger.info("Status code : {}", response.getStatusCode()); - logger.info("Status text : {}", response.getStatusText()); - logger.info("Headers : {}", response.getHeaders()); - logger.debug("Response body: {}", inputStringBuilder.toString()); - logger.debug("=======================response end================================================="); - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorConstants.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorConstants.java new file mode 100644 index 000000000..2f1ad0af2 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorConstants.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor; + +public class ConfigRestAdaptorConstants { + private ConfigRestAdaptorConstants() { + + } + + public static final String SDNC_ROOT_DIR_ENV_VAR_KEY = "SDNC_CONFIG_DIR"; + public static final String REST_ADAPTOR_PROPERTIES_FILE_NAME = "config-rest-adaptor.properties"; + public static final String PROXY_URL_KEY = "proxyUrl"; + public static final String PROXY_URLS_VALUE_SEPARATOR = ","; + public static final String AAF_USERNAME_KEY = "aafUserName"; + public static final String AAF_PSSWD_KEY = "aafPassword"; + public static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion"; + + public static final String PROPERTY_ENV_PROD = "field"; + public static final String PROPERTY_ENV_SOLO = "solo"; + + public static final String REST_ADAPTOR_BASE_PROPERTY = "org.onap.ccsdk.features.rest.adaptors."; + public static final String REST_ADAPTOR_ENV_TYPE = "envtype"; + public static final String REST_ADAPTOR_TYPE_GENERIC = "generic"; + public static final String REST_ADAPTOR_TYPE_SSL = "ssl"; + + public static final String SSL_SERVICE_BASEURL = ".url"; + public static final String SSL_SERVICE_APP = ".application"; + public static final String SSL_SERVICE_TRUST = ".ssl.trust"; + public static final String SSL_SERVICE_TRUST_PSSWD = ".ssl.trust.psswd"; + public static final String SSL_SERVICE_KEY = ".ssl.key"; + public static final String SSL_SERVICE_KEY_PSSWD = ".ssl.key.psswd"; + + public static final String SERVICE_TYPE_PROPERTY = ".type"; + public static final String SERVICE_EANABLED_PROPERTY = ".enable"; + public static final String SERVICE_ENV_PROPERTY = ".env"; + public static final String SERVICE_BASEURL_PROPERTY = ".url"; + public static final String SERVICE_PROPERTYFILE = ".propertyfile"; + public static final String SERVICE_USER_PROPERTY = ".user"; + public static final String SERVICE_APPID_PROPERTY = ".appId"; + public static final String SERVICE_PSSWD_PROPERTY = ".passwd"; + public static final String SERVICE_CLIENTAUTH_PROPERTY = ".clientAuth"; + public static final String SERVICE_AUTHORIZATION_PROPERTY = ".authorization"; + + public static final String SELECTOR_AAI = "aai"; + public static final String SELECTOR_ALTS = "alts"; + public static final String SELECTOR_EIPAM = "eipam"; + public static final String SELECTOR_COSMS = "cosms"; + public static final String SELECTOR_RESTCONF = "restconf"; + public static final String SELECTOR_MODEL_SERVICE = "modelservice"; + public static final String SELECTOR_POLICY_MANAGER = "policymanager"; + public static final String SELECTOR_NRD = "networkresourcediscovery"; + public static final String SELECTOR_NSM = "nsm"; + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorException.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorException.java new file mode 100644 index 000000000..163c30423 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/ConfigRestAdaptorException.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor; + +/** + * ConfigRestAdaptorException.java Purpose: Provide Configuration Rest Adaptor Exception + * + * @version 1.0 + */ +public class ConfigRestAdaptorException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * This is a ConfigRestAdaptorException constructor + * + * @param message + */ + public ConfigRestAdaptorException(String message) { + super(message); + } + + /** + * This is a ConfigRestAdaptorException constructor + * + * @param message + */ + public ConfigRestAdaptorException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/data/RestResponse.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/data/RestResponse.java new file mode 100644 index 000000000..f1a3c7290 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/data/RestResponse.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.data; + +import java.util.Map; + +public class RestResponse { + + private String statusCode; + private String body; + private Map parameters; + private Map responseHeaders; + private Map requestHeaders; + + public String getStatusCode() { + return statusCode; + } + + public void setStatusCode(String statusCode) { + this.statusCode = statusCode; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } + + public Map getResponseHeaders() { + return responseHeaders; + } + + public void setResponseHeaders(Map responseHeaders) { + this.responseHeaders = responseHeaders; + } + + public Map getRequestHeaders() { + return requestHeaders; + } + + public void setRequestHeaders(Map requestHeaders) { + this.requestHeaders = requestHeaders; + } + + @Override + public String toString() { + return "RestResponse [statusCode=" + statusCode + ", body=" + body + ", parameters=" + parameters + + ", responseHeaders=" + responseHeaders + ", requestHeaders=" + requestHeaders + "]"; + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapter.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapter.java new file mode 100644 index 000000000..207e87fc3 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapter.java @@ -0,0 +1,274 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.net.ssl.SSLContext; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.ssl.TrustStrategy; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; +import org.onap.ccsdk.features.rest.adaptor.utils.BasicAuthorizationInterceptor; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.ResourceHttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.util.ResourceUtils; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +abstract class AbstractConfigRestClientAdapter implements ConfigRestClientServiceAdapter { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(AbstractConfigRestClientAdapter.class); + private static final String MS_INIT_FAIL = "Failed to initialise microservice client restTemplate."; + + protected boolean isRestClientServiceAdapaterEnabled = false; + protected boolean isSSLServiceAdapaterEnabled = true; + + protected Map properties = new ConcurrentHashMap<>(); + protected String serviceSelector; + + protected RestTemplate restTemplate; + + protected AbstractConfigRestClientAdapter(Map properties, String serviceSelector) { + this.properties = properties; + this.serviceSelector = serviceSelector; + setRestClientServiceAdapaterEnabled(); + } + + private void setRestClientServiceAdapaterEnabled() { + String isEnabledProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_EANABLED_PROPERTY; + String isRestClientServiceAdapaterEnabledStr = properties.get(isEnabledProperty); + logger.info("Service selector ({}) enable status ({}) ", serviceSelector, + isRestClientServiceAdapaterEnabledStr); + if (StringUtils.isNotBlank(isRestClientServiceAdapaterEnabledStr) + && Boolean.parseBoolean(isRestClientServiceAdapaterEnabledStr)) { + isRestClientServiceAdapaterEnabled = true; + } + } + + private List> getMessageConverters() { + List> converters = new ArrayList<>(); + converters.add(new ByteArrayHttpMessageConverter()); + converters.add(new StringHttpMessageConverter()); + converters.add(new ResourceHttpMessageConverter()); + converters.add(new SourceHttpMessageConverter()); + converters.add(new MappingJackson2HttpMessageConverter()); + return converters; + } + + public void initialise(String user, String pass) { + logger.trace("Config rest template factory user ({}) ", user); + + CloseableHttpClient httpClient = + HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClient); + + restTemplate = new RestTemplate(getMessageConverters()); + restTemplate.setRequestFactory(requestFactory); + if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) { + restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(user, pass)); + } + } + + public void initialiseSSL(String keyStorePath, String trustStorePath, String keyPass, String trustPass) + throws ConfigRestAdaptorException { + logger.trace("SSL rest template factory"); + + TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; + SSLContext sslContext = null; + + try (InputStream keyInput = new FileInputStream(keyStorePath)) { + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(keyInput, keyPass.toCharArray()); + + logger.info("key loaded successfully"); + sslContext = SSLContextBuilder.create().loadKeyMaterial(keyStore, keyPass.toCharArray()).loadTrustMaterial( + ResourceUtils.getFile(trustStorePath), trustPass.toCharArray(), acceptingTrustStrategy).build(); + } catch (Exception e) { + throw new ConfigRestAdaptorException(e.getMessage()); + } + + SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); + CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); + + restTemplate = new RestTemplate(getMessageConverters()); + restTemplate.setRequestFactory(requestFactory); + } + + public T getResource(HttpHeaders headers, String url, Class responseType) throws ConfigRestAdaptorException { + ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.GET, null, responseType); + return processResponse(response, url, HttpMethod.GET); + } + + public T postResource(HttpHeaders headers, String url, Object request, Class responseType) + throws ConfigRestAdaptorException { + ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.POST, request, responseType); + return processResponse(response, url, HttpMethod.POST); + } + + public T exchangeResource(HttpHeaders headers, String url, Object request, Class responseType, String method) + throws ConfigRestAdaptorException { + ResponseEntity response = exchangeForEntity(headers, url, HttpMethod.valueOf(method), request, responseType); + return processResponse(response, url, HttpMethod.valueOf(method)); + } + + public RestResponse getResource(HttpHeaders headers, String url) throws ConfigRestAdaptorException { + return exchangeForEntity(headers, url, HttpMethod.GET, null); + } + + public RestResponse postResource(HttpHeaders headers, String url, Object request) + throws ConfigRestAdaptorException { + return exchangeForEntity(headers, url, HttpMethod.POST, request); + } + + public RestResponse exchangeResource(HttpHeaders headers, String url, Object request, String method) + throws ConfigRestAdaptorException { + return exchangeForEntity(headers, url, HttpMethod.valueOf(method), request); + } + + private RestResponse exchangeForEntity(HttpHeaders headers, String url, HttpMethod httpMethod, Object request) + throws ConfigRestAdaptorException { + RestResponse restResponse = new RestResponse(); + restResponse.setRequestHeaders(headers.toSingleValueMap()); + ResponseEntity response = null; + + try { + if (restTemplate == null) { + logger.error(MS_INIT_FAIL); + } else { + logger.debug("Rest Operation: {}", httpMethod); + logger.debug("url : ({})", url); + logger.debug("headers: ({})", headers); + logger.debug("request: ({})", request); + + if (HttpMethod.GET == httpMethod) { + HttpEntity entity = new HttpEntity<>("parameters", headers); + response = restTemplate.exchange(url, httpMethod, entity, String.class); + } else { + HttpEntity entity = new HttpEntity<>(request, headers); + response = restTemplate.exchange(url, httpMethod, entity, String.class); + } + logger.debug("response: ({})", response); + + if (response != null) { + logger.debug("response status code: ({})", response.getStatusCode()); + restResponse.setBody(response.getBody()); + restResponse.setStatusCode(response.getStatusCode().toString()); + restResponse.setResponseHeaders( + response.getHeaders() != null ? response.getHeaders().toSingleValueMap() : null); + return restResponse; + } + throw new ConfigRestAdaptorException("Rest exchangeForEntity failed to perform "); + } + } catch (HttpClientErrorException clientError) { + logger.debug("clientError: ({})", clientError); + restResponse.setBody(StringUtils.isBlank(clientError.getResponseBodyAsString()) ? clientError.getMessage() + : clientError.getResponseBodyAsString()); + restResponse.setStatusCode(clientError.getStatusCode().toString()); + } catch (Exception e) { + throw new ConfigRestAdaptorException( + String.format("httpMethod (%s) for url (%s) resulted in Exception (%s)", httpMethod, url, e)); + } + return restResponse; + } + + private ResponseEntity exchangeForEntity(HttpHeaders headers, String url, HttpMethod httpMethod, + Object request, Class responseType) throws ConfigRestAdaptorException { + ResponseEntity response = null; + + try { + if (restTemplate == null) { + logger.error(MS_INIT_FAIL); + } else { + logger.debug("Rest Operation: {}", httpMethod); + logger.debug("url : ({})", url); + logger.debug("headers: ({})", headers); + logger.debug("request: ({})", request); + + if (HttpMethod.GET == httpMethod) { + HttpEntity entity = new HttpEntity<>("parameters", headers); + response = restTemplate.exchange(url, httpMethod, entity, responseType); + } else { + HttpEntity entity = new HttpEntity<>(request, headers); + response = restTemplate.exchange(url, httpMethod, entity, responseType); + } + logger.debug("response: ({})", response); + + if (response != null) { + logger.debug("response status code: ({})", response.getStatusCode()); + } else { + throw new ConfigRestAdaptorException("exchangeForEntity failed to perform "); + } + } + } catch (Exception e) { + throw new ConfigRestAdaptorException( + String.format("httpMethod (%s) for url (%s) resulted in Exception (%s)", httpMethod, url, e)); + } + return response; + } + + protected synchronized T processResponse(ResponseEntity response, String url, HttpMethod httpMethod) + throws ConfigRestAdaptorException { + if (response != null) { + if ((HttpMethod.DELETE == httpMethod && (response.getStatusCode() == HttpStatus.NO_CONTENT + || response.getStatusCode() == HttpStatus.NOT_FOUND)) + || ((HttpMethod.GET == httpMethod || HttpMethod.PUT == httpMethod || HttpMethod.POST == httpMethod) + && (response.getStatusCode() == HttpStatus.OK + || response.getStatusCode() == HttpStatus.CREATED))) { + return response.getBody(); + } + throw new ConfigRestAdaptorException( + String.format("Rest Operation is failed with response-code (%s) for the URL (%s)", + response.getStatusCode(), url)); + } + throw new ConfigRestAdaptorException(String.format("Rest Operation is failed for the URL (%s)", url)); + } + + protected synchronized String constructUrl(String baseUrl, String path) { + if (StringUtils.isNotBlank(path)) { + return baseUrl + path; + } else { + return baseUrl; + } + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorService.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorService.java new file mode 100644 index 000000000..12e734ad3 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorService.java @@ -0,0 +1,92 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; + +public interface ConfigRestAdaptorService { + + /** + * Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in + * defined responseType. + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + * @param responseType the type of the return value + */ + public T getResource(String selectorName, String path, Class responseType) throws ConfigRestAdaptorException; + + /** + * Create a new resource by POSTing the given object to the URI template, and returns the response + * as defined responseType + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + * @param request the Object to be POSTed, may be {@code null} + * @param responseType the type of the return value + */ + public T postResource(String selectorName, String path, Object request, Class responseType) + throws ConfigRestAdaptorException; + + /** + * Execute the HTTP method to the given URI template, writing the given request entity to the + * request, and returns the response as defined responseType + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + * @param request the Object to be POSTed, may be {@code null} + * @param responseType the type of the return value + * @param method the HTTP method (GET, POST, etc) + */ + public T exchangeResource(String selectorName, String path, Object request, Class responseType, + String method) throws ConfigRestAdaptorException; + + /** + * Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in + * defined responseType. + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + */ + public RestResponse getResource(String selectorName, String path) throws ConfigRestAdaptorException; + + /** + * Create a new resource by POSTing the given object to the URI template, and returns the response + * as defined responseType + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + * @param request the Object to be POSTed, may be {@code null} + */ + public RestResponse postResource(String selectorName, String path, Object request) + throws ConfigRestAdaptorException; + + /** + * Execute the HTTP method to the given URI template, writing the given request entity to the + * request, and returns the response as defined responseType + * + * @param selectorName the property selector + * @param path the URI path which will append in baseURL mentioned in selector property + * @param request the Object to be POSTed, may be {@code null} + * @param method the HTTP method (GET, POST, etc) + */ + public RestResponse exchangeResource(String selectorName, String path, Object request, String method) + throws ConfigRestAdaptorException; + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java new file mode 100644 index 000000000..c05d6979a --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestAdaptorServiceImpl.java @@ -0,0 +1,146 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigRestAdaptorServiceImpl implements ConfigRestAdaptorService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigRestAdaptorServiceImpl.class); + private Map restProperties = new ConcurrentHashMap<>(); + + public ConfigRestAdaptorServiceImpl(String propertyPath) { + initializeProperties(propertyPath); + try { + String envType = restProperties.get(ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + + ConfigRestAdaptorConstants.REST_ADAPTOR_ENV_TYPE); + + if (!(ConfigRestAdaptorConstants.PROPERTY_ENV_PROD.equalsIgnoreCase(envType) + || ConfigRestAdaptorConstants.PROPERTY_ENV_SOLO.equalsIgnoreCase(envType))) { + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + Runnable task = () -> { + initializeProperties(propertyPath); + }; + executor.scheduleWithFixedDelay(task, 60, 15, TimeUnit.MINUTES); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + private void initializeProperties(String propertyPath) { + logger.trace("Initialising Config rest adaptor Service with property directory ({})", propertyPath); + try { + if (StringUtils.isBlank(propertyPath)) { + propertyPath = System.getProperty(ConfigRestAdaptorConstants.SDNC_ROOT_DIR_ENV_VAR_KEY); + } + + if (StringUtils.isBlank(propertyPath)) { + throw new ConfigRestAdaptorException( + String.format("Failed to get the property directory (%s)", propertyPath)); + } + + // Loading Default config-rest-adaptor.properties + String propertyFile = + propertyPath + File.separator + ConfigRestAdaptorConstants.REST_ADAPTOR_PROPERTIES_FILE_NAME; + + Properties properties = new Properties(); + properties.load(new FileInputStream(propertyFile)); + + logger.trace("Initializing properties details for property file ({}) properties ({})", propertyFile, + properties); + restProperties.putAll(properties.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); + + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + @Override + public T getResource(String serviceSelector, String path, Class responseType) + throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).getResource(path, responseType); + } + + @Override + public T postResource(String serviceSelector, String path, Object request, Class responseType) + throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).postResource(path, request, responseType); + } + + @Override + public T exchangeResource(String serviceSelector, String path, Object request, Class responseType, + String method) throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).exchangeResource(path, request, responseType, + method); + } + + @Override + public RestResponse getResource(String serviceSelector, String path) throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).getResource(path); + } + + @Override + public RestResponse postResource(String serviceSelector, String path, Object request) + throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).postResource(path, request); + } + + @Override + public RestResponse exchangeResource(String serviceSelector, String path, Object request, String method) + throws ConfigRestAdaptorException { + return getRestClientAdapterBySelectorName(serviceSelector).exchangeResource(path, request, method); + } + + private ConfigRestClientServiceAdapter getRestClientAdapterBySelectorName(String serviceSelector) + throws ConfigRestAdaptorException { + String adoptorType = restProperties.get(ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_TYPE_PROPERTY); + if (StringUtils.isNotBlank(adoptorType)) { + if (ConfigRestAdaptorConstants.REST_ADAPTOR_TYPE_GENERIC.equalsIgnoreCase(adoptorType)) { + return new GenericRestClientAdapterImpl(restProperties, serviceSelector); + } else if (ConfigRestAdaptorConstants.REST_ADAPTOR_TYPE_SSL.equalsIgnoreCase(adoptorType)) { + return new SSLRestClientAdapterImpl(restProperties, serviceSelector); + } else { + throw new ConfigRestAdaptorException( + String.format("no implementation for rest adoptor type (%s) for the selector (%s).", + adoptorType, serviceSelector)); + } + } else { + throw new ConfigRestAdaptorException( + String.format("couldn't get rest adoptor type for the selector (%s)", serviceSelector)); + } + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestClientServiceAdapter.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestClientServiceAdapter.java new file mode 100644 index 000000000..7ebc0ef48 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/ConfigRestClientServiceAdapter.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; + +interface ConfigRestClientServiceAdapter { + + public T getResource(String path, Class responseType) throws ConfigRestAdaptorException; + + public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException; + + public T exchangeResource(String path, Object request, Class responseType, String method) + throws ConfigRestAdaptorException; + + public RestResponse getResource(String path) throws ConfigRestAdaptorException; + + public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException; + + public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException; + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientAdapterImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientAdapterImpl.java new file mode 100644 index 000000000..6f9840a0b --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientAdapterImpl.java @@ -0,0 +1,139 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import java.util.Map; +import java.util.UUID; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapter { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(GenericRestClientAdapterImpl.class); + private String baseUrl = ""; + + public GenericRestClientAdapterImpl(Map properties, String serviceSelector) + throws ConfigRestAdaptorException { + super(properties, serviceSelector); + init(serviceSelector); + } + + private void init(String serviceSelector) throws ConfigRestAdaptorException { + try { + if (isRestClientServiceAdapaterEnabled) { + String baseUrlProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_BASEURL_PROPERTY; + String userProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_USER_PROPERTY; + String passProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_PSSWD_PROPERTY; + + baseUrl = properties.get(baseUrlProperty); + String userId = properties.get(userProperty); + String pass = properties.get(passProperty); + + initialise(userId, pass); + logger.info("Initialised restconf adaptor service for selector ({})", serviceSelector); + if (restTemplate == null) { + throw new ConfigRestAdaptorException("couldn't initialise rest selector (" + serviceSelector + ")"); + } + } else { + throw new ConfigRestAdaptorException("rest selector (" + serviceSelector + ") is not enabled"); + } + + } catch (Exception e) { + throw new ConfigRestAdaptorException("GenericRestClientServiceAdapter : " + e.getMessage(), e); + } + } + + @Override + public T getResource(String path, Class responseType) throws ConfigRestAdaptorException { + return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType); + } + + @Override + public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException { + return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType); + } + + @Override + public T exchangeResource(String path, Object request, Class responseType, String method) + throws ConfigRestAdaptorException { + return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method); + } + + @Override + public RestResponse getResource(String path) throws ConfigRestAdaptorException { + return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path)); + } + + @Override + public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException { + return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request); + } + + @Override + public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException { + return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method); + } + + private HttpHeaders formHttpHeaders() { + + HttpHeaders headers = new HttpHeaders(); + + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); + headers.add("X-TransactionId", generateUUID()); + headers.add("X-ECOMP-RequestID", headers.getFirst("X-TransactionId")); + + String appIDPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_APPID_PROPERTY; + String environmentPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_ENV_PROPERTY; + String clientAuthPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_CLIENTAUTH_PROPERTY; + String authorizationPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SERVICE_AUTHORIZATION_PROPERTY; + + if (StringUtils.isNotBlank(properties.get(appIDPath))) { + headers.add("X-FromAppId", properties.get(appIDPath)); + } + if (StringUtils.isNotBlank(properties.get(clientAuthPath))) { + headers.add("ClientAuth", properties.get(clientAuthPath)); + } + if (StringUtils.isNotBlank(properties.get(authorizationPath))) { + headers.add("Authorization", properties.get(authorizationPath)); + } + if (StringUtils.isNotBlank(properties.get(environmentPath))) { + headers.add("Environment", properties.get(environmentPath)); + } + + return headers; + } + + private synchronized String generateUUID() { + return UUID.randomUUID().toString(); + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/SSLRestClientAdapterImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/SSLRestClientAdapterImpl.java new file mode 100644 index 000000000..44736deb1 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/service/SSLRestClientAdapterImpl.java @@ -0,0 +1,131 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import java.util.Map; +import java.util.UUID; + +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.data.RestResponse; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class SSLRestClientAdapterImpl extends AbstractConfigRestClientAdapter { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(SSLRestClientAdapterImpl.class); + private String baseUrl = ""; + private String application = ""; + + public SSLRestClientAdapterImpl(Map properties, String serviceSelector) + throws ConfigRestAdaptorException { + super(properties, serviceSelector); + init(serviceSelector); + } + + private void init(String serviceSelector) throws ConfigRestAdaptorException { + try { + if (isSSLServiceAdapaterEnabled) { + + logger.info("Initializing SSL client for selector ({}), properties ({})", serviceSelector, properties); + + String baseUrlProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_BASEURL; + String applicationProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_APP; + String keyStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_KEY; + String keyStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_KEY_PSSWD; + String trustStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST; + String trustStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector + + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST_PSSWD; + + baseUrl = properties.get(baseUrlProp); + application = properties.get(applicationProp); + + String keyStorePath = properties.get(keyStorePathProp); + String trustStorePath = properties.get(trustStorePathProp); + String keyStorePass = properties.get(keyStorePassProp); + String trustStorePass = properties.get(trustStorePassProp); + + initialiseSSL(keyStorePath, trustStorePath, keyStorePass, trustStorePass); + logger.info("Initialised SSL Client Service adaptor service for selector ({})", serviceSelector); + if (restTemplate == null) { + throw new ConfigRestAdaptorException( + "couldn't initialise SSL Client selector (" + serviceSelector + ")"); + } + } else { + throw new ConfigRestAdaptorException("SSL Client selector (" + serviceSelector + ") is not enabled"); + } + + } catch (Exception e) { + throw new ConfigRestAdaptorException("SSLRestClientAdapterImpl : " + e.getMessage(), e); + } + } + + @Override + public T getResource(String path, Class responseType) throws ConfigRestAdaptorException { + return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType); + } + + @Override + public T postResource(String path, Object request, Class responseType) throws ConfigRestAdaptorException { + return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType); + } + + @Override + public T exchangeResource(String path, Object request, Class responseType, String method) + throws ConfigRestAdaptorException { + return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method); + } + + @Override + public RestResponse getResource(String path) throws ConfigRestAdaptorException { + return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path)); + } + + @Override + public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException { + return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request); + } + + @Override + public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException { + return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method); + } + + private HttpHeaders formHttpHeaders() { + + HttpHeaders headers = new HttpHeaders(); + + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); + headers.add("X-FromAppId", application); + headers.add("X-TransactionId", generateUUID()); + + return headers; + } + + private synchronized String generateUUID() { + return UUID.randomUUID().toString(); + } +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/BasicAuthorizationInterceptor.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/BasicAuthorizationInterceptor.java new file mode 100644 index 000000000..53b4ddf96 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/BasicAuthorizationInterceptor.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.utils; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Base64; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.util.Assert; + +public class BasicAuthorizationInterceptor implements ClientHttpRequestInterceptor { + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + private final String username; + + private final String pass; + + /** + * Create a new interceptor which adds a BASIC authorization header for the given username and pass. + * + * @param username the username to use + * @param pass the password to use + */ + public BasicAuthorizationInterceptor(String username, String pass) { + Assert.hasLength(username, "Username must not be empty"); + this.username = username; + this.pass = (pass != null ? pass : ""); + } + + @Override + public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) + throws IOException { + + String token = Base64.getEncoder().encodeToString((this.username + ":" + this.pass).getBytes(UTF_8)); + request.getHeaders().add("Authorization", "Basic " + token); + return execution.execute(request, body); + } +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/LoggingRequestInterceptor.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/LoggingRequestInterceptor.java new file mode 100644 index 000000000..cb618d05a --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/features/rest/adaptor/utils/LoggingRequestInterceptor.java @@ -0,0 +1,71 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class LoggingRequestInterceptor implements ClientHttpRequestInterceptor { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(LoggingRequestInterceptor.class); + + @Override + public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) + throws IOException { + traceRequest(request, body); + ClientHttpResponse response = execution.execute(request, body); + traceResponse(response); + return response; + } + + @SuppressWarnings({"squid:S2629", "squid:S3457"}) + private void traceRequest(HttpRequest request, byte[] body) throws IOException { + logger.info("===========================request begin================================================"); + logger.info("URI : {}", request.getURI()); + logger.info("Method : {}", request.getMethod()); + logger.info("Headers : {}", request.getHeaders()); + logger.info("Request body: {}", new String(body, "UTF-8")); + logger.debug("==========================request end================================================"); + } + + @SuppressWarnings({"squid:S2629", "squid:S3457"}) + private void traceResponse(ClientHttpResponse response) throws IOException { + StringBuilder inputStringBuilder = new StringBuilder(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), "UTF-8")); + String line = bufferedReader.readLine(); + while (line != null) { + inputStringBuilder.append(line); + inputStringBuilder.append('\n'); + line = bufferedReader.readLine(); + } + logger.info("============================response begin=========================================="); + logger.info("Status code : {}", response.getStatusCode()); + logger.info("Status text : {}", response.getStatusText()); + logger.info("Headers : {}", response.getHeaders()); + logger.debug("Response body: {}", inputStringBuilder.toString()); + logger.debug("=======================response end================================================="); + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 0b6a6ae11..dbc8b5231 100644 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -23,11 +23,11 @@ + class="org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl"> + interface="org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService" /> diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java deleted file mode 100644 index 6c7f114eb..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import java.io.FileInputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class AbstractConfigRestClientAdapterTest { - - Map properties = new HashMap<>(); - - @Before - public void setup() throws Exception { - String propertyfile = "src/test/resources/config-rest-adaptor.properties"; - - Properties restProperties = new Properties(); - restProperties.load(new FileInputStream(propertyfile)); - - properties.putAll(restProperties.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); - } - - @Test - public void testInitGenericRestClient() throws Exception { - ConfigRestClientServiceAdapter genericRestClient = new GenericRestClientAdapterImpl(properties, "modelservice"); - Assert.assertNotNull(genericRestClient); - } - - @Test - public void testInitSSLClient() throws Exception { - ConfigRestClientServiceAdapter sslClient = new SSLRestClientAdapterImpl(properties, "aai"); - Assert.assertNotNull(sslClient); - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java deleted file mode 100644 index 7e7f52261..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -@SuppressWarnings("unchecked") -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.net.ssl.*") -@PrepareForTest({AbstractConfigRestClientAdapter.class}) -public class GenericRestClientServiceTest { - - ConfigRestAdaptorService configRestAdaptorService; - - RestTemplate mockRestTemplate = mock(RestTemplate.class); - - String path = "path"; - - @Before - public void before() throws Exception { - whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate); - - String propertyDir = "src/test/resources"; - configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir); - } - - @Test - public void testGetResource() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.getResource("modelservice", path, String.class); - - Assert.assertEquals(responseBody, body); - } - - @Test - public void testPostResource() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.postResource("modelservice", path, null, String.class); - - Assert.assertEquals(responseBody, body); - } - - @Test - public void testExchange() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET"); - - Assert.assertEquals(responseBody, body); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testGetResourceError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response); - - configRestAdaptorService.getResource("modelservice", path, String.class); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testPostResourceError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any())) - .thenReturn(response); - - configRestAdaptorService.postResource("modelservice", path, null, String.class); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testExchangeError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET"); - } -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java deleted file mode 100644 index a5e757213..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.service; - -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -@SuppressWarnings("unchecked") -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.net.ssl.*") -@PrepareForTest({AbstractConfigRestClientAdapter.class}) -public class SSLClientServiceTest { - - ConfigRestAdaptorService configRestAdaptorService; - - RestTemplate mockRestTemplate = mock(RestTemplate.class); - - String path = "path"; - - @Before - public void before() throws Exception { - whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate); - - String propertyDir = "src/test/resources"; - configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir); - } - - @Test - public void testGetResource() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.getResource("aai", path, String.class); - - Assert.assertEquals(responseBody, body); - } - - @Test - public void testPostResource() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.postResource("aai", path, null, String.class); - - Assert.assertEquals(responseBody, body); - } - - @Test - public void testExchange() throws Exception { - String responseBody = "sampleBodyString"; - ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - String body = configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET"); - - Assert.assertEquals(responseBody, body); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testGetResourceError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response); - - configRestAdaptorService.getResource("aai", path, String.class); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testPostResourceError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any())) - .thenReturn(response); - - configRestAdaptorService.postResource("aai", path, null, String.class); - } - - @Test(expected = ConfigRestAdaptorException.class) - public void testExchangeError() throws Exception { - ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); - when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), - Matchers.any(Class.class))).thenReturn(response); - - configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET"); - } -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java deleted file mode 100644 index e1d0268e1..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.config.rest.adaptor.utils; - -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorServiceImpl; - -@SuppressWarnings("squid:S2187") -public class RestTemplateFactoryTest { - - public static void main(String[] args) { - - String propertyFile = RestTemplateFactoryTest.class.getClassLoader().getResource(".").getPath(); - System.out.println(" Property : " + propertyFile); - - try { - ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl = new ConfigRestAdaptorServiceImpl(propertyFile); - String restconfResponse = genericRestGetMDSALOperation(args, configRestAdaptorServiceImpl); - System.out.println("RestTemplateFactoryTest.main Completed with response :" + restconfResponse); - } catch (ConfigRestAdaptorException e) { - e.printStackTrace(); - } - } - - public static String genericRestGetMDSALOperation(String[] args, - ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl) throws ConfigRestAdaptorException { - String path = "config/Dummy-API:services/service-list/dummy-1234"; - String restconfResponse = configRestAdaptorServiceImpl.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF, - path, String.class); - return restconfResponse; - } - -} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java new file mode 100644 index 000000000..2e091591b --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestClientServiceAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.GenericRestClientAdapterImpl; +import org.onap.ccsdk.features.rest.adaptor.service.SSLRestClientAdapterImpl; + +public class AbstractConfigRestClientAdapterTest { + + Map properties = new HashMap<>(); + + @Before + public void setup() throws Exception { + String propertyfile = "src/test/resources/config-rest-adaptor.properties"; + + Properties restProperties = new Properties(); + restProperties.load(new FileInputStream(propertyfile)); + + properties.putAll(restProperties.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); + } + + @Test + public void testInitGenericRestClient() throws Exception { + ConfigRestClientServiceAdapter genericRestClient = new GenericRestClientAdapterImpl(properties, "modelservice"); + Assert.assertNotNull(genericRestClient); + } + + @Test + public void testInitSSLClient() throws Exception { + ConfigRestClientServiceAdapter sslClient = new SSLRestClientAdapterImpl(properties, "aai"); + Assert.assertNotNull(sslClient); + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java new file mode 100644 index 000000000..f660cca10 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java @@ -0,0 +1,121 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.AbstractConfigRestClientAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +@SuppressWarnings("unchecked") +@RunWith(PowerMockRunner.class) +@PowerMockIgnore("javax.net.ssl.*") +@PrepareForTest({AbstractConfigRestClientAdapter.class}) +public class GenericRestClientServiceTest { + + ConfigRestAdaptorService configRestAdaptorService; + + RestTemplate mockRestTemplate = mock(RestTemplate.class); + + String path = "path"; + + @Before + public void before() throws Exception { + whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate); + + String propertyDir = "src/test/resources"; + configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir); + } + + @Test + public void testGetResource() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.getResource("modelservice", path, String.class); + + Assert.assertEquals(responseBody, body); + } + + @Test + public void testPostResource() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.postResource("modelservice", path, null, String.class); + + Assert.assertEquals(responseBody, body); + } + + @Test + public void testExchange() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET"); + + Assert.assertEquals(responseBody, body); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testGetResourceError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response); + + configRestAdaptorService.getResource("modelservice", path, String.class); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testPostResourceError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any())) + .thenReturn(response); + + configRestAdaptorService.postResource("modelservice", path, null, String.class); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testExchangeError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET"); + } +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java new file mode 100644 index 000000000..e8b3a02ed --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java @@ -0,0 +1,121 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.service; + +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.AbstractConfigRestClientAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +@SuppressWarnings("unchecked") +@RunWith(PowerMockRunner.class) +@PowerMockIgnore("javax.net.ssl.*") +@PrepareForTest({AbstractConfigRestClientAdapter.class}) +public class SSLClientServiceTest { + + ConfigRestAdaptorService configRestAdaptorService; + + RestTemplate mockRestTemplate = mock(RestTemplate.class); + + String path = "path"; + + @Before + public void before() throws Exception { + whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate); + + String propertyDir = "src/test/resources"; + configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir); + } + + @Test + public void testGetResource() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.getResource("aai", path, String.class); + + Assert.assertEquals(responseBody, body); + } + + @Test + public void testPostResource() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.postResource("aai", path, null, String.class); + + Assert.assertEquals(responseBody, body); + } + + @Test + public void testExchange() throws Exception { + String responseBody = "sampleBodyString"; + ResponseEntity response = new ResponseEntity(responseBody, HttpStatus.OK); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + String body = configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET"); + + Assert.assertEquals(responseBody, body); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testGetResourceError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response); + + configRestAdaptorService.getResource("aai", path, String.class); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testPostResourceError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any())) + .thenReturn(response); + + configRestAdaptorService.postResource("aai", path, null, String.class); + } + + @Test(expected = ConfigRestAdaptorException.class) + public void testExchangeError() throws Exception { + ResponseEntity response = new ResponseEntity("", HttpStatus.INTERNAL_SERVER_ERROR); + when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(), + Matchers.any(Class.class))).thenReturn(response); + + configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET"); + } +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java new file mode 100644 index 000000000..cee91d297 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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. + */ + +package org.onap.ccsdk.features.rest.adaptor.utils; + +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl; + +@SuppressWarnings("squid:S2187") +public class RestTemplateFactoryTest { + + public static void main(String[] args) { + + String propertyFile = RestTemplateFactoryTest.class.getClassLoader().getResource(".").getPath(); + System.out.println(" Property : " + propertyFile); + + try { + ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl = new ConfigRestAdaptorServiceImpl(propertyFile); + String restconfResponse = genericRestGetMDSALOperation(args, configRestAdaptorServiceImpl); + System.out.println("RestTemplateFactoryTest.main Completed with response :" + restconfResponse); + } catch (ConfigRestAdaptorException e) { + e.printStackTrace(); + } + } + + public static String genericRestGetMDSALOperation(String[] args, + ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl) throws ConfigRestAdaptorException { + String path = "config/Dummy-API:services/service-list/dummy-1234"; + String restconfResponse = configRestAdaptorServiceImpl.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF, + path, String.class); + return restconfResponse; + } + +} diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties index 4527e8977..22748259b 100644 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties @@ -18,28 +18,28 @@ # Configuration file for SDNC Controller Module # -org.onap.ccsdk.config.rest.adaptors.envtype=solo +org.onap.ccsdk.features.rest.adaptors.envtype=solo # Config Generator Microservices -org.onap.ccsdk.config.rest.adaptors.modelservice.type=generic -org.onap.ccsdk.config.rest.adaptors.modelservice.enable=true -org.onap.ccsdk.config.rest.adaptors.modelservice.url=http://localhost:8080/configgenerator/service/ -org.onap.ccsdk.config.rest.adaptors.modelservice.user=admin -org.onap.ccsdk.config.rest.adaptors.modelservice.passwd=admin +org.onap.ccsdk.features.rest.adaptors.modelservice.type=generic +org.onap.ccsdk.features.rest.adaptors.modelservice.enable=true +org.onap.ccsdk.features.rest.adaptors.modelservice.url=http://localhost:8080/configgenerator/service/ +org.onap.ccsdk.features.rest.adaptors.modelservice.user=admin +org.onap.ccsdk.features.rest.adaptors.modelservice.passwd=admin # Generic RESTCONF Adaptor -org.onap.ccsdk.config.rest.adaptors.restconf.type=generic -org.onap.ccsdk.config.rest.adaptors.restconf.enable=true -org.onap.ccsdk.config.rest.adaptors.restconf.user=admin -org.onap.ccsdk.config.rest.adaptors.restconf.passwd=admin -org.onap.ccsdk.config.rest.adaptors.restconf.url=http://localhost:8181/restconf/ +org.onap.ccsdk.features.rest.adaptors.restconf.type=generic +org.onap.ccsdk.features.rest.adaptors.restconf.enable=true +org.onap.ccsdk.features.rest.adaptors.restconf.user=admin +org.onap.ccsdk.features.rest.adaptors.restconf.passwd=admin +org.onap.ccsdk.features.rest.adaptors.restconf.url=http://localhost:8181/restconf/ # SSL AAI Adaptor -org.onap.ccsdk.config.rest.adaptors.aai.propertyfile=aai.properties -org.onap.ccsdk.config.rest.adaptors.aai.type=ssl -org.onap.ccsdk.config.rest.adaptors.aai.enable=true -org.onap.ccsdk.config.rest.adaptors.aai.url=https://localhost:8443/onap-aai/ -org.onap.ccsdk.config.rest.adaptors.aai.ssl.trust=src/test/resources/truststore.client.jks -org.onap.ccsdk.config.rest.adaptors.aai.ssl.trust.psswd=changeme -org.onap.ccsdk.config.rest.adaptors.aai.ssl.key=src/test/resources/keystore.client.p12 -org.onap.ccsdk.config.rest.adaptors.aai.ssl.key.psswd=changeme +org.onap.ccsdk.features.rest.adaptors.aai.propertyfile=aai.properties +org.onap.ccsdk.features.rest.adaptors.aai.type=ssl +org.onap.ccsdk.features.rest.adaptors.aai.enable=true +org.onap.ccsdk.features.rest.adaptors.aai.url=https://localhost:8443/onap-aai/ +org.onap.ccsdk.features.rest.adaptors.aai.ssl.trust=src/test/resources/truststore.client.jks +org.onap.ccsdk.features.rest.adaptors.aai.ssl.trust.psswd=changeme +org.onap.ccsdk.features.rest.adaptors.aai.ssl.key=src/test/resources/keystore.client.p12 +org.onap.ccsdk.features.rest.adaptors.aai.ssl.key.psswd=changeme -- cgit 1.2.3-korg