diff --git a/oaipmh-core/TODO b/oaipmh-core/TODO index de1cca5aeb01db34711af1fd3c8c6463605d2a26..fb06ba5977282a15fdb60218998b912c0edee1b2 100644 --- a/oaipmh-core/TODO +++ b/oaipmh-core/TODO @@ -7,7 +7,7 @@ DONE 2. implement sets (for the prootype :) -DONE (ListSets still has to be implemented, but it is possible to query for sets in ListIndentifiers and ListRecords) +DONE 3. implement resumtion tokens (later) diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml index 32aad0ecea93abba6048a79b0c27a716b60f8fea..00efa8abf4fe2dcbd4444275926c8b578dfd9aea 100644 --- a/oaipmh-core/pom.xml +++ b/oaipmh-core/pom.xml @@ -202,7 +202,6 @@ </execution> </executions> </plugin> - </plugins> </build> </project> diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..eaf26fe0f505c5228dfc61f6c98339b7777c69dd --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java @@ -0,0 +1,19 @@ +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/DublinCoreBuilder.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java index 00fdef6e2241a30e1a4e3ad1d701a8895a49c946..7f6285a90aa6d0b8fb9df582eef1f651941a7bc6 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java @@ -81,7 +81,7 @@ public final class DublinCoreBuilder { for (String dccoverage : coverages) { ElementType coverageElement = new ElementType(); JAXBElement<ElementType> dcCoreCoverage = getOaiDcObj().createCoverage(coverageElement); - coverageElement.setValue(dccoverage); + coverageElement.setValue(dccoverage); getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreCoverage); } 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 c5d94a8c88cd4f51ec9b3600737a8517969cb48c..344fb72c351980103be4b0d99010d67ec908ed0b 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -39,11 +39,13 @@ import org.apache.commons.logging.LogFactory; public class OAIPMHImpl implements OAIPMHProducer{ - private ErrorHandler error = new ErrorHandler(); - private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); - private ListIdentifiersType listIDs = new ListIdentifiersType(); - private OAI_ESClient oaiEsClient; - + private ErrorHandler error = new ErrorHandler(); + private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + private ListIdentifiersType listIDs = new ListIdentifiersType(); + private OAI_ESClient oaiEsClient; + private static String[] fields; + + public OAIPMHImpl(OAI_ESClient oaiEsClient){ this.oaiEsClient=oaiEsClient; } @@ -354,7 +356,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); + RecordListDeliverer recordList = new RecordListDeliverer(oaiEsClient, TGConstants.TGFields); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); if(recordList.requestChecker(request)){ @@ -372,9 +374,9 @@ public class OAIPMHImpl implements OAIPMHProducer{ oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); }else{ - if(request.getSet()==null){ + //if(request.getSet()==null){ - listRecords = recordList.getRecords(request.getFrom(), request.getUntil()); + listRecords = recordList.getRecordsWithSet(request.getFrom(), request.getUntil(), request.getSet()); if(listRecords!=null){ oai.setListRecords(listRecords); }else{ @@ -382,8 +384,8 @@ public class OAIPMHImpl implements OAIPMHProducer{ request.getUntil() + " results in an empty list"); oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } - } - else{ + //} + /*else{ listRecords = recordList.getRecordsWithSet(request.getFrom(), request.getUntil(), request.getSet()); if(listRecords!=null){ @@ -393,7 +395,7 @@ public class OAIPMHImpl implements OAIPMHProducer{ request.getUntil() + " results in an empty list"); oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } - } + }*/ } }else{ if(request.getIdentifier()!=null){ @@ -529,4 +531,8 @@ public class OAIPMHImpl implements OAIPMHProducer{ } } + + public void setFields(String[] fields){ + OAIPMHImpl.fields = fields; + } } 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 10ffb44e0dc92e267a261ed03739ae03137420f7..d273939f6f01e76c87290c2c5b37f9632f20442a 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java @@ -34,7 +34,7 @@ import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; * TODO Care about repeatable fields as done in TITLE! */ -public class RecordListDeliverer { +public class RecordListDeliverer{ // ** // STATIC FINALS @@ -42,29 +42,11 @@ public class RecordListDeliverer { private static final String CREATED = "created"; private static final String FORMAT = "format"; - private static final String IDENTIFIER = "identifier"; - private static final String DATA_CONTRIBUTOR = "dataContributor"; private static final String URI = "textgridUri"; - private static final String PROJECT_ID = "project.id"; private static final String IS_DERIVED_FROM = "relations.isDerivedFrom"; private static final String TITLE = "title"; - private static final String PID = "pid.value"; private static final String EDITION_ISEDITIONOF = "edition.isEditionOf"; - private static final String EDITION_AGENT = "edition.agent.value"; - private static final String RDITION_LICENSEURI = "edition.license.licenseUri"; - private static final String EDITION_LANGUAGE = "edition.language"; - private static final String BIBCIT_AUTHOR = "edition.source.bibliographicCitation.author.value"; - private static final String BIBCIT_EDITOR = "edition.source.bibliographicCitation.editor.value"; - private static final String BIBCIT_TITLE = "edition.source.bibliographicCitation.editionTitle"; - private static final String BIBCIT_PLACEPUB = "edition.source.bibliographicCitation.placeOfPublication.value"; - private static final String BIBCIT_PUBLISHER = "edition.source.bibliographicCitation.publisher.value"; - private static final String BIBCIT_NO = "edition.source.bibliographicCitation.editionNo"; - private static final String BIBCIT_SERIES = "edition.source.bibliographicCitation.series"; - private static final String BIBCIT_VOLUME = "edition.source.bibliographicCitation.volume"; - private static final String BIBCIT_ISSUE = "edition.source.bibliographicCitation.issue"; - private static final String BIBCIT_EPAGE = "edition.source.bibliographicCitation.epage"; - private static final String BIBCIT_SPAGE = "edition.source.bibliographicCitation.spage"; - private static final String BIBCIT_BIBID = "edition.source.bibliographicCitation.bibidentifier"; + //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"; @@ -72,20 +54,26 @@ public class RecordListDeliverer { 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 // ** - private static org.apache.commons.logging.Log log = LogFactory - .getLog(RecordDeliverer.class); + private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDeliverer.class); // ** // CLASS VARIABLES // ** private OAI_ESClient oaiEsClient; + private String[] fields; private ListRecordsType recordList = new ListRecordsType(); + + /* + * DC-Field Lists + */ + private List<String> contributors = new ArrayList<String>(); private List<String> coverages = new ArrayList<String>(); private List<String> creators = new ArrayList<String>(); @@ -108,255 +96,9 @@ public class RecordListDeliverer { /** * @param oaiEsClient */ - public RecordListDeliverer(OAI_ESClient oaiEsClient) { + public RecordListDeliverer(OAI_ESClient oaiEsClient, String[] fields) { this.oaiEsClient = oaiEsClient; - } - - /** - * @param from - * @param to - * @return - */ - public ListRecordsType getRecords(String from, String to) { - - QueryBuilder queryBuilder = QueryBuilders.rangeQuery(CREATED) - .from(from).to(to); - - SearchRequestBuilder getRecordList = oaiEsClient - .getOaiESClient() - .prepareSearch(oaiEsClient.getEsIndex()) - .setTypes(oaiEsClient.getEsType()) - .addFields(FORMAT, CREATED, EDITION_ISEDITIONOF, EDITION_AGENT, - DATA_CONTRIBUTOR, URI, PROJECT_ID, IS_DERIVED_FROM, - RDITION_LICENSEURI, TITLE, EDITION_LANGUAGE, PID, - BIBCIT_AUTHOR, BIBCIT_EDITOR, BIBCIT_TITLE, - BIBCIT_PLACEPUB, BIBCIT_PUBLISHER, BIBCIT_NO, - BIBCIT_SERIES, BIBCIT_VOLUME, BIBCIT_ISSUE, - BIBCIT_EPAGE, BIBCIT_SPAGE, BIBCIT_BIBID) - .setQuery(queryBuilder) - .setPostFilter(FilterBuilders.existsFilter(EDITION_ISEDITIONOF)) - .setSize(10); - - SearchResponse getRecordListItems = getRecordList.execute().actionGet(); - - if (getRecordListItems != null - && getRecordListItems.getHits().totalHits() > 0) { - - for (SearchHit hit : getRecordListItems.getHits().getHits()) { - - Map<String, SearchHitField> hits = hit.getFields(); - - // 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() - .equals(TextGridMimetypes.EDITION)) { - - ObjectFactory of = new ObjectFactory(); - OaiDcType odt = new OaiDcType(); - DublinCoreBuilder newDbc = new DublinCoreBuilder(odt, - of); - MetadataType metadata = new MetadataType(); - RecordType record = new RecordType(); - HeaderType recordHeader = new HeaderType(); - - String datestamp = hit.getFields().get(CREATED) - .getValue().toString(); - - try { - datestamp = OAIPMHUtillities.convertDateFormat( - datestamp).toXMLFormat(); - } catch (ParseException e1) { - log.debug(e1); - } catch (DatatypeConfigurationException e1) { - log.debug(e1); - } - - String workUri = hit.getFields() - .get(EDITION_ISEDITIONOF).values().get(0) - .toString(); - workUri = workUri - .substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX - .length()); - - /* - * DC-Contributor - */ - - if (hit.getFields().get(EDITION_AGENT) != null) { - contributors.add(hit.getFields() - .get(DATA_CONTRIBUTOR).values().get(0) - .toString()); - } - - /* - * DC-Format - */ - if (hit.getFields().get(FORMAT) != null) { - formats.add(hit.getFields().get(FORMAT).values() - .get(0).toString()); - } - - /* - * DC-Identifier - */ - String identifier = ""; - if (hit.getFields().get(URI) != null) { - identifiers.add(hit.getFields().get(URI).values() - .get(0).toString()); - identifier = identifiers.get(0); - } - if (hit.getFields().get(PID) != null) { - identifiers.add(hit.getFields().get(PID).values() - .get(0).toString()); - } - if (hit.getFields().get(IDENTIFIER) != null) { - identifiers.add(hit.getFields().get(IDENTIFIER) - .values().get(0).toString()); - } - - /* - * DC-Languages - */ - if (hit.getFields().get(EDITION_LANGUAGE) != null) { - languages.add(hit.getFields().get(EDITION_LANGUAGE) - .values().get(0).toString()); - } - - /* - * DC-Publisher - */ - if (hit.getFields().get(BIBCIT_PUBLISHER) != null) { - publishers.add(hit.getFields() - .get(BIBCIT_PUBLISHER).values().get(0) - .toString()); - } - - /* - * DC-Relation - */ - if (hit.getFields().get(PROJECT_ID) != null) { - relations.add(hit.getFields().get(PROJECT_ID) - .values().get(0).toString()); - } - if (hit.getFields().get(IS_DERIVED_FROM) != null) { - relations.add(hit.getFields().get(IS_DERIVED_FROM) - .values().get(0).toString()); - } - /*if (hit.getFields().get(URI) != null) { - relations.add(aggregatorURL.concat(hit.getFields() - .get(URI).values().get(0).toString())); - }*/ - - /* - * DC-Rights - */ - // System.out.println(hit.getFields().get("textgridUri").values().get(0).toString()); - if (hit.getFields().get(RDITION_LICENSEURI) != null) { - rights.add(hit.getFields().get(RDITION_LICENSEURI) - .values().get(0).toString()); - } - - /* - * DC-Source - */ - if (hit.getFields().get(BIBCIT_AUTHOR) != null) { - sources.add(hit.getFields().get(BIBCIT_AUTHOR) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_EDITOR) != null) { - sources.add(hit.getFields().get(BIBCIT_EDITOR) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_TITLE) != null) { - sources.add(hit.getFields().get(BIBCIT_TITLE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_PLACEPUB) != null) { - sources.add(hit.getFields().get(BIBCIT_PLACEPUB) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_PUBLISHER) != null) { - sources.add(hit.getFields().get(BIBCIT_PUBLISHER) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_NO) != null) { - sources.add(hit.getFields().get(BIBCIT_NO).values() - .get(0).toString()); - } - if (hit.getFields().get(BIBCIT_SERIES) != null) { - sources.add(hit.getFields().get(BIBCIT_SERIES) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_VOLUME) != null) { - sources.add(hit.getFields().get(BIBCIT_VOLUME) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_ISSUE) != null) { - sources.add(hit.getFields().get(BIBCIT_ISSUE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_SPAGE) != null) { - sources.add(hit.getFields().get(BIBCIT_SPAGE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_EPAGE) != null) { - sources.add(hit.getFields().get(BIBCIT_EPAGE) - .values().get(0).toString()); - } - if (hit.getFields().get(IDENTIFIER) != null) { - sources.add(hit.getFields().get(BIBCIT_EPAGE) - .values().get(0).toString()); - } - - /* - * DC-Title - */ - if (hit.getFields().get(TITLE) != null) { - for (int i = 0; i < hit.getFields().get(TITLE) - .getValues().size(); i++) { - titles.add(hit.getFields().get(TITLE).values() - .get(i).toString()); - } - } - - /* - * More DC elements - */ - furtherDCElements(workUri, oaiEsClient); - setDCObject(odt, of); - - /* - * Set identifier and date - */ - if (!identifiers.isEmpty()) { - recordHeader.setIdentifier(identifiers.get(0)); - } - // TODO Why take the 0th date here? - if (!dates.isEmpty()) { - recordHeader.setDatestamp(dates.get(0)); - } - - /* - * Clear list and create record list - */ - listClearer(); - - metadata = newDbc.getDC(); - record.setMetadata(metadata); - - HeaderType header = new HeaderType(); - header.setDatestamp(datestamp); - header.setIdentifier(identifier); - - record.setHeader(header); - recordList.getRecord().add(record); - } - } - } - } - - return recordList; + this.fields = fields; } /** @@ -381,29 +123,9 @@ public class RecordListDeliverer { // Only if a value AND a fields map is existing... if (responseWorkValues != null && fieldsMap != null) { - /* - * DC-Coverages - */ - 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) - .getValue().toString()); - } - - /* - * DC-Creators - */ - if (responseWorkValues.getField(WORK_AGENT) != null) { - creators.add(responseWorkValues.getField(WORK_AGENT).getValue() - .toString()); - } + setCoverage(responseWorkValues); + setCreator(responseWorkValues); - /* - * DC-Date - */ try { if (responseWorkValues.getField(CREATED) != null) { dates.add(OAIPMHUtillities.convertDateFormat( @@ -416,93 +138,27 @@ public class RecordListDeliverer { log.debug(e); } - /* - * DC-Description - */ - if (responseWorkValues.getField(WORK_ABSTRACT) != null) { - descriptions.add(responseWorkValues.getField(WORK_ABSTRACT) - .getValue().toString()); - } + setDescription(responseWorkValues); + setRelationForWork(responseWorkValues); + setSubject(responseWorkValues); + setType(responseWorkValues); - /* - * DC-Relation - */ - if (responseWorkValues.getField(IS_DERIVED_FROM) != null) { - relations.add(responseWorkValues.getField(IS_DERIVED_FROM) - .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()); - } - - /* - * DC-Subject - */ - if (responseWorkValues.getField(WORK_ID) != null) { - subjects.add(responseWorkValues.getField(WORK_ID).getValue() - .toString()); - } - - /* - * DC-Type - */ - 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 ListRecordsType getRecordsWithSet(String from, String to, String set) { - - String[] setParts = set.split(":"); - - if(setParts[0].equals("project")){ - setParts[0] = setParts[0].concat(".value"); - } - - QueryBuilder rangeQuery = QueryBuilders.rangeQuery(CREATED) - .from(from).to(to); - - QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(setParts[0], setParts[1]); - - QueryBuilder boolQuery = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); - - - + public void fetchFields(QueryBuilder query, String[] fields){ SearchRequestBuilder getRecordList = oaiEsClient .getOaiESClient() .prepareSearch(oaiEsClient.getEsIndex()) .setTypes(oaiEsClient.getEsType()) - .addFields(FORMAT, CREATED, EDITION_ISEDITIONOF, EDITION_AGENT, - DATA_CONTRIBUTOR, URI, PROJECT_ID, IS_DERIVED_FROM, - RDITION_LICENSEURI, TITLE, EDITION_LANGUAGE, PID, - BIBCIT_AUTHOR, BIBCIT_EDITOR, BIBCIT_TITLE, - BIBCIT_PLACEPUB, BIBCIT_PUBLISHER, BIBCIT_NO, - BIBCIT_SERIES, BIBCIT_VOLUME, BIBCIT_ISSUE, - BIBCIT_EPAGE, BIBCIT_SPAGE, BIBCIT_BIBID) - .setQuery(boolQuery) + .addFields(fields) + .setQuery(query) .setPostFilter(FilterBuilders.existsFilter(EDITION_ISEDITIONOF)) .setSize(10); - - System.out.println(getRecordList); - SearchResponse getRecordListItems = getRecordList.execute().actionGet(); - - - + if (getRecordListItems != null && getRecordListItems.getHits().totalHits() > 0) { @@ -512,18 +168,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() .equals(TextGridMimetypes.EDITION)) { - ObjectFactory of = new ObjectFactory(); - OaiDcType odt = new OaiDcType(); - DublinCoreBuilder newDbc = new DublinCoreBuilder(odt, - of); - MetadataType metadata = new MetadataType(); - RecordType record = new RecordType(); - HeaderType recordHeader = new HeaderType(); - String datestamp = hit.getFields().get(CREATED) .getValue().toString(); @@ -535,199 +183,274 @@ public class RecordListDeliverer { } catch (DatatypeConfigurationException e1) { log.debug(e1); } - + + setContributor(hit, TGConstants.CONTRIBUTOR_LIST); + setFormat(hit, TGConstants.FORMAT_LIST); + setIdentifier(hit, TGConstants.FORMAT_LIST); + setLanguage(hit, TGConstants.LANGUAGE_LIST); + setPublisher(hit, TGConstants.PUBLISHER_LIST); + setRelation(hit, TGConstants.RELATIONS_LIST); + setRights(hit, TGConstants.RIGHTS_LIST); + setSources(hit, TGConstants.SOURCE_LIST); + setTitle(hit, TGConstants.TITLE_LIST); + + //Uri of the work Object to get further DC-Fields String workUri = hit.getFields() .get(EDITION_ISEDITIONOF).values().get(0) - .toString(); - workUri = workUri - .substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX + .toString().substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX .length()); + + furtherDCElements(workUri, oaiEsClient); + buildRecord(); + listClearer(); + } + } + } + } + } + + public RecordType buildRecord(){ + + ObjectFactory of = new ObjectFactory(); + OaiDcType odt = new OaiDcType(); + DublinCoreBuilder newDbc = new DublinCoreBuilder(odt,of); + MetadataType metadata = new MetadataType(); + RecordType record = new RecordType(); + //TODO Test if this is unnecessary + HeaderType recordHeader = new HeaderType(); + + setDCObject(odt, of); + + if (!identifiers.isEmpty()) { + recordHeader.setIdentifier(identifiers.get(0)); + } + // TODO Why take the 0th date here? + if (!dates.isEmpty()) { + recordHeader.setDatestamp(dates.get(0)); + } + + metadata = newDbc.getDC(); + record.setMetadata(metadata); - /* - * DC-Contributor - */ - // System.out.println(hit.getFields().get("textgridUri").values().get(0).toString()); - if (hit.getFields().get(EDITION_AGENT) != null) { - // String contributorUnformatted = - // hit.getFields().get(AGENT).values().get(0).toString(); - contributors.add(hit.getFields() - .get(DATA_CONTRIBUTOR).values().get(0) - .toString()); - // contributors.add(contributorUnformatted); - } - - /* - * DC-Format - */ - if (hit.getFields().get(FORMAT) != null) { - formats.add(hit.getFields().get(FORMAT).values() - .get(0).toString()); - } - - /* - * DC-Identifier - */ - String identifier = ""; - if (hit.getFields().get(URI) != null) { - identifiers.add(hit.getFields().get(URI).values() - .get(0).toString()); - identifier = identifiers.get(0); - } - if (hit.getFields().get(PID) != null) { - identifiers.add(hit.getFields().get(PID).values() - .get(0).toString()); - } - if (hit.getFields().get(IDENTIFIER) != null) { - identifiers.add(hit.getFields().get(IDENTIFIER) - .values().get(0).toString()); - } - - /* - * DC-Languages - */ - if (hit.getFields().get(EDITION_LANGUAGE) != null) { - languages.add(hit.getFields().get(EDITION_LANGUAGE) - .values().get(0).toString()); - } - - /* - * DC-Publisher - */ - if (hit.getFields().get(BIBCIT_PUBLISHER) != null) { - publishers.add(hit.getFields() - .get(BIBCIT_PUBLISHER).values().get(0) - .toString()); - } - - /* - * DC-Relation - */ - if (hit.getFields().get(PROJECT_ID) != null) { - relations.add(hit.getFields().get(PROJECT_ID) - .values().get(0).toString()); - } - if (hit.getFields().get(IS_DERIVED_FROM) != null) { - relations.add(hit.getFields().get(IS_DERIVED_FROM) - .values().get(0).toString()); - } - /*if (hit.getFields().get(URI) != null) { - relations.add(aggregatorURL.concat(hit.getFields() - .get(URI).values().get(0).toString())); - }*/ - - /* - * DC-Rights - */ - // System.out.println(hit.getFields().get("textgridUri").values().get(0).toString()); - if (hit.getFields().get(RDITION_LICENSEURI) != null) { - rights.add(hit.getFields().get(RDITION_LICENSEURI) - .values().get(0).toString()); - } - - /* - * DC-Source - */ - if (hit.getFields().get(BIBCIT_AUTHOR) != null) { - sources.add(hit.getFields().get(BIBCIT_AUTHOR) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_EDITOR) != null) { - sources.add(hit.getFields().get(BIBCIT_EDITOR) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_TITLE) != null) { - sources.add(hit.getFields().get(BIBCIT_TITLE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_PLACEPUB) != null) { - sources.add(hit.getFields().get(BIBCIT_PLACEPUB) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_PUBLISHER) != null) { - sources.add(hit.getFields().get(BIBCIT_PUBLISHER) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_NO) != null) { - sources.add(hit.getFields().get(BIBCIT_NO).values() - .get(0).toString()); - } - if (hit.getFields().get(BIBCIT_SERIES) != null) { - sources.add(hit.getFields().get(BIBCIT_SERIES) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_VOLUME) != null) { - sources.add(hit.getFields().get(BIBCIT_VOLUME) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_ISSUE) != null) { - sources.add(hit.getFields().get(BIBCIT_ISSUE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_SPAGE) != null) { - sources.add(hit.getFields().get(BIBCIT_SPAGE) - .values().get(0).toString()); - } - if (hit.getFields().get(BIBCIT_EPAGE) != null) { - sources.add(hit.getFields().get(BIBCIT_EPAGE) - .values().get(0).toString()); - } - if (hit.getFields().get(IDENTIFIER) != null) { - sources.add(hit.getFields().get(BIBCIT_EPAGE) - .values().get(0).toString()); - } - - /* - * DC-Title - */ - if (hit.getFields().get(TITLE) != null) { - for (int i = 0; i < hit.getFields().get(TITLE) - .getValues().size(); i++) { - titles.add(hit.getFields().get(TITLE).values() - .get(i).toString()); - } - } + record.setHeader(setHeader(set)); + recordList.getRecord().add(record); + + return record; + } + + public ListRecordsType getRecordsWithSet(String from, String to, String set) { + + QueryBuilder query; + QueryBuilder rangeQuery = QueryBuilders.rangeQuery(CREATED).from(from).to(to); + + + if(set!=null){ + this.set = set; + String[] setParts = set.split(":"); - /* - * More DC elements - */ - furtherDCElements(workUri, oaiEsClient); - setDCObject(odt, of); + if(setParts[0].equals("project")){ + setParts[0] = setParts[0].concat(".value"); + } + + QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(setParts[0], setParts[1]); + QueryBuilder boolQuery = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); + + query = boolQuery; + }else { + query = rangeQuery; + } + + fetchFields(query, TGConstants.TGFields); + + return recordList; + } + + 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; + + } + public void setContributor(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + contributors.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setCreator(GetResponse responseWorkValues){ + + if (responseWorkValues.getField(WORK_AGENT) != null) { + creators.add(responseWorkValues.getField(WORK_AGENT).getValue() + .toString()); + } - /* - * Set identifier and date - */ - if (!identifiers.isEmpty()) { - recordHeader.setIdentifier(identifiers.get(0)); - } - // TODO Why take the 0th date here? - if (!dates.isEmpty()) { - recordHeader.setDatestamp(dates.get(0)); - } + } + + + public void setCoverage(GetResponse responseWorkValues){ + + if (responseWorkValues.getField(WORK_SPATIAL) != null) { + coverages.add(responseWorkValues.getField(WORK_SPATIAL) + .getValue().toString()); + } + + 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) + .getValue().toString()); + } - /* - * Clear list and create record list - */ - listClearer(); + } + + public void setDate(SearchHit hit){ + - metadata = newDbc.getDC(); - record.setMetadata(metadata); + } + + public void setDescription(GetResponse responseWorkValues){ + + if (responseWorkValues.getField(WORK_ABSTRACT) != null) { + descriptions.add(responseWorkValues.getField(WORK_ABSTRACT) + .getValue().toString()); + } - HeaderType header = new HeaderType(); - header.setDatestamp(datestamp); - header.setIdentifier(identifier); - header.getSetSpec().add(set); + } + + public void setFormat(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + formats.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setIdentifier(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + identifiers.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setLanguage(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + languages.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setPublisher(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + publishers.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setRelation(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + relations.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setRelationForWork(GetResponse responseWorkValues){ + + if (responseWorkValues.getField(IS_DERIVED_FROM) != null) { + relations.add(responseWorkValues.getField(IS_DERIVED_FROM) + .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){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + rights.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setSources(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + sources.add(hit.getFields().get(field) + .values().get(0).toString()); + } + } + } + + public void setSubject(GetResponse responseWorkValues){ + + if (responseWorkValues.getField(WORK_ID) != null) { + subjects.add(responseWorkValues.getField(WORK_ID).getValue() + .toString()); + } - record.setHeader(header); - recordList.getRecord().add(record); - } + } + + public void setTitle(SearchHit hit, String[] values){ + + for(String field : values){ + if (hit.getFields().get(field) != null) { + for (int i = 0; i < hit.getFields().get(field) + .getValues().size(); i++) { + titles.add(hit.getFields().get(field).values() + .get(i).toString()); } } } - //fieldLoader(getRecordList, set); + } + + public void setType(GetResponse responseWorkValues){ - return recordList; + 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){ @@ -764,10 +487,7 @@ public class RecordListDeliverer { return dbc; } - /** - * - */ - private void listClearer() { + public void listClearer() { this.contributors.clear(); this.coverages.clear(); this.creators.clear(); 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 039d9634d6a8d8925c028ab5725e12bbb716bd18..62dbce87fd88ce621289212b04e4d49ea35b8165 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java @@ -17,12 +17,7 @@ public final class TGConstants { //not called } - public static final String TG_ITEM_IDENTIFIER = "textgridUri"; public static final String TG_ITEM_IDENTIFIER_PREFIX = "textgrid:"; - //static final int ES_PORT = 9300; - - public static final List<String> TEXT_GRID_OBJECTS = Arrays.asList("work", "edition", "text", "collection", "image"); - public static final List<String> TEXTGRID_IDENTIFIERS = Arrays.asList("textgridUri", "pid", "iss", "isbn"); public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = Arrays.asList("textgrid-support@gwdg.de"); public static final String TG_REP_NAME = "TextGrid Repository"; @@ -34,5 +29,56 @@ public final class TGConstants { 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"; - + + public static final String CREATED = "created"; + public static final String FORMAT = "format"; + public static final String IDENTIFIER = "identifier"; + public static final String DATA_CONTRIBUTOR = "dataContributor"; + public static final String URI = "textgridUri"; + public static final String PROJECT_ID = "project.id"; + public static final String IS_DERIVED_FROM = "relations.isDerivedFrom"; + public static final String TITLE = "title"; + public static final String PID = "pid.value"; + public static final String EDITION_ISEDITIONOF = "edition.isEditionOf"; + public static final String EDITION_AGENT = "edition.agent.value"; + public static final String EDITION_LICENSEURI = "edition.license.licenseUri"; + public static final String EDITION_LANGUAGE = "edition.language"; + public static final String BIBCIT_AUTHOR = "edition.source.bibliographicCitation.author.value"; + public static final String BIBCIT_EDITOR = "edition.source.bibliographicCitation.editor.value"; + public static final String BIBCIT_TITLE = "edition.source.bibliographicCitation.editionTitle"; + public static final String BIBCIT_PLACEPUB = "edition.source.bibliographicCitation.placeOfPublication.value"; + public static final String BIBCIT_PUBLISHER = "edition.source.bibliographicCitation.publisher.value"; + public static final String BIBCIT_NO = "edition.source.bibliographicCitation.editionNo"; + public static final String BIBCIT_SERIES = "edition.source.bibliographicCitation.series"; + public static final String BIBCIT_VOLUME = "edition.source.bibliographicCitation.volume"; + public static final String BIBCIT_ISSUE = "edition.source.bibliographicCitation.issue"; + public static final String BIBCIT_EPAGE = "edition.source.bibliographicCitation.epage"; + public static final String BIBCIT_SPAGE = "edition.source.bibliographicCitation.spage"; + public static final String BIBCIT_BIBID = "edition.source.bibliographicCitation.bibidentifier"; + public static final String WORK_ABSTRACT = "work.abstract"; + public static final String WORK_GENRE = "work.genre"; + public static final String WORK_TYPE = "work.type"; + public static final String WORK_SPATIAL = "work.spatial.value"; + public static final String WORK_TEMPORAL = "work.temporal.value"; + public static final String WORK_AGENT = "work.agent.value"; + public static final String WORK_ID = "work.subject.id.value"; + + public static final String[] TGFields = {CREATED, FORMAT, IDENTIFIER, DATA_CONTRIBUTOR, URI, PROJECT_ID, IS_DERIVED_FROM, + TITLE, PID, EDITION_ISEDITIONOF, EDITION_AGENT, EDITION_LICENSEURI, + EDITION_LANGUAGE, BIBCIT_AUTHOR, BIBCIT_EDITOR, BIBCIT_TITLE, BIBCIT_PLACEPUB, + BIBCIT_PUBLISHER, BIBCIT_NO, BIBCIT_SERIES, BIBCIT_VOLUME, BIBCIT_ISSUE, + BIBCIT_EPAGE, BIBCIT_SPAGE, BIBCIT_BIBID, WORK_ABSTRACT, WORK_GENRE, WORK_TYPE, + WORK_SPATIAL, WORK_TEMPORAL, WORK_AGENT, WORK_ID}; + + 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[] 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}; } diff --git a/oaipmh-core/src/main/xsd/oai_dc.xsd b/oaipmh-core/src/main/xsd/oai_dc.xsd index 993c5f03e5313f48cd4c9dca1763a9d7120eace4..bae1bbf375f5dd03bfa5dfec9f867dcbeb02ece0 100644 --- a/oaipmh-core/src/main/xsd/oai_dc.xsd +++ b/oaipmh-core/src/main/xsd/oai_dc.xsd @@ -2,6 +2,7 @@ xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://www.w3.org/2001/XMLSchema" + elementFormDefault="qualified" attributeFormDefault="unqualified"> <annotation> 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 a6359a515ae7f2129d69e2e0234f526388a200e7..f8f1465194d561d07bb7df035e567509984a1a49 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java @@ -182,7 +182,7 @@ public class OaiPmhTest { @Test @Ignore public void testListRecordSets() throws ParseException { - System.out.println("Test for the verb \"GetRecord\" with succesfull response"); + 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", "", "", ""); JAXB.marshal(p, System.out);