From 93c6053ba1025f1194cce83c60c911fe3837fe01 Mon Sep 17 00:00:00 2001
From: "Stefan E. Funk" <funk@sub.uni-goettingen.de>
Date: Wed, 24 Feb 2016 12:18:46 +0100
Subject: [PATCH] Added version method Increased service version

---
 oaipmh-core/pom.xml                           | 54 ++++++++++++-
 .../info/textgrid/middleware/OAIPMHImpl.java  | 80 ++++++++++---------
 .../textgrid/middleware/OAIPMHProducer.java   | 13 ++-
 oaipmh-webapp/pom.xml                         |  4 +-
 pom.xml                                       |  3 +-
 5 files changed, 111 insertions(+), 43 deletions(-)

diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml
index 82804127..4035c0e6 100644
--- a/oaipmh-core/pom.xml
+++ b/oaipmh-core/pom.xml
@@ -4,11 +4,11 @@
 	<parent>
 		<artifactId>oaipmh</artifactId>
 		<groupId>info.textgrid.middleware</groupId>
-		<version>2.1.8-SNAPSHOT</version>
+		<version>2.1.9-SNAPSHOT</version>
 	</parent>
 	<groupId>info.textgrid.middleware</groupId>
 	<artifactId>oaipmh-core</artifactId>
-	<version>2.1.8-SNAPSHOT</version>
+	<version>2.1.9-SNAPSHOT</version>
 	<packaging>jar</packaging>
 	<name>DARIAHDE :: OAI-PMH DataProvider :: Core</name>
 	<url>http://maven.apache.org</url>
@@ -106,6 +106,56 @@
 			</plugins>
 		</pluginManagement>
 		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-antrun-plugin</artifactId>
+				<version>${maven-antrun-plugin.version}</version>
+				<executions>
+					<execution>
+						<id>do-get-sources</id>
+						<phase>generate-sources</phase>
+						<goals>
+							<goal>run</goal>
+						</goals>
+						<configuration>
+							<tasks>
+								<tstamp>
+									<format property="BUILDDATE" pattern="yyyyMMddHHmm" />
+								</tstamp>
+								<echo
+									file="./src/main/java/info/textgrid/middleware/OaipmhServiceVersion.java">
+									package
+									info.textgrid.middleware;
+									public
+									final
+									class
+									OaipmhServiceVersion {
+									private
+									OaipmhServiceVersion() {
+									//
+									}
+									public
+									static
+									final
+									String
+									VERSION
+									=
+									"${project.version}";
+									public static
+									final
+									String
+									BUILDDATE =
+									"${BUILDDATE}";
+									public static final String
+									BUILDNAME
+									=
+									"${project.artifactId}";
+									}</echo>
+							</tasks>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
 			<plugin>
 				<groupId>org.codehaus.mojo</groupId>
 				<artifactId>jaxb2-maven-plugin</artifactId>
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java
index a64755eb..e96ad92b 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java
@@ -21,6 +21,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBElement;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.XMLGregorianCalendar;
@@ -68,6 +69,15 @@ public class OAIPMHImpl implements OAIPMHProducer {
 		this.identifierList = identifierList;
 	}
 
+	@GET
+	@Produces(MediaType.TEXT_PLAIN)
+	@Path("/version")
+	public String getVersion() {
+		return OaipmhServiceVersion.BUILDNAME + "-"
+				+ OaipmhServiceVersion.VERSION + "."
+				+ OaipmhServiceVersion.BUILDDATE;
+	}
+
 	/**
 	 * Getting The request values as QueryParam from a REST request and proceeds
 	 * appropriate to them
@@ -116,11 +126,11 @@ public class OAIPMHImpl implements OAIPMHProducer {
 		setSetRequestValue(set, request);
 		setVerbRequestValue(verb, verbParam, request);
 
-		if(textgrid==true){
+		if (textgrid == true) {
 			request.setValue(TGConstants.TG_REP_BASEURL);
 		}
-		if(dariah==true){
-		    request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
+		if (dariah == true) {
+			request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
 		}
 
 		if (verbParam != null) {
@@ -318,29 +328,28 @@ public class OAIPMHImpl implements OAIPMHProducer {
 			} else {
 				try {
 
-					//if (request.getSet() == null) {
-						identifierList.processIdentifierList(request.getFrom(),
-								request.getUntil(), request.getSet());
-						if (identifierList.processIdentifierList(
-								request.getFrom(), request.getUntil(), request.getSet()) != null) {
-							lit = identifierList.processIdentifierList(
-									request.getFrom(), request.getUntil(), request.getSet());
-							oai.setListIdentifiers(lit);
-						} else {
-							error.setError(TGConstants.OAI_NO_RECORD_MATCH)
-									.setValue(
-											"The combination of the values "
-													+ request.getFrom()
-													+ " and "
-													+ request.getUntil()
-													+ " results in an empty list");
-							oai.getError()
-									.add(error
-											.setError(TGConstants.OAI_NO_RECORD_MATCH));
-						}
-					
-
-					//}
+					// if (request.getSet() == null) {
+					identifierList.processIdentifierList(request.getFrom(),
+							request.getUntil(), request.getSet());
+					if (identifierList.processIdentifierList(request.getFrom(),
+							request.getUntil(), request.getSet()) != null) {
+						lit = identifierList.processIdentifierList(
+								request.getFrom(), request.getUntil(),
+								request.getSet());
+						oai.setListIdentifiers(lit);
+					} else {
+						error.setError(TGConstants.OAI_NO_RECORD_MATCH)
+								.setValue(
+										"The combination of the values "
+												+ request.getFrom() + " and "
+												+ request.getUntil()
+												+ " results in an empty list");
+						oai.getError()
+								.add(error
+										.setError(TGConstants.OAI_NO_RECORD_MATCH));
+					}
+
+					// }
 
 				} catch (Exception e) {
 					// TODO Auto-generated catch block
@@ -464,7 +473,8 @@ public class OAIPMHImpl implements OAIPMHProducer {
 				oai.getError().add(
 						error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
 			} else {
-				listRecords = recordList.getRecordsWithSet(request.getFrom(),request.getUntil(), request.getSet());
+				listRecords = recordList.getRecordsWithSet(request.getFrom(),
+						request.getUntil(), request.getSet());
 				if (recordList.isFoundItems()) {
 					// if(listRecords!=null){
 					oai.setListRecords(listRecords);
@@ -625,7 +635,6 @@ public class OAIPMHImpl implements OAIPMHProducer {
 		if (!verb.isEmpty()) {
 			request.setVerb(verbParam);
 		}
-
 	}
 
 	public RequestType setRequestType(String verb) {
@@ -634,14 +643,13 @@ public class OAIPMHImpl implements OAIPMHProducer {
 
 		return request;
 	}
-	
-	public void setTextGrid(boolean textgrid){
-		this.textgrid=textgrid;
-		
+
+	public void setTextGrid(boolean textgrid) {
+		this.textgrid = textgrid;
 	}
-	
-	public void setDariah(boolean dariah){
-		this.dariah=dariah;
-		
+
+	public void setDariah(boolean dariah) {
+		this.dariah = dariah;
 	}
+
 }
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java
index da223e78..77d94b1a 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java
@@ -7,6 +7,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.DefaultValue;
+import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBElement;
 
 /**
@@ -47,8 +48,16 @@ public interface OAIPMHProducer {
 			@QueryParam("set") @DefaultValue("") String set,
 			@QueryParam("from") @DefaultValue("") String from,
 			@QueryParam("until") @DefaultValue("") String until,
-			@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken
-			
+			@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken	
 	);
 
+	/**
+	 * @return
+	 */
+
+	@GET
+	@Produces(MediaType.TEXT_PLAIN)
+	@Path("/version")
+	public String getVersion();
+	
 }
diff --git a/oaipmh-webapp/pom.xml b/oaipmh-webapp/pom.xml
index a150dbc7..8c263aa9 100644
--- a/oaipmh-webapp/pom.xml
+++ b/oaipmh-webapp/pom.xml
@@ -4,12 +4,12 @@
 	<parent>
 		<artifactId>oaipmh</artifactId>
 		<groupId>info.textgrid.middleware</groupId>
-		<version>2.1.8-SNAPSHOT</version>
+		<version>2.1.9-SNAPSHOT</version>
 	</parent>
 	<groupId>info.textgrid.middleware</groupId>
 	<artifactId>oaipmh-webapp</artifactId>
 	<packaging>war</packaging>
-	<version>2.1.8-SNAPSHOT</version>
+	<version>2.1.9-SNAPSHOT</version>
 	<name>DARIAHDE :: OAI-PMH DataProvider :: Webapp</name>
 	<url>http://maven.apache.org</url>
 	<profiles>
diff --git a/pom.xml b/pom.xml
index ff26f80a..1f2455ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>info.textgrid.middleware</groupId>
   <artifactId>oaipmh</artifactId>
-  <version>2.1.8-SNAPSHOT</version>
+  <version>2.1.9-SNAPSHOT</version>
   <packaging>pom</packaging>
   <name>DARIAHDE :: OAI-PMH DataProvider</name>
   <properties>
@@ -19,6 +19,7 @@
     <slf4j.version>1.7.5</slf4j.version>
     <junit.version>4.11</junit.version>
     <jdk.version>1.7</jdk.version>
+    <maven-antrun-plugin.version>1.3</maven-antrun-plugin.version>
   </properties>
   <url>https://projects.gwdg.de/projects/oai-pmh</url>
   <scm>
-- 
GitLab