Rework some sonar critical and major bugs
[clamp.git] / src / main / java / org / onap / clamp / clds / config / CldsConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.config;
25
26 import com.att.ajsc.common.AjscProvider;
27 import com.att.ajsc.common.AjscService;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import javax.sql.DataSource;
33 import javax.xml.transform.TransformerConfigurationException;
34
35 import org.onap.clamp.clds.client.CldsEventDelegate;
36 import org.onap.clamp.clds.client.DcaeDispatcherServices;
37 import org.onap.clamp.clds.client.DcaeInventoryServices;
38 import org.onap.clamp.clds.client.DcaeReqDelegate;
39 import org.onap.clamp.clds.client.DcaeReqDeleteDelegate;
40 import org.onap.clamp.clds.client.OperationalPolicyDelegate;
41 import org.onap.clamp.clds.client.OperationalPolicyDeleteDelegate;
42 import org.onap.clamp.clds.client.PolicyClient;
43 import org.onap.clamp.clds.client.SdcCatalogServices;
44 import org.onap.clamp.clds.client.SdcSendReqDelegate;
45 import org.onap.clamp.clds.client.StringMatchPolicyDelegate;
46 import org.onap.clamp.clds.client.StringMatchPolicyDeleteDelegate;
47 import org.onap.clamp.clds.client.TcaPolicyDelegate;
48 import org.onap.clamp.clds.client.TcaPolicyDeleteDelegate;
49 import org.onap.clamp.clds.dao.CldsDao;
50 import org.onap.clamp.clds.model.refprop.RefProp;
51 import org.onap.clamp.clds.transform.XslTransformer;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
54 import org.springframework.boot.context.properties.ConfigurationProperties;
55 import org.springframework.context.ApplicationContext;
56 import org.springframework.context.annotation.Bean;
57 import org.springframework.context.annotation.Configuration;
58 import org.springframework.context.annotation.Profile;
59
60 @Configuration
61 @Profile("clamp-default")
62 public class CldsConfiguration {
63
64     @Autowired
65     private ApplicationContext context;
66
67     /**
68      * Clds Identity databse DataSource configuration
69      */
70     @Bean(name = "cldsDataSource")
71     @ConfigurationProperties(prefix = "spring.datasource.cldsdb")
72     public DataSource cldsDataSource() {
73         return DataSourceBuilder.create().build();
74     }
75
76     @Bean(name = "jaxrsProviders")
77     public List<?> jaxrsProviders() {
78         return new ArrayList(context.getBeansWithAnnotation(AjscProvider.class).values());
79     }
80
81     @Bean(name = "jaxrsServices")
82     public List<?> jaxrsServices() {
83         return new ArrayList(context.getBeansWithAnnotation(AjscService.class).values());
84     }
85
86     @Bean(name = "cldsDao")
87     public CldsDao getCldsDao() {
88         CldsDao cldsDao = new CldsDao();
89         cldsDao.setDataSource(cldsDataSource());
90         return cldsDao;
91     }
92
93     @Bean(name = "cldsBpmnTransformer")
94     public XslTransformer getCldsBpmnXslTransformer() throws TransformerConfigurationException {
95         XslTransformer xslTransformer = new XslTransformer();
96         xslTransformer.setXslResourceName("xsl/clds-bpmn-transformer.xsl");
97         return xslTransformer;
98     }
99
100     @Bean
101     public RefProp getRefProp() {
102         return new RefProp();
103     }
104
105     @Bean
106     public PolicyClient getPolicyClient() {
107         return new PolicyClient();
108     }
109
110     @Bean(name = "cldsEventDelegate")
111     public CldsEventDelegate getCldsEventDelegate() {
112         return new CldsEventDelegate();
113     }
114
115     @Bean(name = "dcaeReqDelegate")
116     public DcaeReqDelegate getDcaeReqDelegate() {
117         return new DcaeReqDelegate();
118     }
119
120     @Bean(name = "sdcSendReqDelegate")
121     public SdcSendReqDelegate getSdcSendReqDelegate() {
122         return new SdcSendReqDelegate();
123     }
124
125     @Bean(name = "dcaeReqDeleteDelegate")
126     public DcaeReqDeleteDelegate getDcaeReqDeleteDelegate() {
127         return new DcaeReqDeleteDelegate();
128     }
129
130     @Bean(name = "operationalPolicyDelegate")
131     public OperationalPolicyDelegate getOperationalPolicyDelegate() {
132         return new OperationalPolicyDelegate();
133     }
134
135     @Bean(name = "operationalPolicyDeleteDelegate")
136     public OperationalPolicyDeleteDelegate getOperationalPolicyDeleteDelegate() {
137         return new OperationalPolicyDeleteDelegate();
138     }
139
140     @Bean(name = "stringMatchPolicyDelegate")
141     public StringMatchPolicyDelegate getStringMatchPolicyDelegate() {
142         return new StringMatchPolicyDelegate();
143     }
144
145     @Bean(name = "stringMatchPolicyDeleteDelegate")
146     public StringMatchPolicyDeleteDelegate getStringMatchPolicyDeleteDelegate() {
147         return new StringMatchPolicyDeleteDelegate();
148     }
149
150     @Bean(name = "sdcCatalogServices")
151     public SdcCatalogServices getSdcCatalogServices() {
152         return new SdcCatalogServices();
153     }
154
155     @Bean(name = "dcaeDispatcherServices")
156     public DcaeDispatcherServices getDcaeDispatcherServices() {
157         return new DcaeDispatcherServices();
158     }
159
160     @Bean(name = "dcaeInventoryServices")
161     public DcaeInventoryServices getDcaeInventoryServices() {
162         return new DcaeInventoryServices();
163     }
164
165     @Bean(name = "tcaPolicyDelegate")
166     public TcaPolicyDelegate getTcaPolicyDelegate() {
167         return new TcaPolicyDelegate();
168     }
169
170     @Bean(name = "tcaPolicyDeleteDelegate")
171     public TcaPolicyDeleteDelegate getTcaPolicyDeleteDelegate() {
172         return new TcaPolicyDeleteDelegate();
173     }
174
175 }