summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/CompositionConfig.java
blob: ee8f5c64a3968bc6711c15347c2122220c34bf99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.onap.sdc.dcae.composition;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;

import javax.annotation.PostConstruct;

import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.common.onaplog.OnapLoggerError;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

@Component
@PropertySources({
		@PropertySource(value="classpath:application-fe.properties", ignoreResourceNotFound=true),
		@PropertySource(value="file:${jetty.base}/config/dcae-be/application.properties", ignoreResourceNotFound=true)
})

public class CompositionConfig {

	private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
	private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();

	@Value("${compositionConfig.flowTypes}")
	private String flowTypes;
	@JsonIgnore
	private Map<String, FlowType> flowTypesMap;
	@Value("${compositionConfig.isRuleEditorActive}")
	private boolean isRuleEditorActive;

	// get flowTypes as the parsed keySet
	public Set<String> getFlowTypes() {
		return flowTypesMap.keySet();
	}

	@JsonProperty("isRuleEditorActive")
	public boolean isRuleEditorActive() {
		return isRuleEditorActive;
	}

	public Map<String, FlowType> getFlowTypesMap() {
		return flowTypesMap;
	}

	public static class FlowType {

		private String entryPointPhaseName;
		private String lastPhaseName;

		public String getEntryPointPhaseName() {
			return entryPointPhaseName;
		}

		public void setEntryPointPhaseName(String entryPointPhaseName) {
			this.entryPointPhaseName = entryPointPhaseName;
		}

		public String getLastPhaseName() {
			return lastPhaseName;
		}

		public void setLastPhaseName(String lastPhaseName) {
			this.lastPhaseName = lastPhaseName;
		}
	}


	@PostConstruct
	public void init() {
		try {
			debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Reading flow type definitions from configuration");
			Type map = new TypeToken<Map<String, FlowType>>(){}.getType();
			flowTypesMap = new Gson().fromJson(flowTypes, map);
		} catch (Exception e) {
			errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error – Failed to read flow type definitions");
		}
	}
}