1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.datadictionary.util; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.HashSet; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
import org.kuali.rice.kns.datadictionary.DataObjectEntry; |
24 | |
import org.springframework.context.ApplicationContext; |
25 | |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
26 | |
|
27 | |
public class DictionaryTesterHelper { |
28 | |
|
29 | |
private String outputFileName; |
30 | |
private String className; |
31 | |
private String dictFileName; |
32 | |
private String projectUrl; |
33 | |
|
34 | |
public DictionaryTesterHelper(String outputFileName, |
35 | |
String className, |
36 | |
String projectUrl, |
37 | 0 | String dictFileName) { |
38 | 0 | this.outputFileName = outputFileName; |
39 | 0 | this.className = className; |
40 | 0 | this.projectUrl = projectUrl; |
41 | 0 | this.dictFileName = dictFileName; |
42 | 0 | } |
43 | |
private transient Map<String, DataObjectEntry> objectStructures; |
44 | |
|
45 | |
public List<String> doTest() { |
46 | 0 | ApplicationContext ac = new ClassPathXmlApplicationContext( |
47 | |
"classpath:" + dictFileName); |
48 | 0 | objectStructures = new HashMap(); |
49 | 0 | Map<String, DataObjectEntry> beansOfType = |
50 | |
(Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class); |
51 | 0 | for (DataObjectEntry objStr : beansOfType.values()) { |
52 | 0 | objectStructures.put(objStr.getFullClassName(), objStr); |
53 | 0 | System.out.println("Loading object structure: " + objStr.getFullClassName()); |
54 | |
} |
55 | 0 | DataObjectEntry ode = null; |
56 | 0 | ode = objectStructures.get(className); |
57 | 0 | if (ode == null) { |
58 | 0 | throw new RuntimeException("className is not defined in dictionary: " + className); |
59 | |
} |
60 | 0 | DictionaryValidator validator = new DictionaryValidator(ode, new HashSet()); |
61 | 0 | List<String> errors = validator.validate(); |
62 | 0 | if (errors.size() > 0) { |
63 | 0 | return errors; |
64 | |
} |
65 | 0 | DictionaryFormatter formatter = new DictionaryFormatter(ode, projectUrl, dictFileName, outputFileName); |
66 | 0 | formatter.formatForHtml(); |
67 | 0 | return new ArrayList<String>(); |
68 | |
} |
69 | |
} |