b08e007b03ac607c09066f58b39edf54d564da1e
[ui/dmaapbc.git] /
1 package org.openecomp.dcae.dmaapbc.dbcapp.util;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.context.annotation.Configuration;
5 import org.springframework.context.annotation.PropertySource;
6 import org.springframework.core.env.Environment;
7
8 /**
9  * Publishes a list of constants and methods to access the properties that are
10  * read by Spring from the specified configuration file(s).
11  * 
12  * Should be used like this (and never in a constructor):
13  * 
14  * <pre>
15  * &#64;Autowired
16  * DbcappProperties properties;
17  * </pre>
18  */
19 @Configuration
20 @PropertySource(value = { "${container.classpath:}/WEB-INF/dbcapp/dbcapp.properties" })
21 public class DbcappProperties {
22
23         public static final String DMAAP_REST_URL_LIST = "dmaap.rest.url.list";
24         public static final String DMAAP_MECHID_NAME = "dmaap.mechid.name";
25         public static final String DMAAP_MECHID_PASSWORD = "dmaap.mechid.password";
26         public static final String PROFILE_ACCESS_METHOD = "profile.access.method";
27         public static final String PROFILE_USVC_URL = "profile.microservice.url";
28         public static final String PROFILE_USVC_USER = "profile.microservice.user.name";
29         public static final String PROFILE_USVC_PASS = "profile.microservice.user.password";
30         public static final String DMAAP_PII_TYPE_LIST = "dmaap.pii.type.list";
31
32         private Environment environment;
33
34         public DbcappProperties() {
35         }
36
37         protected Environment getEnvironment() {
38                 return environment;
39         }
40
41         @Autowired
42         public void setEnvironment(final Environment environment) {
43                 this.environment = environment;
44         }
45
46         public boolean containsProperty(String key) {
47                 return environment.containsProperty(key);
48         }
49
50         public String getProperty(String key) {
51                 return environment.getRequiredProperty(key);
52         }
53
54         /**
55          * Gets the values for a comma-separated list property value as a String
56          * array.
57          * 
58          * @param key
59          *            Property key
60          * @return Array of values with leading and trailing whitespace removed;
61          *         null if key is not found.
62          */
63         public String[] getCsvListProperty(final String key) {
64                 String listVal = getProperty(key);
65                 if (listVal == null)
66                         return null;
67                 String[] vals = listVal.split("\\s*,\\s*");
68                 return vals;
69         }
70
71 }