From 39efc6f5df5c340e7c45605ce88cdf2a642fb595 Mon Sep 17 00:00:00 2001 From: mbrodhu <brodhun@sub.uni-goettingen.de> Date: Mon, 12 Jan 2015 14:24:13 +0100 Subject: [PATCH] making fields for GetRecordList and RecordList configurable --- .../textgrid/middleware/DARIAHConstants.java | 19 ----------- .../middleware/DublinCoreFieldLoader.java | 9 +++--- .../info/textgrid/middleware/OAIPMHImpl.java | 28 +++++++++++----- .../textgrid/middleware/RecordDeliverer.java | 32 ++++++++++++++----- .../middleware/RecordListDeliverer.java | 23 ++++++++++--- .../middleware/RepIdentification.java | 2 -- .../info/textgrid/middleware/TGConstants.java | 28 ++++++++++------ .../info/textgrid/middleware/OaiPmhTest.java | 19 +++++------ .../src/main/webapp/WEB-INF/beans.xml | 29 +++++++++++++---- 9 files changed, 118 insertions(+), 71 deletions(-) delete mode 100644 oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java deleted file mode 100644 index eaf26fe0..00000000 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.textgrid.middleware; - -public class DARIAHConstants { - - private static final String CONTRIBUTOR = "dc:contributor"; - private static final String CREATED = "dc:creator"; - private static final String COVERAGE = "dc:coverage"; - private static final String DATE = "dc:date"; - private static final String DESCRIPTION = "dc:description"; - private static final String FORMAT = "dc:format"; - private static final String IDENTIFIER = "dc:identifier"; - private static final String LANGUAGE = "dc:language"; - private static final String PUBLISHER = "dc:language"; - private static final String RELATION = "dc:relation"; - private static final String RIGHTS = "dc:rights"; - private static final String TITLE = "dc:title"; - - -} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java index c45ff6d4..6ff296a6 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java @@ -59,13 +59,14 @@ public class DublinCoreFieldLoader { //----DC-Creator - public static List<String> setCreator(GetResponse responseWorkValues, String field){ + public static List<String> setCreator(GetResponse responseWorkValues, String[] values){ - if (responseWorkValues.getField(field) != null) { - creators.add(responseWorkValues.getField(field).getValue() + for(String field : values){ + if (responseWorkValues.getField(field) != null) { + creators.add(responseWorkValues.getField(field).getValue() .toString()); + } } - return creators; } 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 83a59fc0..8eae2e59 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -43,14 +43,26 @@ public class OAIPMHImpl implements OAIPMHProducer{ private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); private ListIdentifiersType listIDs = new ListIdentifiersType(); private OAI_ESClient oaiEsClient; - private static String[] fields; + //private static String[] fields; private RepIdentification rep; + private RecordListDeliverer recordList; + private RecordDeliverer recDeliv; public OAIPMHImpl(OAI_ESClient oaiEsClient, RepIdentification rep){ this.oaiEsClient=oaiEsClient; this.rep = rep; } + public OAIPMHImpl(OAI_ESClient oaiEsClient, RecordDeliverer recDeliv){ + this.oaiEsClient=oaiEsClient; + this.recDeliv = recDeliv; + } + + public OAIPMHImpl(OAI_ESClient oaiEsClient, RecordListDeliverer recordList){ + this.oaiEsClient=oaiEsClient; + this.recordList = recordList; + } + /** * Getting The request values as QueryParam from a REST request and proceeds appropriate to them * @return OAIPMHType object containing the whole response @@ -137,7 +149,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ //RepIdentification repIdentification = new RepIdentification(); IdentifyType tgRepIdentificationRequest = new IdentifyType(); - //if(rep.requestChecker(request)){ + if(rep.requestChecker(request)){ //tgRepIdentificationRequest.setBaseURL(repIdentification.getBaseUrl()); //tgRepIdentificationRequest.setDeletedRecord(repIdentification.getDeletedRecordStatus()); //tgRepIdentificationRequest.setEarliestDatestamp(repIdentification.getEarliestDatestamp()); @@ -156,7 +168,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ oai.setIdentify(tgRepIdentificationRequest); - /*} + } else{ if(request.getIdentifier()!=null){ errorValues.add("identifier"); @@ -174,7 +186,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments: " + errorValues); oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }*/ + } return oaipmhRoot; } @@ -185,7 +197,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ public JAXBElement<OAIPMHType> getRecordRequest(ObjectFactory obf, OAIPMHType oai, RequestType request){ List<String> errorValues = new ArrayList<String>(); - RecordDeliverer recDeliv = new RecordDeliverer(oaiEsClient, TGConstants.TGFields); + //RecordDeliverer recDeliv = new RecordDeliverer(oaiEsClient, TGConstants.TGFields); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); if(request.getMetadataPrefix()!=null && !request.getMetadataPrefix().equals("oai_dc")){ @@ -365,7 +377,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ public JAXBElement<OAIPMHType> listRecordsRequest(ObjectFactory obf, OAIPMHType oai, RequestType request){ List<String> errorValues = new ArrayList<String>(); ListRecordsType listRecords = new ListRecordsType(); - RecordListDeliverer recordList = new RecordListDeliverer(oaiEsClient, TGConstants.TGFields); + //RecordListDeliverer recordList = new RecordListDeliverer(oaiEsClient, TGConstants.TGFields); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); if(recordList.requestChecker(request)){ @@ -541,7 +553,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ } - public void setFields(String[] fields){ + /*public void setFields(String[] fields){ OAIPMHImpl.fields = fields; - } + }*/ } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDeliverer.java index 975f46af..80030e77 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDeliverer.java @@ -30,6 +30,9 @@ import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; public class RecordDeliverer { private String[] fields; + private String[] workFields; + private boolean textgrid; + private boolean dariah; /* * Lists for the Dublin Core elements. Lists are needed since each DC fields is possible to occures several times @@ -61,9 +64,16 @@ public class RecordDeliverer { private DublinCoreBuilder dbc = new DublinCoreBuilder(odt, of); private OAI_ESClient oaiEsClient; - public RecordDeliverer(OAI_ESClient oaiEsClient, String[] fields){ + public RecordDeliverer(OAI_ESClient oaiEsClient, + String[] fields, + String[] workFields, + boolean textgrid, + boolean dariah){ this.oaiEsClient=oaiEsClient; this.fields = fields; + this.workFields = workFields; + this.textgrid = textgrid; + this.dariah = dariah; } /** @@ -91,12 +101,18 @@ public class RecordDeliverer { if(tgObject.isExists() && tgObject.getField(TGConstants.FORMAT).getValue().toString().equals(TextGridMimetypes.EDITION)){ - - String workUri = tgObject.getField(TGConstants.EDITION_ISEDITIONOF).getValue().toString(); - workUri = workUri.substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX.length()); - putContentIntoDCFieldLists(tgObject, furtherDCElements(workUri)); - + if(dariah == true){ + + } + + if(textgrid == true){ + String workUri = tgObject.getField(TGConstants.EDITION_ISEDITIONOF).getValue().toString(); + workUri = workUri.substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX.length()); + + putContentIntoDCFieldLists(tgObject, furtherDCElements(workUri)); + } + recordHeader.setIdentifier(tgObject.getField(TGConstants.URI).getValue().toString()); recordHeader.setDatestamp(dates.get(0)); @@ -121,7 +137,7 @@ public class RecordDeliverer { .setIndex(oaiEsClient.getEsIndex()) .setType(oaiEsClient.getEsType()) .setId(id) - .setFields(TGConstants.TGWorkFields); + .setFields(workFields); GetResponse responseWorkValues = getWorkValues.execute().actionGet(); @@ -155,7 +171,7 @@ public class RecordDeliverer { sources = DublinCoreFieldLoader.setSources(responseWorkValues, TGConstants.SOURCE_LIST); titles = DublinCoreFieldLoader.setTitle(responseWorkValues, TGConstants.TITLE_LIST); coverages = DublinCoreFieldLoader.setCoverage(responseWorkValues, TGConstants.COVERAGE_LIST); - creators = DublinCoreFieldLoader.setCreator(responseWorkValues2, TGConstants.WORK_AGENT); + creators = DublinCoreFieldLoader.setCreator(responseWorkValues2, TGConstants.CREATOR_LIST); dates = DublinCoreFieldLoader.setDate(responseWorkValues2, TGConstants.DATE_LIST); descriptions = DublinCoreFieldLoader.setDescription(responseWorkValues2, TGConstants.DESCRIPTION_LIST); relations = DublinCoreFieldLoader.setRelationForWork(responseWorkValues2, TGConstants.RELATIONS_FOR_WORK_LIST); 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 be47390f..12a6e5cc 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java @@ -51,6 +51,9 @@ public class RecordListDeliverer { private OAI_ESClient oaiEsClient; private String[] fields; + private String[] workFields; + private boolean textgrid; + private boolean dariah; private ListRecordsType recordList = new ListRecordsType(); /* @@ -79,9 +82,16 @@ public class RecordListDeliverer { /** * @param oaiEsClient */ - public RecordListDeliverer(OAI_ESClient oaiEsClient, String[] fields) { + public RecordListDeliverer(OAI_ESClient oaiEsClient, + String[] fields, + String[] workFields, + boolean textgrid, + boolean dariah) { this.oaiEsClient = oaiEsClient; this.fields = fields; + this.workFields = workFields; + this.textgrid = textgrid; + this.dariah = dariah; } /** @@ -100,11 +110,10 @@ public class RecordListDeliverer { .setIndex(esClient.getEsIndex()) .setType(esClient.getEsType()) .setId(id) - .setFields(TGConstants.TGWorkFields); + .setFields(workFields); GetResponse responseWorkValues = getWorkValues.execute().actionGet(); - return responseWorkValues; } @@ -155,7 +164,11 @@ public class RecordListDeliverer { //Uri of the work Object to get further DC-Fields (only necessary if metadata for the object //is in an other object than just the edition - if(TGConstants.furtherElements == true){ + if(dariah == true){ + + } + + if(textgrid == true){ String workUri = hit.getFields() .get(TGConstants.EDITION_ISEDITIONOF).values().get(0) .toString().substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX @@ -184,7 +197,7 @@ public class RecordListDeliverer { sources = DublinCoreFieldLoader.setSources(hit, TGConstants.SOURCE_LIST); titles = DublinCoreFieldLoader.setTitle(hit, TGConstants.TITLE_LIST); coverages = DublinCoreFieldLoader.setCoverage(responseWorkValues, TGConstants.COVERAGE_LIST); - creators = DublinCoreFieldLoader.setCreator(responseWorkValues, TGConstants.WORK_AGENT); + creators = DublinCoreFieldLoader.setCreator(responseWorkValues, TGConstants.CREATOR_LIST); dates = DublinCoreFieldLoader.setDate(responseWorkValues, TGConstants.DATE_LIST); descriptions = DublinCoreFieldLoader.setDescription(responseWorkValues, TGConstants.DESCRIPTION_LIST); relations = DublinCoreFieldLoader.setRelationForWork(responseWorkValues, TGConstants.RELATIONS_FOR_WORK_LIST); diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RepIdentification.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RepIdentification.java index b48bc4fc..c9f2d9d0 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RepIdentification.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RepIdentification.java @@ -2,7 +2,6 @@ package info.textgrid.middleware; import info.textgrid.middleware.oaipmh.DeletedRecordType; import info.textgrid.middleware.oaipmh.GranularityType; -import info.textgrid.middleware.oaipmh.IdentifyType; import info.textgrid.middleware.oaipmh.RequestType; /** @@ -15,7 +14,6 @@ import info.textgrid.middleware.oaipmh.RequestType; */ public class RepIdentification { - private IdentifyType tgRepInfo = new IdentifyType(); private DeletedRecordType tgDeletetObjects = DeletedRecordType.NO; private GranularityType tgRepGranulartiry = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; 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 3d4c2c88..7bdd7188 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java @@ -17,7 +17,7 @@ public final class TGConstants { //not called } - public static boolean furtherElements = true; + //public static boolean furtherElements = true; public static final String TG_ITEM_IDENTIFIER_PREFIX = "textgrid:"; public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = Arrays.asList("textgrid-support@gwdg.de"); @@ -26,9 +26,9 @@ public final class TGConstants { * Rep Identification String Constants */ - public static final String TG_REP_NAME = "TextGrid Repository"; + //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 TG_REP_OAIPMH_PROTOCOL_VERSION = "2.0"; public static final String METADATA_DC_PREFIX = "oai_dc"; /* @@ -92,22 +92,32 @@ public final class TGConstants { * 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[] CREATOR_LIST = {WORK_AGENT}; public static final String[] DATE_LIST = {CREATED}; + public static final String[] DESCRIPTION_LIST = {WORK_ABSTRACT}; 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[] 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[] SUBJECT_LIST = {WORK_ID}; + public static final String[] TITLE_LIST = {TITLE}; + + + + + + + + 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 9b7d44e8..0e2e6afe 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java @@ -1,10 +1,7 @@ package info.textgrid.middleware; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; + import java.text.ParseException; -import java.util.Properties; import info.textgrid.middleware.oaipmh.DeletedRecordType; import info.textgrid.middleware.oaipmh.GranularityType; @@ -25,8 +22,12 @@ public class OaiPmhTest { DeletedRecordType bla = DeletedRecordType.NO; GranularityType bla2 = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; private RepIdentification rep = new RepIdentification("TextGrid-Repository", "www.textgridrep.de", bla, "2011-06-11T02:32:40Z", bla2, "2.0", "textgrid-support@gwdg.de"); - private OAIPMHImpl testRequest = new OAIPMHImpl(oaiEsClient, rep); - + private RecordDeliverer record = new RecordDeliverer(oaiEsClient, TGConstants.TGFields, TGConstants.TGWorkFields, true, false); + private RecordListDeliverer recordList = new RecordListDeliverer(oaiEsClient, TGConstants.TGFields, TGConstants.TGWorkFields, true, false); + + private OAIPMHImpl testRequest = new OAIPMHImpl(oaiEsClient, record); + private OAIPMHImpl repIdentificationTestRequest = new OAIPMHImpl(oaiEsClient, rep); + private OAIPMHImpl recordListRequest = new OAIPMHImpl(oaiEsClient, recordList); @BeforeClass @@ -76,11 +77,11 @@ public class OaiPmhTest { } @Test - //@Ignore + @Ignore public void testGetRequestIdentify() throws ParseException { System.out.println("Test for the verb \"Identify\" with succesfull response"); - JAXBElement<OAIPMHType> r = testRequest.getRequest("Identify", "", "", + JAXBElement<OAIPMHType> r = repIdentificationTestRequest.getRequest("Identify", "", "", "", "", "", ""); JAXB.marshal(r, System.out); System.out.println("-----------------------------------\n"); @@ -157,7 +158,7 @@ public class OaiPmhTest { @Ignore public void testListRecordSets() throws ParseException { System.out.println("Test for the verb \"ListRecord\" with sets with succesfull response"); - JAXBElement<OAIPMHType> p = testRequest.getRequest("ListRecords", + JAXBElement<OAIPMHType> p = recordListRequest.getRequest("ListRecords", "", "oai_dc", "project.value:Digitale Bibliothek", "", "", ""); JAXB.marshal(p, System.out); System.out.println("-----------------------------------\n"); diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml index 8273a688..a2a5c9fb 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml @@ -73,20 +73,35 @@ http://www.springframework.org/schema/util/spring-util-3.1.xsd </constructor-arg> </bean> - <!-- bean id="RecordList" class="info.textgrid.middleware.RecordListDeliverer"> - <constructor-arg index="0"> - <value>${esFields}</value> + <bean id="RecordList" class="info.textgrid.middleware.RecordListDeliverer"> + <constructor-arg index="1"> + <value>${fields}</value> + </constructor-arg> + <constructor-arg index="2"> + <value>${workFields}</value> </constructor-arg> + <constructor-arg index="3"> + <value>${textgrid}</value> + </constructor-arg> + <constructor-arg index="4"> + <value>${dariah}</value> + </constructor-arg> + </bean> + + <bean id="Record" class="info.textgrid.middleware.RecordDeliverer"> <constructor-arg index="1"> - <value>${esWorkFields}</value> + <value>${fields}</value> </constructor-arg> <constructor-arg index="2"> - <value>${textgridFields}</value> + <value>${workFields}</value> </constructor-arg> <constructor-arg index="3"> - <value>${dariahFields}</value> + <value>${textgrid}</value> </constructor-arg> - </bean --> + <constructor-arg index="4"> + <value>${dariah}</value> + </constructor-arg> + </bean> <!-- REST Interface --> <bean id="rest" class="info.textgrid.middleware.Rest" /> -- GitLab