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.logging.context.impl.MdcDataDebugMessage;
28 import org.openecomp.sdc.logging.types.LoggerConstants;
29 import org.openecomp.sdc.logging.types.LoggerServiceName;
30 import org.openecomp.sdcrests.applicationconfig.rest.ApplicationConfiguration;
31 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto;
32 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto;
33 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
34 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
35 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Scope;
39 import org.springframework.stereotype.Service;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
43 import java.io.InputStream;
44 import java.util.Collection;
47 * Created by Talio on 8/8/2016.
51 @Service("applicationConfiguration")
52 @Scope(value = "prototype")
53 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
55 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
57 private ApplicationConfigManager applicationConfigManager;
60 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
62 mdcDataDebugMessage.debugEntryMessage(null, null);
64 MDC.put(LoggerConstants.SERVICE_NAME,
65 LoggerServiceName.Insert_To_ApplicationConfig_Table.toString());
66 String value = new String(FileUtils.toByteArray(fileContainingSchema));
68 applicationConfigManager.insertIntoTable(namespace, key, value);
70 mdcDataDebugMessage.debugExitMessage(null, null);
71 return Response.ok().build();
75 public Response getFromTable(String namespace, String key) {
77 mdcDataDebugMessage.debugEntryMessage(null, null);
79 MDC.put(LoggerConstants.SERVICE_NAME,
80 LoggerServiceName.Get_From_ApplicationConfig_Table.toString());
81 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
82 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
83 .applyMapping(value, ConfigurationDataDto.class);
85 mdcDataDebugMessage.debugExitMessage(null, null);
87 return Response.ok(valueDto).build();
91 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
93 mdcDataDebugMessage.debugEntryMessage(null, null);
95 MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName
96 .Get_List_From_ApplicationConfig_Table_By_Namespace.toString());
97 Collection<ApplicationConfigEntity> applicationConfigEntities =
98 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
99 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
100 new GenericCollectionWrapper<>();
101 MapApplicationConfigEntityToApplicationConfigDto mapper =
102 new MapApplicationConfigEntityToApplicationConfigDto();
104 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
105 applicationConfigWrapper
106 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
109 mdcDataDebugMessage.debugExitMessage(null, null);
111 return Response.ok(applicationConfigWrapper).build();