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;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Named;
38 import javax.ws.rs.core.Response;
39 import java.io.InputStream;
40 import java.util.Collection;
43 * Created by Talio on 8/8/2016.
47 @Service("applicationConfiguration")
48 @Scope(value = "prototype")
49 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
51 private ApplicationConfigManager applicationConfigManager;
54 public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
55 String value = new String(FileUtils.toByteArray(fileContainingSchema));
56 applicationConfigManager.insertIntoTable(namespace, key, value);
57 return Response.ok().build();
61 public Response getFromTable(String namespace, String key) {
62 ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
63 ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
64 .applyMapping(value, ConfigurationDataDto.class);
65 return Response.ok(valueDto).build();
69 public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
70 Collection<ApplicationConfigEntity> applicationConfigEntities =
71 applicationConfigManager.getListOfConfigurationByNamespace(namespace);
72 GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
73 new GenericCollectionWrapper<>();
74 MapApplicationConfigEntityToApplicationConfigDto mapper =
75 new MapApplicationConfigEntityToApplicationConfigDto();
77 for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
78 applicationConfigWrapper
79 .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
81 return Response.ok(applicationConfigWrapper).build();