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.HashSet;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.support.ClassPathXmlApplicationContext;
26
27 public class DictionaryTesterHelper {
28
29 private String outputDir;
30 private Set<String> configFiles;
31 private ApplicationContext ac = null;
32
33 public DictionaryTesterHelper(String outputDir,
34 Set<String> configFiles) {
35 this.outputDir = outputDir;
36 this.configFiles = configFiles;
37 }
38
39 public void loadApplicationContext() {
40 System.out.println ("DictionaryTesterHelper: begin loading application context");
41 List<String> configLocations = new ArrayList(configFiles);
42
43
44 String[] configLocs = configLocations.toArray(new String[0]);
45 ac = new ClassPathXmlApplicationContext(configLocs);
46 System.out.println ("DictionaryTesterHelper: end loading application context");
47 }
48
49 public Map<String, DataObjectEntry> getDataObjectEntryBeans () {
50 return (Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class);
51 }
52
53 public List<String> doTest() {
54 List<String> outputFileNames = new ArrayList();
55 if (ac == null) {
56 loadApplicationContext ();
57 }
58 Map<String, DataObjectEntry> beansOfType = this.getDataObjectEntryBeans();
59
60 for (String beanId : beansOfType.keySet()) {
61 DataObjectEntry doe = beansOfType.get(beanId);
62 if ("org.kuali.rice.krad.bo.AttributeReferenceDummy".equals(doe.getFullClassName())) {
63 continue;
64 }
65 System.out.println("Processing data object entry: " + doe.getDataObjectClass().getName());
66 DictionaryValidator validator = new DictionaryValidator(doe, new HashSet());
67 List<String> errors = validator.validate();
68 if (errors != null) {
69 if (!errors.isEmpty()) {
70 throw new IllegalArgumentException("Errors validating bean "
71 + beanId + "\n" + this.formatAsString(errors));
72 }
73 }
74 String outputFileName = beanId + ".html";
75 outputFileNames.add(outputFileName);
76 String fullOutputFileName = this.outputDir + "/" + outputFileName;
77 DictionaryFormatter formatter = new DictionaryFormatter(doe, beansOfType, beanId, fullOutputFileName);
78 formatter.formatForHtml();
79 }
80 return outputFileNames;
81 }
82
83 private String formatAsString(List<String> errors) {
84 int i = 0;
85 StringBuilder builder = new StringBuilder();
86 for (String error : errors) {
87 i++;
88 builder.append(i).append(". ").append(error).append("\n");
89 }
90 return builder.toString();
91 }
92 }