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.types.LoggerConstants;
28 import org.openecomp.sdc.logging.types.LoggerServiceName;
29 import org.openecomp.sdcrests.applicationconfig.rest.ApplicationConfiguration;
30 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto;
31 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto;
32 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
33 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
34 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.Scope;
38 import org.springframework.stereotype.Service;
40 import javax.inject.Named;
41 import javax.ws.rs.core.Response;
42 import java.io.InputStream;
43 import java.util.Collection;
46 * Created by Talio on 8/8/2016.
50 @Service("applicationConfiguration")
51 @Scope(value = "prototype")
52 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
54 private ApplicationConfigManager applicationConfigManager;
57 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
58 MDC.put(LoggerConstants.SERVICE_NAME,
59 LoggerServiceName.Insert_To_ApplicationConfig_Table.toString());
60 String value = new String(FileUtils.toByteArray(fileContainingSchema));
62 applicationConfigManager.insertIntoTable(namespace, key, value);
63 return Response.ok().build();
67 public Response getFromTable(String namespace, String key) {
68 MDC.put(LoggerConstants.SERVICE_NAME,
69 LoggerServiceName.Get_From_ApplicationConfig_Table.toString());
70 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
71 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
72 .applyMapping(value, ConfigurationDataDto.class);
73 return Response.ok(valueDto).build();
77 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
78 MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName
79 .Get_List_From_ApplicationConfig_Table_By_Namespace.toString());
80 Collection<ApplicationConfigEntity> applicationConfigEntities =
81 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
82 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
83 new GenericCollectionWrapper<>();
84 MapApplicationConfigEntityToApplicationConfigDto mapper =
85 new MapApplicationConfigEntityToApplicationConfigDto();
87 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
88 applicationConfigWrapper
89 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
91 return Response.ok(applicationConfigWrapper).build();