From 0cdfce0c2b7f0a76c9abf19f6c127ec2aa12eaa0 Mon Sep 17 00:00:00 2001 From: mbrodhu <brodhun@sub.uni-goettingen.de> Date: Mon, 15 Feb 2016 14:38:29 +0100 Subject: [PATCH] list sets changes for dariah --- oaipmh-core/pom.xml | 4 +- .../textgrid/middleware/SetDeliverer.java | 64 ++++++++++++++----- .../info/textgrid/middleware/OaiPmhTest.java | 38 ++++++++--- oaipmh-webapp/pom.xml | 4 +- .../src/main/webapp/WEB-INF/beans.xml | 6 ++ pom.xml | 2 +- 6 files changed, 88 insertions(+), 30 deletions(-) diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml index f52a28b0..b485997b 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.3-SNAPSHOT</version> + <version>2.1.4-SNAPSHOT</version> </parent> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh-core</artifactId> - <version>2.1.3-SNAPSHOT</version> + <version>2.1.4-SNAPSHOT</version> <packaging>jar</packaging> <name>DARIAHDE :: OAI-PMH :: Core</name> <url>http://maven.apache.org</url> diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java index d37ff634..4d43b9f2 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java @@ -4,9 +4,9 @@ import info.textgrid.middleware.oaipmh.ListSetsType; import info.textgrid.middleware.oaipmh.SetType; -import java.util.ArrayList; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.LinkedHashSet; -import java.util.List; import java.util.Set; import org.elasticsearch.action.get.GetRequestBuilder; @@ -21,8 +21,11 @@ public class SetDeliverer { private OAI_ESClient oaiEsClient; - public SetDeliverer(OAI_ESClient oaiEsClient) { + public SetDeliverer(OAI_ESClient oaiEsClient, boolean textgrid, boolean dariah) { this.oaiEsClient = oaiEsClient; + this.textgrid = textgrid; + this.dariah = dariah; + System.out.println(dariah); } private Set<String> identifier = new LinkedHashSet<String>(); @@ -33,8 +36,9 @@ public class SetDeliverer { private String specField; private String specFieldPrefix; private Set<String> project = new LinkedHashSet<String>(); - private Set<String> projectID = new LinkedHashSet<String>(); - private boolean textgrid= true; + private boolean textgrid; + private boolean dariah; + public ListSetsType setListBuilder() { @@ -51,13 +55,18 @@ public class SetDeliverer { .addField("project.id") .setSize(100000); + System.out.println("QUERY: " + request); + SearchResponse getRecordListItems = request.execute().actionGet(); for (SearchHit hit : getRecordListItems.getHits().getHits()) { - System.out.println("testitest: " + textgrid); + if(hit.getFields().get(formatField) != null && hit.getFields().get(formatField).value().equals(formatToFilter)) { - System.out.println("testitest1"); - this.identifier.add(hit.getFields().get(identifierField).values().get(0).toString()); + if(hit.getFields().get(identifierField).values().get(0).toString().startsWith("hdl:")){ + System.out.println(hit.getFields().get(identifierField).values().get(0).toString()); + this.identifier.add(hit.getFields().get(identifierField).values().get(0).toString()); + System.out.println("woohoo"); + } if(textgrid==true){ System.out.println("testitest2"); @@ -87,23 +96,30 @@ public class SetDeliverer { } } else{ - + System.out.println("woho"); for (String identifierSetSpec : this.identifier) { String id = identifierSetSpec; - System.out.println("The id is: " + id); + try { + id = URLDecoder.decode(id, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + //System.out.println("The id is: " + id); if (identifierSetSpec.startsWith(repositoryObjectURIPrefix)) { + System.out.println("1"); id = identifierSetSpec.substring(repositoryObjectURIPrefix.length()); + System.out.println("the new id is: " + id); } - + GetRequestBuilder collectionNameById = this.oaiEsClient .getOaiESClient().prepareGet() .setIndex(this.oaiEsClient.getEsIndex()) .setType(this.oaiEsClient.getEsType()) - .setFields(specField).setId(id); - - GetResponse setSpec = collectionNameById.execute().actionGet(); + .setFields(specField) + .setId(id); - + GetResponse setSpec = collectionNameById.execute().actionGet(); String setName = ""; if(setSpec.isExists()){ if (setSpec != null && setSpec.getField(specField) != null) { @@ -115,7 +131,7 @@ public class SetDeliverer { SetType set = new SetType(); set.setSetName(setName); - set.setSetSpec(specFieldPrefix + ":" + id); + set.setSetSpec(specFieldPrefix + id); setList.getSet().add(set); @@ -172,4 +188,20 @@ public class SetDeliverer { public void setSpecFieldPrefix(String specFieldPrefix) { this.specFieldPrefix = specFieldPrefix; } + + public boolean isTextgrid() { + return textgrid; + } + + public void setTextgrid(boolean textgrid) { + this.textgrid = textgrid; + } + + public boolean isDariah() { + return dariah; + } + + public void setDariah(boolean dariah) { + this.dariah = dariah; + } } 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 c88a7675..b966d60a 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java @@ -40,21 +40,22 @@ public class OaiPmhTest { oaiEsClient,DARIAHConstants.DARIAHFields, DARIAHConstants.DARIAHFields, false, true); - private boolean textgrid; - private boolean dariah; + // private RecordListDeliverer recordList = new // RecordListDeliverer(oaiEsClient, TGConstants.TGFields, // TGConstants.TGWorkFields, true, false); private MetadataFormatListDeliverer metadataFormatList = new MetadataFormatListDeliverer( oaiEsClient); - private SetDeliverer setList = new SetDeliverer(oaiEsClient); + + private SetDeliverer setListDARIAH = new SetDeliverer(oaiEsClient, false, true); + //private SetDeliverer setListTextGrid = new SetDeliverer(oaiEsClient, true, false); private IdentifierListDeliverer identifierList = new IdentifierListDeliverer( oaiEsClient, true, false); private OAIPMHImpl request = new OAIPMHImpl(oaiEsClient, this.rep, this.record, this.recordList, this.metadataFormatList, - this.setList, this.identifierList); + this.setListDARIAH, this.identifierList); /** * @throws Exception @@ -410,7 +411,7 @@ public class OaiPmhTest { // cregId:hdl:6607/0000-0000-26A5-B // dariah:collection:6607/0000-0000-26A5-B JAXBElement<OAIPMHType> r = this.request.getRequest("ListRecords", "", - "oai_dc", "11022/0000-0000-8F60-3", "", "", ""); + "oai_dc", "11022/0000-0000-8FA0-A", "", "", ""); JAXB.marshal(r, System.out); System.out.println("-----------------------------------\n"); } @@ -445,16 +446,35 @@ public class OaiPmhTest { @Test @Ignore public void testListSets() throws ParseException { - this.setList.setFormatField("format"); - this.setList.setFormatToFilter("text/tg.edition+tg.aggregation+xml"); - this.setList.setIdentifierField("textgridUri"); - this.setList.setRepositoryObjectURIPrefix("textgrid:"); + this.setListDARIAH.setFormatField("format"); + this.setListDARIAH.setFormatToFilter("text/tg.edition+tg.aggregation+xml"); + this.setListDARIAH.setIdentifierField("textgridUri"); + this.setListDARIAH.setRepositoryObjectURIPrefix("textgrid:"); JAXBElement<OAIPMHType> r = this.request.getRequest("ListSets", "", "", "", "", "", ""); JAXB.marshal(r, System.out); System.out.println("-----------------------------------\n"); } + /** + * @throws ParseException + */ + @Test + //@Ignore + public void testListSetsDARIAH() throws ParseException { + System.out.println("TEST DARIAH"); + this.setListDARIAH.setFormatField(DARIAHConstants.FORMAT); + this.setListDARIAH.setFormatToFilter(DARIAHConstants.COLLECTION_MIMETYPE); + this.setListDARIAH.setIdentifierField(DARIAHConstants.IDENTIFIER); + this.setListDARIAH.setRepositoryObjectURIPrefix(DARIAHConstants.ITEM_IDENTIFIER_PREFIX); + this.setListDARIAH.setSpecField("descriptiveMetadata.dc:title"); + this.setListDARIAH.setSpecFieldPrefix(DARIAHConstants.ITEM_IDENTIFIER_PREFIX); + JAXBElement<OAIPMHType> r = this.request.getRequest("ListSets", "", "", + "", "", "", ""); + JAXB.marshal(r, System.out); + System.out.println("-----------------------------------\n"); + } + /** * @throws ParseException */ diff --git a/oaipmh-webapp/pom.xml b/oaipmh-webapp/pom.xml index 1184f552..2d9e9d4d 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.3-SNAPSHOT</version> + <version>2.1.4-SNAPSHOT</version> </parent> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh-webapp</artifactId> <packaging>war</packaging> - <version>2.1.3-SNAPSHOT</version> + <version>2.1.4-SNAPSHOT</version> <name>DARIAHDE :: OAI-PMH :: Webapp</name> <url>http://maven.apache.org</url> <profiles> diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml index 7820ca75..57469866 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml @@ -165,6 +165,12 @@ <bean id="SetDeliverer" class="info.textgrid.middleware.SetDeliverer"> <constructor-arg ref="ElasticSearchClient" /> + <constructor-arg index="2"> + <value>${textgrid}</value> + </constructor-arg> + <constructor-arg index="3"> + <value>${dariah}</value> + </constructor-arg> <property name="formatField" value="${formatField}" /> <property name="formatToFilter" value="${formatToFilter}" /> <property name="identifierField" value="${identifierField}" /> diff --git a/pom.xml b/pom.xml index 58642f20..c9e441e1 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.3-SNAPSHOT</version> + <version>2.1.4-SNAPSHOT</version> <packaging>pom</packaging> <name>DARIAHDE :: OAI-PMH</name> <properties> -- GitLab