Changeset 5482
- Timestamp:
- 07/22/14 08:32:59 (10 years ago)
- Location:
- VirtualCollectionRegistry/trunk/VirtualCollectionRegistry
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/pom.xml
r5479 r5482 163 163 </dependency> 164 164 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 167 177 <dependency> 168 178 <groupId>com.sun.jersey.contribs</groupId> -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/Configuration.java
r5416 r5482 5 5 import java.io.IOException; 6 6 import java.util.Properties; 7 7 8 import org.slf4j.Logger; 8 9 import org.slf4j.LoggerFactory; … … 10 11 /** 11 12 * Stores some information needed for establishing connection to resolver server 12 * 13 * 13 14 * @author Thomas Eckart 14 15 * @author Twan Goosen 15 * 16 * 16 17 */ 17 18 public class Configuration { 19 private final static Logger LOG = LoggerFactory.getLogger(Configuration.class); 18 20 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; 20 25 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 } 25 43 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 } 43 51 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 } 51 69 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 } 72 78 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 } 81 93 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 } 96 97 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 } 103 101 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 } 110 105 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 } 117 109 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 } 125 138 } -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/HandleField.java
r5417 r5482 2 2 3 3 /** 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 such4 * 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 5 5 * restrictions. 6 * 6 * 7 7 * @author Thomas Eckart 8 *9 8 */ 10 9 public enum HandleField { -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/PidObject.java
r5417 r5482 12 12 /** 13 13 * Stores most(!) relevant information of a PID JSON object retrieved from the GWDG 14 * 14 * 15 15 * @author Thomas Eckart 16 *17 16 */ 18 17 public class PidObject { … … 37 36 /** 38 37 * Returns handle identifier 39 * 38 * 40 39 * @return handle identifier 41 40 */ … … 46 45 /** 47 46 * Returns stored value in EPIC handle for a specific field 48 * 47 * 49 48 * @param field 50 49 * name of the stored field -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/impl/PidResolverImpl.java
r5417 r5482 12 12 import net.sf.json.JSONArray; 13 13 14 import org.apache.log4j.Logger; 14 import org.slf4j.Logger; 15 import org.slf4j.LoggerFactory; 15 16 16 17 import com.sun.jersey.api.client.Client; … … 27 28 /** 28 29 * Requests information about handle from handle server 29 * 30 * 30 31 * @author Thomas Eckart 31 *32 32 */ 33 33 public class PidResolverImpl implements PidResolver { 34 private final static Logger LOG = Logger .getLogger(PidResolverImpl.class);34 private final static Logger LOG = LoggerFactory.getLogger(PidResolverImpl.class); 35 35 36 36 @Override 37 37 public JSONArray resolvePidAsJSON(final Configuration configuration, final String pid) throws IOException { 38 38 LOG.debug("Searching for \"" + pid + "\" at " + configuration.getServiceBaseURL()); 39 39 … … 54 54 55 55 @Override 56 56 public PidObject resolvePidAsPOJO(final Configuration configuration, final String pid) throws IOException { 57 57 return new PidObject(pid, resolvePidAsJSON(configuration, pid)); 58 58 } 59 59 60 60 @Override 61 61 public Map<String, JSONArray> searchPidAsJSON(final Configuration configuration, Map<HandleField, String> fieldMap) 62 62 throws IOException { 63 63 Map<String, JSONArray> jsonArrayMap = new HashMap<String, JSONArray>(); … … 71 71 72 72 @Override 73 73 public Map<String, PidObject> searchPidAsPOJO(final Configuration configuration, Map<HandleField, String> fieldMap) 74 74 throws IOException { 75 75 Map<String, JSONArray> jsonArrayMap = searchPidAsJSON(configuration, fieldMap); … … 85 85 86 86 @Override 87 87 public List<String> searchPidAsList(final Configuration configuration, Map<HandleField, String> fieldMap) 88 88 throws IOException { 89 89 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 10 10 11 11 import org.apache.commons.httpclient.HttpException; 12 import org.apache.log4j.Logger; 12 import org.slf4j.Logger; 13 import org.slf4j.LoggerFactory; 13 14 14 15 import com.sun.jersey.api.client.Client; … … 23 24 /** 24 25 * Registering new handles at handle server or modifying existing PID entries 25 * 26 * 26 27 * @author Thomas Eckart 27 *28 28 */ 29 29 public class PidWriterImpl implements PidWriter { 30 private final static Logger LOG = Logger .getLogger(PidWriterImpl.class);30 private final static Logger LOG = LoggerFactory.getLogger(PidWriterImpl.class); 31 31 private static final Pattern PID_OUTPUT_PATTERN = Pattern.compile(".*location</dt><dd><a href=\"([0-9A-Z-]+)\">.*"); 32 32 33 33 @Override 34 34 public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap) 35 35 throws HttpException { 36 36 LOG.debug("Try to create handle at " + configuration.getServiceBaseURL() + " with values: " + fieldMap); … … 60 60 61 61 @Override 62 62 public void modifyPid(final Configuration configuration, final String pid, Map<HandleField, String> fieldMap) { 63 63 LOG.debug("Try to modify handle \"" + pid + "\" at " + configuration.getServiceBaseURL() + " with new values: " 64 64 + fieldMap); … … 74 74 /** 75 75 * Generates JSON array that is understood by the EPIC handle service 76 * 76 * 77 77 * @param fieldMap 78 78 * mapping handle field -> value -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/interfaces/PidResolver.java
r5417 r5482 12 12 /** 13 13 * Requests information about handle from handle server 14 * 14 * 15 15 * @author Thomas Eckart 16 *17 16 */ 18 17 public interface PidResolver { … … 20 19 /** 21 20 * Get information about handle from handle server. 22 * 21 * 23 22 * @param configuration 24 23 * @param pid … … 31 30 /** 32 31 * Get information about handle from handle server. 33 * 32 * 34 33 * The returned object only provides some fields of the handle (like referenced URL). To have access to the complete content use resolvePidAsJSON(). 35 * 34 * 36 35 * @param configuration 37 36 * @param pid … … 44 43 /** 45 44 * Search all handles with matching field assignments. 46 * 45 * 47 46 * @param configuration 48 47 * @param fieldMap … … 56 55 /** 57 56 * Search all handles with matching field assignments. 58 * 57 * 59 58 * @param configuration 60 59 * @param fieldMap … … 68 67 /** 69 68 * Search all handles with matching field assignments. 70 * 69 * 71 70 * @param configuration 72 71 * @param fieldMap -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/interfaces/PidWriter.java
r5417 r5482 10 10 /** 11 11 * Registers new handles at handle server or modifies existing handles 12 * 12 * 13 13 * @author Thomas Eckart 14 * 14 * 15 15 */ 16 16 public interface PidWriter { 17 17 /** 18 18 * Try to register a new PID at handle server. Returns registered handle if successful. 19 * 19 * 20 20 * @param configuration 21 21 * @param fieldMap … … 29 29 /** 30 30 * 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 * 32 32 * @param configuration 33 33 * @param pid -
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/pid/EPICPersistentIdentifierConfiguration.java
r5416 r5482 11 11 /** 12 12 * Configuration for 13 * {@link EPICPersistentIdentifier ConfigurationEPIC API v2 persistent identifier provider}.13 * {@link EPICPersistentIdentifierProvider EPIC API v2 persistent identifier provider}. 14 14 * Reads a number of configuration values; assumes a 15 15 * {@link PropertyPlaceholderConfigurer} to be configured.
Note: See TracChangeset
for help on using the changeset viewer.