2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdcrests.applicationconfig.rest.services;
23 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
24 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
25 import org.openecomp.core.utilities.file.FileUtils;
26 import org.openecomp.sdc.applicationconfig.ApplicationConfigManager;
27 import org.openecomp.sdc.common.utils.CommonUtil;
28 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
29 import org.openecomp.sdc.logging.types.LoggerConstants;
30 import org.openecomp.sdc.logging.types.LoggerServiceName;
31 import org.openecomp.sdcrests.applicationconfig.rest.ApplicationConfiguration;
32 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto;
33 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto;
34 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
35 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
36 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Scope;
40 import org.springframework.stereotype.Service;
42 import java.io.InputStream;
43 import java.util.Collection;
44 import javax.inject.Named;
45 import javax.ws.rs.core.Response;
48 * Created by Talio on 8/8/2016.
52 @Service("applicationConfiguration")
53 @Scope(value = "prototype")
54 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
56 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
58 private ApplicationConfigManager applicationConfigManager;
61 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
63 mdcDataDebugMessage.debugEntryMessage(null, null);
65 MDC.put(LoggerConstants.SERVICE_NAME,
66 LoggerServiceName.Insert_To_ApplicationConfig_Table.toString());
67 String value = new String(FileUtils.toByteArray(fileContainingSchema));
69 applicationConfigManager.insertIntoTable(namespace, key, value);
71 mdcDataDebugMessage.debugExitMessage(null, null);
72 return Response.ok().build();
76 public Response getFromTable(String namespace, String key) {
78 mdcDataDebugMessage.debugEntryMessage(null, null);
80 MDC.put(LoggerConstants.SERVICE_NAME,
81 LoggerServiceName.Get_From_ApplicationConfig_Table.toString());
82 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
83 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
84 .applyMapping(value, ConfigurationDataDto.class);
86 mdcDataDebugMessage.debugExitMessage(null, null);
88 return Response.ok(valueDto).build();
92 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
94 mdcDataDebugMessage.debugEntryMessage(null, null);
96 MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName
97 .Get_List_From_ApplicationConfig_Table_By_Namespace.toString());
98 Collection<ApplicationConfigEntity> applicationConfigEntities =
99 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
100 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
101 new GenericCollectionWrapper<>();
102 MapApplicationConfigEntityToApplicationConfigDto mapper =
103 new MapApplicationConfigEntityToApplicationConfigDto();
105 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
106 applicationConfigWrapper
107 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
110 mdcDataDebugMessage.debugExitMessage(null, null);
112 return Response.ok(applicationConfigWrapper).build();