diff --git a/Jenkinsfile b/Jenkinsfile index b508c841cc4caa582143f671fe1c13a2ac48b96b..8db9903a093cab02775c2da5a523dda4c73365a0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,8 +19,8 @@ node { if (snapshot) { doDebSnapshot(pName, 'oaipmh-webapp/target', pVersion) } - else { - doDebRelease(pName, 'oaipmh-webapp/target', pVersion) - } + //else { + // doDebRelease(pName, 'oaipmh-webapp/target', pVersion) + //} } } diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml index d2277bde3146fa6e8e5a0f000c7d16e830cbcb28..46b2b4d6593d0a2a3e8adf1013f00b90e138bf37 100644 --- a/oaipmh-core/pom.xml +++ b/oaipmh-core/pom.xml @@ -5,19 +5,35 @@ <parent> <artifactId>oaipmh</artifactId> <groupId>info.textgrid.middleware</groupId> - <version>3.1.12-SNAPSHOT</version> + <version>3.3.2-SNAPSHOT</version> </parent> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh-core</artifactId> <packaging>jar</packaging> <name>DARIAHDE :: OAI-PMH DataProvider :: Core</name> <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>info.textgrid.utils</groupId> + <artifactId>httpclients</artifactId> + <version>${textgrid.httpclients.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.rdf4j</groupId> + <artifactId>rdf4j-repository-api</artifactId> + <version>3.0.2</version> +</dependency> <dependency> <groupId>info.textgrid.middleware</groupId> <artifactId>crud-common</artifactId> <version>${tgcrud.version}</version> </dependency> + <dependency> + <groupId>info.textgrid.middleware.clients</groupId> + <artifactId>textgrid-clients</artifactId> + <version>3.2.5</version> + </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-security-cors</artifactId> @@ -50,8 +66,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.elasticsearch</groupId> - <artifactId>elasticsearch</artifactId> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>${elasticsearch.version}</version> </dependency> <dependency> @@ -91,6 +107,13 @@ <artifactId>package-info-maven-plugin</artifactId> <version>1.4.5</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.json/json --> +<dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20190722</version> +</dependency> + </dependencies> <build> <pluginManagement> diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java index 35fd6de95723ad75da30714d03a3504a8eae86bb..b3d4938062688a0b46f3ae0ac54d7a26b95a5dbf 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java @@ -4,15 +4,20 @@ import java.util.Arrays; import java.util.List; /** - * Collection of values never changing its content + * <p> + * Collection of values never changing its content. + * </p> * - * @author Maximilian Brodhun: SUB + * @author Maximilian Brodhun, SUB Göttingen */ public final class DARIAHConstants { + /** + * + */ private DARIAHConstants() { - // not called + // } public static final String ITEM_IDENTIFIER_PREFIX = "hdl:"; @@ -21,48 +26,33 @@ public final class DARIAHConstants { public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = Arrays.asList("support@de.dariah.eu"); - /* - * Rep Identification String Constants - */ - + // Rep Identification String Constants public static final String DARIAH_REP_BASEURL = "repository.de.dariah.eu"; public static final String METADATA_DC_PREFIX = "rdf:RDF/rdf:Description"; - /* - * Error String Constants - */ - + // 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) - */ - + // TextGrid Metadata Fields for OAI-PMH Request (Mapping to DC) public static final String CREATED = "descriptiveMetadata.dc:date"; public static final String FORMAT = "descriptiveMetadata.dc:format"; public static final String IDENTIFIER = "administrativeMetadata.dcterms:identifier"; public static final String DATA_CONTRIBUTOR = "descriptiveMetadata.dc:contributor"; - - public static final String[] DARIAHFields = { - "descriptiveMetadata.dc:contributor", "descriptiveMetadata.dc:coverage", - "administrativeMetadata.dcterms:created", "administrativeMetadata.dcterms:modified", - "descriptiveMetadata.dc:description", "descriptiveMetadata.dc:format", - "descriptiveMetadata.dc:identifier", "descriptiveMetadata.dc:language", - "descriptiveMetadata.dc:publisher", "descriptiveMetadata.dc:relation", - "descriptiveMetadata.dc:rights", "descriptiveMetadata.:source", - "descriptiveMetadata.dc:subject", - "descriptiveMetadata.dc:title", "descriptiveMetadata.dc:type", - "administrativeMetadata.dcterms:identifier"}; - + public static final String[] DARIAHFields = + {"descriptiveMetadata.dc:contributor", "descriptiveMetadata.dc:coverage", + "administrativeMetadata.dcterms:created", "administrativeMetadata.dcterms:modified", + "descriptiveMetadata.dc:description", "descriptiveMetadata.dc:format", + "descriptiveMetadata.dc:identifier", "descriptiveMetadata.dc:language", + "descriptiveMetadata.dc:publisher", "descriptiveMetadata.dc:relation", + "descriptiveMetadata.dc:rights", "descriptiveMetadata.:source", + "descriptiveMetadata.dc:subject", "descriptiveMetadata.dc:title", + "descriptiveMetadata.dc:type", "administrativeMetadata.dcterms:identifier"}; public static final String[] DARIAHCollectionFields = {"metadata.dc:title"}; - /* - * String Arrays to define which TextGrid fields belongs to the regarding DC fields - */ - + // String Arrays to define which TextGrid fields belongs to the regarding DC fields public static final String[] CONTRIBUTOR_LIST = {"descriptiveMetadata.dc:contributor"}; public static final String[] COVERAGE_LIST = {"descriptiveMetadata.dc:coverage"}; public static final String[] CREATOR_LIST = {"descriptiveMetadata.dc:cretor"}; 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 fefc729da89cd9e6262f7387b788f57e40cd764a..c9d9c5b1ae8510d53b60023aee3144947d0d80c9 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java @@ -1,7 +1,10 @@ package info.textgrid.middleware; +import java.text.ParseException; import java.util.List; import javax.xml.bind.JAXBElement; +import javax.xml.datatype.DatatypeConfigurationException; + import info.textgrid.middleware.oaipmh.ElementType; import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.OaiDcType; @@ -27,6 +30,7 @@ public final class DublinCoreBuilder { // MetadataType of OAI schema. private MetadataType metadata = new MetadataType(); + // OAI_DC type of oai_dc schema. private OaiDcType tgMappedDC = new OaiDcType(); @@ -104,12 +108,14 @@ public final class DublinCoreBuilder { * </p> * * @param dates + * @throws DatatypeConfigurationException + * @throws ParseException */ - public void setDate(List<String> dates) { + public void setDate(List<String> dates) throws ParseException, DatatypeConfigurationException { for (String dcdate : dates) { ElementType dateElement = new ElementType(); JAXBElement<ElementType> dcCoreDate = oaiDcObj.createDate(dateElement); - dateElement.setValue(dcdate); + dateElement.setValue(OAIPMHUtilities.convertDateFormat(dcdate).toString()); this.tgMappedDC.getTitleOrCreatorOrSubject().add(dcCoreDate); } } 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 23a08fc77dcc0abea9f41cb865cf3c373df9ae56..2451272a1a377ab6236c444c9934c7b450daf6e3 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java @@ -3,8 +3,8 @@ package info.textgrid.middleware; import java.text.ParseException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.xml.datatype.DatatypeConfigurationException; -import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.search.SearchHit; @@ -12,140 +12,34 @@ import org.elasticsearch.search.SearchHit; /** * <p> * The Dublin Core Field Loader takes the results of the ElasticSearch request and puts them into a - * String-List. For each element of Dublin Core exists a seperate list. + * String-List. For each element of Dublin Core exists a separate list. * </p> * * <p> * For each element two functions are necessary because the datatype "SeachHit" could contain more - * then one results and the GetResponse just one + * then one results and the GetResponse just one. * </p> * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 24.05.2019 - * @since 18.02.2014 + * @version 2019-10-29 + * @since 2014-02-18 */ public class DublinCoreFieldLoader { - private static Log log = LogFactory.getLog(OAIPMHImpl.class); + // ** + // STATICS + // ** - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setContributor(SearchHit hit, String[] fields) { - - List<String> contributors = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - contributors.add(hit.getFields().get(field).values().get(0) - .toString()); - } - } - - return contributors; - } + private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core + * This function takes the results of the ElasticSearch resuest + * and fills the String-Lists with the specific values for the dublin core field + * @param responseOfGetRequest result of the ElasticSearch request from a getRequest (Single Result) + * @param fields String List for the specific dublin core field + * @return String List containing the values for the specific dublin core field */ - public static List<String> setContributor(GetResponse responseWorkValues, String[] fields) { - - List<String> contributors = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - contributors.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return contributors; - } - - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setCreator(GetResponse responseWorkValues, String[] fields) { - - List<String> creators = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - creators.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return creators; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setCreator(SearchHit hit, String[] fields) { - - List<String> creators = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - creators.add(hit.getFields().get(field).values().get(0) - .toString()); - } - } - - return creators; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setCoverage(GetResponse responseWorkValues, String[] fields) { - - List<String> coverages = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - coverages.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return coverages; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setCoverage(SearchHit hit, String[] fields) { - - List<String> coverages = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - coverages.add(hit.getFields().get(field).values().get(0) - .toString()); - } - } - - return coverages; - } /** * @param responseWorkValues contains results of the ElasticSearch request @@ -154,8 +48,12 @@ public class DublinCoreFieldLoader { */ public static List<String> setDate(GetResponse responseWorkValues, String[] fields) { + // TODO We don't need this here, I suppose? We have to check the dates here! + // return fillList(responseWorkValues, fields); + List<String> dates = new ArrayList<String>(); + // Transform to OAI-PMH certificated time stamp if (responseWorkValues.isExists()) { for (String field : fields) { try { @@ -193,12 +91,15 @@ public class DublinCoreFieldLoader { List<String> dates = new ArrayList<String>(); + // FIXME TADAA? + System.out.println("TADA"); + for (String field : fields) { if (hit.getFields().get(field) != null) { - try { - dates.add(OAIPMHUtilities.convertDateFormat( - hit.getFields().get(field).values().get(0).toString()).toXMLFormat()); + dates.add(OAIPMHUtilities + .convertDateFormat(hit.getFields().get(field).getValues().get(0).toString()) + .toXMLFormat()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -212,466 +113,84 @@ public class DublinCoreFieldLoader { return dates; } - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setDescription(GetResponse responseWorkValues, String[] fields) { - - List<String> descriptions = new ArrayList<String>(); - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - descriptions.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } + public static List<String> fillList(GetResponse responseWorkValues, String[] fields) { - return descriptions; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setDescription(SearchHit hit, String[] fields) { - - List<String> descriptions = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - descriptions.add(hit.getFields().get(field).values().get(0) - .toString()); - } - } - - return descriptions; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setFormat(SearchHit hit, String[] fields) { - - List<String> formats = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - formats.add(hit.getFields().get(field).values().get(0) - .toString()); - } - } - - return formats; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setFormat(GetResponse responseWorkValues, String[] fields) { - - List<String> formats = new ArrayList<String>(); + List<String> list = new ArrayList<String>(); if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - formats.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return formats; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setIdentifier(SearchHit hit, String[] fields) { - - List<String> identifiers = new ArrayList<String>(); - - String identifier = ""; - for (String field : fields) { - if (hit.getFields().get(field) != null) { - for (int i = 0; i < hit.getFields().get(field).getValues().size(); i++) { - if (hit.getFields().get(field).values().get(i).toString().startsWith("textgrid")) { - identifier = hit.getFields().get(field).values().get(i).toString(); - identifier = identifier.replace(identifier, "https://textgridrep.org/" + identifier); - identifiers.add(identifier); + if (fields != null) { + for (String field : fields) { + if (responseWorkValues.getSourceAsMap().get(field) == null) { + String[] requestedField = field.split("\\."); + Map<String, Object> nestedMap = responseWorkValues.getSourceAsMap(); + String valueOfRequestedField = null; + Map<String, Object> nestedMap2 = null; + for (int i = 0; i < requestedField.length; i++) { + if (i < requestedField.length - 1 && nestedMap != null + && nestedMap.get(requestedField[i]) != null) { + nestedMap2 = (Map<String, Object>) nestedMap.get(requestedField[i]); + } + if (i == requestedField.length - 1 && + nestedMap2 != null && nestedMap2.get(requestedField[i]) != null) { + valueOfRequestedField = nestedMap2.get(requestedField[i]).toString(); + if (valueOfRequestedField.length() > 0) { + list.add(valueOfRequestedField); + } + } + nestedMap = nestedMap2; + } } else { - identifiers.add(hit.getFields().get(field).values().get(i).toString()); - } - } - } - } - - return identifiers; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setIdentifier(GetResponse responseWorkValues, String[] fields) { - - List<String> identifiers = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - - if (responseWorkValues.getField(field) != null) { - List<Object> entireIdentifier = responseWorkValues.getField(field).getValues(); - for (int i = 0; i < responseWorkValues.getField(field).getValues().size(); i++) { - identifiers.add(entireIdentifier.get(i).toString()); + list.add(responseWorkValues.getSourceAsMap().get(field).toString()); } } } } - return identifiers; + return list; } /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setLanguage(SearchHit hit, String[] fields) { - - List<String> languages = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - languages.add(hit.getFields().get(field).values().get(0).toString()); - } - } - - return languages; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setLanguage(GetResponse responseWorkValues, String[] fields) { - - List<String> languages = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - languages.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return languages; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setPublisher(SearchHit hit, String[] fields) { - - List<String> publishers = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - publishers.add(hit.getFields().get(field).values().get(0).toString()); - } - } - - return publishers; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request + * @param hit * @param fields - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setPublisher(GetResponse responseWorkValues, String[] fields) { - - List<String> publishers = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - publishers.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return publishers; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setRelation(SearchHit hit, String[] fields) { - - List<String> relations = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - for (int i = 0; i < hit.getFields().get(field).getValues().size(); i++) { - relations.add(hit.getFields().get(field).values().get(i).toString()); - } - } - } - - return relations; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setRelation(GetResponse responseWorkValues, String[] fields) { - - List<String> relations = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - relations.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return relations; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setRelationForWork(GetResponse responseWorkValues, String[] fields) { - - List<String> relations = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - relations.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return relations; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setRights(SearchHit hit, String[] fields) { - - List<String> rights = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - rights.add(hit.getFields().get(field).values().get(0).toString()); - } - } - - return rights; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setRights(GetResponse responseWorkValues, String[] fields) { - - List<String> rights = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - rights.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return rights; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setSources(SearchHit hit, String[] fields) { - - List<String> sources = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - sources.add(hit.getFields().get(field).values().get(0).toString()); - } - } - - return sources; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setSources(GetResponse responseWorkValues, String[] fields) { - - List<String> sources = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - sources.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - - return sources; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setSubject(GetResponse responseWorkValues, String[] fields) { - - List<String> subjects = new ArrayList<String>(); - - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - subjects.add(responseWorkValues.getField(field).getValue().toString()); - } - } - - return subjects; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setSubject(SearchHit hit, String[] fields) { - - List<String> subjects = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - subjects.add(hit.getFields().get(field).values().get(0).toString()); - } - } - - return subjects; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setTitle(SearchHit hit, String[] fields) { - - List<String> titles = new ArrayList<String>(); - - for (String field : fields) { - 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()); - } - } - } - - return titles; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core + * @return */ - public static List<String> setTitle(GetResponse responseWorkValues, String[] fields) { - - List<String> titles = new ArrayList<String>(); + public static List<String> fillList(SearchHit hit, String[] fields) { - if (responseWorkValues.isExists()) { + List<String> list = new ArrayList<String>(); + + if (fields != null) { for (String field : fields) { - List<Object> entireTitles = responseWorkValues.getField(field).getValues(); - if (responseWorkValues.getField(field) != null) { - for (int i = 0; i < responseWorkValues.getField(field).getValues().size(); i++) { - titles.add(entireTitles.get(i).toString()); + if (hit.getSourceAsMap().get(field) == null) { + String[] requestedField = field.split("\\."); + Map<String, Object> nestedMap = hit.getSourceAsMap(); + String valueOfRequestedField = null; + Map<String, Object> nestedMap2 = null; + for (int i = 0; i < requestedField.length; i++) { + if (i < requestedField.length - 1 && nestedMap != null + && nestedMap.get(requestedField[i]) != null) { + try { + nestedMap2 = (Map<String, Object>) nestedMap.get(requestedField[i]); + } catch (ClassCastException cce) { + + } + } + if (i == requestedField.length - 1 && + nestedMap2 != null && nestedMap2.get(requestedField[i]) != null) { + valueOfRequestedField = nestedMap2.get(requestedField[i]).toString(); + if (valueOfRequestedField.length() > 0) { + list.add(valueOfRequestedField); + } + } + nestedMap = nestedMap2; } + } else { + list.add(hit.getSourceAsMap().get(field).toString()); } } } - return titles; - } - - /** - * @param responseWorkValues contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setType(GetResponse responseWorkValues, String[] fields) { - - List<String> types = new ArrayList<String>(); - - if (responseWorkValues.isExists()) { - if (fields != null) { - for (String field : fields) { - if (responseWorkValues.getField(field) != null) { - types.add(responseWorkValues.getField(field).getValue().toString()); - } - } - } - } - - return types; - } - - /** - * @param hit contains results of the ElasticSearch request - * @param fields containing all fields from ElasticSearch related to this Dublin Core field - * @return all elements mapped from TetxGrid metadata scheme to Dublin Core - */ - public static List<String> setType(SearchHit hit, String[] fields) { - - List<String> types = new ArrayList<String>(); - - for (String field : fields) { - if (hit.getFields().get(field) != null) { - for (int i = 0; i < hit.getFields().get(field).getValues().size(); i++) { - types.add(hit.getFields().get(field).values().get(i).toString()); - } - } - } - - return types; + return list; } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/ErrorHandler.java b/oaipmh-core/src/main/java/info/textgrid/middleware/ErrorHandler.java index 0179698bacf690b712cdebaf30228a6e3d8c6ff7..7ee3483ee6630e3c3247bb7e5f05c1637aa27cf1 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/ErrorHandler.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/ErrorHandler.java @@ -27,14 +27,14 @@ public class ErrorHandler { if (errorDescription.equals("BadArgument")) { this.errorCode = OAIPMHerrorcodeType.BAD_ARGUMENT; - } else if (errorDescription.equals("ResumptionTokenError")) { + } else if (errorDescription.equals("badResumptionToken")) { this.errorCode = OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN; } else if (errorDescription.equals("VerbError")) { this.errorCode = OAIPMHerrorcodeType.BAD_VERB; this.error.setValue("Illegal OAI-PMH verb"); } else if (errorDescription.equals("FormatError")) { this.errorCode = OAIPMHerrorcodeType.CANNOT_DISSEMINATE_FORMAT; - } else if (errorDescription.equals("IDError")) { + } else if (errorDescription.equals("idDoesNotExist")) { this.errorCode = OAIPMHerrorcodeType.ID_DOES_NOT_EXIST; } else if (errorDescription.equals("MetadataFormatError")) { this.error.setValue("There are no metadata formats available for the specified item."); @@ -42,7 +42,9 @@ public class ErrorHandler { this.errorCode = OAIPMHerrorcodeType.NO_RECORDS_MATCH; } else if (errorDescription.equals("SetHierarchyError")) { this.errorCode = OAIPMHerrorcodeType.NO_SET_HIERARCHY; - } + } else if (errorDescription.equals("badVerb")) { + this.errorCode = OAIPMHerrorcodeType.BAD_VERB; + } this.error.setCode(this.errorCode); this.error.setValue(errorValue); diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java index b94d7206b13f27d818585ef1abd7b61ebecca228..e122ab6a314dba262b39b013d77ccc3e97c8b068 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java @@ -1,7 +1,11 @@ package info.textgrid.middleware; +import java.io.IOException; import java.util.ArrayList; import java.util.List; + +import javax.swing.plaf.synth.SynthSpinnerUI; + import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.RequestType; @@ -30,7 +34,7 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD */ @Override public ListIdentifiersType processIdentifierList(String from, String to, String set, - String resumptionToken) { + String resumptionToken) throws IOException { return null; } @@ -44,7 +48,7 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD // Check if metadata prefix is existing and valid. if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() @@ -56,19 +60,18 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD if (request.getResumptionToken() != null) { boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); + System.out.println(request.getResumptionToken() + " exists: " + RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken())); boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); - if (restokDCExisting || restokIDIOMExisting) { - result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " + if (!restokDCExisting || !restokIDIOMExisting) { + System.out.println("BUHUH"); + result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " + request.getResumptionToken() + " argument is invalid or expired."); } } List<String> errorValues = new ArrayList<String>(); - if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) { - errorValues.add("metadataPrefix"); - } if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { errorValues.add("metadataPrefix"); } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java index 6dd234652ce7fac69e2b44696972cd27e38c449d..f4cfecbcaedf4c0855ad42cb4dcef98952c04092 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java @@ -1,34 +1,45 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; import java.util.Hashtable; import java.util.Map; import javax.xml.datatype.DatatypeConfigurationException; import org.apache.commons.logging.LogFactory; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchScrollRequest; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; - /** - * Class to build the Element for a ListIdentifiers request + * <p> + * Class to build the Element for a ListIdentifiers request. + * </p> * - * @author Maximilian Brodhun, SUB - * @version 1.0 - * @since 20.02.2014 + * @author Maximilian Brodhun, SUB Göttingen + * @version 2019-10-28 + * @since 2014-02-20 */ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { private static org.apache.commons.logging.Log log = LogFactory.getLog(IdentifierListDelivererDC.class); + public static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + private String datestamp; private boolean idExist = true; private OAI_ESClient oaiEsClient; @@ -38,27 +49,25 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { private String dateOfObjectCreation; // Field for the object creation in the repository private String repositoryObjectURIPrefix; // private String identifierField; - private static final int lifeTimeResToken = 10000; - - public static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - + private static final int lifeTimeResToken = 100; private int searchResponseSize; + private long resultSize; /** + * <p> * In OAIPMH a ListIdentifiers request is answered by responding the datestamp and the identifier - * of an object Both will be responded in a header element. This function build the header element + * of an object Both will be responded in a header element. This function build the header + * element. + * </p> * * @param datestamp taken from the elasticSearch index (created element) * @param identifier taken from the elasticSearch index (textgridUri) * @return the ListIdentifierElement with the responded header element */ - public IdentifierListDelivererDC(boolean textgrid, boolean dariah) { super(textgrid, dariah); } - - /** * @param datestamp * @param identifier @@ -84,19 +93,23 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { } /** + * <p> * To get the required values for the ListIdentifiers request this function will ask ElasticSearch * for a specific textgridUri the values "created" and "textgridUri". + * </p> * + * <p> * Since the ListIdentifiers request enables the possibility the limit the request in a specific - * time interval, it is necessary to perform a range query on the ElasticSearch index + * time interval, it is necessary to perform a range query on the ElasticSearch index.</p * * @param from : start value for the range query * @param to : end value to the range query * @return after calling the function "setListIdentifierHeader" the return value is the whole * ListIdentifiers element + * @throws IOException */ public ListIdentifiersType processIdentifierList(String from, String to, String set, - String resumptionToken) { + String resumptionToken) throws IOException { // FIXME combine it with with getIdentifierListWithSet and check for empty set @@ -104,19 +117,31 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { QueryBuilder query = setOrNot(set, from, to); SearchResponse listListIdentiferValues; + String[] includes = this.identifierListFields; + String[] excludes = Strings.EMPTY_ARRAY; + //TODO: necessary? + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + + + SearchRequest searchRequest = + new SearchRequest(OAI_ESClient.getEsIndex()).searchType(SearchType.QUERY_THEN_FETCH); + + + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + searchSourceBuilder.query(query); + searchSourceBuilder.size(this.searchResponseSize); + searchSourceBuilder.fetchSource(includes, excludes); + if (resumptionToken != null) { - listListIdentiferValues = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(new TimeValue(lifeTimeResToken)).execute().actionGet(); + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueSeconds(lifeTimeResToken)); + listListIdentiferValues = + OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); } else { - listListIdentiferValues = OAI_ESClient - .getOaiESClient().prepareSearch(OAI_ESClient.getEsIndex()) - .setTypes(OAI_ESClient.getEsType()) - .setScroll(new TimeValue(lifeTimeResToken)) - .addFields(this.identifierListFields) - .setQuery(query) - .setSize(this.searchResponseSize) - .execute() - .actionGet(); + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueMinutes(lifeTimeResToken)); + listListIdentiferValues = + OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); } listListIdentiferValues = hitHandling(listListIdentiferValues, lit, set, listListIdentiferValues.getScrollId()); @@ -135,11 +160,12 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { String set, String resumptionToken) { int i = 0; + setResultSize(listFurtherValues.getHits().totalHits); for (SearchHit hit : listFurtherValues.getHits().getHits()) { i++; if (this.textgrid) { - - String datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); + // hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); + String datestamp = hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); try { datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat(); } catch (ParseException e1) { @@ -147,25 +173,27 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { } catch (DatatypeConfigurationException e1) { log.debug(e1); } - String identifier = hit.getFields().get(this.identifierField).getValue().toString(); + String identifier = hit.getSourceAsMap().get(this.identifierField).toString(); lit = setListIdentifierHeader(datestamp, identifier, lit, set); } if (this.dariah) { - this.datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); + this.datestamp = hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); try { - this.datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); + + this.datestamp = hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); this.datestamp = OAIPMHUtilities.convertDateFormat(this.datestamp).toXMLFormat(); + } catch (ParseException e1) { log.debug(e1); } catch (DatatypeConfigurationException e1) { log.debug(e1); } - String identifier = hit.getFields().get(this.identifierField).getValue().toString(); + String identifier = hit.getSourceAsMap().get(this.identifierField).toString(); lit = setListIdentifierHeader(this.datestamp, identifier, lit, set); } } @@ -354,4 +382,18 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { this.oaiEsClient = oaiEsClient; } + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererInterface.java index 2e9b56f3cc793b0b6c6b322c1bff0733c0fe8fd3..81068740ca4c4907c06a0b004875b47ab0715fe3 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererInterface.java @@ -1,5 +1,6 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; import info.textgrid.middleware.oaipmh.ListIdentifiersType; @@ -15,8 +16,9 @@ public interface IdentifierListDelivererInterface { * @param resumptionToken * @return * @throws ParseException + * @throws IOException */ public ListIdentifiersType processIdentifierList(String from, String to, String set, - String resumptionToken) throws ParseException; + String resumptionToken) throws ParseException, IOException; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDeliverer.java index 6f43397e45deb2dfea88839daab401e6f5acc8ea..04c97e9d0e60a08f192fa1d9171f9074bfb5deba 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDeliverer.java @@ -1,7 +1,11 @@ package info.textgrid.middleware; -import org.elasticsearch.action.get.GetRequestBuilder; +import java.io.IOException; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.common.Strings; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; import info.textgrid.middleware.oaipmh.MetadataFormatType; import info.textgrid.middleware.oaipmh.RequestType; @@ -26,20 +30,33 @@ public class MetadataFormatListDeliverer { */ public ListMetadataFormatsType setMetadataFormatList(String id) { + String[] includes = new String[] {TGConstants.URI}; + String[] excludes = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + ListMetadataFormatsType lmft = new ListMetadataFormatsType(); MetadataFormatType mft = new MetadataFormatType(); - - GetRequestBuilder recordById = OAI_ESClient.getOaiESClient().prepareGet() - .setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()) - .setFields(TGConstants.URI) - .setId(id); - - GetResponse tgObject = recordById.execute().actionGet(); + + GetRequest getRequest = new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id.replace("textgrid:", "")) + .fetchSourceContext(fetchSourceContext); + + /* + * GetRequestBuilder recordById = OAI_ESClient.getEsClient().get(getRequest, GetAction.INSTANCE) + * .setIndex(OAI_ESClient.getEsIndex()) .setType(OAI_ESClient.getEsType()) + * .setFields(TGConstants.URI) .setId(id); + */ + + GetResponse tgObject = null; + try { + tgObject = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if (tgObject.isExists()) { setIdExist(true); - mft.setMetadataPrefix(TGConstants.METADATA_DC_PREFIX); + mft.setMetadataPrefix(OAIPMHUtilities.OAIDC_PREFIX); mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); lmft.getMetadataFormat().add(mft); @@ -60,7 +77,7 @@ public class MetadataFormatListDeliverer { MetadataFormatType mft = new MetadataFormatType(); MetadataFormatType mftIdiomMets = new MetadataFormatType(); - mft.setMetadataPrefix(TGConstants.METADATA_DC_PREFIX); + mft.setMetadataPrefix(OAIPMHUtilities.OAIDC_PREFIX); mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); lmft.getMetadataFormat().add(mft); @@ -81,12 +98,10 @@ public class MetadataFormatListDeliverer { boolean requestCheck = true; - if (request.getFrom() != null || - request.getMetadataPrefix() != null || - request.getResumptionToken() != null) { - + if (request.getFrom() != null + || request.getMetadataPrefix() != null + || request.getResumptionToken() != null) { requestCheck = false; - } else if (request.getSet() != null || request.getUntil() != null) { requestCheck = false; 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 030e4abfb8a79dfda9910c85e4516c5d9e736ef3..a4f4c87f6f94721eaa00b8c046cb84b79ecb19f8 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -238,14 +238,21 @@ public class OAIPMHImpl implements OAIPMHProducer { GetRecordType getRecord = new GetRecordType(); String id = request.getIdentifier(); - getRecord = recDeliv.getRecordById(id); + try { + getRecord = recDeliv.getRecordById(id); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if (getRecord != null) { oaipmhRoot.setGetRecord(getRecord); } else { - ErrorHandler idError = new ErrorHandler(); - idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " - + request.getIdentifier() + " is unknown or illegal in this repository"); + ErrorHandler idError = new ErrorHandler(); + idError.setError(TGConstants.OAI_ID_DOES_NOT_EXIST, "No matching identifier "); oaipmhRoot.getError().add(idError.getError()); } } @@ -276,7 +283,7 @@ public class OAIPMHImpl implements OAIPMHProducer { // If metadataFormat IS SET, set recordListDeliverer accordingly. IdentifierListDelivererInterface idListDeliv = null; if (request.getMetadataPrefix() != null) { - if (request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { + if (request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)) { idListDeliv = this.identifierListDC; } else { idListDeliv = this.identifierListIDIOM; @@ -298,11 +305,23 @@ public class OAIPMHImpl implements OAIPMHProducer { } } - ListIdentifiersType listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(), - request.getUntil(), request.getSet(), request.getResumptionToken()); + ListIdentifiersType listIdentifiers = null; + try { + listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(), request.getUntil(), + request.getSet(), request.getResumptionToken()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if (listIdentifiers != null) { - oaipmhRoot.setListIdentifiers(listIdentifiers); + if (this.identifierListDC.getResultSize() == 0) { + requestErrors.setError("RecordMatchError", + "The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list."); + oaipmhRoot.getError().add(requestErrors.getError()); + } else { + oaipmhRoot.setListIdentifiers(listIdentifiers); + } } else { ErrorHandler idError = new ErrorHandler(); idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " @@ -404,7 +423,7 @@ public class OAIPMHImpl implements OAIPMHProducer { // If metadataFormat IS SET, set recordListDeliverer accordingly. RecordListDelivererInterface recListDeliv = null; if (request.getMetadataPrefix() != null) { - if (request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { + if (request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)) { recListDeliv = this.recordListDC; } else { recListDeliv = this.recordListIDIOM; @@ -429,7 +448,13 @@ public class OAIPMHImpl implements OAIPMHProducer { request.getSet(), request.getResumptionToken()); if (listRecords != null) { - oaipmhRoot.setListRecords(listRecords); + if (this.recordListDC.getResultSize() == 0) { + requestErrors.setError("RecordMatchError", + "The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list."); + oaipmhRoot.getError().add(requestErrors.getError()); + } else { + oaipmhRoot.setListRecords(listRecords); + } } } @@ -448,25 +473,20 @@ public class OAIPMHImpl implements OAIPMHProducer { VerbType verbParam = null; - if (verb == null) { - verb = "Identify"; - } - - if (verb != null && verb.equals("Identify")) { + if (verb!=null && verb.equals("Identify")) { verbParam = VerbType.IDENTIFY; - } else if (verb != null && verb.equals("ListMetadataFormats")) { + } else if (verb!=null && verb.equals("ListMetadataFormats")) { verbParam = VerbType.LIST_METADATA_FORMATS; - } else if (verb != null && verb.equals("ListSets")) { + } else if (verb!=null && verb.equals("ListSets")) { verbParam = VerbType.LIST_SETS; - } else if (verb != null && verb.equals("ListIdentifiers")) { + } else if (verb!=null && verb.equals("ListIdentifiers")) { verbParam = VerbType.LIST_IDENTIFIERS; - } else if (verb != null && verb.equals("ListRecords")) { + } else if (verb!=null && verb.equals("ListRecords")) { verbParam = VerbType.LIST_RECORDS; - } else if (verb != null && verb.equals("GetRecord")) { + } else if (verb!=null && verb.equals("GetRecord")) { verbParam = VerbType.GET_RECORD; - } else { - // FIXME What must be fixed here? --fu - this.error.setError("VerbError", "Illegal OAI verb"); + }else if (verb!=null && verb.length()>0){ + this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); } return verbParam; @@ -632,11 +652,16 @@ public class OAIPMHImpl implements OAIPMHProducer { } else if (verbParam.value().equals("ListRecords")) { response = listRecordsRequest(response, request); } - } else { - this.error.setError("VerbError", "Illegal OAI verb"); - response.getError().add(this.error.getError()); + } else { + if(this.error.getError().getValue()!=null && this.error.getError().getValue().equals("Illegal OAI verb")){ + this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + }else { + this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + } } - + response.setRequest(request); result = obf.createOAIPMH(response); @@ -662,7 +687,7 @@ public class OAIPMHImpl implements OAIPMHProducer { String schemaLocations = OAIPMHUtilities.OAIPMH_NAMESPACE + " " + OAIPMHUtilities.OAIPMH_SCHEMA_LOCATION; // Add OAI_DC and DC schema location if needed. - if (theVerb.equals("GetRecord") || theVerb.endsWith("ListRecords")) { + if (theVerb!=null && (theVerb.equals("GetRecord") || theVerb.endsWith("ListRecords"))) { schemaLocations += OAIPMHUtilities.OAIDC_NAMESPACE + " " + OAIPMHUtilities.OAIDC_SCHEMA_LOCATION + " " + OAIPMHUtilities.DC_NAMESPACE + " " + OAIPMHUtilities.DC_SCHEMA_LOCATION; @@ -693,4 +718,4 @@ public class OAIPMHImpl implements OAIPMHProducer { return result; } -} +} \ No newline at end of file diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java index 77d71174979a2f2d8d61427441f1336c57c09fda..38f03be698493309be1aedb729ac63b524874bd2 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHProducer.java @@ -1,5 +1,7 @@ package info.textgrid.middleware; +import java.io.IOException; + import javax.ws.rs.DefaultValue; import javax.ws.rs.FormParam; import javax.ws.rs.GET; @@ -40,6 +42,7 @@ public interface OAIPMHProducer { * @param until - End value to filter the response for a specific interval * @param resumptionToken - Indicates how many value will be send back in the response * @return OAIPMHType object containing the whole response + * @throws IOException */ @GET @Path("/") @@ -50,7 +53,7 @@ public interface OAIPMHProducer { @QueryParam("set") @DefaultValue("") String set, @QueryParam("from") @DefaultValue("") String from, @QueryParam("until") @DefaultValue("") String until, - @QueryParam("resumptionToken") @DefaultValue("") String resumptionToken); + @QueryParam("resumptionToken") @DefaultValue("") String resumptionToken) throws IOException; /** * <p> @@ -72,6 +75,7 @@ public interface OAIPMHProducer { * @param until - End value to filter the response for a specific interval * @param resumptionToken - Indicates how many value will be send back in the response * @return OAIPMHType object containing the whole response + * @throws IOException */ @POST @Path("/") @@ -82,7 +86,7 @@ public interface OAIPMHProducer { @FormParam("set") @DefaultValue("") String set, @FormParam("from") @DefaultValue("") String from, @FormParam("until") @DefaultValue("") String until, - @FormParam("resumptionToken") @DefaultValue("") String resumptionToken); + @FormParam("resumptionToken") @DefaultValue("") String resumptionToken) throws IOException; /** * @return diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java index 1457e8932cfedd5fae9c8c5a729c4c1c8c02e811..cd74b007fe493737bb0f09de5efdd24e37dcd931 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java @@ -1,19 +1,34 @@ package info.textgrid.middleware; +import java.io.IOException; +import java.io.InputStream; import java.math.BigInteger; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; +import java.util.List; import java.util.Map; import java.util.TimeZone; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.LogFactory; + +import info.textgrid.clients.AuthClient; +import info.textgrid.clients.tgauth.AuthClientException; import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; import info.textgrid.middleware.oaipmh.MetadataFormatType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; +import info.textgrid.namespaces.middleware.tgauth.ProjectInfo; /** * <p> @@ -34,6 +49,7 @@ public class OAIPMHUtilities { public static final String OAIPMH_NAMESPACE = "http://www.openarchives.org/OAI/2.0/"; public static final String OAIPMH_SCHEMA_LOCATION = "http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"; + public static final String OAIDC_PREFIX = "oai_dc"; public static final String OAIDC_NAMESPACE = "http://www.openarchives.org/OAI/2.0/oai_dc/"; public static final String OAIDC_SCHEMA_LOCATION = "http://www.openarchives.org/OAI/2.0/oai_dc.xsd"; @@ -66,6 +82,21 @@ public class OAIPMHUtilities { return tgDublinCore; } + public static List<ProjectInfo> getProjectList() throws AuthClientException { + AuthClient auth = new AuthClient(); + List<ProjectInfo> projectInfos =auth.getAllProjects(); + auth.getAllProjects(); + + return projectInfos; + } + + public static String getProjectName(String projectID) throws AuthClientException { + + AuthClient auth = new AuthClient(); + System.out.println(projectID); + return auth.getProjectInfo(projectID).getName(); + } + /** * <p> * Producing the list of all metadata formats. @@ -189,8 +220,10 @@ public class OAIPMHUtilities { cursorCollector.put(scrollID, cursor); } else { resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); - cursorCollector.put(scrollID, searchResponseSize); + cursorCollector.put(scrollID, searchResponseSize); cursor = 0; + resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + } // Set resumption token string if cursor is less then complete list size: More objects can be @@ -213,5 +246,58 @@ public class OAIPMHUtilities { return null; } + + public static boolean isThisDateValid(String dateToValidate){ + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); + + dateFormat.setLenient(false); + try { + dateFormat.parse(dateToValidate.trim()); + } catch (ParseException pe) { + return false; + } + return true; + } + + public static boolean isThisDateValidToOtherTimeStamp(String dateToValidate){ + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + + dateFormat.setLenient(false); + dateFormat.setLenient(false); + try { + dateFormat.parse(dateToValidate.trim()); + } catch (ParseException pe) { + return false; + } + return true; + } + + + private static final String[] formats = { + "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ssZ", + "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", + "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss", + "MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'", + "MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS", + "MM/dd/yyyy'T'HH:mm:ssZ", "MM/dd/yyyy'T'HH:mm:ss", + "yyyy:MM:dd HH:mm:ss", "yyyyMMdd", }; + + + public static String getFormatOfDate(String d) { + if (d != null) { + for (String parse : formats) { + SimpleDateFormat sdf = new SimpleDateFormat(parse); + try { + sdf.parse(d); + return parse; + } catch (ParseException e) { + + } + } + } + return d; + } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java index 26ee2fbb4508c5eae88ffa42cedcee20b2db4316..a22a718248a3cd866875ae8facb2c75ae8bb739c 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java @@ -1,30 +1,32 @@ package info.textgrid.middleware; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.apache.http.HttpHost; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; /** - * Establishing to connection to an ElasticSearch client + * <p> + * Establishing to connection to an ElasticSearch client. + * </p> * - * @author Maximilian Brodhun - * @version 1.0 - * @since 09.01.2014 - * + * @author Maximilian Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + * @version 2019-10-30 + * @since 2014-01-09 */ public class OAI_ESClient { private Log log = LogFactory.getLog(OAI_ESClient.class); private static String url; - private static int port; + private static int[] ports; private static String esCluster; private static String esIndex; private static String esType; - public static Client oaiESClient; + private static RestHighLevelClient esClient; /** * Constructor for the connection to an ElasticSearch index @@ -33,24 +35,32 @@ public class OAI_ESClient { * @param port for the ElasticSearch connection * @param clusterName indicating the name of the cluster where the index exists */ - @SuppressWarnings("resource") - public OAI_ESClient(String url, String thePort, String clusterName) { - int port = Integer.parseInt(thePort); + public OAI_ESClient(String url, int[] ports, int itemLimit) { - this.log.info("ElasticSearch connection settings:"); - this.log.info("url = " + url); - this.log.info("port = " + port); - this.log.info("cluster name = " + clusterName); + // int port = Integer.parseInt(thePort); + + /* + * this.log.info("ElasticSearch connection settings:"); this.log.info("url = " + url); + * this.log.info("port = " + port); this.log.info("cluster name = " + clusterName); + */ OAI_ESClient.setUrl(url); - OAI_ESClient.setPort(port); - Settings oaiESClusterSettings = - ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build(); + OAI_ESClient.setPorts(ports); + + + List<HttpHost> hosts = new ArrayList<HttpHost>(); + for (int port : ports) { + hosts.add(new HttpHost(url, port, "http")); + } - oaiESClient = new TransportClient(oaiESClusterSettings) - .addTransportAddress(new InetSocketTransportAddress(url, port)); + setEsClient(new RestHighLevelClient( + RestClient.builder( + hosts.toArray(new HttpHost[hosts.size()])))); + + this.log.info( + "ElasticSearchClient started with settings: " + url + " ," + ports.toString() + " http"); } /** @@ -85,13 +95,7 @@ public class OAI_ESClient { OAI_ESClient.esType = esType; } - /** - * - * @return oaiESClient - */ - public static Client getOaiESClient() { - return oaiESClient; - } + /** * @@ -129,24 +133,38 @@ public class OAI_ESClient { * * @return port */ - public static int getPort() { - return port; + public static int[] getPort() { + return ports; } /** * * @param port */ - public static void setPort(int port) { - OAI_ESClient.port = port; + public static void setPorts(int ports[]) { + OAI_ESClient.ports = ports; } /** * * @param oaiClient */ - public static void setOaiESClient(Client theOaiClient) { - OAI_ESClient.oaiESClient = theOaiClient; + public static void setOaiESClient(RestHighLevelClient theOaiClient) { + OAI_ESClient.esClient = theOaiClient; + } + + /** + * @return + */ + public static RestHighLevelClient getEsClient() { + return esClient; + } + + /** + * @param esClient + */ + public static void setEsClient(RestHighLevelClient esClient) { + OAI_ESClient.esClient = esClient; } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java index 299b78fb99c2eeb6909d50c44ef2d315501e9b1f..f5bcfd8a6390756d37654ffe9bd6fd73011da309 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java @@ -1,5 +1,6 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -31,8 +32,9 @@ public class OaiPmhClient { * @param verb * @return * @throws ParseException + * @throws IOException */ - public String request(String verb) throws ParseException { + public String request(String verb) throws ParseException, IOException { return this.producer.getRequest(verb, this.identifier, this.metadataPrefix, this.set, this.from, this.until, this.resumptionToken); } @@ -48,4 +50,4 @@ public class OaiPmhClient { + OaipmhServiceVersion.BUILDDATE; } -} +} \ No newline at end of file diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java index c5af207168d447627aac9536b323ab8e738838ef..59a922ccf081e1deeb46a57a7afef64cec0259b0 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java @@ -39,7 +39,7 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac // Check if metadata prefix is existing and valid. if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java index be88db7b8646cb9735e96be9703bc0d15c7fd777..a7e00f26ead6b58ce52c4e10961acf4bc649ff38 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java @@ -1,26 +1,30 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; import javax.xml.datatype.DatatypeConfigurationException; -import org.elasticsearch.action.get.GetRequestBuilder; +import org.apache.commons.logging.LogFactory; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.common.Strings; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import info.textgrid.middleware.oaipmh.GetRecordType; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.RecordType; /** - * FIXME + * FIXME Was magst Du denn hier fixen, Herr Max? * - * @author Maximilian Brodhun SUB - * @version 1.1 - * @since 17.02.2014 + * @author Maximilian Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + * @version 2019-10-30 + * @since 2014-02-17 */ - public class RecordDelivererDC extends RecordDelivererAbstract { private String[] fields; private String[] workFields; - private String formatField; private String formatToFilter; private String dateOfObjectCreation; @@ -43,13 +47,16 @@ public class RecordDelivererDC extends RecordDelivererAbstract { private String[] languageList; private String[] publisherList; private String[] relationList; - private String[] relationForWorkList; + // FIXME Why is this commented out? I just adapted beans.xml file. + // private String[] relationsForWorkList; private String[] rightList; private String[] sourceList; private String[] subjectList; private String[] titleList; private String[] typeList; + + private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDelivererDC.class); private OAI_ESClient oaiEsClient; /** @@ -65,7 +72,11 @@ public class RecordDelivererDC extends RecordDelivererAbstract { * * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) */ - public GetRecordType getRecordById(String id) { + public GetRecordType getRecordById(String id) throws ParseException, DatatypeConfigurationException { + + String[] includes = this.fields; + String[] excludes = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); GetRecordType getRecordType = new GetRecordType(); RecordType record = new RecordType(); @@ -76,17 +87,20 @@ public class RecordDelivererDC extends RecordDelivererAbstract { changedId = changedId.replace(this.repositoryObjectURIPrefix, ""); } - // TODO Must Index and Type be set here? Isn't it already set in beans.xml? - GetRequestBuilder recordById = - OAI_ESClient - .getOaiESClient() - .prepareGet() - .setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()) - .setFields(this.fields) - .setId(changedId); + GetRequest getRequest = + new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), changedId) + .fetchSourceContext(fetchSourceContext); + GetResponse esResultObject = null; + + try { + esResultObject = + OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); - GetResponse esResultObject = recordById.execute().actionGet(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + log.error("Could not fetch the result of ElasticSearch"); + } if (esResultObject.isExists()) { @@ -94,14 +108,14 @@ public class RecordDelivererDC extends RecordDelivererAbstract { if (this.dariah == true) { dublinCoreBuilder = putContentIntoDCFieldLists(esResultObject); - identifier = esResultObject.getField(this.identifierField).getValue().toString(); + identifier = esResultObject.getSourceAsMap().get(this.identifierField).toString(); String dateOfCreation = "NO_DATE_SET!"; if (esResultObject.getField(this.dateOfObjectCreation) != null) { try { dateOfCreation = OAIPMHUtilities .convertDateFormat( - esResultObject.getField(this.dateOfObjectCreation).getValue().toString()) + esResultObject.getSourceAsMap().get(this.dateOfObjectCreation).toString()) .toXMLFormat(); } catch (ParseException e) { // TODO Auto-generated catch block @@ -112,28 +126,34 @@ public class RecordDelivererDC extends RecordDelivererAbstract { } record.setMetadata(dublinCoreBuilder.getDC()); } - - setRecordHeader(dateOfCreation, identifier, record, dublinCoreBuilder); + String setSpec = DublinCoreFieldLoader.fillList(esResultObject, DARIAHConstants.IDENTIFIER_LIST).get(0); + setRecordHeader(OAIPMHUtilities + .convertDateFormat(dateOfCreation).toString(), identifier, record, dublinCoreBuilder, setSpec); } - if (this.textgrid == true && esResultObject.getField(this.formatField).getValue().toString() - .equals(this.formatToFilter)) { + if (this.textgrid == true + && esResultObject.getSourceAsMap().get(this.formatField).equals(this.formatToFilter)) { - String workUri = - esResultObject.getField(this.relationToFurtherMetadataObject).getValue().toString(); + + String workUri = DublinCoreFieldLoader + .fillList(esResultObject, new String[] {this.relationToFurtherMetadataObject}).get(0); workUri = workUri.substring(this.repositoryObjectURIPrefix.length()); dublinCoreBuilder = putContentIntoDCFieldLists(esResultObject, furtherDCElements(workUri)); - identifier = esResultObject.getField(this.identifierField).getValue().toString(); + identifier = esResultObject.getSourceAsMap().get(this.identifierField).toString(); String dateOfCreation = - esResultObject.getField(this.dateOfObjectCreation).getValue().toString(); - setRecordHeader(dateOfCreation, identifier, record, dublinCoreBuilder); + esResultObject.getSourceAsMap().get(this.dateOfObjectCreation).toString(); + + String setSpec = "project:" + DublinCoreFieldLoader.fillList(esResultObject, TGConstants.RELATIONS_LIST).get(0); + + setRecordHeader(OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, record, dublinCoreBuilder, setSpec); + record.setMetadata(dublinCoreBuilder.getDC()); } getRecordType.setRecord(record); } else { - getRecordType = null; + return null; } return getRecordType; @@ -144,19 +164,22 @@ public class RecordDelivererDC extends RecordDelivererAbstract { // ** /** + * This function builds the header element in the XML file for the OAI-PMH response + * * @param dateOfCreation * @param identifier - * @param record - * @param dbc + * @param record object containing all elements for the record in the OAI-PMH response + * @param dbc object containing the dublin core elements for the XML file * @return */ private static RecordType setRecordHeader(String dateOfCreation, String identifier, - RecordType record, DublinCoreBuilder dbc) { + RecordType record, DublinCoreBuilder dbc, String setSpec) { HeaderType recordHeader = new HeaderType(); - + recordHeader.setIdentifier(identifier); recordHeader.setDatestamp(dateOfCreation); + recordHeader.getSetSpec().add(setSpec); // FIXME Do add set spec here! // if (set != null) { @@ -175,99 +198,98 @@ public class RecordDelivererDC extends RecordDelivererAbstract { */ private GetResponse furtherDCElements(String id) { + String[] includes = this.workFields; + String[] excludes = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext = + new FetchSourceContext(true, includes, excludes); + if (!id.endsWith(".0")) { id = id.concat(".0"); } - GetRequestBuilder getWorkValues = - OAI_ESClient.getOaiESClient() - .prepareGet() - .setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()) - .setId(id) - .setFields(this.workFields); - - GetResponse responseWorkValues = getWorkValues.execute().actionGet(); - - // FIXME MAX!!! DO WE NEED THST DATE??? - // FIXME MAX!!! DO WE NEED THST DATE??? - // FIXME MAX!!! DO WE NEED THST DATE??? - - // try { - // if (responseWorkValues.getField(this.dateOfObjectCreation) != null) { - // this.dates.add(OAIPMHUtillities.convertDateFormat( - // responseWorkValues.getField(this.dateOfObjectCreation).getValue().toString()) - // .toXMLFormat()); - // } - // } catch (ParseException e) { - // log.debug(e); - // } catch (DatatypeConfigurationException e) { - // log.debug(e); - // } + GetRequest getRequest = new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id) + .fetchSourceContext(fetchSourceContext); + GetResponse responseWorkValues = null; + + try { + responseWorkValues = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return responseWorkValues; } /** - * @param responseWorkValues - * @param relatedWorkObject + * In case of TextGrid data from two objects are necessary. The edition object and the linked work + * object. In result for building the DC-Object both objects from the ES-Index are needed + * + * @param responseWorkValues contains the edition object + * @param relatedWorkObject contains the work object related to edition object + * @throws DatatypeConfigurationException + * @throws ParseException */ private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues, - GetResponse relatedWorkObject) { + GetResponse relatedWorkObject) throws ParseException, DatatypeConfigurationException { DublinCoreBuilder result = new DublinCoreBuilder(); // Set DublinCore lists with content from elastic search results due to configuration. result.setContributor( - DublinCoreFieldLoader.setContributor(responseWorkValues, this.contributorList)); - result.setCoverage(DublinCoreFieldLoader.setCoverage(responseWorkValues, this.coverageList)); - result.setCreator(DublinCoreFieldLoader.setCreator(relatedWorkObject, this.creatorList)); - result.setDate(DublinCoreFieldLoader.setDate(relatedWorkObject, this.dateList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.contributorList)); + result.setCoverage(DublinCoreFieldLoader.fillList(responseWorkValues, this.coverageList)); + result.setCreator(DublinCoreFieldLoader.fillList(relatedWorkObject, this.creatorList)); + result.setDate(DublinCoreFieldLoader.fillList(relatedWorkObject, this.dateList)); result.setDescription( - DublinCoreFieldLoader.setDescription(relatedWorkObject, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(responseWorkValues, this.formatList)); + DublinCoreFieldLoader.fillList(relatedWorkObject, this.descriptionList)); + result.setFormat(DublinCoreFieldLoader.fillList(responseWorkValues, this.formatList)); result.setIdentifier( - DublinCoreFieldLoader.setIdentifier(responseWorkValues, this.identifierList)); - result.setLanguage(DublinCoreFieldLoader.setLanguage(responseWorkValues, this.languageList)); - result.setPublisher(DublinCoreFieldLoader.setPublisher(responseWorkValues, this.publisherList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.identifierList)); + result.setLanguage(DublinCoreFieldLoader.fillList(responseWorkValues, this.languageList)); + result.setPublisher(DublinCoreFieldLoader.fillList(responseWorkValues, this.publisherList)); result.setRelation( - DublinCoreFieldLoader.setRelationForWork(responseWorkValues, this.relationList)); - result.setRights(DublinCoreFieldLoader.setRights(responseWorkValues, this.rightList)); - result.setSource(DublinCoreFieldLoader.setSources(responseWorkValues, this.sourceList)); - result.setSubject(DublinCoreFieldLoader.setSubject(relatedWorkObject, this.subjectList)); - result.setTitle(DublinCoreFieldLoader.setTitle(responseWorkValues, this.titleList)); - result.setType(DublinCoreFieldLoader.setType(relatedWorkObject, this.typeList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.relationList)); + result.setRights(DublinCoreFieldLoader.fillList(responseWorkValues, this.rightList)); + result.setSource(DublinCoreFieldLoader.fillList(responseWorkValues, this.sourceList)); + result.setSubject(DublinCoreFieldLoader.fillList(relatedWorkObject, this.subjectList)); + result.setTitle(DublinCoreFieldLoader.fillList(responseWorkValues, this.titleList)); + result.setType(DublinCoreFieldLoader.fillList(relatedWorkObject, this.typeList)); return result; } /** + * This function with just one object as parameter is for DARIAH + * * @param responseWorkValues + * @throws DatatypeConfigurationException + * @throws ParseException */ - private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues) { + private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues) throws ParseException, DatatypeConfigurationException { DublinCoreBuilder result = new DublinCoreBuilder(); // Set DublinCore lists with content from elastic search results due to configuration. result.setContributor( - DublinCoreFieldLoader.setContributor(responseWorkValues, this.contributorList)); - result.setCoverage(DublinCoreFieldLoader.setCoverage(responseWorkValues, this.coverageList)); - result.setCreator(DublinCoreFieldLoader.setCreator(responseWorkValues, this.creatorList)); - result.setDate(DublinCoreFieldLoader.setDate(responseWorkValues, this.dateList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.contributorList)); + result.setCoverage(DublinCoreFieldLoader.fillList(responseWorkValues, this.coverageList)); + result.setCreator(DublinCoreFieldLoader.fillList(responseWorkValues, this.creatorList)); + result.setDate(DublinCoreFieldLoader.fillList(responseWorkValues, this.dateList)); result.setDescription( - DublinCoreFieldLoader.setDescription(responseWorkValues, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(responseWorkValues, this.formatList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.descriptionList)); + result.setFormat(DublinCoreFieldLoader.fillList(responseWorkValues, this.formatList)); result.setIdentifier( - DublinCoreFieldLoader.setIdentifier(responseWorkValues, this.identifierList)); - result.setLanguage(DublinCoreFieldLoader.setLanguage(responseWorkValues, this.languageList)); - result.setPublisher(DublinCoreFieldLoader.setPublisher(responseWorkValues, this.publisherList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.identifierList)); + result.setLanguage(DublinCoreFieldLoader.fillList(responseWorkValues, this.languageList)); + result.setPublisher(DublinCoreFieldLoader.fillList(responseWorkValues, this.publisherList)); result.setRelation( - DublinCoreFieldLoader.setRelation(responseWorkValues, this.relationList)); - result.setRights(DublinCoreFieldLoader.setRights(responseWorkValues, this.rightList)); - result.setSource(DublinCoreFieldLoader.setSources(responseWorkValues, this.sourceList)); - result.setSubject(DublinCoreFieldLoader.setSubject(responseWorkValues, this.subjectList)); - result.setTitle(DublinCoreFieldLoader.setTitle(responseWorkValues, this.titleList)); - result.setType(DublinCoreFieldLoader.setType(responseWorkValues, this.typeList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.relationList)); + result.setRights(DublinCoreFieldLoader.fillList(responseWorkValues, this.rightList)); + result.setSource(DublinCoreFieldLoader.fillList(responseWorkValues, this.sourceList)); + result.setSubject(DublinCoreFieldLoader.fillList(responseWorkValues, this.subjectList)); + result.setTitle(DublinCoreFieldLoader.fillList(responseWorkValues, this.titleList)); + result.setType(DublinCoreFieldLoader.fillList(responseWorkValues, this.typeList)); return result; } @@ -423,12 +445,12 @@ public class RecordDelivererDC extends RecordDelivererAbstract { this.relationList = relationsList; } - /** - * @param relationsList - */ - public void setRelationsForWork(String[] relationsList) { - this.relationForWorkList = relationsList; - } + // /** + // * @param relationsForWorkList + // */ + // public void setRelationsForWork(String[] relationsForWorkList) { + // this.relationsForWorkList = relationsForWorkList; + // } /** * @param rightsList diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java index e0bc710c7abef9029e265dbfbef6931dec58e31d..29d245d8042c04f3bff26ef36eba385d622718b9 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java @@ -1,26 +1,29 @@ package info.textgrid.middleware; +import java.io.IOException; import java.io.StringReader; import java.text.ParseException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; import org.apache.commons.logging.LogFactory; import org.classicmayan.tools.ClassicMayanMetsMods; -import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.common.Strings; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; import info.textgrid.middleware.oaipmh.GetRecordType; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.RecordType; /** - * * @author Maximilian Brodhun, SUB Göttingen - * @since 2019-03-08 + * @author Stefan E. Funk, SUB Göttingen + * @since 2019-10-28 * @version 2019-03-12 - * */ public class RecordDelivererIDIOM extends RecordDelivererAbstract { @@ -50,15 +53,21 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { */ /** + * <p> * ElasticSearch request in non-public index to get the datestamps for the object creation and - * last modification date in TextGrid-Repo + * last modification date in TextGrid-Repo. + * </p> * * @param idInDatabase */ - public void setDatestamps(String idInDatabase) { + String changedId = idInDatabase; + String[] includes = new String[] {TGConstants.CREATED, TGConstants.MODIFIED_FIELD}; + String[] excludes = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + if (idInDatabase.startsWith("textgrid:")) { changedId = idInDatabase.substring("textgrid:".length()); } @@ -66,15 +75,18 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { if (!idInDatabase.contains(".0")) { changedId = changedId + ".0"; } - // sSystem.out.println(changedId); - GetRequestBuilder recordById = OAI_ESClient.getOaiESClient() - .prepareGet() - .setIndex("textgrid-nonpublic") - .setType(OAI_ESClient.getEsType()) - .setFields(TGConstants.CREATED, TGConstants.MODIFIED_FIELD) - .setId(changedId); - GetResponse objectInDatabase = recordById.execute().actionGet(); + GetRequest getRequest = + new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), changedId) + .fetchSourceContext(fetchSourceContext); + GetResponse objectInDatabase = null; + + try { + objectInDatabase = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } System.out.println("id in elasticsearch is: " + changedId); this.dateOfObjectCreation = @@ -87,7 +99,6 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { /** * building the record XML object for the OAI-PMH response */ - public GetRecordType getRecordById(String id) { GetRecordType grt = new GetRecordType(); @@ -126,12 +137,13 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { // ** /** - * Getting the Mets/Mods object for the ClassicMayan artefact and put them into metadata element - * of the OAI-PMH response + * <p> + * Getting the Mets/Mods object for the ClassicMayan artifact and put them into metadata element + * of the OAI-PMH response. + * </p> * - * @return metadata XML-Elment + * @return */ - private MetadataType idiomMets() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -148,12 +160,9 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { return metadataMets; } - - /** * @param dateOfCreation * @param identifier - * @return * @throws ParseException */ private void setRecordHeader(String dateOfCreation, String identifier) throws ParseException { @@ -165,10 +174,16 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { // return recordHeader; } + /** + * @return + */ public OAI_ESClient getOaiEsClient() { return this.oaiEsClient; } + /** + * @param oaiEsClient + */ public void setOaiEsClient(OAI_ESClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java index 133a902258065444fc5e24e4a3915ccade5026ea..c4b353b0a34e26d235d8630f3183247c14924cc2 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java @@ -1,5 +1,9 @@ package info.textgrid.middleware; +import java.text.ParseException; + +import javax.xml.datatype.DatatypeConfigurationException; + import info.textgrid.middleware.oaipmh.GetRecordType; /** @@ -18,7 +22,9 @@ public interface RecordDelivererInterface { * * @param id identifier within database * @return Get the GetRecord response for the request + * @throws DatatypeConfigurationException + * @throws ParseException */ - GetRecordType getRecordById(String id); + GetRecordType getRecordById(String id) throws ParseException, DatatypeConfigurationException; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java index a62afe19609d2a17f75bac188d051f98d7913555..7b0fab41cc31ec6c4baf79e83d96964447c99019 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java @@ -29,9 +29,10 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer ErrorHandler result = new ErrorHandler(); + // Check if metadata prefix is existing and valid. if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() @@ -41,28 +42,43 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer // Check if resumptionToken is invalid or existing. if (request.getResumptionToken() != null) { - boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null - && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); - boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null - && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); - if (restokDCExisting || restokIDIOMExisting) { - result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " - + request.getResumptionToken() + " argument is invalid or expired."); + boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null + && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); + + boolean restokDCExisting = RecordListDelivererDC.cursorCollector != null + && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); + + if (!restokDCExisting && !restokIDIOMExisting) { + result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " + + request.getResumptionToken() + " argument is invalid or expired."); + } } + + + // Check if query to ElastisSearch responses with more then zero results + // FIXME what the heck? + if (true) { + } // Check params in general. List<String> errorValues = new ArrayList<String>(); - if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) { - errorValues.add("metadataPrefix"); - } if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { errorValues.add("metadataPrefix"); } if (request.getIdentifier() != null) { errorValues.add("identifier"); } + if(request.getFrom()!= null && (!OAIPMHUtilities.isThisDateValid(request.getFrom()) && !OAIPMHUtilities.isThisDateValidToOtherTimeStamp(request.getFrom()))) { + errorValues.add("from"); + } + if(request.getUntil() != null && (!OAIPMHUtilities.isThisDateValid(request.getUntil()) && !OAIPMHUtilities.isThisDateValidToOtherTimeStamp(request.getUntil()))) { + errorValues.add("until"); + } + if(request.getFrom()!= null && request.getUntil()!=null && !OAIPMHUtilities.getFormatOfDate(request.getFrom()).equals(OAIPMHUtilities.getFormatOfDate(request.getFrom()))) { + errorValues.add("until, from"); + } if (errorValues.size() > 0) { result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + "or is missing required arguments: " + errorValues); @@ -70,5 +86,6 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer return result; } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java index 621f45e1c84bff637d80cc36963de3a1e8119e00..defe0a3b98cd8fb851f253495f457e285570fea1 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java @@ -1,5 +1,6 @@ package info.textgrid.middleware; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.text.ParseException; @@ -7,14 +8,20 @@ import java.util.Hashtable; import java.util.Map; import javax.xml.datatype.DatatypeConfigurationException; import org.apache.commons.logging.LogFactory; -import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.search.SearchScrollRequest; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListRecordsType; import info.textgrid.middleware.oaipmh.MetadataType; @@ -26,17 +33,28 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; */ public class RecordListDelivererDC extends RecordListDelivererAbstract { + // ** + // FINALS + // ** + + private static final int LIFETIME_RES_TOKEN = 600; + // ** // STATICS // ** private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); // ** // CLASS VARIABLES // ** private OAI_ESClient oaiEsClient; + + private boolean foundItems; + private int searchResponseSize; + private long resultSize; private String[] fields; private String[] workFields; private String formatField; @@ -47,7 +65,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { private String rangeField; private String modifiedField; private String identifierField; - private boolean foundItems; + private String modifiedValue; // ** // DC-Field Lists @@ -63,18 +81,12 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { private String[] languageList; private String[] publisherList; private String[] relationList; - private String[] relationForWorkList; + private String[] relationsForWorkList; private String[] rightList; private String[] sourceList; private String[] subjectList; private String[] titleList; private String[] typeList; - private String modifiedValue; - private static final int lifeTimeResToken = 60000; - - static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - - private int searchResponseSize; /** * @param textgrid @@ -94,7 +106,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @param client * @return */ - public GetResponse furtherDCElements(String id, Client client) { + public GetResponse furtherDCElements(String id, RestHighLevelClient client) { if (id != null) { try { @@ -102,16 +114,20 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { } catch (UnsupportedEncodingException e) { e.printStackTrace(); } - - GetRequestBuilder getWorkValues = - OAI_ESClient.getOaiESClient() - .prepareGet() - .setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()) - .setId(id) - .setFields(this.workFields); - - GetResponse responseWorkValues = getWorkValues.execute().actionGet(); + String[] includes = this.workFields; + String[] excludes = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + GetRequest getRequest = + new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id) + .fetchSourceContext(fetchSourceContext); + + GetResponse responseWorkValues = null; + try { + responseWorkValues = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return responseWorkValues; } @@ -137,6 +153,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { SearchResponse scrollResp; QueryBuilder recordFilter; DublinCoreBuilder dublinCoreBuilder = new DublinCoreBuilder(); + if (this.dariah == true) { recordFilter = query; } else { @@ -144,27 +161,44 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { .must(QueryBuilders.matchPhraseQuery(this.formatField, this.formatToFilter)); } - if (resumptionToken == null) { - scrollResp = OAI_ESClient.getOaiESClient() - .prepareSearch(OAI_ESClient.getEsIndex()) - .setScroll(new TimeValue(lifeTimeResToken)) - .setTypes(OAI_ESClient.getEsType()) - .addFields(this.fields) - .setQuery(recordFilter) - .setSize(this.searchResponseSize) - .execute() - .actionGet(); + SearchRequest searchRequest = new SearchRequest(OAI_ESClient.getEsIndex()); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + + scrollResp = null; + + searchSourceBuilder.query(recordFilter); + searchSourceBuilder.size(this.searchResponseSize); + searchRequest.source(searchSourceBuilder); + + if (resumptionToken != null) { + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueSeconds(LIFETIME_RES_TOKEN)); + + try { + scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } else { - scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(new TimeValue(lifeTimeResToken)).execute().actionGet(); + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueMinutes(LIFETIME_RES_TOKEN)); + try { + scrollResp = OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } log.info("Queried fields: " + this.fields.toString()); - log.info("Lifetime for resumption token is set to: " + lifeTimeResToken); + log.info("Lifetime for resumption token is set to: " + LIFETIME_RES_TOKEN); scrollID = scrollResp.getScrollId(); - long completeListSize = scrollResp.getHits().totalHits(); + long completeListSize = scrollResp.getHits().totalHits; + setResultSize(completeListSize); + if (completeListSize > 0) { setFoundItems(true); @@ -175,45 +209,62 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { if (hit != null && hit.getFields() != null) { try { - if (hit.getFields().get(this.dateOfObjectCreation) != null) { - String datestamp = - hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); + if (hit.getSourceAsMap().get(this.dateOfObjectCreation) != null) { + String datestamp = hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat(); } - } catch (ParseException e1) { - log.debug(e1); - } catch (DatatypeConfigurationException e1) { - log.debug(e1); + } catch (ParseException ee) { + log.debug(ee); + } catch (DatatypeConfigurationException e) { + log.debug(e); } - - this.modifiedValue = hit.getFields().get(this.modifiedField).getValue().toString(); + + this.modifiedValue = hit.getSourceAsMap().get(this.modifiedField).toString(); // TextGrid search! String workUri = ""; - - if (this.textgrid == true && hit.getFields().get(this.formatField).values().get(0) + String[] blaFields = new String[] {this.relationToFurtherMetadataObject}; + if (this.textgrid == true && hit.getSourceAsMap().get(this.formatField) .toString().equals(this.formatToFilter)) { - if (hit.getFields().get(this.relationToFurtherMetadataObject) != null) { - workUri = hit.getFields().get(this.relationToFurtherMetadataObject).values().get(0) - .toString().substring(this.repositoryObjectURIPrefix.length()); + + String setSpec = "project:" + DublinCoreFieldLoader.fillList(hit, TGConstants.RELATIONS_LIST).get(0); + if (DublinCoreFieldLoader.fillList(hit, blaFields).get(0) != null) { + workUri = DublinCoreFieldLoader.fillList(hit, blaFields).get(0) + .substring(this.repositoryObjectURIPrefix.length()); if (!workUri.endsWith(".0")) { workUri = workUri.concat(".0"); } } - - dublinCoreBuilder = putContentIntoDCFieldLists(hit, - furtherDCElements(workUri, OAI_ESClient.getOaiESClient())); - - buildRecord(recordList, set, - hit.getFields().get(this.identifierField).getValue().toString(), dublinCoreBuilder); + try { + dublinCoreBuilder = putContentIntoDCFieldLists(hit, + furtherDCElements(workUri, OAI_ESClient.getEsClient())); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + buildRecord(recordList, set, hit.getSourceAsMap().get(this.identifierField).toString(), + dublinCoreBuilder, setSpec); } if (this.dariah == true) { - dublinCoreBuilder = putContentIntoDCFieldLists2(hit, - furtherDCElements(hit.getId(), OAI_ESClient.getOaiESClient())); + String setSpec = "hdl:" + DublinCoreFieldLoader.fillList(hit, DARIAHConstants.IDENTIFIER_LIST).get(0); + try { + dublinCoreBuilder = putContentIntoDCFieldLists2(hit, + furtherDCElements(hit.getId(), OAI_ESClient.getEsClient())); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } buildRecord(recordList, set, - hit.getFields().get(this.identifierField).getValue().toString(), dublinCoreBuilder); + hit.getSourceAsMap().get(this.identifierField).toString(), dublinCoreBuilder, setSpec); } } } @@ -221,6 +272,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { // Check the need for a resumption token! ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( completeListSize, resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i); + if (resTokenForResponse != null) { recordList.setResumptionToken(resTokenForResponse); } @@ -234,31 +286,33 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @param hit * @param responseWorkValues * @return + * @throws DatatypeConfigurationException + * @throws ParseException */ public DublinCoreBuilder putContentIntoDCFieldLists(SearchHit hit, - GetResponse responseWorkValues) { + GetResponse responseWorkValues) throws ParseException, DatatypeConfigurationException { DublinCoreBuilder result = new DublinCoreBuilder(); - result.setContributor( - DublinCoreFieldLoader.setContributor(responseWorkValues, this.contributorList)); - result.setCoverage(DublinCoreFieldLoader.setCoverage(responseWorkValues, this.coverageList)); - result.setCreator(DublinCoreFieldLoader.setCreator(responseWorkValues, this.creatorList)); - result.setDate(DublinCoreFieldLoader.setDate(responseWorkValues, this.dateList)); + result.setContributor(DublinCoreFieldLoader.fillList(responseWorkValues, this.contributorList)); + result.setCoverage(DublinCoreFieldLoader.fillList(responseWorkValues, this.coverageList)); + result.setCreator(DublinCoreFieldLoader.fillList(responseWorkValues, this.creatorList)); + result.setDate(DublinCoreFieldLoader.fillList(responseWorkValues, this.dateList)); + result.setDescription( - DublinCoreFieldLoader.setDescription(responseWorkValues, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(hit, this.formatList)); - result.setIdentifier(DublinCoreFieldLoader.setIdentifier(hit, this.identifierList)); - result.setLanguage(DublinCoreFieldLoader.setLanguage(hit, this.languageList)); - result.setPublisher(DublinCoreFieldLoader.setPublisher(hit, this.publisherList)); - result.setRelation(DublinCoreFieldLoader.setRelation(hit, this.relationList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.descriptionList)); + result.setFormat(DublinCoreFieldLoader.fillList(hit, this.formatList)); + result.setIdentifier(DublinCoreFieldLoader.fillList(hit, this.identifierList)); + result.setLanguage(DublinCoreFieldLoader.fillList(hit, this.languageList)); + result.setPublisher(DublinCoreFieldLoader.fillList(hit, this.publisherList)); + result.setRelation(DublinCoreFieldLoader.fillList(hit, this.relationList)); result.setRelation( - DublinCoreFieldLoader.setRelationForWork(responseWorkValues, this.relationForWorkList)); - result.setRights(DublinCoreFieldLoader.setRights(hit, this.rightList)); - result.setSource(DublinCoreFieldLoader.setSources(hit, this.sourceList)); - result.setSubject(DublinCoreFieldLoader.setSubject(hit, this.subjectList)); - result.setTitle(DublinCoreFieldLoader.setTitle(hit, this.titleList)); - result.setType(DublinCoreFieldLoader.setType(responseWorkValues, this.typeList)); + DublinCoreFieldLoader.fillList(responseWorkValues, this.relationsForWorkList)); + result.setRights(DublinCoreFieldLoader.fillList(hit, this.rightList)); + result.setSource(DublinCoreFieldLoader.fillList(hit, this.sourceList)); + result.setSubject(DublinCoreFieldLoader.fillList(hit, this.subjectList)); + result.setTitle(DublinCoreFieldLoader.fillList(hit, this.titleList)); + result.setType(DublinCoreFieldLoader.fillList(responseWorkValues, this.typeList)); return result; } @@ -267,27 +321,29 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @param hit * @param responseWorkValues * @return + * @throws DatatypeConfigurationException + * @throws ParseException */ public DublinCoreBuilder putContentIntoDCFieldLists2(SearchHit hit, - GetResponse responseWorkValues) { + GetResponse responseWorkValues) throws ParseException, DatatypeConfigurationException { DublinCoreBuilder result = new DublinCoreBuilder(); - result.setContributor(DublinCoreFieldLoader.setContributor(hit, this.contributorList)); - result.setCoverage(DublinCoreFieldLoader.setCoverage(hit, this.coverageList)); - result.setCreator(DublinCoreFieldLoader.setCreator(hit, this.creatorList)); - result.setDate(DublinCoreFieldLoader.setDate(hit, this.dateList)); - result.setDescription(DublinCoreFieldLoader.setDescription(hit, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(hit, this.formatList)); - result.setIdentifier(DublinCoreFieldLoader.setIdentifier(hit, this.identifierList)); - result.setLanguage(DublinCoreFieldLoader.setLanguage(hit, this.languageList)); - result.setPublisher(DublinCoreFieldLoader.setPublisher(hit, this.publisherList)); - result.setRelation(DublinCoreFieldLoader.setRelation(hit, this.relationList)); - result.setRights(DublinCoreFieldLoader.setRights(hit, this.rightList)); - result.setSource(DublinCoreFieldLoader.setSources(hit, this.sourceList)); - result.setSubject(DublinCoreFieldLoader.setSources(hit, this.subjectList)); - result.setTitle(DublinCoreFieldLoader.setTitle(hit, this.titleList)); - result.setType(DublinCoreFieldLoader.setType(hit, this.typeList)); + result.setContributor(DublinCoreFieldLoader.fillList(hit, this.contributorList)); + result.setCoverage(DublinCoreFieldLoader.fillList(hit, this.coverageList)); + result.setCreator(DublinCoreFieldLoader.fillList(hit, this.creatorList)); + result.setDate(DublinCoreFieldLoader.fillList(hit, this.dateList)); + result.setDescription(DublinCoreFieldLoader.fillList(hit, this.descriptionList)); + result.setFormat(DublinCoreFieldLoader.fillList(hit, this.formatList)); + result.setIdentifier(DublinCoreFieldLoader.fillList(hit, this.identifierList)); + result.setLanguage(DublinCoreFieldLoader.fillList(hit, this.languageList)); + result.setPublisher(DublinCoreFieldLoader.fillList(hit, this.publisherList)); + result.setRelation(DublinCoreFieldLoader.fillList(hit, this.relationList)); + result.setRights(DublinCoreFieldLoader.fillList(hit, this.rightList)); + result.setSource(DublinCoreFieldLoader.fillList(hit, this.sourceList)); + result.setSubject(DublinCoreFieldLoader.fillList(hit, this.subjectList)); + result.setTitle(DublinCoreFieldLoader.fillList(hit, this.titleList)); + result.setType(DublinCoreFieldLoader.fillList(hit, this.typeList)); return result; } @@ -300,14 +356,14 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @return */ public RecordType buildRecord(ListRecordsType recordList, String set, String headerIdentifier, - DublinCoreBuilder dublinCoreBuilder) { + DublinCoreBuilder dublinCoreBuilder, String setSpec) { MetadataType metadata = new MetadataType(); RecordType record = new RecordType(); metadata = dublinCoreBuilder.getDC(); record.setMetadata(metadata); - record.setHeader(setHeader(set, headerIdentifier)); + record.setHeader(setHeader(set, headerIdentifier, setSpec)); recordList.getRecord().add(record); return record; @@ -341,7 +397,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { if (this.textgrid == true) { String[] setParts = set.split(":"); if (setParts[0].equals("project")) { - queryField = "project.id"; + queryField = "project.id"; valueField = setParts[1]; } } @@ -349,6 +405,8 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); QueryBuilder boolQuery = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); + System.out.println(boolQuery); + query = boolQuery; } else { query = rangeQuery; @@ -367,7 +425,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @param headerIdentifier * @return */ - public HeaderType setHeader(final String set, final String headerIdentifier) { + public HeaderType setHeader(final String set, final String headerIdentifier, String setSpec) { HeaderType header = new HeaderType(); String identifierForHeader = headerIdentifier; @@ -389,11 +447,11 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { } header.setIdentifier(identifierForHeader); - + // Set set :-) - if (set != null) { - header.getSetSpec().add(set); - } + //if (set != null) { + header.getSetSpec().add(setSpec); + //} return header; } @@ -543,10 +601,10 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { } /** - * @param relationsList + * @param relationsForWorkList */ - public void setRelationsForWork(String[] relationsList) { - this.relationForWorkList = relationsList; + public void setRelationsForWork(String[] relationsForWorkList) { + this.relationsForWorkList = relationsForWorkList; } /** @@ -689,4 +747,18 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { this.oaiEsClient = oaiEsClient; } + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java index 3f9453d92d9ee281432fe4e5de0ba99e6a7e90aa..7bb92b693ed3f4d5da0f7f68b405912f5e558f11 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -102,7 +102,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { * java.lang.String) */ @Override - public HeaderType setHeader(String set, String headerIdentifier) { + public HeaderType setHeader(String set, String headerIdentifier, String setSpec) { return null; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java index 1dd1f5832b436c2cbb48e67d84ade5af662ca634..93bd63324e27af0c2ba4566aa22b131f91ce3ecd 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java @@ -22,6 +22,6 @@ public interface RecordListDelivererInterface { * @param headerIdentifier * @return */ - public HeaderType setHeader(String set, String headerIdentifier); + public HeaderType setHeader(String set, String headerIdentifier, String setSpec); } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/Rest.java b/oaipmh-core/src/main/java/info/textgrid/middleware/Rest.java index 84c2adfa500a76199a33ed18c6238ac9baacd51c..f0d3a4069db63472c0137f1b004ca64ef19c5e14 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/Rest.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/Rest.java @@ -4,17 +4,14 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import info.textgrid.utils.httpclient.TGHttpConnection; /** * */ +@SuppressWarnings("deprecation") public class Rest { - private Log log = LogFactory.getLog(Rest.class); - /** * @return */ 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 2e81caf1b3dcadc435a5c8ea20ada593351a4d54..1d82d6bd4d5e9293213b3d1f06e40960c458af51 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java @@ -1,29 +1,50 @@ package info.textgrid.middleware; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.Hashtable; -import java.util.Iterator; +import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.Map; +import java.util.List; +import java.util.Map.Entry; import java.util.Set; -import org.elasticsearch.action.get.GetRequestBuilder; + +import org.elasticsearch.search.aggregations.bucket.filter.Filter; +import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; + import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.Script; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.aggregations.Aggregation; +import org.elasticsearch.search.aggregations.AggregationBuilder; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.Aggregations; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; +import org.json.JSONObject; + +import info.textgrid.clients.tgauth.AuthClientException; import info.textgrid.middleware.oaipmh.ListSetsType; import info.textgrid.middleware.oaipmh.SetType; import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; + /** * */ public class SetDeliverer { - private static Map<String, String> setSet = new Hashtable<String, String>(); + //private static Map<String, String> setSet = new Hashtable<String, String>(); private Set<String> identifier = new LinkedHashSet<String>(); private String formatField; @@ -47,52 +68,100 @@ public class SetDeliverer { /** * @return + * @throws AuthClientException + * @throws IOException */ public ListSetsType setListBuilder() { ListSetsType setList = new ListSetsType(); - QueryBuilder aggQuery; - if (this.textgrid) { - aggQuery = QueryBuilders.matchPhraseQuery("format", TextGridMimetypes.EDITION); - } else { - aggQuery = QueryBuilders.matchPhraseQuery("descriptiveMetadata.dc:format", - TextGridMimetypes.DARIAH_COLLECTION); - } - - SearchRequestBuilder request = OAI_ESClient.getOaiESClient() - .prepareSearch(OAI_ESClient.getEsIndex()).setTypes(OAI_ESClient.getEsType()) - .setQuery(aggQuery).addField(this.formatField).addField(this.identifierField) - .addField("project.value").addField("project.id").setSize(100000); - - SearchResponse getRecordListItems = request.execute().actionGet(); + //TODO looking for DARIAH if DARIAH works on ES6 + + + SearchRequest request = new SearchRequest(OAI_ESClient.getEsIndex()); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + AggregationBuilder agg = null; + AggregationBuilder filterPublicProjects = null; + AggregationBuilder projectNameAndID = null; + + + if (this.textgrid) { + Script mergeProjectIDandProjectName = new Script("doc['project.id'].value + '&' + doc['project.value.untouched'].value"); + + filterPublicProjects = AggregationBuilders.filter("projectsPublic", QueryBuilders.boolQuery() + .mustNot(QueryBuilders.existsQuery("nearlyPublished")) + .must(QueryBuilders.matchPhraseQuery("format", TextGridMimetypes.EDITION))); + + projectNameAndID = AggregationBuilders.terms("projects") + .script(mergeProjectIDandProjectName) + .size(1000); + + filterPublicProjects.subAggregation(projectNameAndID); + } + + if (this.dariah){ + agg = AggregationBuilders + .terms("descriptiveMetadata.dc:format") + .field("descriptiveMetadata.dc:format") + .size(10000); + } + + List<String> fieldsForSetRequest = new ArrayList<String>(); + fieldsForSetRequest.add("project.value"); + fieldsForSetRequest.add("project.id"); + + searchSourceBuilder.size(0); + searchSourceBuilder.aggregation(filterPublicProjects); + //searchSourceBuilder.aggregation(projectNameAndID); + + request.source(searchSourceBuilder); + System.out.println(request); + SearchResponse getRecordListItems = null; + + try { + getRecordListItems = OAI_ESClient.getEsClient().search(request, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (this.textgrid == true && getRecordListItems.getAggregations()!=null) { + + String projectName=""; + + for (Entry<String, Aggregation> entry : getRecordListItems.getAggregations().asMap().entrySet()) { + String name = entry.getKey(); + + if (name.equals("projectsPublic")) { + + Filter trytry = getRecordListItems.getAggregations().get("projectsPublic"); + Terms trytry2 = trytry.getAggregations().get("projects"); + for(Bucket bentry : trytry2.getBuckets()) { + projectName = bentry.getKey().toString(); + String [] projectInfos = projectName.split("&"); + + SetType setsForTextGrid = new SetType(); + setsForTextGrid.setSetSpec("project:" + projectInfos[0]); + setsForTextGrid.setSetName(projectInfos[1]); + setList.getSet().add(setsForTextGrid); + + } + } + } + for (SearchHit hit : getRecordListItems.getHits().getHits()) { - if (this.dariah == true && hit.getFields().get(this.identifierField).values().get(0) + + if (this.dariah == true && hit.getSourceAsMap().get(this.identifierField) .toString().startsWith("hdl:")) { - String pid = hit.getFields().get(this.identifierField).values().get(0).toString(); + + String pid = hit.getSourceAsMap().get(this.identifierField).toString(); this.identifier.add(pid); } - - if (this.textgrid == true) { - String projectName = hit.getFields().get("project.value").values().get(0).toString(); - String projectID = hit.getFields().get("project.id").values().get(0).toString(); - String projectSetSpec = projectName.concat(":").concat(projectID); - SetDeliverer.setSet.put(projectID, projectName); - } - } - - if (this.textgrid == true) { - Iterator it = setSet.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry) it.next(); - SetType set = new SetType(); - set.setSetName(pair.getValue().toString()); - set.setSetSpec("project:" + pair.getKey().toString()); - setList.getSet().add(set); + } } - + if (this.dariah == true) { for (String identifierSetSpec : this.identifier) { String id = identifierSetSpec; @@ -104,15 +173,27 @@ public class SetDeliverer { id = identifierSetSpec.substring(this.repositoryObjectURIPrefix.length()); - GetRequestBuilder collectionNameById = - OAI_ESClient.getOaiESClient().prepareGet().setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()).setFields(this.specField).setId(id); + String[] includes2 = new String[] {this.specField}; + String[] excludes2 = Strings.EMPTY_ARRAY; + FetchSourceContext fetchSourceContext2 = + new FetchSourceContext(true, includes2, excludes2); + + GetRequest getRequest = + new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id) + .fetchSourceContext(fetchSourceContext2); + GetResponse setSpec = null; + + try { + setSpec = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - GetResponse setSpec = collectionNameById.execute().actionGet(); String setName = ""; if (setSpec != null && setSpec.isExists()) { if (setSpec.getField(this.specField) != null) { - setName = setSpec.getField(this.specField).getValue().toString(); + setName = setSpec.getSourceAsMap().get(this.specField).toString(); } } @@ -142,6 +223,9 @@ public class SetDeliverer { this.formatField = formatField; } + /** + * @return + */ public String getFormatToFilter() { return this.formatToFilter; } @@ -237,4 +321,4 @@ public class SetDeliverer { this.dariah = dariah; } -} +} \ No newline at end of file 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 50a57cf9d37fbe3eadbd3781c7d04a7fe53d2ef4..eb03a62566cb30275044811e5970acedc1b4ad5d 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java @@ -4,45 +4,40 @@ import java.util.Arrays; import java.util.List; /** - * Collection of values never changing its content + * <p> + * Collection of values never changing its content. + * </p> * - * @author Maximilian Brodhun: SUB + * @author Maximilian Brodhun, SUB Göttingen */ public final class TGConstants { + /** + * + */ private TGConstants() { - // not called + // } - // public static boolean furtherElements = true; - public static final String ITEM_IDENTIFIER_PREFIX = "textgrid:"; public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = - Arrays.asList("textgrid-support@gwdg.de"); + Arrays.asList("support@de.dariah.eu"); - /* - * Repository Identification String Constants - */ - - public static final String TG_REP_BASEURL = "www.textgridrep.de"; - public static final String METADATA_DC_PREFIX = "oai_dc"; + // Repository Identification String Constants + public static final String TG_REP_BASEURL = "textgridrep.org"; public static final String METADATA_IDIOM_PREFIX = "oai_idiom_mets"; - /* - * Error String Constants - */ - + // 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"; public static final String OAI_BAD_RESUMPTION_TOKEN = "badResumptionToken"; + public static final String OAI_ID_DOES_NOT_EXIST = "idDoesNotExist"; + public static final String OAI_VERB_ERROR = "badVerb"; - /* - * TextGrid Metadata Fields for OAI-PMH Request (Mapping to DC) - */ - + // 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"; @@ -78,27 +73,18 @@ public final class TGConstants { public static final String WORK_AGENT = "work.agent.value"; public static final String WORK_ID = "work.subject.id.value"; public static final String MODIFIED_FIELD = "lastModified"; - - 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, MODIFIED_FIELD}; - - 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[] 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, MODIFIED_FIELD}; + 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[] CONTRIBUTOR_LIST = {DATA_CONTRIBUTOR}; - public static final String[] COVERAGE_LIST = { - WORK_SPATIAL, WORK_TEMPORAL}; + 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}; @@ -106,23 +92,16 @@ public final class TGConstants { 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[] 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[] 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[] IDENTIFIER_LIST_FIELDS = {URI, - CREATED, FORMAT}; + public static final String[] TYPE_LIST = {WORK_GENRE, WORK_TYPE}; + public static final String[] IDENTIFIER_LIST_FIELDS = {URI, CREATED, FORMAT}; public static final String RANGE_FIELD = CREATED; + } diff --git a/oaipmh-core/src/main/resources/oai_dc.xsd b/oaipmh-core/src/main/resources/oai_dc.xsd index 88479d78648ab89020b97d1d347cfabc4972e79b..78157e1548c5f875925b2d615a1b36a366205f5c 100644 --- a/oaipmh-core/src/main/resources/oai_dc.xsd +++ b/oaipmh-core/src/main/resources/oai_dc.xsd @@ -1,8 +1,7 @@ -<schema targetNamespace="http://www.openarchives.org/OAI/2.0/oai_dc/" +<schema targetNamespace="http://www.openarchives.org/OAI/2.0/oai_dc/" 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" - + xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <annotation> diff --git a/oaipmh-core/src/main/resources/oai_pmh.xsd b/oaipmh-core/src/main/resources/oai_pmh.xsd index 3fce3b59db458399dfaee104587694ebd9c8805e..12c0cd7a86edb94ded7ed19a3a8ec3c8568a7ae5 100644 --- a/oaipmh-core/src/main/resources/oai_pmh.xsd +++ b/oaipmh-core/src/main/resources/oai_pmh.xsd @@ -313,5 +313,5 @@ <pattern value="([A-Za-z0-9\-_\.!~\*'\(\)])+(:[A-Za-z0-9\-_\.!~\*'\(\)]+)*"/> </restriction> </simpleType> - </schema> + diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDARIAHTest.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDARIAHTest.java index 669b00f968e423e7c0a74aee7efdee9770c0316a..5361990b16cd6d8ca6ecd987e3798bf4d7f241c2 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDARIAHTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDARIAHTest.java @@ -15,8 +15,6 @@ import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; public class OaiPmhDARIAHTest { public static OAI_ESClient oaiEsClient; - DeletedRecordType deletedRecordType = DeletedRecordType.NO; - GranularityType granularityType = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; private static RecordDelivererDC record; private static RecordListDelivererDC recordList; @@ -24,8 +22,10 @@ public class OaiPmhDARIAHTest { private static MetadataFormatListDeliverer metadataFormatList = new MetadataFormatListDeliverer(); private static SetDeliverer setListDARIAH = new SetDeliverer(false, true); + private DeletedRecordType deletedRecordType = DeletedRecordType.NO; + private GranularityType granularityType = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; private RepIdentification rep = new RepIdentification("DARIAH-DE Repository", - "http://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", + "https://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", this.granularityType, "2.0", "funk@sub.uni-goettingen.de"); /** @@ -46,8 +46,8 @@ public class OaiPmhDARIAHTest { */ @BeforeClass public static void setUp() throws Exception { - - oaiEsClient = new OAI_ESClient("localhost", "9302", "dhrep-dariah-dev-public"); + int[] ports = new int[] {9202}; + oaiEsClient = new OAI_ESClient("localhost", ports, 100); OAI_ESClient.setEsIndex("dariah-public"); OAI_ESClient.setEsType("metadata"); @@ -61,7 +61,6 @@ public class OaiPmhDARIAHTest { */ @Test public void testGetRequestIdentify() throws ParseException { - System.out.println("Test for the verb \"Identify\" with succesfull response"); String r = this.request.getRequest("Identify", "", "", "", "", "", ""); System.out.println(r); diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java index 2778d6f2aad9da32a8d60656f2da6c10f82cbaf2..83088d6bf9e3d33951d2209d81ac6fed07424748 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java @@ -9,6 +9,7 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import info.textgrid.utils.httpclient.TGHttpClient; import info.textgrid.utils.httpclient.TGHttpResponse; @@ -20,6 +21,7 @@ import info.textgrid.utils.httpclient.TGHttpResponse; * * @author Stefan E. Funk, SUB Göttingen */ +@Ignore public class OaiPmhDariahdeOnlineTests { // The OAIPMH host to be tested. 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 75713ab5f8127478a9e82368125467ee9adfcb00..e6fe2cd20778b8ef8647520f4a66cc3630e1442c 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java @@ -23,7 +23,6 @@ public class OaiPmhTest { // ** public static OAI_ESClient oaiEsClient; - private static RecordDelivererDC record; private static RecordDelivererIDIOM recordIDIOM; private static RecordListDelivererDC recordList; @@ -32,6 +31,7 @@ public class OaiPmhTest { new IdentifierListDelivererDC(true, false); private static IdentifierListDelivererIDIOM identifierListIDIOM = new IdentifierListDelivererIDIOM(true, false); + private static SetDeliverer setListTextGrid; // ** // CLASS @@ -42,23 +42,22 @@ public class OaiPmhTest { private RepIdentification rep = new RepIdentification("TextGrid-Repository", "www.textgridrep.de", this.bla, "2011-06-11T02:32:40Z", this.bla2, "2.0", "textgrid-support@gwdg.de"); private MetadataFormatListDeliverer metadataFormatList = new MetadataFormatListDeliverer(); - private SetDeliverer setListDARIAH = new SetDeliverer(false, true); - private SetDeliverer setListTextGrid = new SetDeliverer(true, false); - private OAIPMHImpl request = new OAIPMHImpl( this.rep, OaiPmhTest.record, OaiPmhTest.recordIDIOM, OaiPmhTest.recordList, OaiPmhTest.recordListIDIOM, this.metadataFormatList, - this.setListDARIAH, OaiPmhTest.identifierList, OaiPmhTest.identifierListIDIOM); + OaiPmhTest.setListTextGrid, OaiPmhTest.identifierList, OaiPmhTest.identifierListIDIOM); /** * @throws Exception */ @BeforeClass public static void setUp() throws Exception { - oaiEsClient = new OAI_ESClient("localhost", "9302", "tg-esx2-instance"); + int[] ports = new int[] {9202}; + oaiEsClient = new OAI_ESClient("localhost", ports, 100); OAI_ESClient.setEsIndex("textgrid-public"); OAI_ESClient.setEsType("metadata"); + OAI_ESClient.setPorts(ports); record = new RecordDelivererDC(true, false); record.setOaiEsClient(oaiEsClient); record.setWorkFields(TGConstants.TGWorkFields); @@ -78,6 +77,8 @@ public class OaiPmhTest { identifierList = new IdentifierListDelivererDC(true, false); identifierList.setOaiEsClient(oaiEsClient); identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + + setListTextGrid = new SetDeliverer(true, false); } /** @@ -158,6 +159,17 @@ public class OaiPmhTest { System.out.println("-----------------------------------\n"); } + /** + * @throws ParseException + */ + @Test + @Ignore + public void testGetDateFormat() throws ParseException { + System.out.println("Test get time format"); + System.out.println(OAIPMHUtilities.getFormatOfDate("2019-12-02T15:36:13Z")); + System.out.println("-----------------------------------\n"); + } + /** * @throws ParseException */ @@ -174,7 +186,7 @@ public class OaiPmhTest { record.setLanguages(TGConstants.LANGUAGE_LIST); record.setPublishers(TGConstants.PUBLISHER_LIST); record.setRelations(TGConstants.RELATIONS_LIST); - record.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + // record.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); record.setRights(TGConstants.RIGHTS_LIST); record.setSources(TGConstants.SOURCE_LIST); record.setSubjects(TGConstants.SUBJECT_LIST); @@ -189,7 +201,7 @@ public class OaiPmhTest { record.setIdentifierField("textgridUri"); System.out.println("Test for the verb \"GetRecord\" with succesfull response"); - String p = this.request.getRequest("GetRecord", "textgrid:vqn0.0", "oai_dc", "", "", "", ""); + String p = this.request.getRequest("GetRecord", "textgrid:11hp0.0", "oai_dc", "", "", "", ""); System.out.println(p); System.out.println("-----------------------------------\n"); } @@ -232,8 +244,7 @@ public class OaiPmhTest { OaiPmhTest.identifierList.setIdentifierField("textgridUri"); OaiPmhTest.identifierList.setSearchResponseSize("100"); System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); - String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", - "project:TGPR-26236625-1acc-b921-a5fa-53567c3eeb80", "", "", ""); + String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "2000-02-05", "", "junk"); System.out.println(p); System.out.println("-----------------------------------\n"); } @@ -281,6 +292,17 @@ public class OaiPmhTest { System.out.println("-----------------------------------\n"); } + @Test + @Ignore + public void testMissingVerbArgument() throws ParseException { + System.out + .println("Test for request with missing verb argument"); + String p = this.request.getRequest("", "", "", "", "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** * @throws ParseException */ @@ -335,17 +357,20 @@ public class OaiPmhTest { OaiPmhTest.recordList.setIdentifierField("textgridUri"); System.out.println("Test for the verb \"ListRecords\" with sets with succesfull response"); + //String p = this.request.getRequest("ListRecords", "", "oai_dc", "project:TGPR-f89ad029-4eb2-ae5c-6028-5db876513128", "", "", ""); String p = this.request.getRequest("ListRecords", "", "oai_dc", "", "", "", ""); System.out.println(p); - String resToken = ""; + /*String resToken = ""; for (Map.Entry<String, Integer> entry : RecordListDelivererDC.cursorCollector.entrySet()) { resToken = entry.getKey(); - } - String p2 = this.request.getRequest("ListRecords", "", "", "", "", "", resToken); - System.out.println(p2); - System.out.println("HASH MAP AFTER: "); - System.out.println(RecordListDelivererDC.cursorCollector); - System.out.println("-----------------------------------\n"); + String p2 = this.request.getRequest("ListRecords", "", "", "", "", "", resToken); + System.out.println(p2); + System.out.println("HASH MAP AFTER: "); + System.out.println(RecordListDelivererDC.cursorCollector); + System.out.println("-----------------------------------\n"); + }*/ + + } /** @@ -413,7 +438,6 @@ public class OaiPmhTest { OaiPmhTest.recordList.setModifiedField(TGConstants.CREATED); OaiPmhTest.recordList.setIdentifierField(TGConstants.URI); OaiPmhTest.recordList.setSearchResponseSize("100"); - String r = this.request.getRequest("ListRecords", "", "oai_dc", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); @@ -425,7 +449,7 @@ public class OaiPmhTest { @Test @Ignore public void testListMetadataFormatsForIdentifier() throws ParseException { - String r = this.request.getRequest("ListMetadataFormats", "7t.0", "", "", "", "", ""); + String r = this.request.getRequest("ListMetadataFormats", "textgrid:125x1.0", "", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); } @@ -446,12 +470,26 @@ public class OaiPmhTest { */ @Test @Ignore - public void testListSets() throws ParseException { - this.setListTextGrid.setFormatField("format"); - this.setListTextGrid.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); - this.setListTextGrid.setIdentifierField("textgridUri"); - this.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); + public void testListSetsTG() throws ParseException { + OaiPmhTest.setListTextGrid.setFormatField("format"); + OaiPmhTest.setListTextGrid.setFormatToFilter(TextGridMimetypes.EDITION); + OaiPmhTest.setListTextGrid.setIdentifierField("textgridUri"); + OaiPmhTest.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); + String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListSetsDH() throws ParseException { + OaiPmhTest.setListTextGrid.setFormatField("format"); + OaiPmhTest.setListTextGrid.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); + OaiPmhTest.setListTextGrid.setIdentifierField("textgridUri"); + OaiPmhTest.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); @@ -469,10 +507,9 @@ public class OaiPmhTest { OaiPmhTest.identifierList.setIdentifierField("textgridUri"); OaiPmhTest.identifierList.setRepositoryObjectURIPrefix("textgrid:"); OaiPmhTest.identifierList.setSearchResponseSize("100"); - String r = this.request.getRequest("", "", "", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); } -} +} \ No newline at end of file diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java index 952f88aa57dcd74b626760fc72cc7efa981d340f..89829243f5ce567f765e61b29c32c7fb02f38293 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java @@ -14,6 +14,7 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import info.textgrid.utils.httpclient.TGHttpClient; import info.textgrid.utils.httpclient.TGHttpResponse; @@ -25,6 +26,7 @@ import info.textgrid.utils.httpclient.TGHttpResponse; * * @author Stefan E. Funk, SUB Göttingen */ +@Ignore public class OaiPmhTextgridOnlineTests { private static final String OAI_DC_PREFIX = "oai_dc"; @@ -951,7 +953,6 @@ public class OaiPmhTextgridOnlineTests { return true; } - } } diff --git a/oaipmh-webapp/pom.xml b/oaipmh-webapp/pom.xml index 98f972ed3ec1f96238a4dc2a7b2a17c183afc44f..744f8479fa9ed766316107f31122420ca67168b7 100644 --- a/oaipmh-webapp/pom.xml +++ b/oaipmh-webapp/pom.xml @@ -5,7 +5,7 @@ <parent> <artifactId>oaipmh</artifactId> <groupId>info.textgrid.middleware</groupId> - <version>3.1.12-SNAPSHOT</version> + <version>3.3.2-SNAPSHOT</version> </parent> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh-webapp</artifactId> @@ -81,7 +81,7 @@ <build> <finalName>oaipmh</finalName> <plugins> - <!-- Do not deploy WAR and DEB files to the Nexus repository --> + <!-- Do not deploy WAR and DEB files to the Nexus repository --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml index 58fc35dfa03945d96eab35d472ab0039abf56b42..39368f9cf30c49a426ae6159e5fdc4852cc24f86 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml @@ -14,12 +14,14 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> - <description>Configuration for the TextGrid/DARIAH-DE OAI-PMH Interface</description> + <description>Configuration for the TextGrid/DARIAH-DE OAI-PMH Interface + </description> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> - <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <bean id="propertyPlaceholderConfigurer" + class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>file:/etc/dhrep/oaipmh/oaipmh.properties</value> @@ -29,36 +31,47 @@ <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean> - <bean id="ElasticSearchClient" class="info.textgrid.middleware.OAI_ESClient"> - <constructor-arg index="0" value="${elasticSearch.url}" /> - <constructor-arg index="1" value="${elasticSearch.port}" /> - <constructor-arg index="2" value="${elasticSearch.clusterName}" /> + <bean id="ElasticSearchClient" + class="info.textgrid.middleware.OAI_ESClient"> + <constructor-arg index="0" + value="${elasticSearch.url}" /> + <constructor-arg index="1" + value="${elasticSearch.ports}" /> + <constructor-arg index="2" + value="${elasticSearch.itemLimit}" /> <property name="esIndex" value="${elasticSearch.index}" /> <property name="esType" value="${elasticSearch.type}" /> </bean> <!--bean id="drc" class="info.textgrid.middleware.oaipmh.${DeletedRecordInfo}" --> - <bean id="RepIdentification" class="info.textgrid.middleware.RepIdentification"> + <bean id="RepIdentification" + class="info.textgrid.middleware.RepIdentification"> <constructor-arg index="0" value="${RepositoryName}" /> <constructor-arg index="1" value="${BaseUrl}" /> - <constructor-arg index="2" value="${DeletedRecordInfo}" /> - <constructor-arg index="3" value="${EarliestDateStamp}" /> + <constructor-arg index="2" + value="${DeletedRecordInfo}" /> + <constructor-arg index="3" + value="${EarliestDateStamp}" /> <constructor-arg index="4" value="${Granularity}" /> <constructor-arg index="5" value="${ProtocolVersion}" /> <constructor-arg index="6" value="${AdminMail}" /> </bean> - <bean id="RecordListDC" class="info.textgrid.middleware.RecordListDelivererDC"> + <bean id="RecordListDC" + class="info.textgrid.middleware.RecordListDelivererDC"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> <property name="fields" value="${fields}" /> <property name="workFields" value="${workFields}" /> <property name="formatField" value="${formatField}" /> <property name="formatToFilter" value="${formatToFilter}" /> - <property name="dateOfObjectCreation" value="${dateOfObjectCreation}" /> - <property name="relationToFurtherMetadataObject" value="${relationToFurtherMetadataObject}" /> - <property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> <property name="FieldForRange" value="${rangeField}" /> <property name="contributor" value="${contributorList}" /> <property name="coverage" value="${coverageList}" /> @@ -70,7 +83,8 @@ <property name="languages" value="${languageList}" /> <property name="publishers" value="${publisherList}" /> <property name="relations" value="${relationList}" /> - <property name="relationsForWork" value="${relationsForWorkList}" /> + <property name="relationsForWork" + value="${relationsForWorkList}" /> <property name="rights" value="${rightsList}" /> <property name="sources" value="${sourceList}" /> <property name="subjects" value="${subjectList}" /> @@ -78,22 +92,28 @@ <property name="types" value="${typeList}" /> <property name="modifiedField" value="${modifiedField}" /> <property name="identifierField" value="${identifierField}" /> - <property name="searchResponseSize" value="${searchResponseSize}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> </bean> - <bean id="RecordListIDIOM" class="info.textgrid.middleware.RecordListDelivererIDIOM"> + <bean id="RecordListIDIOM" + class="info.textgrid.middleware.RecordListDelivererIDIOM"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> </bean> - <bean scope="prototype" id="RecordDC" class="info.textgrid.middleware.RecordDelivererDC"> + <bean scope="prototype" id="RecordDC" + class="info.textgrid.middleware.RecordDelivererDC"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> <property name="formatField" value="${formatField}" /> <property name="formatToFilter" value="${formatToFilter}" /> - <property name="dateOfObjectCreation" value="${dateOfObjectCreation}" /> - <property name="relationToFurtherMetadataObject" value="${relationToFurtherMetadataObject}" /> - <property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> <property name="identifierField" value="${identifierField}" /> <property name="fields" value="${fields}" /> <property name="workFields" value="${workFields}" /> @@ -107,54 +127,65 @@ <property name="languages" value="${languageList}" /> <property name="publishers" value="${publisherList}" /> <property name="relations" value="${relationList}" /> - <property name="relationsForWork" value="${relationsForWorkList}" /> + <!-- property name="relationsForWork" value="${relationsForWorkList}" / --> <property name="rights" value="${rightsList}" /> <property name="sources" value="${sourceList}" /> <property name="subjects" value="${subjectList}" /> <property name="titles" value="${titleList}" /> <property name="types" value="${typeList}" /> </bean> - - <bean id="RecordIDIOM" class="info.textgrid.middleware.RecordDelivererIDIOM"> + + <bean id="RecordIDIOM" + class="info.textgrid.middleware.RecordDelivererIDIOM"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> </bean> - <bean id="ListIdentifierDC" class="info.textgrid.middleware.IdentifierListDelivererDC"> + <bean id="ListIdentifierDC" + class="info.textgrid.middleware.IdentifierListDelivererDC"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> - <property name="dateOfObjectCreation" value="${dateOfObjectCreation}" /> - <property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" /> - <property name="identifierListFields" value="${identifierListFields}"></property> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="identifierListFields" + value="${identifierListFields}"></property> <property name="FieldForRange" value="${rangeField}" /> <property name="identifierField" value="${identifierField}" /> - <property name="searchResponseSize" value="${searchResponseSize}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> </bean> - - <bean id="ListIdentifierIDIOM" class="info.textgrid.middleware.IdentifierListDelivererIDIOM"> + + <bean id="ListIdentifierIDIOM" + class="info.textgrid.middleware.IdentifierListDelivererIDIOM"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> </bean> - <bean id="SetDeliverer" class="info.textgrid.middleware.SetDeliverer"> + <bean id="SetDeliverer" + class="info.textgrid.middleware.SetDeliverer"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> <property name="formatField" value="${formatField}" /> <property name="formatToFilter" value="${formatToFilter}" /> <property name="identifierField" value="${identifierField}" /> - <property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> <property name="specField" value="${specField}" /> <property name="specFieldPrefix" value="${specFieldPrefix}" /> </bean> - <bean id="MetadataFormatList" class="info.textgrid.middleware.MetadataFormatListDeliverer"> + <bean id="MetadataFormatList" + class="info.textgrid.middleware.MetadataFormatListDeliverer"> </bean> <!-- REST Interface --> <bean id="rest" class="info.textgrid.middleware.Rest" /> - <bean id="cors-filter" class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"> + <bean id="cors-filter" + class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"> <property name="allowOrigins"> <util:list /> </property> @@ -174,7 +205,8 @@ <property name="dariah" value="${dariah}" /> </bean> - <jaxrs:server id="root" address="/root" publishedEndpointUrl="${RS_ENDPOINT}"> + <jaxrs:server id="root" address="/root" + publishedEndpointUrl="${RS_ENDPOINT}"> <jaxrs:serviceBeans> <ref bean="rest" /> </jaxrs:serviceBeans> @@ -183,7 +215,8 @@ </jaxrs:providers> </jaxrs:server> - <jaxrs:server id="queryEndpoint" address="/oai" publishedEndpointUrl="${RS_ENDPOINT}"> + <jaxrs:server id="queryEndpoint" address="/oai" + publishedEndpointUrl="${RS_ENDPOINT}"> <jaxrs:serviceBeans> <ref bean="oai" /> </jaxrs:serviceBeans> diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties index d0c1e94744e1d9da66c675ce6193752b66b81516..d361cc2610e5a880d6efff60d232b343fe7d93d6 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties @@ -2,7 +2,7 @@ ## ElasticSearch Endpoint ## ############################## -RS_ENDPOINT = http://trep.de.dariah.eu/oaipmh +RS_ENDPOINT = https://repository.de.dariah.eu/1.0/oaipmh ############################ ## ElasticSearch Config ## @@ -26,12 +26,12 @@ dariah = true ############################# RepositoryName = DARIAH-DE Repository -BaseUrl = http://trep.de.dariah.eu +BaseUrl = https://repository.de.dariah.eu/1.0/oaipmh/oai DeletedRecordInfo = NO EarliestDateStamp = 2011-06-11T02:32:40Z Granularity = YYYY_MM_DD_THH_MM_SS_Z ProtocolVersion = 2.0 -AdminMail = funk@sub.uni-goettingen.de +AdminMail = support@de.dariah.eu ###################### ## Field Settings ## diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties index b5404bc7f0767fdcf8e2376bffae6b65e1a883c1..155cfca4ca2958aa4ec6e38d70ec700581bee929 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties @@ -2,17 +2,17 @@ ## ElasticSearch Endpoint ## ############################## -RS_ENDPOINT = http://textgrid-esx1.gwdg.de/tgoaipmh +RS_ENDPOINT = https://textgridlab.org/1.0/tgoaipmh ############################ ## ElasticSearch Config ## ############################ elasticSearch.url = 127.0.0.1 -elasticSearch.port = 9302 -elasticSearch.clusterName = tg-esx1-dev-instance +elasticSearch.ports = 9202 9203 elasticSearch.index = textgrid-public elasticSearch.type = metadata +elasticSearch.itemLimit = 100 ######################## ## Project Choosing ## @@ -26,12 +26,12 @@ dariah = false ############################# RepositoryName = TextGrid Repository -BaseUrl = http://textgrid-esx1.gwdg.de +BaseUrl = https://textgridlab.org/1.0/tgoaipmh/oai DeletedRecordInfo = NO EarliestDateStamp = 2011-06-11T02:32:40Z Granularity = YYYY_MM_DD_THH_MM_SS_Z ProtocolVersion = 2.0 -AdminMail = funk@sub.uni-goettingen.de +AdminMail = support@de.dariah.eu ###################### ## Field Settings ## diff --git a/pom.xml b/pom.xml index 7113d3893d557199ec99d88d16d9e3bcc8addbc7..9f2c8dfc33ac59445f024286f909056f98586b9a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh</artifactId> - <version>3.1.12-SNAPSHOT</version> + <version>3.3.2-SNAPSHOT</version> <packaging>pom</packaging> <name>DARIAHDE :: OAI-PMH DataProvider</name> <properties> @@ -13,7 +13,7 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <cxf.version>3.2.8</cxf.version> <spring.version>4.0.2.RELEASE</spring.version> - <elasticsearch.version>1.7.5</elasticsearch.version> + <elasticsearch.version>6.5.4</elasticsearch.version> <antlr-runtime.version>3.2</antlr-runtime.version> <antlr-maven-plugin.version>3.2</antlr-maven-plugin.version> <slf4j.version>1.7.5</slf4j.version>