| 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 | 4 | String dictFileName) { |
| 38 | 4 | this.outputFileName = outputFileName; |
| 39 | 4 | this.className = className; |
| 40 | 4 | this.projectUrl = projectUrl; |
| 41 | 4 | this.dictFileName = dictFileName; |
| 42 | 4 | } |
| 43 | |
private transient Map<String, DataObjectEntry> objectStructures; |
| 44 | |
|
| 45 | |
public List<String> doTest() { |
| 46 | 4 | ApplicationContext ac = new ClassPathXmlApplicationContext( |
| 47 | |
"classpath:" + dictFileName); |
| 48 | 4 | objectStructures = new HashMap(); |
| 49 | 4 | Map<String, DataObjectEntry> beansOfType = |
| 50 | |
(Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class); |
| 51 | 4 | for (DataObjectEntry objStr : beansOfType.values()) { |
| 52 | 4 | objectStructures.put(objStr.getFullClassName(), objStr); |
| 53 | 4 | System.out.println("Loading object structure: " + objStr.getFullClassName()); |
| 54 | |
} |
| 55 | 4 | DataObjectEntry ode = null; |
| 56 | 4 | ode = objectStructures.get(className); |
| 57 | 4 | if (ode == null) { |
| 58 | 0 | throw new RuntimeException("className is not defined in dictionary: " + className); |
| 59 | |
} |
| 60 | 4 | DictionaryValidator validator = new DictionaryValidator(ode, new HashSet()); |
| 61 | 4 | List<String> errors = validator.validate(); |
| 62 | 4 | if (errors.size() > 0) { |
| 63 | 0 | return errors; |
| 64 | |
} |
| 65 | 4 | DictionaryFormatter formatter = new DictionaryFormatter(ode, projectUrl, dictFileName, outputFileName); |
| 66 | 4 | formatter.formatForHtml(); |
| 67 | 4 | return new ArrayList<String>(); |
| 68 | |
} |
| 69 | |
} |