Changeset 4029


Ignore:
Timestamp:
11/16/13 12:36:06 (11 years ago)
Author:
keeloo
Message:

Added support for a separate facet concepts file used for testing only

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  
    200200    private static String solrUrl = "";
    201201   
     202    @Element(required = false)
     203    private static String facetMappingFile = "";
     204   
    202205    @Element
    203206    private static String profileSchemaUrl = "";
     
    222225     * application configuration.
    223226     */
    224     @Element
     227    @Element(required = false)
    225228    private static String nationalProjectMapping = "";
    226229   
     
    608611        solrUrl = param;
    609612    }
     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    }
    610637
    611638    /**
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIParserVTDXML.java

    r2805 r4029  
    5959            LOG.info("FILE WITH WEIRD HTTP THINGY! " + tolog);
    6060        }
    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);
    6267    }
    6368
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetConceptMapping.java

    r4016 r4029  
    1717
    1818/**
    19  * Corresponds to the facetConcepts.xml file.
     19 * Corresponds to the facet concepts file.
     20 *
    2021 * This class holds the mapping of facet name -> facetConcepts/patterns
    2122 * 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  
    3737    }
    3838
    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
    4956        FacetMapping result = mapping.get(xsd);
    5057        if (result == null) {
    51             result = createMapping(xsd);
     58            result = createMapping(facetConcepts, xsd);
    5259            mapping.put(xsd, result);
    5360        }
     
    5663
    5764    /**
    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
    6477        FacetMapping result = new FacetMapping();
    6578        // 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);
    6780        try {
    6881            //The magic
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/NationalProjectPostProcessor.java

    r2774 r4029  
    2626        private final static Logger LOG = LoggerFactory.getLogger(NationalProjectPostProcessor.class);
    2727
    28         //private static String mappingFileName = "nationalProjectsMapping.xml";
    2928        private static Map<String, String> nationalProjectMap = null;
    3029
     
    4847                if(nationalProjectMap == null)
    4948                        nationalProjectMap = getNationalProjectMapping();
    50                 return nationalProjectMap;
    51         }
     49        return nationalProjectMap;
     50    }
    5251
    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";
    5758        }
    58                 LOG.debug("Creating national project map.");
     59
    5960        try {
    6061            Map<String, String> result = new HashMap<String, String>();
     
    6566            Document doc;
    6667
    67             // File mappingFile = new File(mappingFileName);
    68 
    6968            // first, try to open the packaged mapping file
    7069            InputStream mappingFileAsStream;
    71             mappingFileAsStream = NationalProjectPostProcessor.class.getResourceAsStream(mappingFileName);
     70            mappingFileAsStream = NationalProjectPostProcessor.class.getResourceAsStream(projectsMappingFile);
    7271
    7372            if (mappingFileAsStream != null) {
     
    7877                File mappingAsFile;
    7978
    80                 mappingAsFile = new File(mappingFileName);
     79                mappingAsFile = new File(projectsMappingFile);
    8180
    8281                if (mappingAsFile == null) {
     
    8685                doc = builder.parse(mappingAsFile);
    8786            }
    88          
     87
    8988            XPath xpath = XPathFactory.newInstance().newXPath();
    9089            NodeList nodeList = (NodeList) xpath.evaluate("//nationalProjectMapping", doc, XPathConstants.NODESET);
    9190            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();
    9493                result.put(mdCollectionDisplayName, nationalProject);
    9594            }
     
    9897            throw new RuntimeException("Cannot instantiate postProcessor:", e);
    9998        }
    100         }
     99    }
    101100
    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 = "";
    108110        content += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
    109111        content += "<nationalProjects>\n";
     
    113115        File file = null;
    114116        try {
    115                 file = File.createTempFile("vlo.nationalTestMapping", ".map");
    116                 FileUtils.writeStringToFile(file, content, "UTF-8");
     117            file = File.createTempFile("vlo.nationalTestMapping", ".map");
     118            FileUtils.writeStringToFile(file, content, "UTF-8");
    117119        } catch (IOException ioe) {
    118                 ioe.printStackTrace();
    119                 LOG.error("Could not create temporary national project mapping file");
     120            ioe.printStackTrace();
     121            LOG.error("Could not create temporary national project mapping file");
    120122        }
    121123
    122124        return file;
    123         }
     125    }
    124126}
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/VLOMarshaller.java

    r3648 r4029  
    1010
    1111public class VLOMarshaller {
    12     private final static String FACETCONCEPTS_FILENAME = "facetConcepts.xml";
    1312
    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       
    1625        return unmarshal(inputStream);
    17 
    1826    }
    1927
    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) {
    2135        try {
    2236            JAXBContext jc = JAXBContext.newInstance(FacetConceptMapping.class);
    2337            Unmarshaller u = jc.createUnmarshaller();
    24             FacetConceptMapping result = (FacetConceptMapping) u.unmarshal(in);
     38            FacetConceptMapping result = (FacetConceptMapping) u.unmarshal(inputStream);
    2539            result.check();
    2640            return result;
     
    3044    }
    3145
    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) {
    3353        try {
    3454            JAXBContext jc = JAXBContext.newInstance(FacetConceptMapping.class);
     
    3656            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    3757            StringWriter writer = new StringWriter();
    38             marshaller.marshal(f, writer);
     58            marshaller.marshal(outputFile, writer);
    3959            return writer.toString();
    4060        } catch (JAXBException e) {
     
    4262        }
    4363    }
    44 
    4564}
  • vlo/trunk/vlo_importer/src/main/resources/VloConfig.xml

    r4019 r4029  
    5050   
    5151    <solrUrl>http://localhost:8084/vlo_solr/</solrUrl>
     52   
     53    <facetMappingFile>/facetConceptMapping.xml</facetMappingFile>
    5254   
    5355    <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  
    2424    @Test
    2525    public void testCreateCMDIDataFromCorpus() throws Exception {
     26       
     27        // make sure the mapping file for testing is used
     28        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     29
    2630        String content = "";
    2731        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    8488    @Test
    8589    public void testCreateCMDIDataFromSession() throws Exception {
     90       
     91        // make sure the mapping file for testing is used
     92        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     93
    8694        String content = "";
    8795        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    405413    @Test
    406414    public void testCreateCMDISessionSmall() throws Exception {
     415       
     416        // make sure the mapping file for testing is used
     417        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     418
    407419        String content = "";
    408420        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    430442    @Test
    431443    public void testEmptyFieldsShouldBeNull() throws Exception {
     444       
     445        // make sure the mapping file for testing is used
     446        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     447
    432448        String content = "";
    433449        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    518534    @Test
    519535    public void testOlac() throws Exception {
     536
     537        // make sure the mapping file for testing is used
     538        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     539
    520540        String content = "";
    521541        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    600620    @Test
    601621    public void testOlacMultiFacets() throws Exception {
     622       
     623        // make sure the mapping file for testing is used
     624        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     625
    602626        String content = "";
    603627        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    691715    @Test
    692716    public void testIgnoreWhiteSpaceFacets() throws Exception {
     717       
     718        // make sure the mapping file for testing is used
     719        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     720
    693721        String content = "";
    694722        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    713741    @Test
    714742    public void testCountryCodesPostProcessing() throws Exception {
     743       
     744        // make sure the mapping file for testing is used
     745        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     746
    715747        String content = "";
    716748        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    735767    @Test
    736768    public void testLanguageCodesPostProcessing() throws Exception {
     769       
     770        // make sure the mapping file for testing is used
     771        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     772
    737773        String content = "";
    738774        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    762798    @Test
    763799    public void testOlacCollection() throws Exception {
     800       
     801        // make sure the mapping file for testing is used
     802        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     803
    764804        String content = "";
    765805        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    810850    @Test
    811851    public void testLrtCollection() throws Exception {
     852       
     853        // make sure the mapping file for testing is used
     854        VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     855
    812856        String content = "";
    813857        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     
    867911        assertEquals("Written Corpus", doc.getFieldValue(FacetConstants.FIELD_RESOURCE_CLASS));
    868912    }
    869 
    870913}
  • vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactoryTest.java

    r3996 r4029  
    1212
    1313public 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";
    1425
    1526    private final static Logger LOG = LoggerFactory.getLogger(FacetMappingFactoryTest.class);
     
    1829    public void testGetImdiMapping() {
    1930        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);
    2232       
    2333        List<FacetConfiguration> facets = facetMapping.getFacets();
     
    159169    public void testGetOlacMapping() {
    160170        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);
    162172       
    163173        List<FacetConfiguration> facets = facetMapping.getFacets();
     
    267277    public void testGetLrtMapping() {
    268278        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
    271281        List<FacetConfiguration> facets = facetMapping.getFacets();
    272282        assertEquals(16, facets.size());
     
    379389    @Test
    380390    public void testGetIdMapping() throws Exception {
     391
    381392        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
    384395        List<FacetConfiguration> facets = facetMapping.getFacets();
    385396       
  • vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/MetadataImporterTest.java

    r3935 r4029  
    8080        assertEquals("kleve-route", getValue(doc, FacetConstants.FIELD_NAME));
    8181        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));
    8383        assertEquals("video/x-mpeg1|../Media/elan-example1.mpg", getValue(doc, FacetConstants.FIELD_RESOURCE));
    8484    }
     
    260260            @Override
    261261            void startImport() throws MalformedURLException {
    262 
     262               
     263                // make sure the mapping file for testing is used
     264                VloConfig.setFacetMappingFile("/facetConceptsTest.xml");
     265               
    263266                List<DataRoot> dataRoots = checkDataRoots();
    264267                long start = System.currentTimeMillis();
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetedSearchPage.java

    r4021 r4029  
    4545    private final SearchPageQuery query;
    4646    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();
    4849   
    4950    /**
Note: See TracChangeset for help on using the changeset viewer.