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