1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.r2.common.datadictionary; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.LinkedHashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
import org.kuali.rice.krad.datadictionary.DataObjectEntry; |
24 | |
import org.kuali.student.r2.common.constants.CommonServiceConstants; |
25 | |
import org.kuali.student.r2.common.datadictionary.dto.DictionaryEntryInfo; |
26 | |
import org.kuali.student.r2.common.datadictionary.service.DataDictionaryService; |
27 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
28 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
29 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
30 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
31 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
32 | |
import org.springframework.context.ApplicationContext; |
33 | |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class DataDictionaryServiceImpl implements DataDictionaryService, RiceDataDictionaryServiceInfc { |
42 | |
|
43 | 0 | private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(DataDictionaryServiceImpl.class); |
44 | |
private String serviceNamespaceSuffix; |
45 | |
private Map<String, DictionaryEntryInfo> studMap; |
46 | |
private Map<String, DataObjectEntry> riceMap; |
47 | |
|
48 | 0 | public DataDictionaryServiceImpl() { |
49 | 0 | } |
50 | |
|
51 | |
public String getServiceNamespaceSuffix() { |
52 | 0 | return serviceNamespaceSuffix; |
53 | |
} |
54 | |
|
55 | |
public void setServiceNamespaceSuffix(String serviceNamespaceSuffix) { |
56 | 0 | this.serviceNamespaceSuffix = serviceNamespaceSuffix; |
57 | 0 | } |
58 | |
|
59 | |
|
60 | |
public void setDictionaryLocations(List<String> locations) throws IOException { |
61 | 0 | studMap = new LinkedHashMap<String, DictionaryEntryInfo>(); |
62 | 0 | riceMap = new LinkedHashMap<String, DataObjectEntry>(); |
63 | 0 | for (String location : locations) { |
64 | 0 | ApplicationContext ac = new ClassPathXmlApplicationContext(location); |
65 | 0 | Map<String, DataObjectEntry> beansOfType = |
66 | |
(Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class); |
67 | 0 | for (DataObjectEntry entry : beansOfType.values()) { |
68 | 0 | log.debug(entry.getDataObjectClass()); |
69 | 0 | riceMap.put(entry.getFullClassName(), entry); |
70 | 0 | studMap.put(calcRefObjectURI (entry.getDataObjectClass()), new Rice2StudentDictionaryEntryConverter().convert(entry)); |
71 | |
} |
72 | 0 | } |
73 | 0 | } |
74 | |
|
75 | |
private String calcRefObjectURI (Class<?> objectClass) { |
76 | 0 | return CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + this.serviceNamespaceSuffix + "/" + objectClass.getSimpleName(); |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public DictionaryEntryInfo getDataDictionaryEntry(String entryKey, ContextInfo context) |
81 | |
throws OperationFailedException, |
82 | |
MissingParameterException, |
83 | |
PermissionDeniedException, |
84 | |
DoesNotExistException { |
85 | 0 | DictionaryEntryInfo entry = studMap.get(entryKey); |
86 | 0 | if (entry == null) { |
87 | 0 | throw new DoesNotExistException(entryKey); |
88 | |
} |
89 | 0 | return entry; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public List<String> getDataDictionaryEntryKeys(ContextInfo context) |
94 | |
throws OperationFailedException, |
95 | |
MissingParameterException, |
96 | |
PermissionDeniedException { |
97 | 0 | return new ArrayList(studMap.keySet()); |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public DataObjectEntry getDataObjectEntry(String entryKey) { |
102 | 0 | return riceMap.get(entryKey); |
103 | |
} |
104 | |
} |