From b7105ec464750300a17b32c861d7f0107519ae07 Mon Sep 17 00:00:00 2001
From: "Stefan E. Funk" <funk@sub.uni-goettingen.de>
Date: Wed, 6 Jul 2022 16:51:52 +0200
Subject: [PATCH] chore: fix (maybe) listrecords with set bug

---
 .../IdentifierListDelivererAbstract.java      | 13 ++++---
 .../textgrid/middleware/OAIPMHUtilities.java  | 27 +++++++-------
 .../RecordListDelivererAbstract.java          |  6 ++--
 .../middleware/RecordListDelivererDC.java     | 35 +++++++++----------
 4 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java
index b72d8c3b..ef688acf 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java
@@ -5,9 +5,8 @@ import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 import javax.xml.datatype.DatatypeConfigurationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -33,7 +32,7 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD
   // STATIC
   // **
 
-  private static Log log = LogFactory.getLog(RecordListDelivererAbstract.class);
+  private static Logger log = Logger.getGlobal();
 
   // **
   // CLASS
@@ -140,9 +139,9 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD
         try {
           datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat();
         } catch (ParseException e) {
-          log.error(e.getMessage());
+          log.severe(e.getMessage());
         } catch (DatatypeConfigurationException e) {
-          log.error(e.getMessage());
+          log.severe(e.getMessage());
         }
         String identifier = hit.getSourceAsMap().get(this.identifierField).toString();
         lit = setListIdentifierHeader(datestamp, identifier, lit, set);
@@ -157,10 +156,10 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD
         try {
           this.datestamp = OAIPMHUtilities.convertDateFormat(this.datestamp).toXMLFormat();
         } catch (ParseException e) {
-          log.error(e.getMessage());
+          log.severe(e.getMessage());
           // FIXME Go to ERROR state!
         } catch (DatatypeConfigurationException e) {
-          log.error(e.getMessage());
+          log.severe(e.getMessage());
           // FIXME Go to ERROR state!
         }
 
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java
index 8fea5655..3356351d 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java
@@ -15,14 +15,13 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.logging.Logger;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.XMLGregorianCalendar;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.elasticsearch.action.get.GetRequest;
 import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.client.RequestOptions;
@@ -55,7 +54,7 @@ import info.textgrid.namespaces.middleware.tgauth.ProjectInfo;
  */
 public class OAIPMHUtilities {
 
-  private static Log log = LogFactory.getLog(OAIPMHUtilities.class);
+  private static Logger log = Logger.getAnonymousLogger();
 
   // **
   // FINALS
@@ -213,7 +212,7 @@ public class OAIPMHUtilities {
   public static XMLGregorianCalendar convertDateFormat(String originalDateTimeString)
       throws ParseException, DatatypeConfigurationException {
 
-    log.debug("original date time string: " + originalDateTimeString);
+    log.fine("original date time string: " + originalDateTimeString);
 
     SimpleDateFormat tgItemTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
     Date date = tgItemTime.parse(originalDateTimeString);
@@ -265,7 +264,7 @@ public class OAIPMHUtilities {
       final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID,
       final int searchResponseSize, final int i) {
 
-    log.debug("Creating a ResumptionToken:\n " + "CompleteListSize: " + completeListSize + "\n"
+    log.fine("Creating a ResumptionToken:\n " + "CompleteListSize: " + completeListSize + "\n"
         + "ResumptionToken: " + resumptionToken + "\n" + "CursorCollector: " + cursorCollector
         + "\n" + "ScrollID: " + scrollID + "\n" + "SearchResponseSize: " + searchResponseSize + "\n"
         + "IterationStep: " + i);
@@ -295,7 +294,7 @@ public class OAIPMHUtilities {
         cursor = searchResponseSize;
         resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor));
 
-        log.debug("New ResumptionToken created from scroll ID: " + cursorCollector.get(scrollID));
+        log.fine("New ResumptionToken created from scroll ID: " + cursorCollector.get(scrollID));
       }
 
       // Set resumption token string if cursor is less then complete list size: More objects can be
@@ -398,8 +397,8 @@ public class OAIPMHUtilities {
    */
   public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) {
 
-    log.debug("JSON: " + (resultFromGetRequestInES == null ? "NULL" : resultFromGetRequestInES));
-    log.debug("FIELDS: " + fields);
+    log.fine("JSON: " + (resultFromGetRequestInES == null ? "NULL" : resultFromGetRequestInES));
+    log.fine("FIELDS: " + fields);
 
     List<String> fieldResults = new ArrayList<String>();
 
@@ -407,7 +406,7 @@ public class OAIPMHUtilities {
     for (String field : fields) {
       String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP);
 
-      log.debug("field[" + count++ + "]: " + field);
+      log.fine("field[" + count++ + "]: " + field);
 
       JSONObject singlePath = resultFromGetRequestInES;
       try {
@@ -432,11 +431,11 @@ public class OAIPMHUtilities {
           }
         }
       } catch (JSONException e) {
-        log.debug("IGNORING JSON ERROR: " + e.getMessage());
+        log.fine("IGNORING JSON ERROR: " + e.getMessage());
       }
     }
 
-    log.debug("field results: " + fieldResults);
+    log.fine("field results: " + fieldResults);
 
     return fieldResults;
   }
@@ -467,7 +466,7 @@ public class OAIPMHUtilities {
         }
       }
     } catch (JSONException e) {
-      log.debug("IGNORING JSON ERROR: " + e.getMessage());
+      log.fine("IGNORING JSON ERROR: " + e.getMessage());
     }
 
     return fieldResults;
@@ -582,11 +581,11 @@ public class OAIPMHUtilities {
       String id = prefix[1];
       if (IDENTIFIER_PREFIXES_TO_FILTER.contains(px)) {
         result = id;
-        log.debug("incoming id has been filtered to: " + result);
+        log.fine("incoming id has been filtered to: " + result);
       }
     }
 
-    log.debug("  ##  omit prefix? " + identifier + " --> " + result);
+    log.fine("  ##  omit prefix? " + identifier + " --> " + result);
 
     return result;
   }
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java
index 50af3030..86c495bb 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java
@@ -1,9 +1,9 @@
 package info.textgrid.middleware;
 
+
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.util.logging.Logger;
 import info.textgrid.middleware.oaipmh.RequestType;
 import info.textgrid.middleware.oaipmh.ResumptionTokenType;
 
@@ -15,7 +15,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType;
  */
 public abstract class RecordListDelivererAbstract implements RecordListDelivererInterface {
 
-  protected static Log log = LogFactory.getLog(RecordListDelivererAbstract.class);
+  protected static Logger log = Logger.getLogger(RecordListDelivererAbstract.class.getName());
 
   protected OAI_ESClient oaiEsClient;
 
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java
index 4435cefa..1cdac462 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java
@@ -7,8 +7,6 @@ import java.text.ParseException;
 import java.util.Hashtable;
 import java.util.Map;
 import javax.xml.datatype.DatatypeConfigurationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.elasticsearch.action.get.GetRequest;
 import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.search.SearchRequest;
@@ -45,7 +43,6 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract {
   // STATICS
   // **
 
-  private static Log log = LogFactory.getLog(OAIPMHImpl.class);
   protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>();
 
   // **
@@ -87,11 +84,13 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract {
    * @param client
    * @return
    */
-  public GetResponse furtherDCElements(String id, RestHighLevelClient client) {
+  public GetResponse furtherDCElements(final String id, final RestHighLevelClient client) {
 
-    if (id != null) {
+    String identifier = id;
+
+    if (identifier != null) {
       try {
-        id = URLDecoder.decode(id, "UTF-8");
+        identifier = URLDecoder.decode(id, "UTF-8");
       } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
@@ -100,7 +99,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract {
       String[] excludes = Strings.EMPTY_ARRAY;
       FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes);
       GetRequest getRequest =
-          new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id)
+          new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), identifier)
               .fetchSourceContext(fetchSourceContext);
 
       GetResponse responseWorkValues = null;
@@ -262,16 +261,16 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract {
 
       // Check the need for a resumption token!
 
-      log.debug("  ##  completeListSize: " + completeListSize);
-      log.debug("  ##  resumptionToken: " + resumptionToken);
-      log.debug("  ##  scrollid: " + scrollID);
-      log.debug("  ##  searchResponseSize: " + this.searchResponseSize);
+      log.fine("  ##  completeListSize: " + completeListSize);
+      log.fine("  ##  resumptionToken: " + resumptionToken);
+      log.fine("  ##  scrollid: " + scrollID);
+      log.fine("  ##  searchResponseSize: " + this.searchResponseSize);
 
       ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize,
           resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i);
 
       if (resTokenForResponse != null) {
-        log.debug("  ##  resTokenForResponse: " + resTokenForResponse.getValue());
+        log.fine("  ##  resTokenForResponse: " + resTokenForResponse.getValue());
       }
 
       recordList.setResumptionToken(resTokenForResponse);
@@ -341,12 +340,12 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract {
       // FOR DHREP ONLY: Add record with set metadata in it (to also find collection metadata in
       // Repository Search!)
       // FIXME Put query field into config!
-      if (this.dariah && set != null && !set.isEmpty()) {
-        QueryBuilder setQuery = QueryBuilders
-            .matchQuery("administrativeMetadata.dcterms:identifier", this.specFieldPrefix + set);
-
-        fetchFields(QueryBuilders.boolQuery().must(setQuery), recordList, resumptionToken, set);
-      }
+      // if (this.dariah && set != null && !set.isEmpty()) {
+      // QueryBuilder setQuery = QueryBuilders
+      // .matchQuery("administrativeMetadata.dcterms:identifier", this.specFieldPrefix + set);
+      //
+      // fetchFields(QueryBuilders.boolQuery().must(setQuery), recordList, resumptionToken, set);
+      // }
 
     } catch (UnsupportedEncodingException e) {
       // TODO Auto-generated catch block
-- 
GitLab