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=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
23 package org.openecomp.sdcrests.applicationconfig.rest.services;
25 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
26 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
27 import org.openecomp.core.utilities.file.FileUtils;
28 import org.openecomp.sdc.applicationconfig.ApplicationConfigManager;
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;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
39 import javax.inject.Named;
40 import javax.ws.rs.core.Response;
41 import java.io.InputStream;
42 import java.util.Collection;
45 * Created by Talio on 8/8/2016.
49 @Service("applicationConfiguration")
50 @Scope(value = "prototype")
51 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
53 private final ApplicationConfigManager applicationConfigManager;
56 public ApplicationConfigurationImpl(ApplicationConfigManager applicationConfigManager) {
57 this.applicationConfigManager = applicationConfigManager;
61 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
62 String value = new String(FileUtils.toByteArray(fileContainingSchema));
63 applicationConfigManager.insertIntoTable(namespace, key, value);
64 return Response.ok().build();
68 public Response getFromTable(String namespace, String key) {
69 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
70 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
71 .applyMapping(value, ConfigurationDataDto.class);
72 return Response.ok(valueDto).build();
76 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
77 Collection<ApplicationConfigEntity> applicationConfigEntities =
78 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
79 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
80 new GenericCollectionWrapper<>();
81 MapApplicationConfigEntityToApplicationConfigDto mapper =
82 new MapApplicationConfigEntityToApplicationConfigDto();
84 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
85 applicationConfigWrapper
86 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
88 return Response.ok(applicationConfigWrapper).build();