[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / application-config-rest / application-config-rest-services / src / main / java / org / openecomp / sdcrests / applicationconfig / rest / services / ApplicationConfigurationImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  */
20
21 package org.openecomp.sdcrests.applicationconfig.rest.services;
22
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.common.utils.CommonUtil;
28 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
29 import org.openecomp.sdc.logging.types.LoggerConstants;
30 import org.openecomp.sdc.logging.types.LoggerServiceName;
31 import org.openecomp.sdcrests.applicationconfig.rest.ApplicationConfiguration;
32 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto;
33 import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto;
34 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
35 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
36 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
37 import org.slf4j.MDC;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Scope;
40 import org.springframework.stereotype.Service;
41
42 import java.io.InputStream;
43 import java.util.Collection;
44 import javax.inject.Named;
45 import javax.ws.rs.core.Response;
46
47 /**
48  * Created by Talio on 8/8/2016.
49  */
50
51 @Named
52 @Service("applicationConfiguration")
53 @Scope(value = "prototype")
54 public class ApplicationConfigurationImpl implements ApplicationConfiguration {
55
56   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
57   @Autowired
58   private ApplicationConfigManager applicationConfigManager;
59
60   @Override
61   public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) {
62
63     mdcDataDebugMessage.debugEntryMessage(null, null);
64
65     MDC.put(LoggerConstants.SERVICE_NAME,
66         LoggerServiceName.Insert_To_ApplicationConfig_Table.toString());
67     String value = new String(FileUtils.toByteArray(fileContainingSchema));
68
69     applicationConfigManager.insertIntoTable(namespace, key, value);
70
71     mdcDataDebugMessage.debugExitMessage(null, null);
72     return Response.ok().build();
73   }
74
75   @Override
76   public Response getFromTable(String namespace, String key) {
77
78     mdcDataDebugMessage.debugEntryMessage(null, null);
79
80     MDC.put(LoggerConstants.SERVICE_NAME,
81         LoggerServiceName.Get_From_ApplicationConfig_Table.toString());
82     ConfigurationData value = applicationConfigManager.getFromTable(namespace, key);
83     ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto()
84         .applyMapping(value, ConfigurationDataDto.class);
85
86     mdcDataDebugMessage.debugExitMessage(null, null);
87
88     return Response.ok(valueDto).build();
89   }
90
91   @Override
92   public Response getListOfConfigurationByNamespaceFromTable(String namespace) {
93
94     mdcDataDebugMessage.debugEntryMessage(null, null);
95
96     MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName
97         .Get_List_From_ApplicationConfig_Table_By_Namespace.toString());
98     Collection<ApplicationConfigEntity> applicationConfigEntities =
99         applicationConfigManager.getListOfConfigurationByNamespace(namespace);
100     GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper =
101         new GenericCollectionWrapper<>();
102     MapApplicationConfigEntityToApplicationConfigDto mapper =
103         new MapApplicationConfigEntityToApplicationConfigDto();
104
105     for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) {
106       applicationConfigWrapper
107           .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class));
108     }
109
110     mdcDataDebugMessage.debugExitMessage(null, null);
111
112     return Response.ok(applicationConfigWrapper).build();
113   }
114 }