Changeset 4029
- Timestamp:
- 11/16/13 12:36:06 (11 years ago)
- Location:
- vlo/trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java
r4019 r4029 200 200 private static String solrUrl = ""; 201 201 202 @Element(required = false) 203 private static String facetMappingFile = ""; 204 202 205 @Element 203 206 private static String profileSchemaUrl = ""; … … 222 225 * application configuration. 223 226 */ 224 @Element 227 @Element(required = false) 225 228 private static String nationalProjectMapping = ""; 226 229 … … 608 611 solrUrl = param; 609 612 } 613 614 /** 615 * Get the value of the facetMappingFile parameter<br><br> 616 * 617 * For a description of the parameter, refer to the general VLO 618 * documentation. 619 * 620 * @return the value 621 */ 622 static public String getFacetConceptsFile() { 623 return facetMappingFile; 624 } 625 626 /** 627 * Set the value of the facetMappingFile parameter<br><br> 628 * 629 * For a description of the parameter, refer to the general VLO 630 * documentation. 631 * 632 * @param param the value 633 */ 634 public static void setFacetMappingFile(String param) { 635 facetMappingFile = param; 636 } 610 637 611 638 /** -
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIParserVTDXML.java
r2805 r4029 59 59 LOG.info("FILE WITH WEIRD HTTP THINGY! " + tolog); 60 60 } 61 return FacetMappingFactory.getFacetMapping(xsd); 61 String facetConceptsFile = VloConfig.getFacetConceptsFile(); 62 if (facetConceptsFile.length() == 0){ 63 // use the packaged facet mapping file 64 facetConceptsFile = "/facetConcepts.xml"; 65 } 66 return FacetMappingFactory.getFacetMapping(facetConceptsFile, xsd); 62 67 } 63 68 -
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetConceptMapping.java
r4016 r4029 17 17 18 18 /** 19 * Corresponds to the facetConcepts.xml file. 19 * Corresponds to the facet concepts file. 20 * 20 21 * This class holds the mapping of facet name -> facetConcepts/patterns 21 22 * A facetConcept is a ISOcat conceptLink e.g.: http://www.isocat.org/datcat/DC-2544 -
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactory.java
r4016 r4029 37 37 } 38 38 39 public static FacetMapping getFacetMapping(String xsd) { 40 return INSTANCE.getOrCreateMapping(xsd); 41 } 42 43 /** 44 * If cashed gives that result, otherwise makes a new one (in the createMapping method below).. 45 * @param xsd 46 * @return 47 */ 48 private FacetMapping getOrCreateMapping(String xsd) { 39 public static FacetMapping getFacetMapping(String facetConceptsFile, String xsd) { 40 return INSTANCE.getOrCreateMapping(facetConceptsFile, xsd); 41 } 42 43 /** 44 * Get facet concept mapping. 45 * 46 * Get facet mapping used to map meta data based on a facet concepts 47 * file and url to cmdi meta data profile. 48 49 * @param facetConcepts name of the facet concepts file 50 * @param xsd url of xml schema of cmdi profile 51 * 52 * @return facet concept mapping 53 */ 54 private FacetMapping getOrCreateMapping(String facetConcepts, String xsd) { 55 // check if concept mapping has already been created 49 56 FacetMapping result = mapping.get(xsd); 50 57 if (result == null) { 51 result = createMapping( xsd);58 result = createMapping(facetConcepts, xsd); 52 59 mapping.put(xsd, result); 53 60 } … … 56 63 57 64 /** 58 * Asks conceptLinkPathMapping to create the actual xpaths. 59 * Does a bunch of bookkeeping in order to get the FacetMapping. 60 * @param xsd URL of XML Schema of some CMDI profile 61 * @return 62 */ 63 private FacetMapping createMapping(String xsd) { 65 * Create facet concept mapping. 66 * 67 * Create facet mapping used to map meta data based on a facet concept 68 * mapping file and url to cmdi meta data profile. 69 * 70 * @param facetConcepts name of the facet concepts file 71 * @param xsd url of xml schema of cmdi profile 72 * 73 * @return the facet mapping used to map meta data to facets 74 */ 75 private FacetMapping createMapping(String facetConcepts, String xsd) { 76 64 77 FacetMapping result = new FacetMapping(); 65 78 // Gets the configuration. VLOMarshaller only reads in the facetconceptmapping.xml file and returns the result (though the reading in is implicit). 66 FacetConceptMapping conceptMapping = VLOMarshaller.getFacetConceptMapping( );79 FacetConceptMapping conceptMapping = VLOMarshaller.getFacetConceptMapping(facetConcepts); 67 80 try { 68 81 //The magic -
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/NationalProjectPostProcessor.java
r2774 r4029 26 26 private final static Logger LOG = LoggerFactory.getLogger(NationalProjectPostProcessor.class); 27 27 28 //private static String mappingFileName = "nationalProjectsMapping.xml";29 28 private static Map<String, String> nationalProjectMap = null; 30 29 … … 48 47 if(nationalProjectMap == null) 49 48 nationalProjectMap = getNationalProjectMapping(); 50 returnnationalProjectMap;51 49 return nationalProjectMap; 50 } 52 51 53 private Map<String, String> getNationalProjectMapping() { 54 String mappingFileName = VloConfig.getNationalProjectMapping(); 55 if(mappingFileName == null){ 56 throw new RuntimeException("Configuration Error, NationalProjectMapping is null"); 52 private Map<String, String> getNationalProjectMapping() { 53 String projectsMappingFile = VloConfig.getNationalProjectMapping(); 54 55 if (projectsMappingFile.length() == 0) { 56 // use the packaged project mapping file 57 projectsMappingFile = "/nationalProjectsMapping.xml"; 57 58 } 58 LOG.debug("Creating national project map."); 59 59 60 try { 60 61 Map<String, String> result = new HashMap<String, String>(); … … 65 66 Document doc; 66 67 67 // File mappingFile = new File(mappingFileName);68 69 68 // first, try to open the packaged mapping file 70 69 InputStream mappingFileAsStream; 71 mappingFileAsStream = NationalProjectPostProcessor.class.getResourceAsStream( mappingFileName);70 mappingFileAsStream = NationalProjectPostProcessor.class.getResourceAsStream(projectsMappingFile); 72 71 73 72 if (mappingFileAsStream != null) { … … 78 77 File mappingAsFile; 79 78 80 mappingAsFile = new File( mappingFileName);79 mappingAsFile = new File(projectsMappingFile); 81 80 82 81 if (mappingAsFile == null) { … … 86 85 doc = builder.parse(mappingAsFile); 87 86 } 88 87 89 88 XPath xpath = XPathFactory.newInstance().newXPath(); 90 89 NodeList nodeList = (NodeList) xpath.evaluate("//nationalProjectMapping", doc, XPathConstants.NODESET); 91 90 for (int i = 1; i <= nodeList.getLength(); i++) { 92 String mdCollectionDisplayName = xpath.evaluate("//nationalProjectMapping[" +i+"]/MdCollectionDisplayName", doc).trim();93 String nationalProject = xpath.evaluate("//nationalProjectMapping[" +i+"]/NationalProject", doc).trim();91 String mdCollectionDisplayName = xpath.evaluate("//nationalProjectMapping[" + i + "]/MdCollectionDisplayName", doc).trim(); 92 String nationalProject = xpath.evaluate("//nationalProjectMapping[" + i + "]/NationalProject", doc).trim(); 94 93 result.put(mdCollectionDisplayName, nationalProject); 95 94 } … … 98 97 throw new RuntimeException("Cannot instantiate postProcessor:", e); 99 98 } 100 99 } 101 100 102 /** 103 * Create temporary and minimal mapping file for testing purposes and as backup solution 104 * @return minimal file for national projects mapping (e.g. ANDES -> CLARIN-EU) 105 */ 106 private File createMinimalMappingFile() { 107 String content = ""; 101 /** 102 * Create temporary and minimal mapping file for testing purposes and as 103 * backup solution 104 * 105 * @return minimal file for national projects mapping (e.g. ANDES -> 106 * CLARIN-EU) 107 */ 108 private File createMinimalMappingFile() { 109 String content = ""; 108 110 content += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; 109 111 content += "<nationalProjects>\n"; … … 113 115 File file = null; 114 116 try { 115 116 117 file = File.createTempFile("vlo.nationalTestMapping", ".map"); 118 FileUtils.writeStringToFile(file, content, "UTF-8"); 117 119 } catch (IOException ioe) { 118 119 120 ioe.printStackTrace(); 121 LOG.error("Could not create temporary national project mapping file"); 120 122 } 121 123 122 124 return file; 123 125 } 124 126 } -
vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/VLOMarshaller.java
r3648 r4029 10 10 11 11 public class VLOMarshaller { 12 private final static String FACETCONCEPTS_FILENAME = "facetConcepts.xml";13 12 14 public static FacetConceptMapping getFacetConceptMapping() { 15 InputStream inputStream = VLOMarshaller.class.getResourceAsStream("/" + FACETCONCEPTS_FILENAME); 13 /** 14 * Get facet concepts mapping from a facet concept mapping file 15 * 16 * @param facetConcepts name of the facet concepts file 17 * @return the facet concept mapping 18 */ 19 public static FacetConceptMapping getFacetConceptMapping( 20 String facetConcepts) { 21 22 InputStream inputStream = 23 VLOMarshaller.class.getResourceAsStream(facetConcepts); 24 16 25 return unmarshal(inputStream); 17 18 26 } 19 27 20 static FacetConceptMapping unmarshal(InputStream in) { 28 /** 29 * Get object from input stream 30 * 31 * @param inputStream 32 * @return 33 */ 34 static FacetConceptMapping unmarshal(InputStream inputStream) { 21 35 try { 22 36 JAXBContext jc = JAXBContext.newInstance(FacetConceptMapping.class); 23 37 Unmarshaller u = jc.createUnmarshaller(); 24 FacetConceptMapping result = (FacetConceptMapping) u.unmarshal(in );38 FacetConceptMapping result = (FacetConceptMapping) u.unmarshal(inputStream); 25 39 result.check(); 26 40 return result; … … 30 44 } 31 45 32 static String marshal(FacetConceptMapping f) { 46 /** 47 * Put facet mapping object in output file 48 * 49 * @param outputFile 50 * @return 51 */ 52 static String marshal(FacetConceptMapping outputFile) { 33 53 try { 34 54 JAXBContext jc = JAXBContext.newInstance(FacetConceptMapping.class); … … 36 56 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 37 57 StringWriter writer = new StringWriter(); 38 marshaller.marshal( f, writer);58 marshaller.marshal(outputFile, writer); 39 59 return writer.toString(); 40 60 } catch (JAXBException e) { … … 42 62 } 43 63 } 44 45 64 } -
vlo/trunk/vlo_importer/src/main/resources/VloConfig.xml
r4019 r4029 50 50 51 51 <solrUrl>http://localhost:8084/vlo_solr/</solrUrl> 52 53 <facetMappingFile>/facetConceptMapping.xml</facetMappingFile> 52 54 53 55 <profileSchemaUrl>http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/{PROFILE_ID}/xsd</profileSchemaUrl> -
vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/CMDIDataProcessorTest.java
r3935 r4029 24 24 @Test 25 25 public void testCreateCMDIDataFromCorpus() throws Exception { 26 27 // make sure the mapping file for testing is used 28 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 29 26 30 String content = ""; 27 31 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 84 88 @Test 85 89 public void testCreateCMDIDataFromSession() throws Exception { 90 91 // make sure the mapping file for testing is used 92 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 93 86 94 String content = ""; 87 95 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 405 413 @Test 406 414 public void testCreateCMDISessionSmall() throws Exception { 415 416 // make sure the mapping file for testing is used 417 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 418 407 419 String content = ""; 408 420 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 430 442 @Test 431 443 public void testEmptyFieldsShouldBeNull() throws Exception { 444 445 // make sure the mapping file for testing is used 446 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 447 432 448 String content = ""; 433 449 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 518 534 @Test 519 535 public void testOlac() throws Exception { 536 537 // make sure the mapping file for testing is used 538 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 539 520 540 String content = ""; 521 541 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 600 620 @Test 601 621 public void testOlacMultiFacets() throws Exception { 622 623 // make sure the mapping file for testing is used 624 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 625 602 626 String content = ""; 603 627 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 691 715 @Test 692 716 public void testIgnoreWhiteSpaceFacets() throws Exception { 717 718 // make sure the mapping file for testing is used 719 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 720 693 721 String content = ""; 694 722 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 713 741 @Test 714 742 public void testCountryCodesPostProcessing() throws Exception { 743 744 // make sure the mapping file for testing is used 745 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 746 715 747 String content = ""; 716 748 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 735 767 @Test 736 768 public void testLanguageCodesPostProcessing() throws Exception { 769 770 // make sure the mapping file for testing is used 771 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 772 737 773 String content = ""; 738 774 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 762 798 @Test 763 799 public void testOlacCollection() throws Exception { 800 801 // make sure the mapping file for testing is used 802 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 803 764 804 String content = ""; 765 805 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 810 850 @Test 811 851 public void testLrtCollection() throws Exception { 852 853 // make sure the mapping file for testing is used 854 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 855 812 856 String content = ""; 813 857 content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 867 911 assertEquals("Written Corpus", doc.getFieldValue(FacetConstants.FIELD_RESOURCE_CLASS)); 868 912 } 869 870 913 } -
vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactoryTest.java
r3996 r4029 12 12 13 13 public class FacetMappingFactoryTest { 14 15 private final static String FACETCONCEPTS_FILENAME = "/facetConceptsTest.xml"; 16 17 private final static String IMDI_PROFILE_URL = 18 "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1271859438204/xsd"; 19 private final static String OLAC_PROFILE_URL = 20 "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd"; 21 private final static String LRT_PROFILE_URL = 22 "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1289827960126/xsd"; 23 private final static String ID_PROFILE_URL = 24 "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1290431694629/xsd"; 14 25 15 26 private final static Logger LOG = LoggerFactory.getLogger(FacetMappingFactoryTest.class); … … 18 29 public void testGetImdiMapping() { 19 30 FacetMapping facetMapping = FacetMappingFactory 20 .getFacetMapping("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1271859438204/xsd");// IMDI Session 21 // profile xsd 31 .getFacetMapping(FACETCONCEPTS_FILENAME, IMDI_PROFILE_URL); 22 32 23 33 List<FacetConfiguration> facets = facetMapping.getFacets(); … … 159 169 public void testGetOlacMapping() { 160 170 FacetMapping facetMapping = FacetMappingFactory 161 .getFacetMapping( "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd");171 .getFacetMapping(FACETCONCEPTS_FILENAME, OLAC_PROFILE_URL); 162 172 163 173 List<FacetConfiguration> facets = facetMapping.getFacets(); … … 267 277 public void testGetLrtMapping() { 268 278 FacetMapping facetMapping = FacetMappingFactory 269 .getFacetMapping( "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1289827960126/xsd");270 279 .getFacetMapping(FACETCONCEPTS_FILENAME, LRT_PROFILE_URL); 280 271 281 List<FacetConfiguration> facets = facetMapping.getFacets(); 272 282 assertEquals(16, facets.size()); … … 379 389 @Test 380 390 public void testGetIdMapping() throws Exception { 391 381 392 FacetMapping facetMapping = FacetMappingFactory 382 .getFacetMapping( "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1290431694629/xsd");383 393 .getFacetMapping(FACETCONCEPTS_FILENAME, ID_PROFILE_URL); 394 384 395 List<FacetConfiguration> facets = facetMapping.getFacets(); 385 396 -
vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/MetadataImporterTest.java
r3935 r4029 80 80 assertEquals("kleve-route", getValue(doc, FacetConstants.FIELD_NAME)); 81 81 assertEquals(sessionFile.getAbsolutePath(), getValue(doc, FacetConstants.FIELD_FILENAME)); 82 assertEquals("video ", getValue(doc, FacetConstants.FIELD_FORMAT));82 assertEquals("video/x-mpeg1", getValue(doc, FacetConstants.FIELD_FORMAT)); 83 83 assertEquals("video/x-mpeg1|../Media/elan-example1.mpg", getValue(doc, FacetConstants.FIELD_RESOURCE)); 84 84 } … … 260 260 @Override 261 261 void startImport() throws MalformedURLException { 262 262 263 // make sure the mapping file for testing is used 264 VloConfig.setFacetMappingFile("/facetConceptsTest.xml"); 265 263 266 List<DataRoot> dataRoots = checkDataRoots(); 264 267 long start = System.currentTimeMillis(); -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetedSearchPage.java
r4021 r4029 45 45 private final SearchPageQuery query; 46 46 private final static AutoCompleteDao autoCompleteDao = new AutoCompleteDao(); 47 private final static Map<String, FacetConcept> facetNameMap = VLOMarshaller.getFacetConceptMapping().getFacetConceptMap(); 47 private final static String facetConceptsFile = VloConfig.getFacetConceptsFile(); 48 private final static Map<String, FacetConcept> facetNameMap = VLOMarshaller.getFacetConceptMapping(facetConceptsFile).getFacetConceptMap(); 48 49 49 50 /**
Note: See TracChangeset
for help on using the changeset viewer.