From aadfe37989584ddef47872f221b349423fa78cbe Mon Sep 17 00:00:00 2001 From: "Stefan E. Funk" <funk@sub.uni-goettingen.de> Date: Mon, 1 Dec 2014 18:03:51 +0100 Subject: [PATCH] Added some finals. --- .../middleware/RecordListDeliverer.java | 449 +++++++++--------- 1 file changed, 218 insertions(+), 231 deletions(-) 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 a324d7b9..0205f1e7 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDeliverer.java @@ -30,30 +30,74 @@ import info.textgrid.middleware.oaipmh.RequestType; public class RecordListDeliverer { - private ListRecordsType recordList = new ListRecordsType(); - - private static org.apache.commons.logging.Log log = LogFactory - .getLog(RecordDeliverer.class); - - private List<String> contributors = new ArrayList<String>(); - private List<String> coverages = new ArrayList<String>(); - private List<String> creators = new ArrayList<String>(); - private List<String> dates = new ArrayList<String>(); - private List<String> descriptions = new ArrayList<String>(); - private List<String> formats = new ArrayList<String>(); - private List<String> identifiers = new ArrayList<String>(); - private List<String> languages = new ArrayList<String>(); - private List<String> publishers = new ArrayList<String>(); - private List<String> relations = new ArrayList<String>(); - private List<String> rights = new ArrayList<String>(); - private List<String> sources = new ArrayList<String>(); - private List<String> subjects = new ArrayList<String>(); - private List<String> titles = new ArrayList<String>(); - private List<String> types = new ArrayList<String>(); + // ** + // STATIC FINALS + // ** + + 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 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"; + + // ** + // STATICS + // ** + + private static org.apache.commons.logging.Log log = LogFactory + .getLog(RecordDeliverer.class); + + // ** + // CLASS VARIABLES + // ** private OAI_ESClient oaiEsClient; - - String aggregatorURL = "http://textgrid-esx2.gwdg.de/1.0/aggregator/teicorpus/"; + private ListRecordsType recordList = new ListRecordsType(); + private List<String> contributors = new ArrayList<String>(); + private List<String> coverages = new ArrayList<String>(); + private List<String> creators = new ArrayList<String>(); + private List<String> dates = new ArrayList<String>(); + private List<String> descriptions = new ArrayList<String>(); + private List<String> formats = new ArrayList<String>(); + private List<String> identifiers = new ArrayList<String>(); + private List<String> languages = new ArrayList<String>(); + private List<String> publishers = new ArrayList<String>(); + private List<String> relations = new ArrayList<String>(); + private List<String> rights = new ArrayList<String>(); + private List<String> sources = new ArrayList<String>(); + private List<String> subjects = new ArrayList<String>(); + private List<String> titles = new ArrayList<String>(); + private List<String> types = new ArrayList<String>(); + + // TODO Make configurable! + private String aggregatorURL = "http://textgrid-esx2.gwdg.de/1.0/aggregator/teicorpus/"; /** * @param oaiEsClient @@ -69,41 +113,22 @@ public class RecordListDeliverer { */ public ListRecordsType getRecords(String from, String to) { - QueryBuilder queryBuilder = QueryBuilders.rangeQuery("created") + 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.value", - "dataContributor", - "textgridUri", - "project.id", - "relations.isDerivedFrom", - "edition.license.licenseUri", - "title", - "edition.language", - "pid.value", - "edition.source.bibliographicCitation.author.value", - "edition.source.bibliographicCitation.editor.value", - "edition.source.bibliographicCitation.editionTitle", - "edition.source.bibliographicCitation.placeOfPublication.value", - "edition.source.bibliographicCitation.publisher.value", - "edition.source.bibliographicCitation.editionNo", - "edition.source.bibliographicCitation.series", - "edition.source.bibliographicCitation.volume", - "edition.source.bibliographicCitation.issue", - "edition.source.bibliographicCitation.epage", - "edition.source.bibliographicCitation.spage", - "edition.source.bibliographicCitation.bibidentifier") + .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")) + .setPostFilter(FilterBuilders.existsFilter(EDITION_ISEDITIONOF)) .setSize(10); SearchResponse getRecordListItems = getRecordList.execute().actionGet(); @@ -113,7 +138,7 @@ public class RecordListDeliverer { for (SearchHit hit : getRecordListItems.getHits().getHits()) { if (hit != null - && hit.getFields().get("format").values().get(0) + && hit.getFields().get(FORMAT).values().get(0) .toString() .equals("text/tg.edition+tg.aggregation+xml")) { @@ -124,8 +149,8 @@ public class RecordListDeliverer { RecordType record = new RecordType(); HeaderType recordHeader = new HeaderType(); - String datestamp = hit.getFields().get("created") - .getValue().toString(); + String datestamp = hit.getFields().get(CREATED).getValue() + .toString(); try { datestamp = OAIPMHUtillities.convertDateFormat( @@ -136,7 +161,7 @@ public class RecordListDeliverer { log.debug(e1); } - String workUri = hit.getFields().get("edition.isEditionOf") + String workUri = hit.getFields().get(EDITION_ISEDITIONOF) .values().get(0).toString(); workUri = workUri .substring(TGConstants.TG_ITEM_IDENTIFIER_PREFIX @@ -147,10 +172,10 @@ public class RecordListDeliverer { */ // System.out.println(hit.getFields().get("textgridUri").values().get(0).toString()); if (hit != null - && hit.getFields().get("edition.agent.value") != null) { + && hit.getFields().get(EDITION_AGENT) != null) { // String contributorUnformatted = - // hit.getFields().get("edition.agent.value").values().get(0).toString(); - contributors.add(hit.getFields().get("dataContributor") + // hit.getFields().get(AGENT).values().get(0).toString(); + contributors.add(hit.getFields().get(DATA_CONTRIBUTOR) .values().get(0).toString()); // contributors.add(contributorUnformatted); } @@ -159,8 +184,8 @@ public class RecordListDeliverer { * DC-Format */ if (hit != null) { - formats.add(hit.getFields().get("format").values() - .get(0).toString()); + formats.add(hit.getFields().get(FORMAT).values().get(0) + .toString()); } /* @@ -168,19 +193,16 @@ public class RecordListDeliverer { */ String identifier = ""; if (hit != null) { - identifiers.add(hit.getFields().get("textgridUri") - .values().get(0).toString()); + identifiers.add(hit.getFields().get(URI).values() + .get(0).toString()); identifier = identifiers.get(0); } - - if (hit != null && hit.getFields().get("pid.value") != null) { - identifiers.add(hit.getFields().get("pid.value") - .values().get(0).toString()); + if (hit != null && hit.getFields().get(PID) != null) { + identifiers.add(hit.getFields().get(PID).values() + .get(0).toString()); } - - if (hit != null - && hit.getFields().get("identifier") != null) { - identifiers.add(hit.getFields().get("identifier") + if (hit != null && hit.getFields().get(IDENTIFIER) != null) { + identifiers.add(hit.getFields().get(IDENTIFIER) .values().get(0).toString()); } @@ -188,8 +210,8 @@ public class RecordListDeliverer { * DC-Languages */ if (hit != null - && hit.getFields().get("edition.language") != null) { - languages.add(hit.getFields().get("edition.language") + && hit.getFields().get(EDITION_LANGUAGE) != null) { + languages.add(hit.getFields().get(EDITION_LANGUAGE) .values().get(0).toString()); } @@ -197,34 +219,26 @@ public class RecordListDeliverer { * DC-Publisher */ if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.publisher") != null) { - publishers - .add(hit.getFields() - .get("edition.source.bibliographicCitation.publisher") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_PUBLISHER) != null) { + publishers.add(hit.getFields().get(BIBCIT_PUBLISHER) + .values().get(0).toString()); } /* * DC-Relation */ if (hit != null) { - relations.add(hit.getFields().get("project.id") - .values().get(0).toString()); + relations.add(hit.getFields().get(PROJECT_ID).values() + .get(0).toString()); } - if (hit != null - && hit.getFields().get("relations.isDerivedFrom") != null) { - relations.add(hit.getFields() - .get("relations.isDerivedFrom").values().get(0) - .toString()); + && hit.getFields().get(IS_DERIVED_FROM) != null) { + relations.add(hit.getFields().get(IS_DERIVED_FROM) + .values().get(0).toString()); } - if (hit != null) { - relations - .add(aggregatorURL.concat(hit.getFields() - .get("textgridUri").values().get(0) - .toString())); + relations.add(aggregatorURL.concat(hit.getFields() + .get(URI).values().get(0).toString())); } /* @@ -232,117 +246,77 @@ public class RecordListDeliverer { */ // System.out.println(hit.getFields().get("textgridUri").values().get(0).toString()); if (hit != null - && hit.getFields() - .get("edition.license.licenseUri") != null) { - rights.add(hit.getFields() - .get("edition.license.licenseUri").values() - .get(0).toString()); + && hit.getFields().get(RDITION_LICENSEURI) != null) { + rights.add(hit.getFields().get(RDITION_LICENSEURI) + .values().get(0).toString()); } /* * DC-Source */ if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.author.value") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.author.value") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_AUTHOR) != null) { + sources.add(hit.getFields().get(BIBCIT_AUTHOR).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.editor.value") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.editor.value") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_EDITOR) != null) { + sources.add(hit.getFields().get(BIBCIT_EDITOR).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.editionTitle") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.editionTitle") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_TITLE) != null) { + sources.add(hit.getFields().get(BIBCIT_TITLE).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.placeOfPublication.value") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.placeOfPublication.value") + && hit.getFields().get(BIBCIT_PLACEPUB) != null) { + sources.add(hit.getFields().get(BIBCIT_PLACEPUB) .values().get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.publisher.value") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.publisher.value") + && hit.getFields().get(BIBCIT_PUBLISHER) != null) { + sources.add(hit.getFields().get(BIBCIT_PUBLISHER) .values().get(0).toString()); } - if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.editionNo") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.editionNo") - .values().get(0).toString()); + if (hit != null && hit.getFields().get(BIBCIT_NO) != null) { + sources.add(hit.getFields().get(BIBCIT_NO).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.series") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.series") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_SERIES) != null) { + sources.add(hit.getFields().get(BIBCIT_SERIES).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.volume") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.volume") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_VOLUME) != null) { + sources.add(hit.getFields().get(BIBCIT_VOLUME).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.issue") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.issue") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_ISSUE) != null) { + sources.add(hit.getFields().get(BIBCIT_ISSUE).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.spage") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.spage") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_SPAGE) != null) { + sources.add(hit.getFields().get(BIBCIT_SPAGE).values() + .get(0).toString()); } if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.epage") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.epage") - .values().get(0).toString()); + && hit.getFields().get(BIBCIT_EPAGE) != null) { + sources.add(hit.getFields().get(BIBCIT_EPAGE).values() + .get(0).toString()); } - if (hit != null - && hit.getFields() - .get("edition.source.bibliographicCitation.bibidentifier") != null) { - sources.add(hit - .getFields() - .get("edition.source.bibliographicCitation.epage") - .values().get(0).toString()); + if (hit != null && hit.getFields().get(IDENTIFIER) != null) { + sources.add(hit.getFields().get(BIBCIT_EPAGE).values() + .get(0).toString()); } /* * DC-Title */ - titles.add(hit.getFields().get("title").values().get(0) + titles.add(hit.getFields().get(TITLE).values().get(0) .toString()); furtherDCElements(workUri, oaiEsClient); @@ -368,7 +342,6 @@ public class RecordListDeliverer { record.setHeader(header); recordList.getRecord().add(record); - } } } else { @@ -378,6 +351,14 @@ public class RecordListDeliverer { return recordList; } + /** + * @param id + * @param esClient + */ + /** + * @param id + * @param esClient + */ /** * @param id * @param esClient @@ -390,37 +371,37 @@ public class RecordListDeliverer { .setIndex(esClient.getEsIndex()) .setType(esClient.getEsType()) .setId(id) - .setFields("created", "work.abstract", - "relations.isDerivedFrom", "textgridUri", "work.genre", - "title", "work.type", "work.spatial.value", - "work.temporal.value", "work.agent.value", - "work.subject.id.value"); + .setFields(CREATED, WORK_ABSTRACT, IS_DERIVED_FROM, URI, + WORK_GENRE, TITLE, WORK_TYPE, WORK_SPATIAL, + WORK_TEMPORAL, WORK_AGENT, WORK_ID); GetResponse responseWorkValues = getWorkValues.execute().actionGet(); - /** + /* * DC-Coverages */ if (responseWorkValues != null - && responseWorkValues.getField("work.spatial.value") != null) { - coverages.add(responseWorkValues.getField("work.spatial.value") - .getValue().toString()); - coverages.add(responseWorkValues.getField("work.temporal.value") - .getValue().toString()); + && responseWorkValues.getField(WORK_SPATIAL) != null) { + coverages.add(responseWorkValues.getField(WORK_SPATIAL).getValue() + .toString()); + } + if (responseWorkValues != null + && responseWorkValues.getField(WORK_TEMPORAL) != null) { + coverages.add(responseWorkValues.getField(WORK_TEMPORAL).getValue() + .toString()); } - /** + /* * DC-Creators */ if (responseWorkValues != null - && responseWorkValues.getField("work.agent.value") != null) { - creators.add(responseWorkValues.getField("work.agent.value") - .getValue().toString()); + && responseWorkValues.getField(WORK_AGENT) != null) { + creators.add(responseWorkValues.getField(WORK_AGENT).getValue() + .toString()); } - String singleDate = null; if (responseWorkValues != null) { - singleDate = responseWorkValues.getField("created").getValue() + singleDate = responseWorkValues.getField(CREATED).getValue() .toString(); } @@ -442,8 +423,8 @@ public class RecordListDeliverer { * DC-Description */ if (responseWorkValues != null - && responseWorkValues.getField("work.abstract") != null) { - descriptions.add(responseWorkValues.getField("work.abstract") + && responseWorkValues.getField(WORK_ABSTRACT) != null) { + descriptions.add(responseWorkValues.getField(WORK_ABSTRACT) .getValue().toString()); } @@ -451,35 +432,41 @@ public class RecordListDeliverer { * DC-Relation */ if (responseWorkValues != null - && responseWorkValues.getField("relations.isDerivedFrom") != null) { - relations.add(responseWorkValues - .getField("relations.isDerivedFrom").getValue().toString()); + && responseWorkValues.getField(IS_DERIVED_FROM) != null) { + relations.add(responseWorkValues.getField(IS_DERIVED_FROM) + .getValue().toString()); + } + if (responseWorkValues != null + && responseWorkValues.getField(TITLE) != null) { + relations.add(responseWorkValues.getField(TITLE).getValue() + .toString()); + } + if (responseWorkValues != null + && responseWorkValues.getField(URI) != null) { + relations.add(responseWorkValues.getField(URI).getValue() + .toString()); } - relations.add(responseWorkValues.getField("title").getValue() - .toString()); - relations.add(responseWorkValues.getField("textgridUri").getValue() - .toString()); /* * DC-Subject */ if (responseWorkValues != null - && responseWorkValues.getField("work.subject.id.value") != null) { - subjects.add(responseWorkValues.getField("work.subject.id.value") - .getValue().toString()); + && responseWorkValues.getField(WORK_ID) != null) { + subjects.add(responseWorkValues.getField(WORK_ID).getValue() + .toString()); } /* * DC-Type */ if (responseWorkValues != null - && responseWorkValues.getField("work.genre") != null) { - types.add(responseWorkValues.getField("work.genre").getValue() + && responseWorkValues.getField(WORK_GENRE) != null) { + types.add(responseWorkValues.getField(WORK_GENRE).getValue() .toString()); } if (responseWorkValues != null - && responseWorkValues.getField("work.type") != null) { - types.add(responseWorkValues.getField("work.type").getValue() + && responseWorkValues.getField(WORK_TYPE) != null) { + types.add(responseWorkValues.getField(WORK_TYPE).getValue() .toString()); } @@ -494,21 +481,21 @@ public class RecordListDeliverer { DublinCoreBuilder dbc = new DublinCoreBuilder(odt, of); - dbc.setContributor(contributors); - dbc.setCoverage(coverages); - dbc.setCreator(creators); - dbc.setDate(dates); - dbc.setDescription(descriptions); - dbc.setFormat(formats); - dbc.setIdentifier(identifiers); - dbc.setLanguage(languages); - dbc.setPublisher(publishers); - dbc.setRelation(relations); - dbc.setRights(rights); - dbc.setSource(sources); - dbc.setSubject(subjects); - dbc.setTitle(titles); - dbc.setType(types); + dbc.setContributor(this.contributors); + dbc.setCoverage(this.coverages); + dbc.setCreator(this.creators); + dbc.setDate(this.dates); + dbc.setDescription(this.descriptions); + dbc.setFormat(this.formats); + dbc.setIdentifier(this.identifiers); + dbc.setLanguage(this.languages); + dbc.setPublisher(this.publishers); + dbc.setRelation(this.relations); + dbc.setRights(this.rights); + dbc.setSource(this.sources); + dbc.setSubject(this.subjects); + dbc.setTitle(this.titles); + dbc.setType(this.types); return dbc; } @@ -517,21 +504,21 @@ public class RecordListDeliverer { * */ private void listClearer() { - contributors.clear(); - coverages.clear(); - creators.clear(); - dates.clear(); - descriptions.clear(); - formats.clear(); - identifiers.clear(); - languages.clear(); - publishers.clear(); - relations.clear(); - rights.clear(); - sources.clear(); - subjects.clear(); - titles.clear(); - types.clear(); + this.contributors.clear(); + this.coverages.clear(); + this.creators.clear(); + this.dates.clear(); + this.descriptions.clear(); + this.formats.clear(); + this.identifiers.clear(); + this.languages.clear(); + this.publishers.clear(); + this.relations.clear(); + this.rights.clear(); + this.sources.clear(); + this.subjects.clear(); + this.titles.clear(); + this.types.clear(); } /** -- GitLab