From 48ae5f693d63d148c4859c5f7ff6d20fe30dd566 Mon Sep 17 00:00:00 2001
From: "Stefan E. Funk" <funk@sub.uni-goettingen.de>
Date: Wed, 16 May 2018 17:10:07 +0200
Subject: [PATCH] added @Override again... seems to be the only difference.

---
 .../info/textgrid/middleware/OAIPMHImpl.java  | 311 +++++++++++-------
 .../textgrid/middleware/OAIPMHProducer.java   | 125 ++++---
 2 files changed, 258 insertions(+), 178 deletions(-)

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 56ba5f75..bb629cc4 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java
@@ -1,40 +1,38 @@
 package info.textgrid.middleware;
 
-import info.textgrid.middleware.oaipmh.GetRecordType;
-import info.textgrid.middleware.oaipmh.IdentifyType;
-import info.textgrid.middleware.oaipmh.ListIdentifiersType;
-import info.textgrid.middleware.oaipmh.ListMetadataFormatsType;
-import info.textgrid.middleware.oaipmh.ListRecordsType;
-import info.textgrid.middleware.oaipmh.ListSetsType;
-import info.textgrid.middleware.oaipmh.OAIPMHType;
-import info.textgrid.middleware.oaipmh.ObjectFactory;
-import info.textgrid.middleware.oaipmh.RequestType;
-import info.textgrid.middleware.oaipmh.VerbType;
-import java.io.IOException;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
-import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 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;
 import org.apache.commons.logging.LogFactory;
+import info.textgrid.middleware.oaipmh.GetRecordType;
+import info.textgrid.middleware.oaipmh.IdentifyType;
+import info.textgrid.middleware.oaipmh.ListIdentifiersType;
+import info.textgrid.middleware.oaipmh.ListMetadataFormatsType;
+import info.textgrid.middleware.oaipmh.ListRecordsType;
+import info.textgrid.middleware.oaipmh.ListSetsType;
+import info.textgrid.middleware.oaipmh.OAIPMHType;
+import info.textgrid.middleware.oaipmh.ObjectFactory;
+import info.textgrid.middleware.oaipmh.RequestType;
+import info.textgrid.middleware.oaipmh.VerbType;
 
 /**
+ * <p>
  * This class takes all possible arguments of an OAI-PMH request and proceeds depended on the given
- * arguments. It also deals as response handler
+ * arguments. It also deals as response handler.
+ * </p>
  * 
- * @author Maximilian Brodhun: SUB
- * @version 1.0
- * @since 29.01.2014
- *
+ * @author Maximilian Brodhun, SUB Göttingen
+ * @version 2018-05-16
+ * @since 2014-01-29
  */
-
 public class OAIPMHImpl implements OAIPMHProducer {
 
   private ErrorHandler error = new ErrorHandler();
@@ -51,6 +49,15 @@ public class OAIPMHImpl implements OAIPMHProducer {
 
   ListIdentifiersType lit = new ListIdentifiersType();
 
+  /**
+   * @param oaiEsClient
+   * @param rep
+   * @param recDeliv
+   * @param recordList
+   * @param metadataFormatList
+   * @param setList
+   * @param identifierList
+   */
   public OAIPMHImpl(OAI_ESClient oaiEsClient, RepIdentification rep, RecordDeliverer recDeliv,
       RecordListDeliverer recordList, MetadataFormatListDeliverer metadataFormatList,
       SetDeliverer setList, IdentifierListDeliverer identifierList) {
@@ -63,100 +70,59 @@ public class OAIPMHImpl implements OAIPMHProducer {
     this.identifierList = identifierList;
   }
 
-  /**
-   * <p>
-   * Getting The request values as QueryParam from a REST request and proceeds appropriate to them.
-   * </p>
+  // /*
+  // * (non-Javadoc)
+  // *
+  // * @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String,
+  // * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+  // */
+  // @POST
+  // @Path("/")
+  // @Produces(MediaType.TEXT_XML)
+  // public JAXBElement<OAIPMHType> postRequest(String verb, String identifier, String
+  // metadataPrefix,
+  // String set, String from, String until, String resumptionToken) {
+  // return handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
+  // }
+
+  /*
+   * (non-Javadoc)
    * 
-   * @return OAIPMHType object containing the whole response
+   * @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String,
+   * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
    */
-  @Override
   @GET
   @Path("/")
-  @Produces("text/xml")
-  public JAXBElement<OAIPMHType> getRequest(@QueryParam("verb") String verb,
-      @QueryParam("identifier") @DefaultValue("") String identifier,
-      @QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
-      @QueryParam("set") @DefaultValue("") String set,
-      @QueryParam("from") @DefaultValue("") String from,
-      @QueryParam("until") @DefaultValue("") String until,
-      @QueryParam("resumptionToken") @DefaultValue("") String resumptionToken) {
-
-    ObjectFactory obf = new ObjectFactory();
-    OAIPMHType response = new OAIPMHType();
-    JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(response);
-    VerbType verbParam = setVerb(verb);
-    RequestType request = new RequestType();
-
-    /*----Setting the responseDate of today-----*/
-    try {
-      XMLGregorianCalendar convertedDateFormat;
-      convertedDateFormat = OAIPMHUtillities
-          .convertDateFormat(OAIPMHUtillities.getXMLGregorianCalendarNow().toString());
-      response.setResponseDate(convertedDateFormat);
-    } catch (ParseException e) {
-      log.debug("can not parse date format");
-    } catch (DatatypeConfigurationException e) {
-      log.debug("Datatype configuration failed");
-    }
-
-    /* converting the request values */
-
-    setFromRequestValue(from, request);
-    setUntilRequestValue(until, request);
-    setIdentifierRequestValue(identifier, request);
-    setMetadataPrefixRequestValue(metadataPrefix, request);
-    setResumptionTokenRequestValue(resumptionToken, request);
-    setSetRequestValue(set, request);
-    // request.setSet(set);
-    request.setVerb(verbParam);
-
-    if (textgrid == true) {
-      request.setValue(TGConstants.TG_REP_BASEURL);
-    }
-    if (dariah == true) {
-      request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
-    }
-
-    if (verbParam != null) {
-      if (verbParam.value().equals("Identify")) {
-        oaipmhRoot = identifyRequest(obf, response, request);
-      } else if (verbParam.value().equals("GetRecord")) {
-        oaipmhRoot = getRecordRequest(obf, response, request);
-      } else if (verbParam.value().equals("ListIdentifiers")) {
-        try {
-          oaipmhRoot = listIdentifiersRequest(obf, response, request);
-        } catch (ParseException e) {
-          // TODO Auto-generated catch block
-          e.printStackTrace();
-        }
-      } else if (verbParam.value().equals("ListSets")) {
-        oaipmhRoot = listSetsRequest(obf, response, request);
-      } else if (verbParam.value().equals("ListMetadataFormats")) {
-        oaipmhRoot = listMetadataFormatsRequest(identifier, obf, response, request);
-      } else if (verbParam.value().equals("ListRecords")) {
-        oaipmhRoot = listRecordsRequest(obf, response, request);
-      }
-    } else {
-      response.getError().add(error.setError("VerbError"));
-
-    }
-
-    response.setRequest(request);
-
-    oaipmhRoot.setValue(response);
-
-    return oaipmhRoot;
+  @Produces(MediaType.TEXT_XML)
+  @Override
+  public JAXBElement<OAIPMHType> getRequest(String verb, String identifier, String metadataPrefix,
+      String set, String from, String until, String resumptionToken) {
+    return handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
+  }
 
+  /**
+   * @return
+   */
+  @GET
+  @Path("/version")
+  @Produces(MediaType.TEXT_PLAIN)
+  public String getVersion() {
+    return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "."
+        + OaipmhServiceVersion.BUILDDATE;
   }
 
   /**
    * checks the Identify request of correctness and response including errors in case of an
    * incorrect request
+   * 
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
    */
-
   public JAXBElement<OAIPMHType> identifyRequest(ObjectFactory obf, OAIPMHType oai,
       RequestType request) {
+
     List<String> errorValues = new ArrayList<String>();
     JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
     IdentifyType tgRepIdentificationRequest = new IdentifyType();
@@ -203,10 +169,15 @@ public class OAIPMHImpl implements OAIPMHProducer {
   /**
    * checks the GetRecord request of correctness and response including errors in case of an
    * incorrect request
+   * 
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
    */
-
   public JAXBElement<OAIPMHType> getRecordRequest(ObjectFactory obf, OAIPMHType oai,
       RequestType request) {
+
     List<String> errorValues = new ArrayList<String>();
     // RecordDeliverer recDeliv = new RecordDeliverer(oaiEsClient,
     // TGConstants.TGFields);
@@ -268,6 +239,10 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * checks the ListIdentifiers request of correctness and response including errors in case of an
    * incorrect request
    * 
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
    * @throws ParseException
    */
   public JAXBElement<OAIPMHType> listIdentifiersRequest(ObjectFactory obf, OAIPMHType oai,
@@ -328,25 +303,32 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * checks the ListSets request of correctness and response including errors in case of an
    * incorrect request
    * 
-   * @throws IOException
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
    */
   public JAXBElement<OAIPMHType> listSetsRequest(ObjectFactory obf, OAIPMHType oai,
       RequestType request) {
 
     ListSetsType sl = new ListSetsType();
-
     JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
-
     sl = this.setList.setListBuilder();
-
     oai.setListSets(sl);
 
-
     return oaipmhRoot;
   }
 
+  /**
+   * @param id
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
+   */
   public JAXBElement<OAIPMHType> listMetadataFormatsRequest(String id, ObjectFactory obf,
       OAIPMHType oai, RequestType request) {
+
     List<String> errorValues = new ArrayList<String>();
     ListMetadataFormatsType listMF = new ListMetadataFormatsType();
     JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
@@ -392,8 +374,15 @@ public class OAIPMHImpl implements OAIPMHProducer {
     return oaipmhRoot;
   }
 
+  /**
+   * @param obf
+   * @param oai
+   * @param request
+   * @return
+   */
   public JAXBElement<OAIPMHType> listRecordsRequest(ObjectFactory obf, OAIPMHType oai,
       RequestType request) {
+
     // System.out.println("blablablabla");
     List<String> errorValues = new ArrayList<String>();
     ListRecordsType listRecords = new ListRecordsType();
@@ -445,6 +434,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * @return verbParam: the verbParam as an OAIPMH verb type
    */
   public VerbType setVerb(String verb) {
+
     VerbType verbParam = null;
 
     if (verb == null) {
@@ -477,11 +467,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
    */
 
   public void setFromRequestValue(String from, RequestType request) {
-
     if (!from.isEmpty()) {
       request.setFrom(from);
     }
-
   }
 
   /**
@@ -489,13 +477,10 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * 
    * @param until
    */
-
   public void setUntilRequestValue(String until, RequestType request) {
-
     if (!until.isEmpty()) {
       request.setUntil(until);
     }
-
   }
 
   /**
@@ -503,9 +488,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * 
    * @param identifier
    */
-
   public void setIdentifierRequestValue(String identifier, RequestType request) {
-
     if (!identifier.isEmpty()) {
       request.setIdentifier(identifier);
     }
@@ -516,13 +499,10 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * 
    * @param metadataPrefix
    */
-
   public void setMetadataPrefixRequestValue(String metadataPrefix, RequestType request) {
-
     if (!metadataPrefix.isEmpty()) {
       request.setMetadataPrefix(metadataPrefix);
     }
-
   }
 
   /**
@@ -530,46 +510,121 @@ public class OAIPMHImpl implements OAIPMHProducer {
    * 
    * @param resumptionToken
    */
-
   public void setResumptionTokenRequestValue(String resumptionToken, RequestType request) {
-
     if (!resumptionToken.isEmpty()) {
       request.setResumptionToken(resumptionToken);
     }
   }
 
   /**
+   * <p>
    * Setting the set value for the request
+   * </p>
    * 
    * @param set
+   * @param request
    */
-
   public void setSetRequestValue(String set, RequestType request) {
-
     if (!set.isEmpty()) {
       request.setSet(set);
     }
   }
 
-
-
+  /**
+   * @param textgrid
+   */
   public void setTextGrid(boolean textgrid) {
     this.textgrid = textgrid;
   }
 
+  /**
+   * @param dariah
+   */
   public void setDariah(boolean dariah) {
     this.dariah = dariah;
   }
 
+  // **
+  // PRIVATE METHODS
+  // **
+
   /**
+   * @param verb
+   * @param identifier
+   * @param metadataPrefix
+   * @param set
+   * @param from
+   * @param until
+   * @param resumptionToken
    * @return
    */
-  @GET
-  @Path("/version")
-  @Produces(MediaType.TEXT_PLAIN)
-  public String getVersion() {
-    return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "."
-        + OaipmhServiceVersion.BUILDDATE;
+  private JAXBElement<OAIPMHType> handleRequest(String verb, String identifier,
+      String metadataPrefix, String set, String from, String until, String resumptionToken) {
+
+    ObjectFactory obf = new ObjectFactory();
+    OAIPMHType response = new OAIPMHType();
+    JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(response);
+    VerbType verbParam = setVerb(verb);
+    RequestType request = new RequestType();
+
+    /*----Setting the responseDate of today-----*/
+    try {
+      XMLGregorianCalendar convertedDateFormat;
+      convertedDateFormat = OAIPMHUtillities
+          .convertDateFormat(OAIPMHUtillities.getXMLGregorianCalendarNow().toString());
+      response.setResponseDate(convertedDateFormat);
+    } catch (ParseException e) {
+      log.debug("can not parse date format");
+    } catch (DatatypeConfigurationException e) {
+      log.debug("Datatype configuration failed");
+    }
+
+    /* converting the request values */
+
+    setFromRequestValue(from, request);
+    setUntilRequestValue(until, request);
+    setIdentifierRequestValue(identifier, request);
+    setMetadataPrefixRequestValue(metadataPrefix, request);
+    setResumptionTokenRequestValue(resumptionToken, request);
+    setSetRequestValue(set, request);
+    // request.setSet(set);
+    request.setVerb(verbParam);
+
+    if (textgrid == true) {
+      request.setValue(TGConstants.TG_REP_BASEURL);
+    }
+    if (dariah == true) {
+      request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
+    }
+
+    if (verbParam != null) {
+      if (verbParam.value().equals("Identify")) {
+        oaipmhRoot = identifyRequest(obf, response, request);
+      } else if (verbParam.value().equals("GetRecord")) {
+        oaipmhRoot = getRecordRequest(obf, response, request);
+      } else if (verbParam.value().equals("ListIdentifiers")) {
+        try {
+          oaipmhRoot = listIdentifiersRequest(obf, response, request);
+        } catch (ParseException e) {
+          // TODO Auto-generated catch block
+          e.printStackTrace();
+        }
+      } else if (verbParam.value().equals("ListSets")) {
+        oaipmhRoot = listSetsRequest(obf, response, request);
+      } else if (verbParam.value().equals("ListMetadataFormats")) {
+        oaipmhRoot = listMetadataFormatsRequest(identifier, obf, response, request);
+      } else if (verbParam.value().equals("ListRecords")) {
+        oaipmhRoot = listRecordsRequest(obf, response, request);
+      }
+    } else {
+      response.getError().add(error.setError("VerbError"));
+    }
+
+    response.setRequest(request);
+
+    oaipmhRoot.setValue(response);
+
+    return oaipmhRoot;
   }
 
 }
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 f95e265b..450bdb68 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java
@@ -1,73 +1,98 @@
 package info.textgrid.middleware;
 
 import info.textgrid.middleware.oaipmh.OAIPMHType;
-
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBElement;
 
 /**
+ * <p>
  * Interface to the get Request function
+ * </p>
  * 
  * @author Maximilian Brodhun, SUB
- * @version 1.0
- * @since 15.01.2014
+ * @version 2018-05-16
+ * @since 2014-01-15
  */
 
 public interface OAIPMHProducer {
 
-	/**
-	 * 
-	 * @param verb
-	 *            The parameter verb is a required parameter to all requests.
-	 *            Depending on it the request will be proceed. Possible values
-	 *            are: GetRecord, Identify, ListIdentifiers,
-	 *            ListMetadataFormats, ListRecords and ListSets In case of other
-	 *            verbs an error response will be send back
-	 * 
-	 * @param identifier
-	 *            This value indicates if the request will be proceed just for a
-	 *            single identifier of the repository
-	 * @param metadataPrefix
-	 *            To limit the response just for a special metadata format this
-	 *            value can be used. The prefix "oai_dc" has to be supported by
-	 *            all repositories
-	 * @param set
-	 *            To represent the architecture of the repository it is possible
-	 *            to make sets which work like categories. At the moment
-	 *            textgrid does not support sets
-	 * @param from
-	 *            Start value to filter the response for a specific interval
-	 * @param until
-	 *            End value to filter the response for a specific interval
-	 * @param resumptionToken
-	 *            Indicates how many value will be send back in the response
-	 *
-	 */
-    @POST
-	@GET
-	@Path("/")
-	@Produces(MediaType.TEXT_XML)
-	JAXBElement<OAIPMHType> getRequest(
-			@QueryParam("verb") String verb,
-			@QueryParam("identifier") @DefaultValue("") String identifier,
-			@QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
-			@QueryParam("set") @DefaultValue("") String set,
-			@QueryParam("from") @DefaultValue("") String from,
-			@QueryParam("until") @DefaultValue("") String until,
-			@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken);
+  /**
+   * <p>
+   * Getting the request values as QueryParam from a REST GET request and proceeds appropriate to
+   * them.
+   * </p>
+   * 
+   * @param verb - The parameter verb is a required parameter to all requests. Depending on it the
+   *        request will be proceed. Possible values are: GetRecord, Identify, ListIdentifiers,
+   *        ListMetadataFormats, ListRecords and ListSets In case of other verbs an error response
+   *        will be send back
+   * @param identifier - This value indicates if the request will be proceed just for a single
+   *        identifier of the repository
+   * @param metadataPrefix - To limit the response just for a special metadata format this value can
+   *        be used. The prefix "oai_dc" has to be supported by all repositories
+   * @param set - To represent the architecture of the repository it is possible to make sets which
+   *        work like categories. At the moment textgrid does not support sets
+   * @param from - Start value to filter the response for a specific interval
+   * @param until - End value to filter the response for a specific interval
+   * @param resumptionToken - Indicates how many value will be send back in the response
+   * @return OAIPMHType object containing the whole response
+   */
+  @GET
+  @Path("/")
+  @Produces(MediaType.TEXT_XML)
+  JAXBElement<OAIPMHType> getRequest(@QueryParam("verb") String verb,
+      @QueryParam("identifier") @DefaultValue("") String identifier,
+      @QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
+      @QueryParam("set") @DefaultValue("") String set,
+      @QueryParam("from") @DefaultValue("") String from,
+      @QueryParam("until") @DefaultValue("") String until,
+      @QueryParam("resumptionToken") @DefaultValue("") String resumptionToken);
+
+//  /**
+//   * <p>
+//   * Getting the request values as FormParams from a REST POST request and proceeds appropriate to
+//   * them.
+//   * </p>
+//   * 
+//   * @param verb - The parameter verb is a required parameter to all requests. Depending on it the
+//   *        request will be proceed. Possible values are: GetRecord, Identify, ListIdentifiers,
+//   *        ListMetadataFormats, ListRecords and ListSets In case of other verbs an error response
+//   *        will be send back
+//   * @param identifier - This value indicates if the request will be proceed just for a single
+//   *        identifier of the repository
+//   * @param metadataPrefix - To limit the response just for a special metadata format this value can
+//   *        be used. The prefix "oai_dc" has to be supported by all repositories
+//   * @param set - To represent the architecture of the repository it is possible to make sets which
+//   *        work like categories. At the moment textgrid does not support sets
+//   * @param from - Start value to filter the response for a specific interval
+//   * @param until - End value to filter the response for a specific interval
+//   * @param resumptionToken - Indicates how many value will be send back in the response
+//   * @return OAIPMHType object containing the whole response
+//   */
+//  @POST
+//  @Path("/")
+//  @Produces(MediaType.TEXT_XML)
+//  JAXBElement<OAIPMHType> postRequest(@FormParam("verb") String verb,
+//      @FormParam("identifier") @DefaultValue("") String identifier,
+//      @FormParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
+//      @FormParam("set") @DefaultValue("") String set,
+//      @FormParam("from") @DefaultValue("") String from,
+//      @FormParam("until") @DefaultValue("") String until,
+//      @FormParam("resumptionToken") @DefaultValue("") String resumptionToken);
 
-	/**
-	 * @return
-	 */
-	@GET
-	@Path("/version")
-	@Produces(MediaType.TEXT_PLAIN)
-	String getVersion();
+  /**
+   * @return
+   */
+  @GET
+  @Path("/version")
+  @Produces(MediaType.TEXT_PLAIN)
+  String getVersion();
 
 }
-- 
GitLab