Changeset 5482


Ignore:
Timestamp:
07/22/14 08:32:59 (10 years ago)
Author:
Twan Goosen
Message:

Updated the PID services according to a the new version (2.0.6-SNAPSHOT) provided by Thomas Eckart

Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/pom.xml

    r5479 r5482  
    163163        </dependency>
    164164
    165         <!-- Libraries required for de.uni_leipzig.* EPIC library (todo: replace
    166         with dependency on detached library) -->
     165        <!--
     166            Below: libraries required for de.uni_leipzig.* EPIC library
     167           
     168            TODO: replace with dependency on detached library once available
     169
     170            <dependency>
     171                <groupId>de.uni_leipzig.asv</groupId>
     172                <artifactId>clarin.webservices.pidservices2</artifactId>
     173                <version>2.0.6-SNAPSHOT</version>
     174            </dependency>
     175        -->
     176
    167177        <dependency>
    168178            <groupId>com.sun.jersey.contribs</groupId>
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/Configuration.java

    r5416 r5482  
    55import java.io.IOException;
    66import java.util.Properties;
     7
    78import org.slf4j.Logger;
    89import org.slf4j.LoggerFactory;
     
    1011/**
    1112 * Stores some information needed for establishing connection to resolver server
    12  *
     13 * 
    1314 * @author Thomas Eckart
    1415 * @author Twan Goosen
    15  *
     16 * 
    1617 */
    1718public class Configuration {
     19        private final static Logger LOG = LoggerFactory.getLogger(Configuration.class);
    1820
    19     private final static Logger LOG = LoggerFactory.getLogger(Configuration.class);
     21        private String serviceBaseURL;
     22        private String handlePrefix;
     23        private String user;
     24        private String password;
    2025
    21     private final String serviceBaseURL;
    22     private final String handlePrefix;
    23     private final String user;
    24     private final String password;
     26        /**
     27         * Creates a configuration from the <em>config.properties</em> file. Expecting the following properties in the file:
     28         * <ul>
     29         * <li>SERVICE_BASE_URL</li>
     30         * <li>HANDLE_PREFIX</li>
     31         * <li>USER</li>
     32         * <li>PASSWORD</li>
     33         * </ul>
     34         *
     35         * A missing property will result in a runtime exception
     36         *
     37         * @throws IOException
     38         *             if the properties file could not be read
     39         */
     40        public Configuration() throws IOException {
     41                this(readProperties("config.properties"));
     42        }
    2543
    26     /**
    27      * Creates a configuration from the <em>config.properties</em>
    28      * file. Expecting the following properties in the file:
    29      * <ul>
    30      * <li>SERVICE_BASE_URL</li>
    31      * <li>HANDLE_PREFIX</li>
    32      * <li>USER</li>
    33      * <li>PASSWORD</li>
    34      * </ul>
    35      *
    36      * A missing property will result in a runtime exception
    37      *
    38      * @throws IOException if the properties file could not be read
    39      */
    40     public Configuration() throws IOException {
    41         this(readProperties("config.properties"));
    42     }
     44        public static Properties readProperties(String file) throws IOException {
     45                final Properties properties = new Properties();
     46                try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
     47                        properties.load(stream);
     48                }
     49                return properties;
     50        }
    4351
    44     public static Properties readProperties(String file) throws IOException {
    45         final Properties properties = new Properties();
    46         try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
    47             properties.load(stream);
    48         }
    49         return properties;
    50     }
     52        /**
     53         * Creates a configuration from properties. Expecting the following properties:
     54         * <ul>
     55         * <li>SERVICE_BASE_URL</li>
     56         * <li>HANDLE_PREFIX</li>
     57         * <li>USER</li>
     58         * <li>PASSWORD</li>
     59         * </ul>
     60         * A missing property will result in a runtime exception
     61         *
     62         *
     63         * @param properties
     64         */
     65        public Configuration(Properties properties) {
     66                this(getRequiredProperty(properties, "SERVICE_BASE_URL"), getRequiredProperty(properties, "HANDLE_PREFIX"),
     67                                getRequiredProperty(properties, "USER"), getRequiredProperty(properties, "PASSWORD"));
     68        }
    5169
    52     /**
    53      * Creates a configuration from properties. Expecting the following
    54      * properties:
    55      * <ul>
    56      * <li>SERVICE_BASE_URL</li>
    57      * <li>HANDLE_PREFIX</li>
    58      * <li>USER</li>
    59      * <li>PASSWORD</li>
    60      * </ul>
    61      * A missing property will result in a runtime exception
    62      *
    63      *
    64      * @param properties
    65      */
    66     public Configuration(Properties properties) {
    67         this(getRequiredProperty(properties, "SERVICE_BASE_URL"),
    68                 getRequiredProperty(properties, "HANDLE_PREFIX"),
    69                 getRequiredProperty(properties, "USER"),
    70                 getRequiredProperty(properties, "PASSWORD"));
    71     }
     70        private static String getRequiredProperty(Properties properties, String name) {
     71                final String value = properties.getProperty(name);
     72                if (value == null) {
     73                        throw new RuntimeException("Required property " + name + " missing!");
     74                }
     75                LOG.debug("Read PID client configuration parameter {}: '{}'", name, value);
     76                return value;
     77        }
    7278
    73     private static String getRequiredProperty(Properties properties, String name) {
    74         final String value = properties.getProperty(name);
    75         if (value == null) {
    76             throw new RuntimeException("Required property " + name + " missing!");
    77         }
    78         LOG.debug("Read PID client configuration parameter {}: '{}'", name, value);
    79         return value;
    80     }
     79        /**
     80         *
     81         * @param serviceBaseURL
     82         * @param handlePrefix
     83         * @param user
     84         * @param password
     85         */
     86        public Configuration(final String serviceBaseURL, final String handlePrefix, final String user,
     87                        final String password) {
     88                this.serviceBaseURL = serviceBaseURL;
     89                this.handlePrefix = handlePrefix;
     90                this.user = user;
     91                this.password = password;
     92        }
    8193
    82     /**
    83      *
    84      * @param serviceBaseURL
    85      * @param handlePrefix
    86      * @param user
    87      * @param password
    88      */
    89     public Configuration(final String serviceBaseURL, final String handlePrefix, final String user,
    90             final String password) {
    91         this.serviceBaseURL = serviceBaseURL;
    92         this.handlePrefix = handlePrefix;
    93         this.user = user;
    94         this.password = password;
    95     }
     94        public void setServiceBaseURL(final String serviceBaseURL) {
     95                this.serviceBaseURL = serviceBaseURL;
     96        }
    9697
    97     /**
    98      * @return serviceBaseURL (e.g. http://handle.gwdg.de:8080/pidservice/)
    99      */
    100     public String getServiceBaseURL() {
    101         return serviceBaseURL;
    102     }
     98        public void setHandlePrefix(final String handlePrefix) {
     99                this.handlePrefix = handlePrefix;
     100        }
    103101
    104     /**
    105      * @return handle prefix (e.g. 11022)
    106      */
    107     public String getHandlePrefix() {
    108         return handlePrefix;
    109     }
     102        public void setUser(final String user) {
     103                this.user = user;
     104        }
    110105
    111     /**
    112      * @return resolver account name
    113      */
    114     public String getUser() {
    115         return user;
    116     }
     106        public void setPassword(final String password) {
     107                this.password = password;
     108        }
    117109
    118     /**
    119      *
    120      * @return resolver password
    121      */
    122     public String getPassword() {
    123         return password;
    124     }
     110        /**
     111         * @return serviceBaseURL (e.g. http://handle.gwdg.de:8080/pidservice/)
     112         */
     113        public String getServiceBaseURL() {
     114                return serviceBaseURL;
     115        }
     116
     117        /**
     118         * @return handle prefix (e.g. 11022)
     119         */
     120        public String getHandlePrefix() {
     121                return handlePrefix;
     122        }
     123
     124        /**
     125         * @return resolver account name
     126         */
     127        public String getUser() {
     128                return user;
     129        }
     130
     131        /**
     132         *
     133         * @return resolver password
     134         */
     135        public String getPassword() {
     136                return password;
     137        }
    125138}
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/HandleField.java

    r5417 r5482  
    22
    33/**
    4  * Fields that can be stored via the EPIC v2 API. This enumeration is a restriction of allowed fields in this project. The EPIC API does not have such
     4 * Fields that can be stored via the EPIC v2 API. This enumeration is a restriction of allowed fields <em>in this project</em>. The EPIC API does not have such
    55 * restrictions.
    6  *
     6 * 
    77 * @author Thomas Eckart
    8  *
    98 */
    109public enum HandleField {
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/PidObject.java

    r5417 r5482  
    1212/**
    1313 * Stores most(!) relevant information of a PID JSON object retrieved from the GWDG
    14  *
     14 * 
    1515 * @author Thomas Eckart
    16  *
    1716 */
    1817public class PidObject {
     
    3736        /**
    3837         * Returns handle identifier
    39          *
     38         * 
    4039         * @return handle identifier
    4140         */
     
    4645        /**
    4746         * Returns stored value in EPIC handle for a specific field
    48          *
     47         * 
    4948         * @param field
    5049         *            name of the stored field
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/impl/PidResolverImpl.java

    r5417 r5482  
    1212import net.sf.json.JSONArray;
    1313
    14 import org.apache.log4j.Logger;
     14import org.slf4j.Logger;
     15import org.slf4j.LoggerFactory;
    1516
    1617import com.sun.jersey.api.client.Client;
     
    2728/**
    2829 * Requests information about handle from handle server
    29  *
     30 * 
    3031 * @author Thomas Eckart
    31  *
    3232 */
    3333public class PidResolverImpl implements PidResolver {
    34         private final static Logger LOG = Logger.getLogger(PidResolverImpl.class);
     34        private final static Logger LOG = LoggerFactory.getLogger(PidResolverImpl.class);
    3535
    3636        @Override
    37     public JSONArray resolvePidAsJSON(final Configuration configuration, final String pid) throws IOException {
     37        public JSONArray resolvePidAsJSON(final Configuration configuration, final String pid) throws IOException {
    3838                LOG.debug("Searching for \"" + pid + "\" at " + configuration.getServiceBaseURL());
    3939
     
    5454
    5555        @Override
    56     public PidObject resolvePidAsPOJO(final Configuration configuration, final String pid) throws IOException {
     56        public PidObject resolvePidAsPOJO(final Configuration configuration, final String pid) throws IOException {
    5757                return new PidObject(pid, resolvePidAsJSON(configuration, pid));
    5858        }
    5959
    6060        @Override
    61     public Map<String, JSONArray> searchPidAsJSON(final Configuration configuration, Map<HandleField, String> fieldMap)
     61        public Map<String, JSONArray> searchPidAsJSON(final Configuration configuration, Map<HandleField, String> fieldMap)
    6262                        throws IOException {
    6363                Map<String, JSONArray> jsonArrayMap = new HashMap<String, JSONArray>();
     
    7171
    7272        @Override
    73     public Map<String, PidObject> searchPidAsPOJO(final Configuration configuration, Map<HandleField, String> fieldMap)
     73        public Map<String, PidObject> searchPidAsPOJO(final Configuration configuration, Map<HandleField, String> fieldMap)
    7474                        throws IOException {
    7575                Map<String, JSONArray> jsonArrayMap = searchPidAsJSON(configuration, fieldMap);
     
    8585
    8686        @Override
    87     public List<String> searchPidAsList(final Configuration configuration, Map<HandleField, String> fieldMap)
     87        public List<String> searchPidAsList(final Configuration configuration, Map<HandleField, String> fieldMap)
    8888                        throws IOException {
    8989                LOG.debug("Searching at " + configuration.getServiceBaseURL() + " with: " + fieldMap);
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/impl/PidWriterImpl.java

    r5417 r5482  
    1010
    1111import org.apache.commons.httpclient.HttpException;
    12 import org.apache.log4j.Logger;
     12import org.slf4j.Logger;
     13import org.slf4j.LoggerFactory;
    1314
    1415import com.sun.jersey.api.client.Client;
     
    2324/**
    2425 * Registering new handles at handle server or modifying existing PID entries
    25  *
     26 * 
    2627 * @author Thomas Eckart
    27  *
    2828 */
    2929public class PidWriterImpl implements PidWriter {
    30         private final static Logger LOG = Logger.getLogger(PidWriterImpl.class);
     30        private final static Logger LOG = LoggerFactory.getLogger(PidWriterImpl.class);
    3131        private static final Pattern PID_OUTPUT_PATTERN = Pattern.compile(".*location</dt><dd><a href=\"([0-9A-Z-]+)\">.*");
    3232
    3333        @Override
    34     public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap)
     34        public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap)
    3535                        throws HttpException {
    3636                LOG.debug("Try to create handle at " + configuration.getServiceBaseURL() + " with values: " + fieldMap);
     
    6060
    6161        @Override
    62     public void modifyPid(final Configuration configuration, final String pid, Map<HandleField, String> fieldMap) {
     62        public void modifyPid(final Configuration configuration, final String pid, Map<HandleField, String> fieldMap) {
    6363                LOG.debug("Try to modify handle \"" + pid + "\" at " + configuration.getServiceBaseURL() + " with new values: "
    6464                                + fieldMap);
     
    7474        /**
    7575         * Generates JSON array that is understood by the EPIC handle service
    76          *
     76         * 
    7777         * @param fieldMap
    7878         *            mapping handle field -> value
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/interfaces/PidResolver.java

    r5417 r5482  
    1212/**
    1313 * Requests information about handle from handle server
    14  *
     14 * 
    1515 * @author Thomas Eckart
    16  *
    1716 */
    1817public interface PidResolver {
     
    2019        /**
    2120         * Get information about handle from handle server.
    22          *
     21         * 
    2322         * @param configuration
    2423         * @param pid
     
    3130        /**
    3231         * Get information about handle from handle server.
    33          *
     32         * 
    3433         * The returned object only provides some fields of the handle (like referenced URL). To have access to the complete content use resolvePidAsJSON().
    35          *
     34         * 
    3635         * @param configuration
    3736         * @param pid
     
    4443        /**
    4544         * Search all handles with matching field assignments.
    46          *
     45         * 
    4746         * @param configuration
    4847         * @param fieldMap
     
    5655        /**
    5756         * Search all handles with matching field assignments.
    58          *
     57         * 
    5958         * @param configuration
    6059         * @param fieldMap
     
    6867        /**
    6968         * Search all handles with matching field assignments.
    70          *
     69         * 
    7170         * @param configuration
    7271         * @param fieldMap
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/interfaces/PidWriter.java

    r5417 r5482  
    1010/**
    1111 * Registers new handles at handle server or modifies existing handles
    12  *
     12 * 
    1313 * @author Thomas Eckart
    14  *
     14 * 
    1515 */
    1616public interface PidWriter {
    1717        /**
    1818         * Try to register a new PID at handle server. Returns registered handle if successful.
    19          *
     19         * 
    2020         * @param configuration
    2121         * @param fieldMap
     
    2929        /**
    3030         * Modify existing PID. This method overwrites all existing fields! Fields that should remain stored for the PID have to be added to fieldMap.
    31          *
     31         * 
    3232         * @param configuration
    3333         * @param pid
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/pid/EPICPersistentIdentifierConfiguration.java

    r5416 r5482  
    1111/**
    1212 * Configuration for
    13  * {@link EPICPersistentIdentifierConfiguration EPIC API v2 persistent identifier provider}.
     13 * {@link EPICPersistentIdentifierProvider EPIC API v2 persistent identifier provider}.
    1414 * Reads a number of configuration values; assumes a
    1515 * {@link PropertyPlaceholderConfigurer} to be configured.
Note: See TracChangeset for help on using the changeset viewer.