376cfca93318c9101e5d307a32d9cbddd9bb4598
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.applicationconfig.impl;
22
23 import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
24 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
25 import org.openecomp.core.utilities.applicationconfig.impl.ApplicationConfigImpl;
26 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
27 import org.openecomp.sdc.applicationconfig.ApplicationConfigManager;
28 import org.openecomp.sdc.common.errors.CoreException;
29 import org.openecomp.sdc.common.errors.ErrorCategory;
30 import org.openecomp.sdc.common.errors.ErrorCode;
31 import org.openecomp.sdc.datatypes.error.ErrorLevel;
32 import org.openecomp.sdc.logging.api.Logger;
33 import org.openecomp.sdc.logging.api.LoggerFactory;
34 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
35 import org.openecomp.sdc.logging.types.LoggerConstants;
36 import org.openecomp.sdc.logging.types.LoggerErrorCode;
37 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
38 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
39
40 import java.util.Collection;
41
42 /**
43  * Created by Talio on 8/8/2016.
44  */
45 public class ApplicationConfigManagerImpl implements ApplicationConfigManager {
46
47   private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
48
49   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
50       "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
51   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
52       "Error occurred while loading questionnaire schema templates";
53   private ApplicationConfig applicationConfig = new ApplicationConfigImpl();
54
55   @Override
56   public void insertIntoTable(String namespace, String key, String value) {
57     try {
58       applicationConfig.insertValue(namespace, key, value);
59     } catch (Exception exception) {
60       log.debug("",exception);
61       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
62           LoggerTragetServiceName.INSERT_INTO_APPLICATION_CONFIG, ErrorLevel.ERROR.name(),
63           LoggerErrorCode.DATA_ERROR.getErrorCode(),
64           LoggerErrorDescription.INSERT_INTO_APPLICATION_CONFIG);
65       throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory
66           .APPLICATION).withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).withMessage(
67           SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).build());
68     }
69   }
70
71   @Override
72   public ConfigurationData getFromTable(String namespace, String key) {
73     return applicationConfig.getConfigurationData(namespace, key);
74   }
75
76   @Override
77   public Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace) {
78     return applicationConfig.getListOfConfigurationByNamespace(namespace);
79   }
80 }