DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_be / src / main / java / org / onap / sdc / dcae / composition / CompositionConfig.java
1 package org.onap.sdc.dcae.composition;
2
3 import java.lang.reflect.Type;
4 import java.util.Map;
5 import java.util.Set;
6
7 import javax.annotation.PostConstruct;
8
9 import org.onap.sdc.common.onaplog.OnapLoggerDebug;
10 import org.onap.sdc.common.onaplog.OnapLoggerError;
11 import org.onap.sdc.common.onaplog.Enums.LogLevel;
12 import org.springframework.beans.factory.annotation.Value;
13 import org.springframework.context.annotation.PropertySource;
14 import org.springframework.context.annotation.PropertySources;
15 import org.springframework.stereotype.Component;
16
17 import com.fasterxml.jackson.annotation.JsonIgnore;
18 import com.fasterxml.jackson.annotation.JsonProperty;
19 import com.google.gson.Gson;
20 import com.google.gson.reflect.TypeToken;
21
22 @Component
23 @PropertySources({
24                 @PropertySource(value="classpath:application-fe.properties", ignoreResourceNotFound=true),
25                 @PropertySource(value="file:${jetty.base}/config/dcae-be/application.properties", ignoreResourceNotFound=true)
26 })
27
28 public class CompositionConfig {
29
30         private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
31         private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
32
33         @Value("${compositionConfig.flowTypes}")
34         private String flowTypes;
35         @JsonIgnore
36         private Map<String, FlowType> flowTypesMap;
37         @Value("${compositionConfig.isRuleEditorActive}")
38         private boolean isRuleEditorActive;
39
40         // get flowTypes as the parsed keySet
41         public Set<String> getFlowTypes() {
42                 return flowTypesMap.keySet();
43         }
44
45         @JsonProperty("isRuleEditorActive")
46         public boolean isRuleEditorActive() {
47                 return isRuleEditorActive;
48         }
49
50         public Map<String, FlowType> getFlowTypesMap() {
51                 return flowTypesMap;
52         }
53
54         public static class FlowType {
55
56                 private String entryPointPhaseName;
57                 private String lastPhaseName;
58
59                 public String getEntryPointPhaseName() {
60                         return entryPointPhaseName;
61                 }
62
63                 public void setEntryPointPhaseName(String entryPointPhaseName) {
64                         this.entryPointPhaseName = entryPointPhaseName;
65                 }
66
67                 public String getLastPhaseName() {
68                         return lastPhaseName;
69                 }
70
71                 public void setLastPhaseName(String lastPhaseName) {
72                         this.lastPhaseName = lastPhaseName;
73                 }
74         }
75
76
77         @PostConstruct
78         public void init() {
79                 try {
80                         debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Reading flow type definitions from configuration");
81                         Type map = new TypeToken<Map<String, FlowType>>(){}.getType();
82                         flowTypesMap = new Gson().fromJson(flowTypes, map);
83                 } catch (Exception e) {
84                         errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error – Failed to read flow type definitions");
85                 }
86         }
87 }