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.sdcrests.applicationconfig.rest.ApplicationConfiguration;
28 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto;
29 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto;
30 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
31 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
32 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Scope;
36 import org.springframework.stereotype.Service;
38 import java.io.InputStream;
39 import java.util.Collection;
40 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
45 @Service("applicationConfiguration")
46 @Scope(value = "prototype")
47 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
50 private ApplicationConfigManager applicationConfigManager;
54 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
55 String value = new String(FileUtils.toByteArray(fileContainingSchema));
57 applicationConfigManager.insertIntoTable(namespace, key, value);
59 return Response.ok().build();
63 public Response getFromTable(String namespace, String key) {
64 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
65 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
66 .applyMapping(value, ConfigurationDataDto.class);
68 return Response.ok(valueDto).build();
72 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
73 Collection<ApplicationConfigEntity> applicationConfigEntities =
74 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
75 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
76 new GenericCollectionWrapper<>();
77 MapApplicationConfigEntityToApplicationConfigDto mapper =
78 new MapApplicationConfigEntityToApplicationConfigDto();
80 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
81 applicationConfigWrapper
82 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
85 return Response.ok(applicationConfigWrapper).build();