From 1e73e583e3a0b73835034df569260b5bc8822ee0 Mon Sep 17 00:00:00 2001
From: mbrodhu <brodhun@sub.uni-goettingen.de>
Date: Tue, 6 Jan 2015 13:02:44 +0100
Subject: [PATCH] less hardcoded dependencies for the fetch fields. Now in an
 extra constant class. TODO: make it configurable with beans

---
 oaipmh-core/pom.xml                           |   4 +-
 .../middleware/RecordListDeliverer.java       | 179 ++++++++----------
 .../info/textgrid/middleware/TGConstants.java |  27 +++
 .../info/textgrid/middleware/OaiPmhTest.java  |  16 +-
 oaipmh-webapp/pom.xml                         |   4 +-
 pom.xml                                       |   2 +-
 6 files changed, 121 insertions(+), 111 deletions(-)

diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml
index 6506c215..4cd3edad 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>1.3.5-SNAPSHOT</version>
+		<version>1.3.6-SNAPSHOT</version>
 	</parent>
 	<groupId>info.textgrid.middleware</groupId>
 	<artifactId>oaipmh-core</artifactId>
-	<version>1.3.5-SNAPSHOT</version>
+	<version>1.3.6-SNAPSHOT</version>
 	<packaging>jar</packaging>
 	<name>TextGrid :: TG-OAI-PMH :: Core</name>
 	<url>http://maven.apache.org</url>
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java
index d273939f..e7954349 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java
@@ -36,26 +36,11 @@ import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes;
 
 public class RecordListDeliverer{
 
-	// **
-	// STATIC FINALS
-	// **
-
-	private static final String						CREATED				= "created";
-	private static final String						FORMAT				= "format";
-	private static final String						URI					= "textgridUri";
-	private static final String						IS_DERIVED_FROM		= "relations.isDerivedFrom";
-	private static final String						TITLE				= "title";
-	private static final String						EDITION_ISEDITIONOF	= "edition.isEditionOf";
 	//private static final String						BIBCIT_BIBID		= "edition.source.bibliographicCitation.bibidentifier";
-	private static final String						WORK_ABSTRACT		= "work.abstract";
-	private static final String						WORK_GENRE			= "work.genre";
-	private static final String						WORK_TYPE			= "work.type";
-	private static final String						WORK_SPATIAL		= "work.spatial.value";
-	private static final String						WORK_TEMPORAL		= "work.temporal.value";
-	private static final String						WORK_AGENT			= "work.agent.value";
-	private static final String						WORK_ID				= "work.subject.id.value";
+	
 	
 	private String set;
+	
 	// **
 	// STATICS
 	// **
@@ -102,9 +87,13 @@ public class RecordListDeliverer{
 	}
 
 	/**
+	 * the furtherDCElementes fetches the specified fields from the work object. 
+	 * This function is called from the function fetchFields 
+	 * 
 	 * @param id
 	 * @param esClient
 	 */
+	
 	public void furtherDCElements(String id, OAI_ESClient esClient) {
 
 		GetRequestBuilder getWorkValues = esClient
@@ -113,9 +102,7 @@ public class RecordListDeliverer{
 				.setIndex(esClient.getEsIndex())
 				.setType(esClient.getEsType())
 				.setId(id)
-				.setFields(CREATED, WORK_ABSTRACT, IS_DERIVED_FROM, URI,
-						WORK_GENRE, TITLE, WORK_TYPE, WORK_SPATIAL,
-						WORK_TEMPORAL, WORK_AGENT, WORK_ID);
+				.setFields(TGConstants.TGWorkFields);
 
 		GetResponse responseWorkValues = getWorkValues.execute().actionGet();
 		Map<String, GetField> fieldsMap = responseWorkValues.getFields();
@@ -123,30 +110,23 @@ public class RecordListDeliverer{
 		// Only if a value AND a fields map is existing...
 		if (responseWorkValues != null && fieldsMap != null) {
 
-			setCoverage(responseWorkValues);
-			setCreator(responseWorkValues);
-
-			try {
-				if (responseWorkValues.getField(CREATED) != null) {
-					dates.add(OAIPMHUtillities.convertDateFormat(
-							responseWorkValues.getField(CREATED).getValue()
-									.toString()).toXMLFormat());
-				}
-			} catch (ParseException e) {
-				log.debug(e);
-			} catch (DatatypeConfigurationException e) {
-				log.debug(e);
-			}
-
-			setDescription(responseWorkValues);
-			setRelationForWork(responseWorkValues);
-			setSubject(responseWorkValues);
-			setType(responseWorkValues);
-
+			setCoverage(responseWorkValues, TGConstants.COVERAGE_LIST);
+			setCreator(responseWorkValues, TGConstants.WORK_AGENT);
+			setDate(responseWorkValues, TGConstants.DATE_LIST);
+			setDescription(responseWorkValues, TGConstants.DESCRIPTION_LIST);
+			setRelationForWork(responseWorkValues, TGConstants.RELATIONS_FOR_WORK_LIST);
+			setSubject(responseWorkValues, TGConstants.SUBJECT_LIST);
+			setType(responseWorkValues, TGConstants.TYPE_LIST);
 		}
 	}
 	
-	public void fetchFields(QueryBuilder query, String[] fields){
+	/**
+	 * The fetchFields function filters all edition and fetch the specified fields 
+	 * 
+	 * @param query
+	 */
+	
+	public void fetchFields(QueryBuilder query){
 		
 		SearchRequestBuilder getRecordList = oaiEsClient
 				.getOaiESClient()
@@ -154,8 +134,8 @@ public class RecordListDeliverer{
 				.setTypes(oaiEsClient.getEsType())
 				.addFields(fields)
 				.setQuery(query)
-				.setPostFilter(FilterBuilders.existsFilter(EDITION_ISEDITIONOF))
-				.setSize(10);
+				.setPostFilter(FilterBuilders.existsFilter(TGConstants.EDITION_ISEDITIONOF))
+				.setSize(1000);
 		
 		SearchResponse getRecordListItems = getRecordList.execute().actionGet();
 
@@ -169,10 +149,10 @@ public class RecordListDeliverer{
 				// Only if we have a search response AND a hit field map...
 				if (hit != null && hits != null) {
 					
-					if (hit.getFields().get(FORMAT).values().get(0).toString()
+					if (hit.getFields().get(TGConstants.FORMAT).values().get(0).toString()
 							.equals(TextGridMimetypes.EDITION)) {
 
-						String datestamp = hit.getFields().get(CREATED)
+						String datestamp = hit.getFields().get(TGConstants.CREATED)
 								.getValue().toString();
 
 						try {
@@ -196,7 +176,7 @@ public class RecordListDeliverer{
 
 						//Uri of the work Object to get further DC-Fields
 						String workUri = hit.getFields()
-								.get(EDITION_ISEDITIONOF).values().get(0)
+								.get(TGConstants.EDITION_ISEDITIONOF).values().get(0)
 								.toString().substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX
 										.length());
 						
@@ -241,7 +221,7 @@ public class RecordListDeliverer{
 	public ListRecordsType getRecordsWithSet(String from, String to, String set) {
 		
 		QueryBuilder query;
-		QueryBuilder rangeQuery = QueryBuilders.rangeQuery(CREATED).from(from).to(to);
+		QueryBuilder rangeQuery = QueryBuilders.rangeQuery(TGConstants.CREATED).from(from).to(to);
 		
 		
 		if(set!=null){
@@ -260,18 +240,21 @@ public class RecordListDeliverer{
 			query = rangeQuery;
 		}
 		
-		fetchFields(query, TGConstants.TGFields);
+		fetchFields(query);
 		
 		return recordList;
 	}
 	
+	/*
+	 * Function to set the Dublin Core fields
+	 */
+	
 	public HeaderType setHeader(String set){
 		
 		HeaderType header = new HeaderType();
 		header.setDatestamp(dates.get(0));
 		header.setIdentifier(identifiers.get(0));
 		if(set!=null){
-			System.out.println(set);
 			header.getSetSpec().add(set);
 		}
 		return header;
@@ -287,46 +270,51 @@ public class RecordListDeliverer{
 		}
 	}
 	
-	public void setCreator(GetResponse responseWorkValues){
+	public void setCreator(GetResponse responseWorkValues, String field){
 		
-		if (responseWorkValues.getField(WORK_AGENT) != null) {
-			creators.add(responseWorkValues.getField(WORK_AGENT).getValue()
+		if (responseWorkValues.getField(field) != null) {
+			creators.add(responseWorkValues.getField(field).getValue()
 					.toString());
 		}
-
 	}
 	
 	
-	public void setCoverage(GetResponse responseWorkValues){
-		
-		if (responseWorkValues.getField(WORK_SPATIAL) != null) {
-			coverages.add(responseWorkValues.getField(WORK_SPATIAL)
-					.getValue().toString());
-		}
+	public void setCoverage(GetResponse responseWorkValues, String[] values){
 		
-		if (responseWorkValues.getField(WORK_SPATIAL) != null) {
-			coverages.add(responseWorkValues.getField(WORK_SPATIAL)
-					.getValue().toString());
-		}
-		if (responseWorkValues.getField(WORK_TEMPORAL) != null) {
-			coverages.add(responseWorkValues.getField(WORK_TEMPORAL)
+		for(String field : values){
+			if (responseWorkValues.getField(field) != null) {
+				coverages.add(responseWorkValues.getField(field)
 					.getValue().toString());
+			}
 		}
-
 	}
 	
-	public void setDate(SearchHit hit){
+	public void setDate(GetResponse responseWorkValues, String[] values){
 		
+		for(String field : values){
+			try {
+				if (responseWorkValues.getField(field) != null) {
+					dates.add(OAIPMHUtillities.convertDateFormat(
+						responseWorkValues.getField(field).getValue()
+								.toString()).toXMLFormat());
+				}
+			} catch (ParseException e) {
+			log.debug(e);
+			} catch (DatatypeConfigurationException e) {
+				log.debug(e);
+			}
+		}
 
 	}
 	
-	public void setDescription(GetResponse responseWorkValues){
+	public void setDescription(GetResponse responseWorkValues, String[] values){
 		
-		if (responseWorkValues.getField(WORK_ABSTRACT) != null) {
-			descriptions.add(responseWorkValues.getField(WORK_ABSTRACT)
+		for(String field : values){
+			if (responseWorkValues.getField(field) != null) {
+				descriptions.add(responseWorkValues.getField(field)
 					.getValue().toString());
+			}
 		}
-
 	}
 	
 	public void setFormat(SearchHit hit, String[] values){
@@ -379,20 +367,15 @@ public class RecordListDeliverer{
 		}
 	}
 	
-	public void setRelationForWork(GetResponse responseWorkValues){
+	public void setRelationForWork(GetResponse responseWorkValues, String[] values){
 		
-		if (responseWorkValues.getField(IS_DERIVED_FROM) != null) {
-			relations.add(responseWorkValues.getField(IS_DERIVED_FROM)
+		for(String field : values){
+			if (responseWorkValues.getField(field) != null) {
+				descriptions.add(responseWorkValues.getField(field)
 					.getValue().toString());
+			}
 		}
-		if (responseWorkValues.getField(TITLE) != null) {
-			relations.add(responseWorkValues.getField(TITLE).getValue()
-					.toString());
-		}
-		if (responseWorkValues.getField(URI) != null) {
-			relations.add(responseWorkValues.getField(URI).getValue()
-					.toString());
-		}
+
 	}
 	
 	public void setRights(SearchHit hit, String[] values){
@@ -415,11 +398,13 @@ public class RecordListDeliverer{
 		}
 	}
 	
-	public void setSubject(GetResponse responseWorkValues){
+	public void setSubject(GetResponse responseWorkValues, String[] values){
 		
-		if (responseWorkValues.getField(WORK_ID) != null) {
-			subjects.add(responseWorkValues.getField(WORK_ID).getValue()
-					.toString());
+		for(String field : values){
+			if (responseWorkValues.getField(field) != null) {
+				subjects.add(responseWorkValues.getField(field)
+					.getValue().toString());
+			}
 		}
 
 	}
@@ -437,28 +422,26 @@ public class RecordListDeliverer{
 		}
 	}
 	
-	public void setType(GetResponse responseWorkValues){
+	public void setType(GetResponse responseWorkValues, String[] values){
 		
-		if (responseWorkValues.getField(WORK_GENRE) != null) {
+		for(String field : values){
+			if (responseWorkValues.getField(field) != null) {
+				types.add(responseWorkValues.getField(field)
+					.getValue().toString());
+			}
+		}
+		
+		/*if (responseWorkValues.getField(WORK_GENRE) != null) {
 			types.add(responseWorkValues.getField(WORK_GENRE).getValue()
 					.toString());
 		}
 		if (responseWorkValues.getField(WORK_TYPE) != null) {
 			types.add(responseWorkValues.getField(WORK_TYPE).getValue()
 					.toString());
-		}
+		}*/
 
 	}
 	
-	
-	public void fieldLoader(SearchRequestBuilder getRecordList, String set){
-		
-	
-
-		
-	}
-	
-	
 	/**
 	 * @param odt
 	 * @param of
diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java
index 62dbce87..1782bb90 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java
@@ -20,16 +20,28 @@ public final class TGConstants {
 	public static final String TG_ITEM_IDENTIFIER_PREFIX = "textgrid:";
 	public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = Arrays.asList("textgrid-support@gwdg.de");
 	
+	/*
+	 * Rep Identification String Constants
+	 */
+	
 	public static final String TG_REP_NAME = "TextGrid Repository";
 	public static final String TG_REP_BASEURL = "www.textgridrep.de";
 	public static final String TG_REP_OAIPMH_PROTOCOL_VERSION = "2.0";
 	public static final String METADATA_DC_PREFIX = "oai_dc";
 	
+	/*
+	 * Error String Constants
+	 */
+	
 	public static final String OAI_BAD_ARGUMENT = "BadArgument";
 	public static final String OAI_METADATA_FORMAT_ERROR = "FormatError";
 	public static final String OAI_NO_RECORD_MATCH = "RecordMatchError";
 	public static final String OAI_NO_SET_HIERARCHY = "SetHierarchyError";
 	
+	/*
+	 * TextGrid Metadata Fields for OAI-PMH Request (Mapping to DC)
+	 */
+	
 	public static final String	CREATED				= "created";
 	public static final String	FORMAT				= "format";
 	public static final String	IDENTIFIER			= "identifier";
@@ -70,15 +82,30 @@ public final class TGConstants {
 													   BIBCIT_EPAGE, BIBCIT_SPAGE, BIBCIT_BIBID, WORK_ABSTRACT, WORK_GENRE, WORK_TYPE, 
 													   WORK_SPATIAL, WORK_TEMPORAL, WORK_AGENT, WORK_ID};
 	
+	public static final String[] TGWorkFields 		= {CREATED, WORK_ABSTRACT, IS_DERIVED_FROM, URI, 
+												 	   WORK_GENRE, TITLE, WORK_TYPE, WORK_SPATIAL, 
+												       WORK_TEMPORAL, WORK_AGENT, WORK_ID};
+	
+	/*
+	 * String Arrays to define which TextGrid fields belongs to the regarding DC fields 
+	 */
+	
 	public static final String[] RIGHTS_LIST 		= {EDITION_LICENSEURI};
 	public static final String[] SOURCE_LIST 		= {BIBCIT_AUTHOR, BIBCIT_EDITOR, BIBCIT_TITLE, BIBCIT_PLACEPUB,
 												   	   BIBCIT_PUBLISHER, BIBCIT_NO, BIBCIT_SERIES, BIBCIT_VOLUME, BIBCIT_ISSUE,
 												   	   BIBCIT_SPAGE, BIBCIT_EPAGE};
 	public static final String[] TITLE_LIST 		= {TITLE};
 	public static final String[] CONTRIBUTOR_LIST 	= {DATA_CONTRIBUTOR};
+	public static final String[] COVERAGE_LIST		= {WORK_SPATIAL, WORK_TEMPORAL};
+	public static final String[] DATE_LIST			= {CREATED};
 	public static final String[] FORMAT_LIST 		= {FORMAT};
 	public static final String[] IDENTIFIER_LIST 	= {URI, PID, IDENTIFIER};
 	public static final String[] LANGUAGE_LIST 		= {EDITION_LANGUAGE};
 	public static final String[] PUBLISHER_LIST 	= {BIBCIT_PUBLISHER};
 	public static final String[] RELATIONS_LIST 	= {PROJECT_ID, IS_DERIVED_FROM};
+	public static final String[] RELATIONS_FOR_WORK_LIST 	= {IS_DERIVED_FROM, TITLE, URI};
+	public static final String[] SUBJECT_LIST		= {WORK_ID};
+	public static final String[] TYPE_LIST			= {WORK_GENRE, WORK_TYPE};
+	public static final String[] DESCRIPTION_LIST 	= {WORK_ABSTRACT};
+	
 }
diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java
index f8f14651..2011549b 100644
--- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java
+++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java
@@ -45,7 +45,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testDateNow() throws DatatypeConfigurationException {
 		System.out.println("---------------Now Version-----------------");
 		XMLGregorianCalendar nowTest = OAIPMHUtillities
@@ -55,7 +55,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testDateGregorianType() throws ParseException,
 			DatatypeConfigurationException {
 		String dateformatbefore = "2012-02-06T20:48:39.614+01:00";
@@ -69,7 +69,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testDateStringType() throws ParseException,
 			DatatypeConfigurationException {
 		String dateformatbefore = "2012-02-06T20:48:39.614+01:00";
@@ -82,7 +82,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	@Ignore
+	//@Ignore
 	public void testListSets() throws ParseException {
 
 		JAXBElement<OAIPMHType> r = testRequest.getRequest("ListSets", "", "",
@@ -101,7 +101,7 @@ public class OaiPmhTest {
 	
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testGetRequestIdentify() throws ParseException {
 
 		System.out
@@ -113,7 +113,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testGetRequestIdentifyVerbError() throws ParseException {
 		JAXBElement<OAIPMHType> t = testRequest.getRequest("Identify", "", "a",
 				"", "", "", "");
@@ -122,7 +122,7 @@ public class OaiPmhTest {
 	}
 
 	@Test
-	//@Ignore
+	@Ignore
 	public void testGetRequestIdentifyArgumentError() throws ParseException {
 		System.out
 				.println("Test for the verb \"Identify\" with error response");
@@ -184,7 +184,7 @@ public class OaiPmhTest {
 	public void testListRecordSets() throws ParseException {
 		System.out.println("Test for the verb \"ListRecord\" with sets with succesfull response");
 		JAXBElement<OAIPMHType> p = testRequest.getRequest("ListRecords",
-				"", "oai_dc", "project.value:St. Matthias Test 07", "", "", "");
+				"", "oai_dc", "project.value:Digitale Bibliothek", "", "", "");
 		JAXB.marshal(p, System.out);
 		System.out.println("-----------------------------------\n");
 
diff --git a/oaipmh-webapp/pom.xml b/oaipmh-webapp/pom.xml
index 8b49c980..a4fbb8b3 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>1.3.5-SNAPSHOT</version>
+		<version>1.3.6-SNAPSHOT</version>
 	</parent>
 	<groupId>info.textgrid.middleware</groupId>
 	<artifactId>oaipmh-webapp</artifactId>
 	<packaging>war</packaging>
-	<version>1.3.5-SNAPSHOT</version>
+	<version>1.3.6-SNAPSHOT</version>
 	<name>TextGrid :: OAI-PMH :: Webapp</name>
 	<url>http://maven.apache.org</url>
 	<profiles>
diff --git a/pom.xml b/pom.xml
index 47c5110e..f553ad78 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>1.3.5-SNAPSHOT</version>
+  <version>1.3.6-SNAPSHOT</version>
   <packaging>pom</packaging>
   <name>TextGrid :: TG-OAI-PMH :: Parent</name>
   <properties>
-- 
GitLab