Changeset 4509


Ignore:
Timestamp:
02/13/14 14:42:31 (10 years ago)
Author:
twagoo
Message:

Written marshaller/unmarshaller for VloConfig?

Location:
vlo/branches/vlo-3.0
Files:
3 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-commons/pom.xml

    r4480 r4509  
    1818    <dependencies>
    1919        <dependency>
    20             <groupId>org.simpleframework</groupId>
    21             <artifactId>simple-xml</artifactId>
    22             <version>2.4.1</version>
    23         </dependency>
    24         <dependency>
    2520            <groupId>javax.servlet</groupId>
    2621            <artifactId>servlet-api</artifactId>
     
    2823            <scope>provided</scope>
    2924        </dependency>
     25        <dependency>
     26            <groupId>org.slf4j</groupId>
     27            <artifactId>slf4j-log4j12</artifactId>
     28            <version>${slf4j.version}</version>
     29            <scope>test</scope>
     30        </dependency>
     31        <dependency>
     32            <groupId>xmlunit</groupId>
     33            <artifactId>xmlunit</artifactId>
     34            <version>1.5</version>
     35            <scope>test</scope>
     36            <type>xml</type>
     37            <classifier>ivy</classifier>
     38        </dependency>
    3039    </dependencies>
    3140</project>
  • vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/DataRoot.java

    r4480 r4509  
    1 
    21package eu.clarin.cmdi.vlo.config;
    32
    43import java.io.File;
    5 import org.simpleframework.xml.Element;
    6 import org.simpleframework.xml.Root;
     4import javax.xml.bind.annotation.XmlElement;
     5import javax.xml.bind.annotation.XmlRootElement;
    76
    87/**
    98 * A dataRoot describes the meta data sources.
    10  * 
     9 *
    1110 * In an XML file, a dataRoot is reflected like this:<br><br>
    12  * 
    13  * {@literal <DataRoot>} 
     11 *
     12 * {@literal <DataRoot>}
    1413 *      {@literal<originName>}name{@literal</originName>}
    1514 *      {@literal<rootFile>}topLevelMetadataDirectory/{@literal</rootFile>}
     
    1817 *      {@literal<deleteFirst>}falseOrTrue{@literal</deleteFirst>}
    1918 * {@literal</DataRoot>}
    20  * 
     19 *
    2120 * @author keeloo
    2221 */
    23 @Root // Simple directive
     22@XmlRootElement(name = "DataRoot")
    2423public class DataRoot extends Object {
    25    
     24
    2625    /**
    2726     * Constructor method
    2827     */
    29     public DataRoot (){
    30     }
    31    
     28    public DataRoot() {
     29    }
     30
    3231    /**
    3332     * Constructor method
    34      * 
     33     *
    3534     * @param originName name describing the meta data
    3635     * @param rootFile top level directory in which the meta data is stored
    3736     * @param prefix left part of the rootFile
    38      * @param toStrip if you want to create the URL to the meta data, this is 
     37     * @param toStrip if you want to create the URL to the meta data, this is
    3938     * the part to be removed from the rootFile
    40      * @param deleteFirst 
     39     * @param deleteFirst
    4140     */
    4241    public DataRoot(String originName, File rootFile, String prefix, String toStrip, Boolean deleteFirst) {
     
    4443        this.rootFile = rootFile;
    4544        this.prefix = prefix;
    46         this.tostrip = toStrip;
     45        this.toStrip = toStrip;
    4746        this.deleteFirst = deleteFirst;
    4847    }
    49    
     48
    5049    /**
    5150     * Test for equality of the object itself and the object passed to it
    52      * 
     51     *
    5352     * @param dataRoot
    5453     * @return true if the object equals this, false otherwise
    5554     */
    5655    @Override
    57     public boolean equals (Object object){
     56    public boolean equals(Object object) {
    5857        boolean equal = false;
    59        
     58
    6059        if (object == null) {
    6160            // define this object to be different from nothing
    6261        } else {
    63             if (! (object instanceof DataRoot)) {
     62            if (!(object instanceof DataRoot)) {
    6463                // the object is not a DataRoot, define it not to be equal
    6564            } else {
     
    6766                equal = this.rootFile.equals(((DataRoot) object).rootFile) && equal;
    6867                equal = this.prefix.equals(((DataRoot) object).prefix) && equal;
    69                 equal = this.tostrip.equals(((DataRoot) object).tostrip) && equal;
     68                equal = this.toStrip.equals(((DataRoot) object).toStrip) && equal;
    7069
    7170                equal = this.deleteFirst == ((DataRoot) object).deleteFirst && equal;
    7271            }
    7372        }
    74        
     73
    7574        return equal;
    7675    }
     
    7877    /**
    7978     * Generate by the ide
    80      * 
     79     *
    8180     * @return hash code
    8281     */
     
    8786        hash = 29 * hash + (this.rootFile != null ? this.rootFile.hashCode() : 0);
    8887        hash = 29 * hash + (this.prefix != null ? this.prefix.hashCode() : 0);
    89         hash = 29 * hash + (this.tostrip != null ? this.tostrip.hashCode() : 0);
     88        hash = 29 * hash + (this.toStrip != null ? this.toStrip.hashCode() : 0);
    9089        hash = 29 * hash + (this.deleteFirst ? 1 : 0);
    9190        return hash;
     
    9594     * name describing the meta data
    9695     */
    97     @Element // Simple directive
    9896    private String originName;
    99  
     97
    10098    /**
    10199     * top level directory in which the meta data is stored
    102100     */
    103     @Element
    104101    private File rootFile;
    105    
    106     /**
    107      * Web equivalent of the toStrip. For example: 
    108      * 
     102
     103    /**
     104     * Web equivalent of the toStrip. For example:
     105     *
    109106     * /lat/apache/htdocs/
    110107     */
    111     @Element 
    112108    private String prefix;
    113109
    114110    /**
    115      * Left part of the rootFile 
     111     * Left part of the rootFile
    116112     *
    117113     * By first removing {@literal tostrip} from {@literal rootFile} and then
     
    119115     * the URL to the meta data.
    120116     */
    121     @Element
    122     private String tostrip;
    123    
     117    @XmlElement(name = "tostrip")
     118    private String toStrip;
     119
    124120    /**
    125121     * Flag to signal the removal of records from the Solr server
    126      * 
    127      * The value of this flag overrides the value defined in the {@lieteral
    128      * VloConfig.xml} file. With the deleteFirst flag you can control the
    129      * removal of the records originating from originName.
    130      */
    131     @Element
     122     *
     123     * The value of this flag overrides the value defined in the {
     124     *
     125     * @lieteral VloConfig.xml} file. With the deleteFirst flag you can control
     126     * the removal of the records originating from originName.
     127     */
    132128    private boolean deleteFirst = false;
    133129
     
    135131     * Get the value of the prefix element<br><br>
    136132     *
    137      * For a description of the element, refer to the general VLO
    138      * documentation.
     133     * For a description of the element, refer to the general VLO documentation.
    139134     *
    140135     * @return the value
     
    147142     * Set the value of the prefix element<br><br>
    148143     *
    149      * For a description of the element, refer to the general VLO
    150      * documentation.
     144     * For a description of the element, refer to the general VLO documentation.
    151145     *
    152146     * @param prefix the value
     
    159153     * Get the value of the {@literal tostrip} element<br><br>
    160154     *
    161      * For a description of the element, refer to the general VLO
    162      * documentation.
     155     * For a description of the element, refer to the general VLO documentation.
    163156     *
    164157     * @return the value
    165158     */
    166159    public String getToStrip() {
    167         return tostrip;
     160        return toStrip;
    168161    }
    169162
     
    171164     * Set the value of the {@literal tostrip} element<br><br>
    172165     *
    173      * For a description of the element, refer to the general VLO
    174      * documentation.
     166     * For a description of the element, refer to the general VLO documentation.
    175167     *
    176168     * @param tostrip the value
    177169     */
    178170    public void setTostrip(String tostrip) {
    179         this.tostrip = tostrip;
     171        this.toStrip = tostrip;
    180172    }
    181173
     
    183175     * Get the value of the originName element<br><br>
    184176     *
    185      * For a description of the element, refer to the general VLO
    186      * documentation.
    187      *
    188      * @return the value
    189      */   
     177     * For a description of the element, refer to the general VLO documentation.
     178     *
     179     * @return the value
     180     */
    190181    public String getOriginName() {
    191182        return originName;
     
    195186     * Set the value of the originName element<br><br>
    196187     *
    197      * For a description of the element, refer to the general VLO
    198      * documentation.
     188     * For a description of the element, refer to the general VLO documentation.
    199189     *
    200190     * @param originName the value
    201      */   
     191     */
    202192    public void setOriginName(String originName) {
    203193        this.originName = originName;
     
    207197     * Get the value of the rootFile element<br><br>
    208198     *
    209      * For a description of the element, refer to the general VLO
    210      * documentation.
    211      *
    212      * @return the value
    213      */   
     199     * For a description of the element, refer to the general VLO documentation.
     200     *
     201     * @return the value
     202     */
    214203    public File getRootFile() {
    215204        return rootFile;
     
    219208     * Set the value of the rootFile element<br><br>
    220209     *
    221      * For a description of the element, refer to the general VLO
    222      * documentation.
     210     * For a description of the element, refer to the general VLO documentation.
    223211     *
    224212     * @param rootFile the value
    225      */   
     213     */
    226214    public void setRootFile(File rootFile) {
    227215        this.rootFile = rootFile;
     
    231219     * Set the value of the deleteFirst element<br><br>
    232220     *
    233      * For a description of the element, refer to the general VLO
    234      * documentation.
     221     * For a description of the element, refer to the general VLO documentation.
    235222     *
    236223     * @param deleteFirst the value
    237      */   
     224     */
    238225    public void setDeleteFirst(boolean deleteFirst) {
    239226        this.deleteFirst = deleteFirst;
     
    243230     * Get the value of the deleteFirst element<br><br>
    244231     *
    245      * For a description of the element, refer to the general VLO
    246      * documentation.
    247      *
    248      * @return the value
    249      */   
     232     * For a description of the element, refer to the general VLO documentation.
     233     *
     234     * @return the value
     235     */
    250236    public boolean deleteFirst() {
    251237        return deleteFirst;
    252238    }
     239
     240    @Override
     241    public String toString() {
     242        return String.format("originName: %s; rootFile: %s; prefix: %s; toStrip: %s; deleteFirst: %b", originName, rootFile, prefix, toStrip, deleteFirst);
     243    }
     244
    253245}
    254 
  • vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/DefaultVloConfigFactory.java

    r4507 r4509  
    1515 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
     17package eu.clarin.cmdi.vlo.config;
    1718
    18 package eu.clarin.cmdi.vlo.config;
     19import java.io.InputStream;
     20import javax.xml.bind.JAXBException;
     21import javax.xml.transform.stream.StreamSource;
    1922
    2023/**
     
    2427public class DefaultVloConfigFactory implements VloConfigFactory {
    2528
     29    public static final String DEFAULT_CONFIG_RESOURCE = "/VloConfig.xml";
     30    private final VloConfigMarshaller marshaller;
     31
     32    public DefaultVloConfigFactory() {
     33        try {
     34            this.marshaller = new VloConfigMarshaller();
     35        } catch (JAXBException ex) {
     36            throw new RuntimeException("Could not instantiate configuration marshaller while constructing configuration factory", ex);
     37        }
     38    }
     39
    2640    public VloConfig newConfig() {
    27         return new VloConfig();
     41        InputStream configResourceStream = getClass().getResourceAsStream(DEFAULT_CONFIG_RESOURCE);
     42        try {
     43            return marshaller.unmarshal(new StreamSource(configResourceStream));
     44        } catch (JAXBException ex) {
     45            throw new RuntimeException("Could not read default configuration due to deserialization error", ex);
     46        }
    2847    }
    29    
    3048}
  • vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java

    r4507 r4509  
    44import java.net.URLEncoder;
    55import java.util.List;
    6 import org.simpleframework.xml.Root;
     6import javax.xml.bind.annotation.XmlElement;
     7import javax.xml.bind.annotation.XmlElementWrapper;
     8import javax.xml.bind.annotation.XmlRootElement;
    79
    810/**
     
    1113 * @author keeloo, twagoo
    1214 */
    13 @Root
     15@XmlRootElement(name = "VloConfig")
    1416public class VloConfig {
    1517
     
    4143    private int solrTimeOut = 0;
    4244
    43     private List<DataRoot> dataRoots;
     45    @XmlElementWrapper(name="dataRoots")
     46    @XmlElement(name="DataRoot")
     47    private List<DataRoot> dataRoot;
    4448
    4549    private int maxFileSize = 0;
     
    6771
    6872    // services
    69     private String FederatedContentSearchUrl = "";
     73    private String federatedContentSearchUrl = "";
    7074
    7175    private boolean useHandleResolver = false;
    7276
     77    @XmlElement
    7378    private String profileSchemaUrl = "";
    7479
     
    7782    private String handleServerUrl = "";
    7883
     84    @XmlElement
    7985    private String imdiBrowserUrl = "";
    8086
     
    9399     * An array of facetFields<br><br>
    94100     *
    95      * In case of an array of elements, the number of elements in the array
    96      * needs to be communicated to the Simple framework. The following would be
    97      * a correct description of an array of three facet fields<br><br>
    98      *
    99      * {@literal <facetFields length="3">}<br> {@literal    <facetField>}<br>
    100      * {@literal       fieldOne}<br> {@literal    </facetField>}<br>
    101      * {@literal    <facetField>}<br> {@literal       fieldTwo}<br>
    102      * {@literal    </facetField>}<br> {@literal    <facetField>}<br>
    103      * {@literal       fieldThree}<br> {@literal    </facetField>}<br>
    104      * {@literal </facetFields>}<br><br>
    105      *
    106      * To let Simple now it has to interpret the facetFields element as an
    107      * array, use the ElementArray directive. Use the directive to let Simple
    108      * know that the elements inside 'facetFields' are named 'facetField'.
    109      */
    110     //Array(entry = "facetField")
    111     private String[] facetFields = {"", "", ""};
     101     * To let JAXB know it has to interpret the facetFields element as an array,
     102     * use the XmlElementWrapper directive. Use the directive to let JAXB know
     103     * that the elements inside 'facetFields' are named 'facetField'.
     104     */
     105    @XmlElementWrapper(name = "facetFields")
     106    private String[] facetField = {"", "", ""};
    112107
    113108    // test related parameters
     
    182177     * @return the value
    183178     */
    184     public boolean deleteAllFirst() {
     179    public boolean getDeleteAllFirst() {
    185180        return deleteAllFirst;
    186181    }
     
    351346     */
    352347    public List<DataRoot> getDataRoots() {
    353         return dataRoots;
     348        return dataRoot;
    354349    }
    355350
     
    363358     */
    364359    public void setDataRoots(List<DataRoot> param) {
    365         dataRoots = param;
     360        dataRoot = param;
    366361    }
    367362
     
    506501     * @param param the value
    507502     */
    508     public void setProfileSchemaUrl(String param) {
     503    public void setComponentRegistryProfileSchema(String param) {
    509504        profileSchemaUrl = param;
    510505    }
     
    567562     * @return the value
    568563     */
    569     public String getIMDIBrowserUrl(String handle) {
     564    public String getImdiBrowserUrl(String handle) {
    570565        String result;
    571566        try {
     
    585580     * @param param the value
    586581     */
    587     public void setIMDIBrowserUrl(String param) {
     582    public void setImdiBrowserUrl(String param) {
    588583        imdiBrowserUrl = param;
    589584    }
     
    645640     * @return the value
    646641     */
     642    @XmlElement(name = "FederatedContentSearchUrl")
    647643    public String getFederatedContentSearchUrl() {
    648         return FederatedContentSearchUrl;
     644        return federatedContentSearchUrl;
    649645    }
    650646
     
    658654     */
    659655    public void setFederatedContentSearchUrl(String param) {
    660         FederatedContentSearchUrl = param;
     656        federatedContentSearchUrl = param;
    661657    }
    662658
     
    694690     */
    695691    public String[] getFacetFields() {
    696         return facetFields;
     692        return facetField;
    697693    }
    698694
     
    706702     */
    707703    public void setFacetFields(String[] param) {
    708         facetFields = param;
     704        facetField = param;
    709705    }
    710706
  • vlo/branches/vlo-3.0/vlo-commons/src/test/java/eu/clarin/cmdi/vlo/config/DefaultVloConfigFactoryTest.java

    r4507 r4509  
    88import java.util.List;
    99import static org.junit.Assert.*;
    10 import org.junit.BeforeClass;
     10import org.junit.Before;
    1111import org.junit.Test;
    1212
     
    2020    }
    2121   
    22     private static VloConfig config;
    23    
    24     @BeforeClass
    25     public static void setUp() {       
     22    private VloConfig config;
     23   
     24    @Before
     25    public void setUp() {       
    2626        config = new DefaultVloConfigFactory().newConfig();
    2727    }
     
    5454        System.out.println("getDataRoots");
    5555       
    56         List rootsReturned = config.getDataRoots();
    57        
    58         assertEquals(dataRoots, rootsReturned);
     56        List<DataRoot> rootsReturned = config.getDataRoots();
     57        assertArrayEquals(dataRoots.toArray(), rootsReturned.toArray());
    5958    }
    6059
     
    285284       
    286285        boolean expResult = true;
    287         boolean result = config.deleteAllFirst();
     286        boolean result = config.getDeleteAllFirst();
    288287       
    289288        assertEquals(expResult, result);
     
    302301        config.setDeleteAllFirst(param);
    303302
    304         boolean result = config.deleteAllFirst();
     303        boolean result = config.getDeleteAllFirst();
    305304       
    306305        assertEquals(param, result);
     
    407406        System.out.println("getSolrUrl");
    408407       
    409         String expResult = "http://localhost:8084/vlo_solr/";
     408        String expResult = "http://localhost:8080/vlo_solr/";
    410409        String result = config.getSolrUrl();
    411410       
     
    520519            expResult = "http://corpus1.mpi.nl/ds/imdi_browser?openpath=" + "handle";
    521520        }
    522         String result = config.getIMDIBrowserUrl("handle");
     521        String result = config.getImdiBrowserUrl("handle");
    523522
    524523        assertEquals(expResult, result);
     
    535534        String param = "http://corpus1.mpi.nl/ds/imdi_browser?openpath=";
    536535       
    537         config.setIMDIBrowserUrl(param);
     536        config.setImdiBrowserUrl(param);
    538537
    539538        String expResult;
     
    544543        }
    545544       
    546         String result = config.getIMDIBrowserUrl("handle");
     545        String result = config.getImdiBrowserUrl("handle");
    547546
    548547        assertEquals(expResult, result);
  • vlo/branches/vlo-3.0/vlo-commons/src/test/resources/log4j.properties

    r4480 r4509  
    33log4j.appender.Stdout.layout.conversionPattern=%d %p [%c{1}#%M:%L] - %m%n
    44
    5 log4j.rootLogger=INFO,Stdout
     5log4j.rootLogger=DEBUG,Stdout
    66
    7 log4j.logger.org.apache.wicket=INFO
    8 log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
    9 log4j.logger.org.apache.wicket.version=INFO
    10 log4j.logger.org.apache.wicket.RequestCycle=INFO
    11 
    12 
  • vlo/branches/vlo-3.0/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r4507 r4509  
    122122        try {
    123123            // Delete the whole Solr db
    124             if (config.deleteAllFirst()) {
     124            if (config.getDeleteAllFirst()) {
    125125                LOG.info("Deleting original data...");
    126126                solrServer.deleteByQuery("*:*");
     
    155155           
    156156            // delete outdated entries (based on maxDaysInSolr parameter)
    157             if(config.getMaxDaysInSolr() > 0 && config.deleteAllFirst() == false) {
     157            if(config.getMaxDaysInSolr() > 0 && config.getDeleteAllFirst() == false) {
    158158                LOG.info("Deleting old files that were not seen for more than "+config.getMaxDaysInSolr()+" days...");
    159159                solrServer.deleteByQuery(FacetConstants.FIELD_LAST_SEEN+":[* TO NOW-"+config.getMaxDaysInSolr()+"DAYS]");
  • vlo/branches/vlo-3.0/vlo-importer/src/test/java/eu/clarin/cmdi/vlo/importer/ImporterTestcase.java

    r4507 r4509  
    1414    private final VloConfigFactory configFactory = new DefaultVloConfigFactory();
    1515    protected VloConfig config;
    16 
    1716    private File testDir;
    1817
     
    3635
    3736        // read the configuration defined in the packaged configuration file
    38         config = configFactory.newConfig();
     37        MetadataImporter.config = configFactory.newConfig();
    3938
    4039        // optionally, modify the configuration here
    41         config.setComponentRegistryRESTURL("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/");
     40        MetadataImporter.config.setComponentRegistryRESTURL("http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/");
     41        config = MetadataImporter.config;       
    4242    }
    4343
Note: See TracChangeset for help on using the changeset viewer.