1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.consumer;
15
16 import java.io.IOException;
17 import java.util.HashMap;
18 import java.util.Map;
19 import java.util.Properties;
20
21 import com.xmlsolutions.annotation.Requirement;
22
23 import uk.nhs.interoperability.capabilities.ITKProfileManager;
24 import uk.nhs.interoperability.util.ITKApplicationProperties;
25 import uk.nhs.interoperability.util.Logger;
26
27
28
29
30
31
32
33
34 public class ITKProfileManagerImpl implements ITKProfileManager {
35
36
37 private static final String SUPPORTED_PROFILE_PREFIX = "profileId.";
38
39
40 private Map<String, Integer> supportedProfiles;
41
42
43
44
45 public ITKProfileManagerImpl() {
46 Properties props = new Properties();
47 try {
48 props.load(this.getClass().getResourceAsStream("/profile.properties"));
49 this.loadProps(props);
50 } catch (IOException e) {
51 Logger.error("Could not load supported profile configuration - no profiles will be supported", e);
52 }
53
54 }
55
56
57
58
59
60
61 public ITKProfileManagerImpl(Properties props) {
62 this.loadProps(props);
63 }
64
65
66
67
68
69
70 private void loadProps(Properties props) {
71 this.supportedProfiles = new HashMap<String, Integer>();
72 try {
73
74 Properties profileProps = ITKApplicationProperties.getPropertiesMatching(props, SUPPORTED_PROFILE_PREFIX);
75 for (Map.Entry<Object, Object> entry : profileProps.entrySet()) {
76 String profileId = entry.getKey().toString().substring(SUPPORTED_PROFILE_PREFIX.length());
77 String supportLevelStr = entry.getValue().toString();
78 if (supportLevelStr.equalsIgnoreCase("ACCEPTED")) {
79 this.supportedProfiles.put(profileId, new Integer(ITKProfileManager.ACCEPTED));
80 } else if (supportLevelStr.equalsIgnoreCase("DEPRECATED")) {
81 this.supportedProfiles.put(profileId, new Integer(ITKProfileManager.DEPRECATED));
82 } else {
83
84 this.supportedProfiles.put(profileId, new Integer(ITKProfileManager.NOT_SUPPORTED));
85 }
86 }
87 } catch (Throwable t) {
88 Logger.fatal("Error loading supported profiles information, no profiles will be supported!", t);
89 }
90 }
91
92
93
94
95 @Override
96 @Requirement(traceTo={"COR-DEH-09"}, status="implemented")
97 public int getProfileSupportLevel(String profileId) {
98 return this.supportedProfiles.containsKey(profileId) ? this.supportedProfiles.get(profileId).intValue() : ITKProfileManager.NOT_SUPPORTED;
99 }
100
101 }