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 f016943331dea4cb95fafe6a41e5be6a1b7d4fd7..2ffea1db102523d4dae322973f43e48fd2cfbbd2 100644 --- a/oaipmh-core/pom.xml +++ b/oaipmh-core/pom.xml @@ -5,19 +5,38 @@ <parent> <artifactId>oaipmh</artifactId> <groupId>info.textgrid.middleware</groupId> - <version>3.3.16</version> + <version>4.0.0</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> + <url>https://projects.gwdg.de/projects/oai-pmh</url> + <dependencies> + <dependency> + <groupId>org.eclipse.rdf4j</groupId> + <artifactId>rdf4j-repository-api</artifactId> + <version>3.0.2</version> + </dependency> + <dependency> + <groupId>info.textgrid.middleware</groupId> + <artifactId>const</artifactId> + <version>${common.version}</version> + </dependency> + <dependency> + <groupId>info.textgrid.utils</groupId> + <artifactId>httpclients</artifactId> + <version>${common.version}</version> + </dependency> + <dependency> <groupId>info.textgrid.middleware</groupId> - <artifactId>crud-common</artifactId> - <version>${tgcrud.version}</version> + <artifactId>ltputils</artifactId> + <version>${common.version}</version> + </dependency> + <dependency> + <groupId>info.textgrid.middleware.clients</groupId> + <artifactId>textgrid-clients</artifactId> + <version>${common.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> @@ -51,46 +70,71 @@ <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> --> + <!-- <groupId>org.slf4j</groupId> --> + <!-- <artifactId>slf4j-api</artifactId> --> + <!-- <version>${slf4j.version}</version> --> + <!-- </dependency> --> + <!-- <dependency> --> + <!-- <groupId>org.slf4j</groupId> --> + <!-- <artifactId>jcl-over-slf4j</artifactId> --> + <!-- <version>${slf4j.version}</version> --> + <!-- <scope>runtime</scope> --> + <!-- </dependency> --> + <!-- <dependency> --> + <!-- <groupId>org.slf4j</groupId> --> + <!-- <artifactId>slf4j-log4j12</artifactId> --> + <!-- <version>${slf4j.version}</version> --> + <!-- <scope>runtime</scope> --> + <!-- </dependency> --> + <!-- <dependency> --> + <!-- <groupId>log4j</groupId> --> + <!-- <artifactId>log4j</artifactId> --> + <!-- <version>1.2.14</version> --> + <!-- </dependency> --> + <dependency> - <groupId>info.textgrid.utils</groupId> - <artifactId>httpclients</artifactId> - <version>${tghttpclients.version}</version> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.13.0</version> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>${slf4j.version}</version> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.0</version> </dependency> + <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>${slf4j.version}</version> - <scope>runtime</scope> + <groupId>org.classicmayan.tools</groupId> + <artifactId>metsModsMapping</artifactId> + <version>1.1.9</version> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>${slf4j.version}</version> - <scope>runtime</scope> + <groupId>de.shadowhunt.maven.plugins</groupId> + <artifactId>package-info-maven-plugin</artifactId> + <version>1.4.5</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.json/json --> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.14</version> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20190722</version> </dependency> <dependency> - <groupId>org.classicmayan.tools</groupId> - <artifactId>metsModsMapping</artifactId> - <version>1.1.15</version> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> </dependency> + + <!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream --> <dependency> - <groupId>de.shadowhunt.maven.plugins</groupId> - <artifactId>package-info-maven-plugin</artifactId> - <version>1.4.5</version> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.4.12</version> </dependency> </dependencies> <build> diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java deleted file mode 100644 index 35fd6de95723ad75da30714d03a3504a8eae86bb..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DARIAHConstants.java +++ /dev/null @@ -1,87 +0,0 @@ -package info.textgrid.middleware; - -import java.util.Arrays; -import java.util.List; - -/** - * Collection of values never changing its content - * - * @author Maximilian Brodhun: SUB - */ - -public final class DARIAHConstants { - - private DARIAHConstants() { - // not called - } - - public static final String ITEM_IDENTIFIER_PREFIX = "hdl:"; - public static final String COLLECTIONREGISTRY_PREFIX = "dariah:collection:"; - public static final String COLLECTION_MIMETYPE = "text/vnd.dariah.dhrep.collection+turtle"; - public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = - Arrays.asList("support@de.dariah.eu"); - - /* - * 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 - */ - - 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) - */ - - 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[] DARIAHCollectionFields = {"metadata.dc:title"}; - - /* - * 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"}; - public static final String[] DATE_LIST = {"administrativeMetadata.dcterms:modified"}; - public static final String[] DESCRIPTION_LIST = {"descriptiveMetadata.dc:description"}; - public static final String[] FORMAT_LIST = {"descriptiveMetadata.dc:format"}; - public static final String[] IDENTIFIER_LIST = {"descriptiveMetadata.dc:identifier"}; - public static final String[] LANGUAGE_LIST = {"descriptiveMetadata.dc:language"}; - public static final String[] PUBLISHER_LIST = {"descriptiveMetadata.dc:publisher"}; - public static final String[] RELATIONS_LIST = {"descriptiveMetadata.dc:relation"}; - public static final String[] RIGHTS_LIST = {"descriptiveMetadata.dc:rights"}; - public static final String[] SOURCE_LIST = {"descriptiveMetadata.dc:source"}; - public static final String[] SUBJECT_LIST = {"descriptiveMetadata.dc:subject"}; - public static final String[] TITLE_LIST = {"descriptiveMetadata.dc:title"}; - public static final String[] TYPE_LIST = {"descriptiveMetadata.dc:type"}; - public static final String[] IDENTIFIER_LIST_FIELDS = - {"administrativeMetadata.dcterms:identifier", "administrativeMetadata.dcterms:modified", - "descriptiveMetadata.dc:identifier", "descriptiveMetadata.dc:date", - "descriptiveMetadata.dc:format"}; - public static final String RANGE_FIELD = "administrativeMetadata.dcterms:modified"; - public static final String MODIFIED_FIELD = "administrativeMetadata.dcterms:modified"; -} 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..35dc7c8e80882876e01d0abc2379e224f1dc793b 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,11 @@ package info.textgrid.middleware; +import java.text.ParseException; import java.util.List; import javax.xml.bind.JAXBElement; +import javax.xml.datatype.DatatypeConfigurationException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import info.textgrid.middleware.oaipmh.ElementType; import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.OaiDcType; @@ -22,11 +26,14 @@ import info.textgrid.middleware.oaipmh.ObjectFactory; public final class DublinCoreBuilder { + private static Log log = LogFactory.getLog(RecordListDelivererAbstract.class); + // Object factory for all the DC elements. private static ObjectFactory oaiDcObj = new ObjectFactory(); // MetadataType of OAI schema. private MetadataType metadata = new MetadataType(); + // OAI_DC type of oai_dc schema. private OaiDcType tgMappedDC = new OaiDcType(); @@ -104,12 +111,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); } } @@ -157,11 +166,19 @@ public final class DublinCoreBuilder { * @param identifiers */ public void setIdentifier(List<String> identifiers) { - for (String dcidentifier : identifiers) { - ElementType identifierElement = new ElementType(); - identifierElement.setValue(dcidentifier); - JAXBElement<ElementType> dcCoreIdentifier = oaiDcObj.createIdentifier(identifierElement); - this.tgMappedDC.getTitleOrCreatorOrSubject().add(dcCoreIdentifier); + + log.debug("idlist: " + (identifiers == null ? "NULL" : identifiers)); + + if (identifiers != null) { + for (String dcidentifier : identifiers) { + + log.debug("id: " + dcidentifier); + + ElementType identifierElement = new ElementType(); + identifierElement.setValue(dcidentifier); + JAXBElement<ElementType> dcCoreIdentifier = oaiDcObj.createIdentifier(identifierElement); + this.tgMappedDC.getTitleOrCreatorOrSubject().add(dcCoreIdentifier); + } } } @@ -315,22 +332,4 @@ public final class DublinCoreBuilder { return this.metadata; } - /** - * @return tgMappedDc - * @deprecated - */ - @Deprecated - public OaiDcType getTgMappedDC() { - return this.tgMappedDC; - } - - /** - * @return oaiDcObj - * @deprecated - */ - @Deprecated - public ObjectFactory getOaiDcObj() { - return oaiDcObj; - } - } 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..ebadcab036470c0a96ef51273bd5a1b6f035a9fb 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreFieldLoader.java @@ -3,6 +3,7 @@ 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; @@ -12,140 +13,36 @@ 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; - } - - /** - * @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> 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; - } + private static Log log = LogFactory.getLog(DublinCoreFieldLoader.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 request 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> 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 +51,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 +94,14 @@ public class DublinCoreFieldLoader { List<String> dates = new ArrayList<String>(); + log.debug("TADAAAAAAA! (tadaaaaa?)"); + 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(); @@ -213,465 +116,96 @@ public class DublinCoreFieldLoader { } /** - * @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()); - } - } - } - - 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 + * @param responseWorkValues + * @param fields + * @return */ - public static List<String> setFormat(GetResponse responseWorkValues, String[] fields) { + @SuppressWarnings("unchecked") + public static List<String> fillListFromTGWorkValues(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(OAIPMHUtilities.ES_DIVIDER_REGEXP); + 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) { + try { + nestedMap2 = (Map<String, Object>) nestedMap.get(requestedField[i]); + } catch (ClassCastException e) { + e.printStackTrace(); + } + if (nestedMap.get(requestedField[i]) instanceof Map<?, ?>) { + } + } + 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; - } - - /** - * @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; + return list; } /** - * @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) { + @SuppressWarnings("unchecked") + public static List<String> fillList(SearchHit hit, String[] fields) { - List<String> titles = new ArrayList<String>(); + List<String> list = new ArrayList<String>(); - if (responseWorkValues.isExists()) { + 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(OAIPMHUtilities.ES_DIVIDER_REGEXP); + 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 e) { + e.printStackTrace(); + } + } + 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..2c817d91761e3d8873cfc659668260d3446c1d98 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java @@ -1,17 +1,71 @@ package info.textgrid.middleware; +import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; +import java.util.Hashtable; import java.util.List; +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.json.JSONObject; +import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.RequestType; +import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** * */ public abstract class IdentifierListDelivererAbstract implements IdentifierListDelivererInterface { + // ** + // FINALS + // ** + + protected static final int lifeTimeResToken = 100; + + // ** + // STATIC + // ** + + private static org.apache.commons.logging.Log log = + LogFactory.getLog(RecordListDelivererAbstract.class); + protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + + // ** + // CLASS + // ** + protected boolean textgrid; protected boolean dariah; + protected boolean foundItems; + protected long resultSize; + protected int searchResponseSize; + protected ResumptionTokenType resTokenForResponse; + protected String datestamp; + protected boolean idExist = true; + protected OAI_ESClient oaiEsClient; + protected String[] identifierListFields; // Fields for the elasticsearch request + protected String rangeField; // Field for the optional range query + protected String dateOfObjectCreation; // Field for the object creation in the repository + protected String repositoryObjectURIPrefix; + protected String identifierField; + protected String formatField; + protected String formatToFilter; + protected String specField; + protected String specFieldPrefix; /** * @param textgrid @@ -22,17 +76,9 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD this.dariah = dariah; } - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.IdentifierListDelivererInterface#processIdentifierList(java.lang. - * String, java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public ListIdentifiersType processIdentifierList(String from, String to, String set, - String resumptionToken) { - return null; - } + // ** + // PUBLIC METHODS + // ** /** * @param request @@ -44,9 +90,10 @@ 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(TGConstants.METADATA_IDIOM_PREFIX)) { - result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + result.setError(OAIPMHConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() + " is not supported by the item identified by the value of: " + request.getIdentifier()); @@ -54,21 +101,22 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD // 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 " + boolean restokDCExisting = IdentifierListDelivererDC.cursorCollector != null + && IdentifierListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); + boolean restokIDIOMExisting = IdentifierListDelivererIDIOM.cursorCollector != null + && IdentifierListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); + boolean restok = cursorCollector != null + && cursorCollector.containsKey(request.getResumptionToken()); + + if (!restokDCExisting && !restokIDIOMExisting && !restok) { + + result.setError(OAIPMHConstants.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"); } @@ -76,11 +124,436 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD errorValues.add("identifier"); } if (errorValues.size() > 0) { - result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + result.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + "or is missing required arguments: " + errorValues); } return result; } + /** + * <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.</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) throws IOException, ParseException { + + // FIXME combine it with with getIdentifierListWithSet and check for empty set + + ListIdentifiersType lit = new ListIdentifiersType(); + 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) { + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueSeconds(lifeTimeResToken)); + listListIdentiferValues = + OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); + } else { + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueMinutes(lifeTimeResToken)); + listListIdentiferValues = + OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); + } + + listListIdentiferValues = + hitHandling(listListIdentiferValues, lit, set, listListIdentiferValues.getScrollId()); + + return lit; + } + + /** + * @param listFurtherValues + * @param lit + * @param set + * @param resumptionToken + * @return + */ + public SearchResponse hitHandling(SearchResponse listFurtherValues, ListIdentifiersType lit, + String set, String resumptionToken) { + + int i = 0; + long size = listFurtherValues.getHits().totalHits; + setResultSize(size); + + log.debug("hits: " + size); + + for (SearchHit hit : listFurtherValues.getHits().getHits()) { + i++; + + log.debug("hit " + i + ": " + hit.getId()); + + // Handle TextGrid. + if (this.textgrid) { + String datestamp = hit.getSourceAsMap().get(this.dateOfObjectCreation).toString(); + try { + datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat(); + } catch (ParseException e) { + log.error(e.getMessage()); + } catch (DatatypeConfigurationException e) { + log.error(e.getMessage()); + } + String identifier = hit.getSourceAsMap().get(this.identifierField).toString(); + lit = setListIdentifierHeader(datestamp, identifier, lit, set); + } + + // Handle DARIAH. + else if (this.dariah) { + + log.debug("dateOfObjectCreation: " + this.dateOfObjectCreation); + + JSONObject json = new JSONObject(hit.getSourceAsMap()); + + // Get modifiedDate field and convert datestamp. + this.datestamp = OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation); + try { + log.debug("datestamp: " + this.datestamp); + + this.datestamp = OAIPMHUtilities.convertDateFormat(this.datestamp).toXMLFormat(); + + log.debug("datestamp converted: " + this.datestamp); + + } catch (ParseException e) { + log.error(e.getMessage()); + // FIXME Go to ERROR state! + } catch (DatatypeConfigurationException e) { + log.error(e.getMessage()); + // FIXME Go to ERROR state! + } + + // Get identifier field. + String identifier = OAIPMHUtilities.fieldLoader(json, this.identifierField); + + log.debug("identifier: " + identifier); + + lit = setListIdentifierHeader(this.datestamp, identifier, lit, set); + } + } + + // Check the need for a resumption token! + ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( + listFurtherValues.getHits().getTotalHits(), resumptionToken, cursorCollector, + listFurtherValues.getScrollId(), this.searchResponseSize, i); + if (resTokenForResponse != null) { + lit.setResumptionToken(resTokenForResponse); + } + + return listFurtherValues; + } + + /** + * @param datestamp + * @param identifier + * @param lit + * @param set + * @return + */ + private ListIdentifiersType setListIdentifierHeader(String datestamp, String identifier, + ListIdentifiersType lit, String set) { + + HeaderType header = new HeaderType(); + header.setDatestamp(datestamp); + header.setIdentifier(identifier); + + if (set != null) { + header.getSetSpec().add(this.specFieldPrefix + set); + } + lit.getHeader().add(header); + + return lit; + } + + /** + * @param set + * @param from + * @param until + * @return + */ + public QueryBuilder setOrNot(String set, String from, String until) { + + QueryBuilder rangeQuery = QueryBuilders.rangeQuery(this.rangeField).from(from).to(until); + QueryBuilder formatQuery = QueryBuilders.matchPhrasePrefixQuery("format", this.formatToFilter); + QueryBuilder query; + + if (set != null) { + String queryField = ""; + String valueField = ""; + + if (this.dariah == true) { + queryField = "descriptiveMetadata.dc:relation"; + valueField = set; + } + + if (this.textgrid == true) { + String[] setParts = set.split(":"); + if (setParts[0].equals("project")) { + queryField = "project.id"; + valueField = setParts[1]; + } + } + + QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); + if (this.dariah) { + query = matchQuery; + } else { + query = QueryBuilders.boolQuery().must(matchQuery).must(formatQuery).must(rangeQuery); + } + + } else { + if (this.dariah == true) + query = rangeQuery; + else + query = QueryBuilders.boolQuery().must(rangeQuery).must(formatQuery); + } + + return query; + } + + // ** + // GETTERS & SETTERS + // ** + + /** + * @return + */ + public boolean isFoundItems() { + return this.foundItems; + } + + /** + * @param foundItems + */ + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } + + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + + /** + * @return + */ + public ResumptionTokenType getResTokenForResponse() { + return this.resTokenForResponse; + } + + /** + * @param resTokenForResponse + */ + public void setResTokenForResponse(ResumptionTokenType resTokenForResponse) { + this.resTokenForResponse = resTokenForResponse; + } + + /** + * @return + */ + public String getFieldForRange() { + return this.rangeField; + } + + /** + * @param fieldForRange + */ + public void setFieldForRange(String fieldForRange) { + this.rangeField = fieldForRange; + } + + /** + * @return + */ + public OAI_ESClient getOaiEsClient() { + return this.oaiEsClient; + } + + /** + * @param oaiEsClient + */ + public void setOaiEsClient(OAI_ESClient oaiEsClient) { + this.oaiEsClient = oaiEsClient; + } + + /** + * @param lit + * @return + */ + public ListIdentifiersType getLit(ListIdentifiersType lit) { + return lit; + } + + /** + * @return + */ + public String getDateOfObjectCreation() { + return this.dateOfObjectCreation; + } + + /** + * @param dateOfObjectCreation + */ + public void setDateOfObjectCreation(String dateOfObjectCreation) { + this.dateOfObjectCreation = dateOfObjectCreation; + } + + /** + * @param repositoryObjectURIPrefix + */ + public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { + this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; + } + + /** + * @return + */ + public String getRepositoryObjectURIPrefix() { + return this.repositoryObjectURIPrefix; + } + + /** + * @param validItem + */ + public void setIdExist(boolean validItem) { + this.idExist = validItem; + } + + /** + * @return + */ + public boolean getIdExist() { + return this.idExist; + } + + /** + * @return + */ + public String[] getIdentifierListFields() { + return this.identifierListFields; + } + + /** + * @param identifierListFields + */ + public void setIdentifierListFields(String[] identifierListFields) { + this.identifierListFields = identifierListFields; + } + + /** + * @return + */ + public String getFormatField() { + return this.formatField; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public String getFormatToFilter() { + return this.formatToFilter; + } + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @return + */ + public String getIdentifierField() { + return this.identifierField; + } + + /** + * @param identifierPrefix + */ + public void setIdentifierField(String identifierPrefix) { + this.identifierField = identifierPrefix; + } + + /** + * @return + */ + public int getSearchResponseSize() { + return this.searchResponseSize; + } + + /** + * @param searchResponseSize + */ + public void setSearchResponseSize(String searchResponseSize) { + this.searchResponseSize = Integer.parseInt(searchResponseSize); + } + + /** + * @return + */ + public String getSpecField() { + return this.specField; + } + + /** + * @param specField + */ + public void setSpecField(String specField) { + this.specField = specField; + } + + /** + * @return + */ + public String getSpecFieldPrefix() { + return this.specFieldPrefix; + } + + /** + * @param specFieldPrefix + */ + public void setSpecFieldPrefix(String specFieldPrefix) { + this.specFieldPrefix = specFieldPrefix; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDATACITE.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDATACITE.java new file mode 100644 index 0000000000000000000000000000000000000000..ea7a7535dc074de0b842c06f6c3b332a8102a5ce --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDATACITE.java @@ -0,0 +1,24 @@ +package info.textgrid.middleware; + +/** + * <p> + * Class to build the Element for a ListIdentifiers request. + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + * @version 2021-07-06 + * @since 2014-02-20 + */ + +public class IdentifierListDelivererDATACITE extends IdentifierListDelivererAbstract { + + /** + * @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 IdentifierListDelivererDATACITE(boolean textgrid, boolean dariah) { + super(textgrid, dariah); + } + +} 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..6aad6aaa70261e0f106e49c816ec1f0b3f82f8a6 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java @@ -1,357 +1,31 @@ package info.textgrid.middleware; -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.SearchResponse; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -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 + * @author Stefan E. Funk, SUB Göttingen + * @version 2021-07-06 + * @since 2014-02-20 */ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { - private static org.apache.commons.logging.Log log = - LogFactory.getLog(IdentifierListDelivererDC.class); - private String datestamp; - private boolean idExist = true; - private OAI_ESClient oaiEsClient; - - private String[] identifierListFields; // Fields for the elasticsearch request - private String rangeField; // Field for the optional range query - 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 int searchResponseSize; - /** + * <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 - * @param lit - * @param set - * @return - */ - private static ListIdentifiersType setListIdentifierHeader(String datestamp, String identifier, - ListIdentifiersType lit, String set) { - - // FIXME Delete this function and check for empty set string in setListIdentifierHeaderWithSet - - HeaderType header = new HeaderType(); - header.setDatestamp(datestamp); - header.setIdentifier(identifier); - - if (set != null) { - header.getSetSpec().add(set); - } - lit.getHeader().add(header); - - return lit; - } - - /** - * To get the required values for the ListIdentifiers request this function will ask ElasticSearch - * for a specific textgridUri the values "created" and "textgridUri". - * - * 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 - * - * @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 - */ - public ListIdentifiersType processIdentifierList(String from, String to, String set, - String resumptionToken) { - - // FIXME combine it with with getIdentifierListWithSet and check for empty set - - ListIdentifiersType lit = new ListIdentifiersType(); - QueryBuilder query = setOrNot(set, from, to); - SearchResponse listListIdentiferValues; - - if (resumptionToken != null) { - listListIdentiferValues = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(new TimeValue(lifeTimeResToken)).execute().actionGet(); - } 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(); - } - listListIdentiferValues = - hitHandling(listListIdentiferValues, lit, set, listListIdentiferValues.getScrollId()); - - return lit; - } - - /** - * @param listFurtherValues - * @param lit - * @param set - * @param resumptionToken - * @return - */ - public SearchResponse hitHandling(SearchResponse listFurtherValues, ListIdentifiersType lit, - String set, String resumptionToken) { - - int i = 0; - for (SearchHit hit : listFurtherValues.getHits().getHits()) { - i++; - if (this.textgrid) { - - String datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); - try { - datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat(); - } catch (ParseException e1) { - log.debug(e1); - } catch (DatatypeConfigurationException e1) { - log.debug(e1); - } - String identifier = hit.getFields().get(this.identifierField).getValue().toString(); - - lit = setListIdentifierHeader(datestamp, identifier, lit, set); - } - - if (this.dariah) { - - this.datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); - - try { - this.datestamp = hit.getFields().get(this.dateOfObjectCreation).getValue().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(); - lit = setListIdentifierHeader(this.datestamp, identifier, lit, set); - } - } - - // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( - listFurtherValues.getHits().getTotalHits(), resumptionToken, cursorCollector, - listFurtherValues.getScrollId(), this.searchResponseSize, i); - if (resTokenForResponse != null) { - lit.setResumptionToken(resTokenForResponse); - } - - return listFurtherValues; - } - - /** - * @param set - * @param from - * @param to - * @return - */ - public QueryBuilder setOrNot(String set, String from, String to) { - - String filterFormat = ""; - if (this.textgrid == true) { - filterFormat = TextGridMimetypes.EDITION; - } else { - filterFormat = TextGridMimetypes.DARIAH_COLLECTION; - } - - QueryBuilder rangeQuery = QueryBuilders.rangeQuery(this.rangeField).from(from).to(to); - QueryBuilder formatQuery = QueryBuilders.matchPhrasePrefixQuery("format", filterFormat); - QueryBuilder query; - - if (set != null) { - String queryField = ""; - String valueField = ""; - - if (this.dariah == true) { - queryField = "descriptiveMetadata.dc:relation"; - valueField = set; - } - - if (this.textgrid == true) { - String[] setParts = set.split(":"); - if (setParts[0].equals("project")) { - queryField = "project.id"; - valueField = setParts[1]; - } - } - - QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); - if (this.dariah) { - query = matchQuery; - } else { - query = QueryBuilders.boolQuery().must(matchQuery).must(formatQuery); - } - - } else { - if (this.dariah == true) - query = rangeQuery; - else - query = QueryBuilders.boolQuery().must(rangeQuery).must(formatQuery); - } - - return query; - } - - /** - * @param lit - * @return - */ - public ListIdentifiersType getLit(ListIdentifiersType lit) { - return lit; - } - - /** - * @return - */ - public String getDateOfObjectCreation() { - return this.dateOfObjectCreation; - } - - /** - * @param dateOfObjectCreation - */ - public void setDateOfObjectCreation(String dateOfObjectCreation) { - this.dateOfObjectCreation = dateOfObjectCreation; - } - - /** - * @param repositoryObjectURIPrefix - */ - public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { - this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; - } - - /** - * @return - */ - public String getRepositoryObjectURIPrefix() { - return this.repositoryObjectURIPrefix; - } - - /** - * @param validItem - */ - public void setIdExist(boolean validItem) { - this.idExist = validItem; - } - - /** - * @return - */ - public boolean getIdExist() { - return this.idExist; - } - - /** - * @return - */ - public String[] getIdentifierListFields() { - return this.identifierListFields; - } - - /** - * @param identifierListFields - */ - public void setIdentifierListFields(String[] identifierListFields) { - this.identifierListFields = identifierListFields; - } - - /** - * @return - */ - public String getFieldForRange() { - return this.rangeField; - } - - /** - * @param fieldForRange - */ - public void setFieldForRange(String fieldForRange) { - this.rangeField = fieldForRange; - } - - /** - * @return - */ - public String getIdentifierField() { - return this.identifierField; - } - - /** - * @param identifierPrefix - */ - public void setIdentifierField(String identifierPrefix) { - this.identifierField = identifierPrefix; - } - - /** - * @return - */ - public int getSearchResponseSize() { - return this.searchResponseSize; - } - - /** - * @param searchResponseSize - */ - public void setSearchResponseSize(String searchResponseSize) { - this.searchResponseSize = Integer.parseInt(searchResponseSize); - } - - /** - * @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/IdentifierListDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java index 6cd8567271dfb0e7336e8528f3a52337e06f6ae3..63cb57318dcdb95ced2c791c481dba87b94a6cd9 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java @@ -1,17 +1,20 @@ package info.textgrid.middleware; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import org.classicmayan.tools.Queries; +import java.io.IOException; +import java.text.ParseException; +import org.apache.commons.logging.Log; +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.client.RequestOptions; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.QueryBuilder; - +import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.search.SearchHit; - +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.json.JSONObject; import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; @@ -20,8 +23,8 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; */ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract { - static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - private boolean foundItems; + private static Log log = LogFactory.getLog(IdentifierListDelivererIDIOM.class); + /** * @param textgrid * @param dariah @@ -37,82 +40,99 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac * String, java.lang.String, java.lang.String, java.lang.String) */ public ListIdentifiersType processIdentifierList(final String from, final String to, - final String set, final String resumptionToken) { - - String resTokenValue = resumptionToken; - - QueryBuilder recordFilterForClassicMayan; - QueryBuilder rangeQuery; - - rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); - recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery) - .must(QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) - .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) - .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); - + final String set, final String resumptionToken) throws ParseException, IOException { + + // String resTokenValue = resumptionToken; + ListIdentifiersType identifierList = new ListIdentifiersType(); - //List<String> artefactURIs = new ArrayList<String>(); - //Queries queries = new Queries(); - + + BoolQueryBuilder recordFilterForClassicMayan; + RangeQueryBuilder rangeQuery; + + rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); + + recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery) + .must(QueryBuilders.matchPhraseQuery("project.id", + "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) + .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) + .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); + + + // List<String> artefactURIs = new ArrayList<String>(); + // Queries queries = new Queries(); + SearchResponse scrollResp; - - if (resumptionToken == null) { - //artefactURIs = queries.getArtefactList(0); - - scrollResp = OAI_ESClient.getOaiESClient() - .prepareSearch("textgrid-nonpublic") - .setScroll(TimeValue.timeValueHours(24L)) - .setTypes(OAI_ESClient.getEsType()) - .addFields("lastModified", "textgridUri", "project.id") - .setQuery(recordFilterForClassicMayan) - .setSize(30) - .execute() - .actionGet(); - - // Create resumption token for every request only (we do need the same token for resuming - // because we are using a hash map for counting the calls). - //resTokenValue = UUID.randomUUID().toString(); + + SearchRequest searchRequest = new SearchRequest("textgrid-nonpublic"); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + + scrollResp = null; + + searchSourceBuilder.query(recordFilterForClassicMayan); + searchSourceBuilder.size(30); + searchRequest.source(searchSourceBuilder); + + if (resumptionToken != null) { + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueHours(24L)); + try { + scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } else { // Use given resumption token here. - scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueHours(24L)); + try { + scrollResp = OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // scrollResp = OAI_ESClient.getEsClient().prepareSearchScroll(resumptionToken) + // .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); } - String scrollID = scrollResp.getScrollId(); - - long completeListSize = scrollResp.getHits().totalHits(); - - //long listSize = Queries.getAmountOfArtefacts(); - if (completeListSize > 0) { - setFoundItems(true); - int i = 0; - - for (SearchHit hit : scrollResp.getHits().getHits()) { - i++; - String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); - identifierList.getHeader() - .add(idiomRecord.getRecordById(textgridURI).getRecord().getHeader()); - } - - // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, - resumptionToken, cursorCollector, scrollID, 30, i); - if (resTokenForResponse != null) { - identifierList.setResumptionToken(resTokenForResponse); - } - }else { - setFoundItems(false); - } + String scrollID = scrollResp.getScrollId(); + + long completeListSize = scrollResp.getHits().totalHits; + + // long listSize = Queries.getAmountOfArtefacts(); + if (completeListSize > 0) { + setFoundItems(true); + int i = 0; + + for (SearchHit hit : scrollResp.getHits().getHits()) { + i++; + String textgridURI = + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), "textgridUri"); + // hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); + + log.debug("TextGrid URI: " + textgridURI); + + RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); + + identifierList.getHeader() + .add(idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord().getHeader()); + } + /* + * for (String artefactURI : artefactURIs) { RecordDelivererIDIOM idiomRecord = new + * RecordDelivererIDIOM(true, false); identifierList.getHeader() + * .add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader()); i++; } + */ + + // Check the need for a resumption token! + ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, + resumptionToken, cursorCollector, scrollID, 30, i); + if (resTokenForResponse != null) { + identifierList.setResumptionToken(resTokenForResponse); + } + } else { + setFoundItems(false); + } return identifierList; } - - public boolean isFoundItems() { - return foundItems; - } - - public void setFoundItems(boolean foundItems) { - this.foundItems = foundItems; - } } 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 deleted file mode 100644 index 6f43397e45deb2dfea88839daab401e6f5acc8ea..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDeliverer.java +++ /dev/null @@ -1,112 +0,0 @@ -package info.textgrid.middleware; - -import org.elasticsearch.action.get.GetRequestBuilder; -import org.elasticsearch.action.get.GetResponse; -import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; -import info.textgrid.middleware.oaipmh.MetadataFormatType; -import info.textgrid.middleware.oaipmh.RequestType; - -/** - * - */ -public class MetadataFormatListDeliverer { - - private boolean idExist = true; - - /** - * - */ - public MetadataFormatListDeliverer() { - // - } - - /** - * @param id - * @return - */ - public ListMetadataFormatsType setMetadataFormatList(String id) { - - 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(); - - if (tgObject.isExists()) { - setIdExist(true); - mft.setMetadataPrefix(TGConstants.METADATA_DC_PREFIX); - mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); - mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); - lmft.getMetadataFormat().add(mft); - } else { - setIdExist(false); - lmft = null; - } - - return lmft; - } - - /** - * @return - */ - public ListMetadataFormatsType setMetadataFormatListWithoutId() { - - ListMetadataFormatsType lmft = new ListMetadataFormatsType(); - MetadataFormatType mft = new MetadataFormatType(); - MetadataFormatType mftIdiomMets = new MetadataFormatType(); - - mft.setMetadataPrefix(TGConstants.METADATA_DC_PREFIX); - mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); - mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); - lmft.getMetadataFormat().add(mft); - - mftIdiomMets.setMetadataPrefix(TGConstants.METADATA_IDIOM_PREFIX); - mftIdiomMets.setMetadataNamespace(OAIPMHUtilities.METS_NAMESPACE); - mftIdiomMets.setSchema(OAIPMHUtilities.METS_SCHEMA_LOCATION); - lmft.getMetadataFormat().add(mftIdiomMets); - - return lmft; - } - - /** - * @param request - * @return - */ - public boolean requestChecker(RequestType request) { - - boolean requestCheck = true; - - if (request.getFrom() != null || - request.getMetadataPrefix() != null || - request.getResumptionToken() != null) { - - requestCheck = false; - - } else if (request.getSet() != null || - request.getUntil() != null) { - requestCheck = false; - } - - return requestCheck; - } - - /** - * @return - */ - public boolean isIdExist() { - return this.idExist; - } - - /** - * @param idExist - */ - public void setIdExist(boolean idExist) { - this.idExist = idExist; - } - -} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java new file mode 100644 index 0000000000000000000000000000000000000000..57b99df694dc68ab1d053e017fdb8f7a3612a36a --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java @@ -0,0 +1,94 @@ +package info.textgrid.middleware; + +import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; +import info.textgrid.middleware.oaipmh.MetadataFormatType; +import info.textgrid.middleware.oaipmh.RequestType; + +/** + * + */ +public abstract class MetadataFormatListDelivererAbs + implements MetadataFormatListDelivererInterface { + + // + // CLASS + // + + private boolean idExist = true; + + /** + * @param textgrid + * @param dariah + */ + public MetadataFormatListDelivererAbs() { + // + } + + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.MetadataFormatListDelivererInterface#setMetadataFormatList() + */ + public ListMetadataFormatsType setMetadataFormatList() { + + ListMetadataFormatsType result = new ListMetadataFormatsType(); + + // Add default metadata format (oai_dc). + MetadataFormatType mft = new MetadataFormatType(); + mft.setMetadataPrefix(OAIPMHUtilities.OAIDC_PREFIX); + mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); + mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); + result.getMetadataFormat().add(mft); + + // Add metadata format for OPEN AIRE. + MetadataFormatType mftOpenAire = new MetadataFormatType(); + mftOpenAire.setMetadataNamespace(OAIPMHUtilities.OPEN_AIRE_NAMESPACE); + mftOpenAire.setMetadataPrefix(OAIPMHConstants.METADATA_OPENAIRE_PREFIX); + mftOpenAire.setSchema(OAIPMHUtilities.OPEN_AIRE_SCHEMA_LOCATION); + result.getMetadataFormat().add(mftOpenAire); + + return result; + } + + /* + * (non-Javadoc) + * + * @see + * info.textgrid.middleware.MetadataFormatListDelivererInterface#requestChecker(info.textgrid. + * middleware.oaipmh.RequestType) + */ + public boolean requestChecker(RequestType request) { + + boolean requestCheck = true; + + if (request.getFrom() != null + || request.getMetadataPrefix() != null + || request.getResumptionToken() != null) { + requestCheck = false; + } else if (request.getSet() != null + || request.getUntil() != null) { + requestCheck = false; + } + + return requestCheck; + } + + // + // GETTERS & SETTERS + // + + /** + * @return + */ + public boolean isIdExist() { + return this.idExist; + } + + /** + * @param idExist + */ + public void setIdExist(boolean idExist) { + this.idExist = idExist; + } + +} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java new file mode 100644 index 0000000000000000000000000000000000000000..f609e84675304ff600dc391428ad4105725b9404 --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java @@ -0,0 +1,30 @@ +package info.textgrid.middleware; + +import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; + +/** + * + */ +public class MetadataFormatListDelivererDH extends MetadataFormatListDelivererAbs { + + /** + * @param textgrid + * @param dariah + */ + public MetadataFormatListDelivererDH() { + // NOTE We do not have specific metadata formats for DHREP right now. + } + + /* + * (non-Javadoc) + * + * @see + * info.textgrid.middleware.MetadataFormatListDelivererInterface#setMetadataFormatList(java.lang. + * String) + */ + public ListMetadataFormatsType setMetadataFormatList(String id) { + // Get things from abstract class. + return super.setMetadataFormatList(); + } + +} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..3e373e85dd1a5a88d8789a528e1593220649be84 --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererInterface.java @@ -0,0 +1,28 @@ +package info.textgrid.middleware; + +import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; +import info.textgrid.middleware.oaipmh.RequestType; + +/** + * + */ +public interface MetadataFormatListDelivererInterface { + + /** + * @param id + * @return + */ + public ListMetadataFormatsType setMetadataFormatList(String id); + + /** + * @return + */ + public ListMetadataFormatsType setMetadataFormatList(); + + /** + * @param request + * @return + */ + public boolean requestChecker(RequestType request); + +} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java new file mode 100644 index 0000000000000000000000000000000000000000..6667695c347ee0f7508d26e13b5de2325fa3454a --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java @@ -0,0 +1,93 @@ +package info.textgrid.middleware; + +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; + +/** + * + */ +public class MetadataFormatListDelivererTG extends MetadataFormatListDelivererAbs { + + /** + * + */ + public MetadataFormatListDelivererTG() { + // + } + + /* + * (non-Javadoc) + * + * @see + * info.textgrid.middleware.MetadataFormatListDelivererInterface#setMetadataFormatList(java.lang. + * String) + */ + 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(); + MetadataFormatType openAireMetadataFormat = new MetadataFormatType(); + + GetRequest getRequest = new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), + id.replace("textgrid:", "")).fetchSourceContext(fetchSourceContext); + + 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(OAIPMHUtilities.OAIDC_PREFIX); + mft.setMetadataNamespace(OAIPMHUtilities.OAIDC_NAMESPACE); + mft.setSchema(OAIPMHUtilities.OAIDC_SCHEMA_LOCATION); + + openAireMetadataFormat.setMetadataPrefix(OAIPMHConstants.METADATA_OPENAIRE_PREFIX); + openAireMetadataFormat.setMetadataNamespace(OAIPMHUtilities.OPEN_AIRE_NAMESPACE); + openAireMetadataFormat.setSchema(OAIPMHUtilities.OPEN_AIRE_SCHEMA_LOCATION); + + lmft.getMetadataFormat().add(mft); + lmft.getMetadataFormat().add(openAireMetadataFormat); + + } else { + setIdExist(false); + lmft = null; + } + + return lmft; + } + + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.MetadataFormatListDelivererAbs#setMetadataFormatList() + */ + public ListMetadataFormatsType setMetadataFormatList() { + + // Get things from abstract class. + ListMetadataFormatsType result = super.setMetadataFormatList(); + + // Add metadata format for IDIOM. + MetadataFormatType mftIdiomMets = new MetadataFormatType(); + mftIdiomMets.setMetadataPrefix(OAIPMHConstants.METADATA_IDIOM_PREFIX); + mftIdiomMets.setMetadataNamespace(OAIPMHUtilities.METS_NAMESPACE); + mftIdiomMets.setSchema(OAIPMHUtilities.METS_SCHEMA_LOCATION); + result.getMetadataFormat().add(mftIdiomMets); + + return result; + } + +} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHConstants.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..f4241cd52f204fb679a6b7fb5ed3f647b31a8101 --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHConstants.java @@ -0,0 +1,83 @@ +package info.textgrid.middleware; + +/** + * <p> + * Collection of values never changing its content. + * </p> + * + * @author Maximilian Brodhun, SUB Göttingen + */ + +public final class OAIPMHConstants { + + // ** + // GENERAL CONSTANTS + // ** + + public static final String URI_IDENTIIER_TYPE = "URI"; + + // Metadata Prefixes + public static final String METADATA_IDIOM_PREFIX = "oai_idiom_mets"; + public static final String METADATA_OPENAIRE_PREFIX = "oai_datacite"; + + // 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"; + + // ** + // DARIAH CONSTANTS + // ** + + public static final String REPOSITORY_BASEURL = "repository.de.dariah.eu"; + + // For testing only. + // TODO Run tests with real configuration, we changed a lot currently! + public static final String TEST_DARIAH_ITEM_IDENTIFIER_PREFIX = "hdl:"; + public static final String TEST_DARIAH_COLLECTIONREGISTRY_PREFIX = "dariah:collection:"; + public static final String TEST_DARIAH_COLLECTION_MIMETYPE = + "text/vnd.dariah.dhrep.collection+turtle"; + + // DARIAH Metadata Fields for OAI-PMH Request (Mapping to DC) + public static final String TEST_DARIAH_CREATED = "descriptiveMetadata.dc:date"; + public static final String TEST_DARIAH_FORMAT = "descriptiveMetadata.dc:format"; + public static final String TEST_DARIAH_IDENTIFIER = "administrativeMetadata.dcterms:identifier"; + public static final String[] TEST_DARIAH_FIELDS = + {"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"}; + + // String Arrays to define which TextGrid fields belongs to the regarding DC fields + public static final String[] TEST_DARIAH_CONTRIBUTOR_LIST = + {"descriptiveMetadata.dc:contributor"}; + public static final String[] TEST_DARIAH_COVERAGE_LIST = {"descriptiveMetadata.dc:coverage"}; + public static final String[] TEST_DARIAH_CREATOR_LIST = {"descriptiveMetadata.dc:cretor"}; + public static final String[] TEST_DARIAH_DATE_LIST = {"administrativeMetadata.dcterms:modified"}; + public static final String[] TEST_DARIAH_DESCRIPTION_LIST = + {"descriptiveMetadata.dc:description"}; + public static final String[] TEST_DARIAH_FORMAT_LIST = {"descriptiveMetadata.dc:format"}; + public static final String[] TEST_DARIAH_IDENTIFIER_LIST = {"descriptiveMetadata.dc:identifier"}; + public static final String[] TEST_DARIAH_LANGUAGE_LIST = {"descriptiveMetadata.dc:language"}; + public static final String[] TEST_DARIAH_PUBLISHER_LIST = {"descriptiveMetadata.dc:publisher"}; + public static final String[] TEST_DARIAH_RELATIONS_LIST = {"descriptiveMetadata.dc:relation"}; + public static final String[] TEST_DARIAH_RIGHTS_LIST = {"descriptiveMetadata.dc:rights"}; + public static final String[] TEST_DARIAH_SOURCE_LIST = {"descriptiveMetadata.dc:source"}; + public static final String[] TEST_DARIAH_SUBJECT_LIST = {"descriptiveMetadata.dc:subject"}; + public static final String[] TEST_DARIAH_TITLE_LIST = {"descriptiveMetadata.dc:title"}; + public static final String[] TEST_DARIAH_TYPE_LIST = {"descriptiveMetadata.dc:type"}; + public static final String[] TEST_DARIAH_IDENTIFIER_LIST_FIELDS = + {"administrativeMetadata.dcterms:identifier", "administrativeMetadata.dcterms:modified", + "descriptiveMetadata.dc:identifier", "descriptiveMetadata.dc:date", + "descriptiveMetadata.dc:format"}; + public static final String TEST_DARIAH_RANGE_FIELD = "administrativeMetadata.dcterms:modified"; + public static final String TEST_DARIAH_MODIFIED_FIELD = "administrativeMetadata.dcterms:modified"; +} 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 1a31c6115a8ae5e188cab871cc1b0cacaeaad94e..e03760b5f9c00256e6b6a0a86a74675695090a92 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -32,11 +32,13 @@ import info.textgrid.middleware.oaipmh.VerbType; * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2019-10-29 + * @version 2021-07-12 * @since 2014-01-29 */ public class OAIPMHImpl implements OAIPMHProducer { + // NOTE Changed OpenAireIdentifierList into IdentifierListDelivererDATACITE! + // ** // STATICS // ** @@ -50,17 +52,24 @@ public class OAIPMHImpl implements OAIPMHProducer { private ErrorHandler error = new ErrorHandler(); private Log log = LogFactory.getLog(OAIPMHImpl.class); private RepIdentification rep; + private RecordListDelivererDC recordListDC; private RecordListDelivererIDIOM recordListIDIOM; + // private OpenAireRecordList openAireRecordList; + private RecordListDelivererDATACITE recordListDATACITE; - private RecordDelivererDC recDelivDC; - private RecordDelivererIDIOM recDelivIDIOM; + private RecordDelivererDC recordDC; + private RecordDelivererIDIOM recordIDIOM; + // private OpenAireRecord openAireRecord; + private RecordDelivererDATACITE recordDATACITE; private IdentifierListDelivererDC identifierListDC; private IdentifierListDelivererIDIOM identifierListIDIOM; + // private OpenAireIdentifierList openAireIdentifierList; + private IdentifierListDelivererDATACITE identifierListDATACITE; - private MetadataFormatListDeliverer metadataFormatList; - private SetDeliverer setList; + private MetadataFormatListDelivererInterface metadataFormatList; + private SetListDeliverer setList; // ** // PUBLIC @@ -71,29 +80,58 @@ public class OAIPMHImpl implements OAIPMHProducer { /** * @param rep - * @param recDelivDC - * @param recDelivIDIOM + * @param recordDC + * @param recordIDIOM + * @param recordDATACITE * @param recordListDC * @param recordListIDIOM + * @param recordListDATACITE * @param metadataFormatList * @param setList * @param identifierList * @param identifierListIDIOM + * @param identifierListDATACITE */ - public OAIPMHImpl(RepIdentification rep, RecordDelivererDC recDelivDC, - RecordDelivererIDIOM recDelivIDIOM, RecordListDelivererDC recordListDC, - RecordListDelivererIDIOM recordListIDIOM, MetadataFormatListDeliverer metadataFormatList, - SetDeliverer setList, IdentifierListDelivererDC identifierList, - IdentifierListDelivererIDIOM identifierListIDIOM) { + public OAIPMHImpl( + RepIdentification rep, // 0 + RecordDelivererDC recordDC, // 1 + RecordDelivererIDIOM recordIDIOM, // 2 + // OpenAireRecord openAireRecord, // 3 + RecordDelivererDATACITE recordDATACITE, // 3 + RecordListDelivererDC recordListDC, // 4 + RecordListDelivererIDIOM recordListIDIOM, // 5 + // OpenAireRecordList openAireRecordList, // 6 + RecordListDelivererDATACITE recordListDATACITE, // 6 + MetadataFormatListDelivererInterface metadataFormatList, // 7 + SetListDeliverer setList, // 8 + IdentifierListDelivererDC identifierList, // 9 + IdentifierListDelivererIDIOM identifierListIDIOM, // 10 + // OpenAireIdentifierList openAireIdentifierList // 11 + IdentifierListDelivererDATACITE identifierListDATACITE // 11 + ) { this.rep = rep; - this.recDelivDC = recDelivDC; - this.recDelivIDIOM = recDelivIDIOM; + + this.recordDC = recordDC; + this.recordIDIOM = recordIDIOM; + // this.openAireRecord = openAireRecord; + this.recordDATACITE = recordDATACITE; + this.recordListDC = recordListDC; this.recordListIDIOM = recordListIDIOM; - this.metadataFormatList = metadataFormatList; - this.setList = setList; + // this.openAireRecordList = openAireRecordList; + this.recordListDATACITE = recordListDATACITE; + this.identifierListDC = identifierList; this.identifierListIDIOM = identifierListIDIOM; + // this.openAireIdentifierList = openAireIdentifierList; + this.identifierListDATACITE = identifierListDATACITE; + + this.metadataFormatList = metadataFormatList; + + this.log + .debug("MetadataFormatList implementing class: " + metadataFormatList.getClass().getName()); + + this.setList = setList; } /* @@ -102,15 +140,27 @@ public class OAIPMHImpl implements OAIPMHProducer { * @see info.textgrid.middleware.OAIPMHProducer#postRequest(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ - public String postRequest(String verb, String identifier, String metadataPrefix, String set, - String from, String until, String resumptionToken) { + public String postRequest(final String verb, final String identifier, final String metadataPrefix, + final String set, final String from, final String until, final String resumptionToken) { String result = ""; + // Check IDs. + String checkedID = OAIPMHUtilities.omitPrefixFromIdentifier(identifier); + String checkedSET = OAIPMHUtilities.omitPrefixFromIdentifier(set); + try { result = getStringFromJAXBOAIElement(verb, - handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken)); - } catch (ParseException e) { + handleRequest( + verb, + checkedID, + metadataPrefix, + checkedSET, + from, + until, + resumptionToken)); + + } catch (ParseException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -124,15 +174,27 @@ public class OAIPMHImpl implements OAIPMHProducer { * @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ - public String getRequest(String verb, String identifier, String metadataPrefix, - String set, String from, String until, String resumptionToken) { + public String getRequest(final String verb, final String identifier, final String metadataPrefix, + final String set, final String from, final String until, final String resumptionToken) { String result = ""; + // Check IDs. + String checkedID = OAIPMHUtilities.omitPrefixFromIdentifier(identifier); + String checkedSET = OAIPMHUtilities.omitPrefixFromIdentifier(set); + try { result = getStringFromJAXBOAIElement(verb, - handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken)); - } catch (ParseException e) { + handleRequest( + verb, + checkedID, + metadataPrefix, + checkedSET, + from, + until, + resumptionToken)); + + } catch (ParseException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -194,7 +256,7 @@ public class OAIPMHImpl implements OAIPMHProducer { errorValues.add("Set"); } - this.error.setError(TGConstants.OAI_BAD_ARGUMENT, + this.error.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments: " + errorValues); oaipmhRoot.getError().add(this.error.getError()); } @@ -227,25 +289,38 @@ public class OAIPMHImpl implements OAIPMHProducer { else { // Default is DC. - RecordDelivererInterface recDeliv = this.recDelivDC; + RecordDelivererInterface recDeliv = this.recordDC; // Take IDIOM if IDIOM prefix. - if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - recDeliv = this.recDelivIDIOM; + if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX)) { + recDeliv = this.recordIDIOM; + } + if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + recDeliv = this.recordDATACITE; } // Finally start the QUERY! 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(); + } catch (IOException 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"); + idError.setError(OAIPMHConstants.OAI_ID_DOES_NOT_EXIST, "No matching identifier "); oaipmhRoot.getError().add(idError.getError()); } } @@ -276,10 +351,13 @@ 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 { + } else if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX)) { idListDeliv = this.identifierListIDIOM; + } else if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + // idListDeliv = this.openAireIdentifierList; + idListDeliv = this.identifierListDATACITE; } } @@ -291,21 +369,36 @@ public class OAIPMHImpl implements OAIPMHProducer { boolean restokIDIOMExisting = IdentifierListDelivererIDIOM.cursorCollector != null && IdentifierListDelivererIDIOM.cursorCollector .containsKey(request.getResumptionToken()); + boolean restokOpenAireExisting = OAIPMHUtilities.cursorCollector != null + && IdentifierListDelivererAbstract.cursorCollector + .containsKey(request.getResumptionToken()); if (restokDCExisting) { idListDeliv = this.identifierListDC; } else if (restokIDIOMExisting) { idListDeliv = this.identifierListIDIOM; + } else if (restokOpenAireExisting) { + // idListDeliv = this.openAireIdentifierList; + idListDeliv = this.identifierListDATACITE; } } - ListIdentifiersType listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(), - request.getUntil(), request.getSet(), request.getResumptionToken()); + ListIdentifiersType listIdentifiers = null; + try { + this.log.debug("GET FROM: " + request.getFrom()); + this.log.debug("GET UNTIL: " + request.getUntil()); + + 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); } else { ErrorHandler idError = new ErrorHandler(); - idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " + idError.setError(OAIPMHConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " + request.getIdentifier() + " is unknown or illegal in this repository"); oaipmhRoot.getError().add(idError.getError()); } @@ -328,38 +421,34 @@ public class OAIPMHImpl implements OAIPMHProducer { ListSetsType sl = this.setList.setListBuilder(); - if (this.setList.requestChecker(request)) { - oaipmhRoot.setListSets(sl); - }else { - List<String> errorValues = new ArrayList<String>(); - ErrorHandler badArgument = new ErrorHandler(); - if (request.getIdentifier() != null) { - errorValues.add("identifier"); - } - if (request.getFrom() != null) { - errorValues.add("from"); - } - if (request.getMetadataPrefix() != null) { - errorValues.add("metadataPrefix"); - } - if (request.getResumptionToken() != null) { - errorValues.add("ResumptionToken"); - } - if (request.getUntil() != null) { - errorValues.add("until"); - } - if (request.getSet() != null) { - errorValues.add("set"); - } - - badArgument.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments: " + errorValues); - oaipmhRoot.getError().add(badArgument.getError()); - } + oaipmhRoot.setListSets(sl); + } else { + List<String> errorValues = new ArrayList<String>(); + ErrorHandler badArgument = new ErrorHandler(); + if (request.getIdentifier() != null) { + errorValues.add("identifier"); + } + if (request.getFrom() != null) { + errorValues.add("from"); + } + if (request.getMetadataPrefix() != null) { + errorValues.add("metadataPrefix"); + } + if (request.getResumptionToken() != null) { + errorValues.add("ResumptionToken"); + } + if (request.getUntil() != null) { + errorValues.add("until"); + } + if (request.getSet() != null) { + errorValues.add("set"); + } - - - + badArgument.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, + "The request includes illegal arguments: " + errorValues); + oaipmhRoot.getError().add(badArgument.getError()); + } return oaipmhRoot; } @@ -373,13 +462,16 @@ public class OAIPMHImpl implements OAIPMHProducer { public OAIPMHtype listMetadataFormatsRequest(String id, OAIPMHtype oaipmhRoot, RequestType request) { + this.log.debug("request: " + request.getValue()); + this.log.debug("id: " + id); + List<String> errorValues = new ArrayList<String>(); ListMetadataFormatsType listMF = new ListMetadataFormatsType(); if (this.metadataFormatList.requestChecker(request)) { if (id.isEmpty()) { - listMF = this.metadataFormatList.setMetadataFormatListWithoutId(); + listMF = this.metadataFormatList.setMetadataFormatList(); } else { listMF = this.metadataFormatList.setMetadataFormatList(request.getIdentifier()); } @@ -387,7 +479,7 @@ public class OAIPMHImpl implements OAIPMHProducer { if (listMF != null) { oaipmhRoot.setListMetadataFormats(listMF); } else { - this.error.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " + this.error.setError(OAIPMHConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " + request.getIdentifier() + " is unknown or illegal in this repository"); oaipmhRoot.getError().add(this.error.getError()); } @@ -411,7 +503,7 @@ public class OAIPMHImpl implements OAIPMHProducer { errorValues.add("until"); } - this.error.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal " + this.error.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, "The request includes illegal " + "arguments or is missing required arguments: " + errorValues); oaipmhRoot.getError().add(this.error.getError()); } @@ -423,8 +515,11 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param oai * @param request * @return + * @throws ParseException + * @throws IOException */ - public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) { + public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) + throws ParseException, IOException { // Check request's syntax. ErrorHandler requestErrors = RecordListDelivererAbstract.requestChecker(request); @@ -436,11 +531,15 @@ 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 { + } + if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX)) { recListDeliv = this.recordListIDIOM; } + if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + recListDeliv = this.recordListDATACITE; + } } // If metadata format IS NOT SET, check resumption token hash maps to decide if we have to @@ -450,20 +549,34 @@ public class OAIPMHImpl implements OAIPMHProducer { && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); - + + boolean restokOpenAireExisting = RecordListDelivererAbstract.cursorCollector != null + && RecordListDelivererAbstract.cursorCollector + .containsKey(request.getResumptionToken()); + if (restokDCExisting) { recListDeliv = this.recordListDC; } else if (restokIDIOMExisting) { - recListDeliv = this.recordListIDIOM; + } else if (restokOpenAireExisting) { + recListDeliv = this.recordListDATACITE; } } - ListRecordsType listRecords = recListDeliv.getRecords(request.getFrom(), request.getUntil(), - request.getSet(), request.getResumptionToken()); + ListRecordsType listRecords = recListDeliv.getRecords( + request.getFrom(), + request.getUntil(), + request.getSet(), + request.getResumptionToken()); if (listRecords != null) { + /* + * 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); + // } } } @@ -472,7 +585,7 @@ public class OAIPMHImpl implements OAIPMHProducer { /** * <p> - * Taking the sting from the REST request and converting into an OAIPMH verb type. + * Taking the string from the REST request and converting into an OAIPMH verb type. * </p> * * @param verb : what is to within the repository @@ -482,10 +595,6 @@ public class OAIPMHImpl implements OAIPMHProducer { VerbType verbParam = null; - if (verb == null) { - verb = "Identify"; - } - if (verb != null && verb.equals("Identify")) { verbParam = VerbType.IDENTIFY; } else if (verb != null && verb.equals("ListMetadataFormats")) { @@ -498,9 +607,13 @@ public class OAIPMHImpl implements OAIPMHProducer { verbParam = VerbType.LIST_RECORDS; } 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(OAIPMHConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + } + // Verb not set --> please do use verb=Identify! + // FIXME Is the following appropriate?? Do we miss any error messages that way?? + else { + verbParam = VerbType.IDENTIFY; } return verbParam; @@ -613,10 +726,11 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param resumptionToken * @return * @throws ParseException + * @throws IOException */ private JAXBElement<OAIPMHtype> handleRequest(String verb, String identifier, String metadataPrefix, String set, String from, String until, String resumptionToken) - throws ParseException { + throws ParseException, IOException { JAXBElement<OAIPMHtype> result; @@ -646,10 +760,10 @@ public class OAIPMHImpl implements OAIPMHProducer { request.setVerb(verbParam); if (this.textgrid == true) { - request.setValue(TGConstants.TG_REP_BASEURL); + request.setValue(TGConstants.REPOSITORY_BASEURL); } if (this.dariah == true) { - request.setValue(DARIAHConstants.DARIAH_REP_BASEURL); + request.setValue(OAIPMHConstants.REPOSITORY_BASEURL); } if (verbParam != null) { @@ -667,8 +781,14 @@ public class OAIPMHImpl implements OAIPMHProducer { response = listRecordsRequest(response, request); } } else { - this.error.setError("VerbError", "Illegal OAI verb"); - response.getError().add(this.error.getError()); + if (this.error.getError().getValue() != null + && this.error.getError().getValue().equals("Illegal OAI verb")) { + this.error.setError(OAIPMHConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + } else { + this.error.setError(OAIPMHConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + } } response.setRequest(request); @@ -687,7 +807,7 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param theJAXBOAIElement * @return */ - private static String getStringFromJAXBOAIElement(final String theVerb, + public static String getStringFromJAXBOAIElement(final String theVerb, final JAXBElement<OAIPMHtype> theJAXBOAIElement) { String result = ""; @@ -695,18 +815,25 @@ public class OAIPMHImpl implements OAIPMHProducer { // Always add OAIPMH schema location. 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; + + // Add the openaire datacite schemas as well, please. schemaLocations += - OAIPMHUtilities.OAIDC_NAMESPACE + " " + OAIPMHUtilities.OAIDC_SCHEMA_LOCATION + - " " + OAIPMHUtilities.DC_NAMESPACE + " " + OAIPMHUtilities.DC_SCHEMA_LOCATION; + " " + OAIPMHUtilities.OPEN_AIRE_NAMESPACE + " " + OAIPMHUtilities.OAIPMH_SCHEMA_LOCATION + + " " + + OAIPMHUtilities.DATACITE_NAMESPACE + " " + OAIPMHUtilities.DATACITE_SCHEMA_LOCATION; } // PLEASE NOTE We always get oai_dc and dc prefixes defined in the root element due to the // bindings.xml file. Seems to be no problem for the time being. try { - // OBACHT! GEMOKEL! Add schemaLocations to OAI root element here! + // OBACHT! Maybe GEMOKEL! Add schemaLocations to OAI root element here! JAXBContext jc = JAXBContext.newInstance(OAIPMHtype.class); Marshaller marshaller = jc.createMarshaller(); 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 890419d4ac11403eb71c28c6171732f6044c62ed..9534300ced39e5014a1536e499568c8f3d9e3fff 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,47 @@ package info.textgrid.middleware; +import java.io.IOException; +import java.io.StringWriter; import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; import java.util.Map; +import java.util.Properties; +import java.util.Set; import java.util.TimeZone; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; +import org.apache.commons.logging.Log; 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.search.fetch.subphase.FetchSourceContext; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import info.textgrid.clients.AuthClient; +import info.textgrid.clients.tgauth.AuthClientException; +import info.textgrid.middleware.oaipmh.GetRecordType; +import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; import info.textgrid.middleware.oaipmh.MetadataFormatType; +import info.textgrid.middleware.oaipmh.MetadataType; +import info.textgrid.middleware.oaipmh.RecordType; +import info.textgrid.middleware.oaipmh.Resource; import info.textgrid.middleware.oaipmh.ResumptionTokenType; +import info.textgrid.namespaces.middleware.tgauth.ProjectInfo; /** * <p> @@ -22,11 +50,13 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; * </p> * * @author Maximilian Brodhun, SUB Göttingen - * @version 2019-10-29 + * @version 2021-07-12 * @since 2014-01-29 */ public class OAIPMHUtilities { + private static Log log = LogFactory.getLog(OAIPMHUtilities.class); + // ** // FINALS // ** @@ -34,28 +64,67 @@ 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"; + public static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/"; public static final String DC_SCHEMA_LOCATION = "https://dublincore.org/schemas/xmls/simpledc20021212.xsd"; + public static final String METS_NAMESPACE = "http://www.loc.gov/METS/"; public static final String METS_SCHEMA_LOCATION = "http://www.loc.gov/standards/mets/mets.xsd"; + public static final String OPEN_AIRE_NAMESPACE = "http://namespace.openaire.eu/oaf"; + public static final String OPEN_AIRE_SCHEMA_LOCATION = + "https://www.openaire.eu/schema/1.0/oaf-1.0.xsd"; + + public static final String DATACITE_PREFIX = "datacite"; + public static final String DATACITE_NAMESPACE = "http://datacite.org/schema/kernel-3"; + public static final String DATACITE_SCHEMA_LOCATION = + "https://schema.datacite.org/meta/kernel-3/metadata.xsd"; + + public static final String ES_DIVIDER_CHAR = "."; + public static final String ES_DIVIDER_REGEXP = "\\."; + + public static final String PREFIX_DEVIDER = ":"; + public static final String PREFIX_HDL = "hdl"; + public static final String PREFIX_TEXTGRID = "textgrid"; + public static final Set<String> IDENTIFIER_PREFIXES_TO_FILTER = new HashSet<String>(Arrays.asList( + PREFIX_HDL, + PREFIX_TEXTGRID)); + + // ** + // CLASS + // ** + + private String rangeField; + private long resultSize; + private boolean foundItems; + private String formatField; + private ResumptionTokenType resTokenForResponse; + private String formatToFilter; + private int searchResponseSize; + // ** // STATICS // ** - private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + + // private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); - - public static boolean isOAIPMH_RequestArgument(String verb){ - String allowedArgument= "^[identifier,from,until,set,resumptionToken,metadataPrefix]*$"; - return verb.matches(allowedArgument); + /** + * @param verb + * @return + */ + public static boolean isOAIPMH_RequestArgument(String verb) { + String allowedArgument = "^[identifier,from,until,set,resumptionToken,metadataPrefix]*$"; + return verb.matches(allowedArgument); } - - + /** * <p> * Since TextGrid just supports DC the only returned MetadataFormat is DublinCore. @@ -73,6 +142,29 @@ public class OAIPMHUtilities { return tgDublinCore; } + /** + * @return + * @throws AuthClientException + */ + public static List<ProjectInfo> getProjectList() throws AuthClientException { + + AuthClient auth = new AuthClient(); + List<ProjectInfo> projectInfos = auth.getAllProjects(); + auth.getAllProjects(); + + return projectInfos; + } + + /** + * @param projectID + * @return + * @throws AuthClientException + */ + public static String getProjectName(String projectID) throws AuthClientException { + AuthClient auth = new AuthClient(); + return auth.getProjectInfo(projectID).getName(); + } + /** * <p> * Producing the list of all metadata formats. @@ -121,6 +213,8 @@ public class OAIPMHUtilities { public static XMLGregorianCalendar convertDateFormat(String originalDateTimeString) throws ParseException, DatatypeConfigurationException { + log.debug("original date time string: " + originalDateTimeString); + SimpleDateFormat tgItemTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); Date date = tgItemTime.parse(originalDateTimeString); SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); @@ -168,63 +262,485 @@ public class OAIPMHUtilities { * @return A resumption token if applicable, null otherwise. */ public static ResumptionTokenType getResumptionToken(final long completeListSize, - final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, - final int searchResponseSize, final int i) { - - log.info("Creating a ResumptionToken:\n " + - "CompleteListSize: " + completeListSize + "\n" + - "ResumptionToken: " + resumptionToken + "\n" + - "CursorCollector: " + cursorCollector + "\n" + - "ScrollID: " + scrollID + "\n" + - "SearchResponseSize: " + scrollID + "\n" + - "IterationStep: " + i); - - int cursor; - - // Three cases here: - // 1. Complete list size is > searchResponseSize and a token already is existing: we need to - // check hash map! - // 2. Complete list size is > searchResponseSize and we have no token: we do need one! - // 3. Complete list size is <= searchResponseSize (we do not need a token! do nothing!) - - if (completeListSize > searchResponseSize) { - ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); - - if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { - cursor = cursorCollector.get(resumptionToken).intValue() + i; - if(cursor-searchResponseSize == 0) { - cursor *= 2; - } - resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); - cursorCollector.put(scrollID, cursor); - } else { - resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); - cursorCollector.put(scrollID, searchResponseSize); - cursor = searchResponseSize; - resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); - - } - - // Set resumption token string if cursor is less then complete list size: More objects can be - // delivered! - if (cursor < completeListSize) { - resTokenForResponse.setValue(scrollID); - } - - // Remove resumption token string if cursor is bigger then or equal complete list size: This - // is the last response, no more objects are available! - if (cursor >= completeListSize) { - //cursor =; - resTokenForResponse.setValue(""); - } - - // Set complete list size. - resTokenForResponse.setCompleteListSize(BigInteger.valueOf(completeListSize)); - - return resTokenForResponse; - } - - return null; - } + final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, + final int searchResponseSize, final int i) { + + log.debug("Creating a ResumptionToken:\n " + + "CompleteListSize: " + completeListSize + "\n" + + "ResumptionToken: " + resumptionToken + "\n" + + "CursorCollector: " + cursorCollector + "\n" + + "ScrollID: " + scrollID + "\n" + + "SearchResponseSize: " + scrollID + "\n" + + "IterationStep: " + i); + + int cursor; + + // Three cases here: + // 1. Complete list size is > searchResponseSize and a token already is existing: we need to + // check hash map! + // 2. Complete list size is > searchResponseSize and we have no token: we do need one! + // 3. Complete list size is <= searchResponseSize (we do not need a token! do nothing!) + + if (completeListSize > searchResponseSize) { + ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); + + if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { + cursor = cursorCollector.get(resumptionToken).intValue() + i; + if (cursor == 100) { + cursor = 200; + } + resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + cursorCollector.put(scrollID, cursor); + } else { + resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); + cursorCollector.put(scrollID, searchResponseSize); + cursor = 100; + resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + + } + + // Set resumption token string if cursor is less then complete list size: More objects can be + // delivered! + if (cursor < completeListSize) { + resTokenForResponse.setValue(scrollID); + } + + // Remove resumption token string if cursor is bigger then or equal complete list size: This + // is the last response, no more objects are available! + if (cursor >= completeListSize) { + resTokenForResponse.setValue(""); + } + + // Set complete list size. + resTokenForResponse.setCompleteListSize(BigInteger.valueOf(completeListSize)); + + return resTokenForResponse; + } + + return null; + } + + /** + * @param dateToValidate + * @return + */ + 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; + } + + /** + * @param dateToValidate + * @return + */ + 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",}; + + /** + * @param d + * @return + */ + 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; + } + + /** + * <p> + * Loads the field with MORE params from an array! + * </p> + * + * @param resultFromGetRequestInES + * @param fields + * @return Returns MORE params as a list! + */ + public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) { + + log.debug("JSON: " + (resultFromGetRequestInES == null ? "NULL" : resultFromGetRequestInES)); + log.debug("FIELDS: " + fields); + + List<String> fieldResults = new ArrayList<String>(); + + int count = 0; + for (String field : fields) { + String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP); + + log.debug("field[" + count++ + "]: " + field); + + JSONObject singlePath = resultFromGetRequestInES; + try { + for (int i = 0; i < fieldPathForESIndex.length; i++) { + if (i < fieldPathForESIndex.length - 1) { + singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); + } else if (fieldPathForESIndex.length == 1) { + JSONObject resultiDingsda = + resultFromGetRequestInES.getJSONObject(fieldPathForESIndex[i]); + fieldResults.add(resultiDingsda.toString()); + } else { + String res = singlePath.get(fieldPathForESIndex[i]).toString(); + if (res.startsWith("[")) { + JSONArray array = new JSONArray(res); + for (int j = 0; j < array.length(); j++) { + String find = array.getString(j).toString(); + fieldResults.add(find); + } + } else { + fieldResults.add(singlePath.get(fieldPathForESIndex[i]).toString()); + } + } + } + } catch (JSONException e) { + log.error("IGNORING JSON ERROR: " + e.getMessage()); + } + } + + log.debug("field results: " + fieldResults); + + return fieldResults; + } + + /** + * <p> + * Loads the field with ONE param! + * </p> + * + * @param resultFromGetRequestInES + * @param field + * @return Returns only ONE String! + */ + public static String fieldLoader(JSONObject resultFromGetRequestInES, String field) { + + String fieldResults = ""; + + String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP); + JSONObject singlePath = resultFromGetRequestInES; + try { + for (int i = 0; i < fieldPathForESIndex.length; i++) { + if (i < fieldPathForESIndex.length - 1) { + singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); + } else if (fieldPathForESIndex.length == 1) { + fieldResults = resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString(); + } else { + fieldResults = singlePath.get(fieldPathForESIndex[i]).toString(); + } + } + } catch (JSONException e) { + log.error("IGNORING JSON ERROR: " + e.getMessage()); + } + + return fieldResults; + } + + /** + * @param theElasticSearchIndexToUse + * @param idInElasticSearchIndex The ID to get the ES record from. + * @param includes Including the fields to fetch from the elastic search index. + * @param excludes Excluding the fields to fetch from the elastic search index. + * @return + * @throws IOException + */ + protected static GetResponse getRcordByIDFromElasticSearch(String theElasticSearchIndexToUse, + String idInElasticSearchIndex, String[] includes, String[] excludes) throws IOException { + + // Setting the source context for fetching the fields from the elastic search index + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + + // Building the getRequest against the elastic search index + GetRequest getRequest = + new GetRequest(theElasticSearchIndexToUse, OAI_ESClient.getEsType(), idInElasticSearchIndex) + .fetchSourceContext(fetchSourceContext); + + // Declaration of the result from the get-request + GetResponse esResultObject = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + + return esResultObject; + } + + /** + * @param resource + * @throws JAXBException + */ + public static void marshal(Resource resource) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(Resource.class); + Marshaller marshaller = jc.createMarshaller(); + StringWriter stringWriter = new StringWriter(); + marshaller.marshal(resource, stringWriter); + marshaller.marshal(resource, System.out); + } + + /** + * @param metadata + * @param header + * @return + */ + public static GetRecordType getRecordType(Object metadata, HeaderType header) { + + MetadataType metadataType = new MetadataType(); + RecordType recordType = new RecordType(); + GetRecordType getRecordType = new GetRecordType(); + + metadataType.setAny(metadata); + recordType.setMetadata(metadataType); + recordType.setHeader(header); + getRecordType.setRecord(recordType); + + return getRecordType; + } + + /** + * @param propertyName + * @param propFile + * @return + */ + @Deprecated + public static String[][] fetchArrayFromPropFile(String propertyName, Properties propFile) { + + // FIXME Why get a 2D array and only use the first element in RecordDelivererDatacite? + // BTW Where does the ";" come from anyway? + + // Get array split up by the semicolon. + String[] a = propFile.getProperty(propertyName).split(";"); + + // Create the two dimensional array with correct size. + String[][] array = new String[a.length][a.length]; + + // Combine the arrays split by semicolon and comma. + for (int i = 0; i < a.length; i++) { + array[i] = a[i].split(","); + } + + return array; + } + + /** + * @param propertyName + * @param propFile + * @return + */ + public static String[] fetchFieldsFromPropFile(String propertyName, Properties propFile) { + // Trim with whitespaces, so we get the array with results trimmed. + return propFile.getProperty(propertyName).split("\\s*,\\s*"); + } + + /** + * <p> + * Check identifier for prefixes: Remove "textgrid:" and "hdl:" prefixes. + * </p> + * + * @param identifier + * @return The identifier without prefix, if contained in defined prefix list. + */ + public static String omitPrefixFromIdentifier(final String identifier) { + + String result = identifier; + + if (identifier != null && !identifier.isEmpty() && identifier.contains(PREFIX_DEVIDER)) { + String prefix[] = identifier.split(PREFIX_DEVIDER); + String px = prefix[0]; + String id = prefix[1]; + if (IDENTIFIER_PREFIXES_TO_FILTER.contains(px)) { + result = id; + log.debug("incoming id has been filtered to: " + result); + } + } + + return result; + } + + /** + * @param dateOfCreation + * @param identifier + * @param setSpec + * @return + */ + public static HeaderType computeTheF______Header(final String dateOfCreation, + final String identifier, final String setSpec) { + + HeaderType result = new HeaderType(); + + result.setIdentifier(identifier); + result.setDatestamp(dateOfCreation); + + log.debug( + "Header (DoC / ID / setSpec): " + dateOfCreation + " / " + identifier + " / " + setSpec); + + if (setSpec != null && !setSpec.isEmpty()) { + result.getSetSpec().add(setSpec); + } + + return result; + } + + /** + * <p> + * Get the setSpec, if given, check for prefix, if not given, use prefix and given ID. + * </p> + * + * @param theSetSpec + * @param theSpecPrefix + * @param theID + * @return A valid setSpec value for the set. + */ + protected static String getSetSpec(String theSetSpec, String theSpecPrefix, String theID) { + + String result = theSetSpec; + + // Check given setSpec value, add ID if empty. + if (result == null || result.isEmpty() || result.equals(theSpecPrefix)) { + result = theID; + } + + // Then check for prefix, add prefix, if necessary. + if (!result.startsWith(theSpecPrefix)) { + result = theSpecPrefix + result; + } + + return result; + } + + // ** + // GETTERS & SETTERS + // ** + + /** + * @return + */ + public String getRangeField() { + return this.rangeField; + } + + /** + * @param rangeField + */ + public void setRangeField(String rangeField) { + this.rangeField = rangeField; + } + + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + + /** + * @return + */ + public boolean isFoundItems() { + return this.foundItems; + } + + /** + * @param foundItems + */ + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } + + /** + * @return + */ + public ResumptionTokenType getResTokenForResponse() { + return this.resTokenForResponse; + } + + /** + * @param resTokenForResponse + */ + public void setResTokenForResponse(ResumptionTokenType resTokenForResponse) { + this.resTokenForResponse = resTokenForResponse; + } + + /** + * @return + */ + public String setFormatField() { + return this.formatField; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public String getFormatToFilter() { + return this.formatToFilter; + } + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @return + */ + public int getSearchResponseSize() { + return this.searchResponseSize; + } + + /** + * @param searchResponseSize + */ + public void setSearchResponseSize(int searchResponseSize) { + this.searchResponseSize = searchResponseSize; + } } 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..6a553f50384d68229f17f49550e20ac935197a0b 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java @@ -5,11 +5,9 @@ import java.util.List; import info.textgrid.middleware.oaipmh.RequestType; /** - * FIXME - * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2019-03-07 + * @version 2021-07-21 * @since 2019-03-07 */ @@ -18,6 +16,38 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac protected boolean textgrid; protected boolean dariah; + protected OAI_ESClient oaiEsClient; + + protected String[] fields; + protected String[] workFields; + + protected String formatField; + protected String formatToFilter; + protected String dateOfObjectCreation; + protected String relationToFurtherMetadataObject; + protected String repositoryObjectURIPrefix; + protected String identifierField; + protected String specField; + protected String specFieldPrefix; + + // Lists for the Dublin Core elements. Lists are needed since each DC fields is possible to occur + // several times. + protected String[] contributorList; + protected String[] coverageList; + protected String[] creatorList; + protected String[] dateList; + protected String[] descriptionList; + protected String[] formatList; + protected String[] identifierList; + protected String[] languageList; + protected String[] publisherList; + protected String[] relationList; + protected String[] rightsList; + protected String[] sourceList; + protected String[] subjectList; + protected String[] titleList; + protected String[] typeList; + /** * @param textgrid * @param dariah @@ -39,9 +69,10 @@ 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(TGConstants.METADATA_IDIOM_PREFIX)) { - result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + result.setError(OAIPMHConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() + " is not supported by the item identified by the value of: " + request.getIdentifier()); @@ -70,7 +101,7 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac errorValues.add("identifier"); } if (errorValues.size() > 0) { - result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + result.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + "or is missing required arguments: " + errorValues); } } @@ -78,4 +109,260 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac return result; } + // ** + // GETTERS AND SETTERS + // ** + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public String getDateOfObjectCreation() { + return this.dateOfObjectCreation; + } + + /** + * @param dateOfObjectCreation + */ + public void setDateOfObjectCreation(String dateOfObjectCreation) { + this.dateOfObjectCreation = dateOfObjectCreation; + } + + /** + * @return + */ + public String getRelationToFurtherMetadataObject() { + return this.relationToFurtherMetadataObject; + } + + /** + * @param relationToFurtherMetadataObject + */ + public void setRelationToFurtherMetadataObject(String relationToFurtherMetadataObject) { + this.relationToFurtherMetadataObject = relationToFurtherMetadataObject; + } + + /** + * @return + */ + public String getRepositoryObjectURIPrefix() { + return this.repositoryObjectURIPrefix; + } + + /** + * @param repositoryObjectURIPrefix + */ + public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { + this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; + } + + /** + * @return + */ + public String getIdentifierField() { + return this.identifierField; + } + + /** + * @param identifierPrefix + */ + public void setIdentifierField(String identifierPrefix) { + this.identifierField = identifierPrefix; + } + + /** + * @param contributorList + */ + public void setContributor(String[] contributorList) { + this.contributorList = contributorList; + } + + /** + * @return + */ + public String[] getContributor() { + return this.contributorList; + } + + /** + * @param coveragesList + */ + public void setCoverage(String[] coveragesList) { + this.coverageList = coveragesList; + } + + /** + * @param creatorsList + */ + public void setCreator(String[] creatorsList) { + this.creatorList = creatorsList; + } + + /** + * @param datesList + */ + public void setDates(String[] datesList) { + this.dateList = datesList; + } + + /** + * @param descriptionsList + */ + public void setDescriptions(String[] descriptionsList) { + this.descriptionList = descriptionsList; + } + + /** + * @param formatsList + */ + public void setFormats(String[] formatsList) { + this.formatList = formatsList; + } + + /** + * @param identifiersList + */ + public void setIdentifiers(String[] identifiersList) { + this.identifierList = identifiersList; + } + + /** + * @param languagesList + */ + public void setLanguages(String[] languagesList) { + this.languageList = languagesList; + } + + /** + * @param publishersList + */ + public void setPublishers(String[] publishersList) { + this.publisherList = publishersList; + } + + /** + * @param relationsList + */ + public void setRelations(String[] relationsList) { + this.relationList = relationsList; + } + + /** + * @param rightsList + */ + public void setRights(String[] rightsList) { + this.rightsList = rightsList; + } + + /** + * @param sourcesList + */ + public void setSources(String[] sourcesList) { + this.sourceList = sourcesList; + } + + /** + * @param subjectsList + */ + public void setSubjects(String[] subjectsList) { + this.subjectList = subjectsList; + } + + /** + * @param titlesList + */ + public void setTitles(String[] titlesList) { + this.titleList = titlesList; + } + + /** + * @param typesList + */ + public void setTypes(String[] typesList) { + this.typeList = typesList; + } + + /** + * @return + */ + public OAI_ESClient getOaiEsClient() { + return this.oaiEsClient; + } + + /** + * @param oaiEsClient + */ + public void setOaiEsClient(OAI_ESClient oaiEsClient) { + this.oaiEsClient = oaiEsClient; + } + + /** + * @return + */ + public String[] getWorkFields() { + return this.workFields; + } + + /** + * @param workFields + */ + public void setWorkFields(String[] workFields) { + this.workFields = workFields; + } + + /** + * @param fields + */ + public void setFields(String[] fields) { + this.fields = fields; + } + + /** + * @return + */ + public String[] getFields() { + return this.fields; + } + + /** + * @return + */ + public String getSpecField() { + return this.specField; + } + + /** + * @param specField + */ + public void setSpecField(String specField) { + this.specField = specField; + } + + /** + * @return + */ + public String getSpecFieldPrefix() { + return this.specFieldPrefix; + } + + /** + * @param specFieldPrefix + */ + public void setSpecFieldPrefix(String specFieldPrefix) { + this.specFieldPrefix = specFieldPrefix; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java new file mode 100644 index 0000000000000000000000000000000000000000..7b0a94aad214cd3d1278c1a92b1544efdb60ee59 --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java @@ -0,0 +1,1253 @@ +package info.textgrid.middleware; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.util.List; +import java.util.Properties; +import javax.xml.datatype.DatatypeConfigurationException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.elasticsearch.common.Strings; +import org.json.JSONObject; +import org.springframework.stereotype.Component; +import info.textgrid.middleware.common.LTPUtils; +import info.textgrid.middleware.common.RDFConstants; +import info.textgrid.middleware.common.TextGridMimetypes; +import info.textgrid.middleware.oaipmh.ContributorType; +import info.textgrid.middleware.oaipmh.DateType; +import info.textgrid.middleware.oaipmh.GetRecordType; +import info.textgrid.middleware.oaipmh.HeaderType; +import info.textgrid.middleware.oaipmh.OpenaireDescriptionType; +import info.textgrid.middleware.oaipmh.RelatedIdentifierType; +import info.textgrid.middleware.oaipmh.RelationType; +import info.textgrid.middleware.oaipmh.Resource; +import info.textgrid.middleware.oaipmh.Resource.AlternateIdentifiers; +import info.textgrid.middleware.oaipmh.Resource.AlternateIdentifiers.AlternateIdentifier; +import info.textgrid.middleware.oaipmh.Resource.Contributors; +import info.textgrid.middleware.oaipmh.Resource.Contributors.Contributor; +import info.textgrid.middleware.oaipmh.Resource.Creators; +import info.textgrid.middleware.oaipmh.Resource.Creators.Creator; +import info.textgrid.middleware.oaipmh.Resource.Creators.Creator.NameIdentifier; +import info.textgrid.middleware.oaipmh.Resource.Dates; +import info.textgrid.middleware.oaipmh.Resource.Dates.Date; +import info.textgrid.middleware.oaipmh.Resource.Descriptions; +import info.textgrid.middleware.oaipmh.Resource.Descriptions.Description; +import info.textgrid.middleware.oaipmh.Resource.Formats; +import info.textgrid.middleware.oaipmh.Resource.GeoLocations; +import info.textgrid.middleware.oaipmh.Resource.GeoLocations.GeoLocation; +import info.textgrid.middleware.oaipmh.Resource.Identifier; +import info.textgrid.middleware.oaipmh.Resource.RelatedIdentifiers; +import info.textgrid.middleware.oaipmh.Resource.RelatedIdentifiers.RelatedIdentifier; +import info.textgrid.middleware.oaipmh.Resource.ResourceType; +import info.textgrid.middleware.oaipmh.Resource.RightsList; +import info.textgrid.middleware.oaipmh.Resource.RightsList.Rights; +import info.textgrid.middleware.oaipmh.Resource.Sizes; +import info.textgrid.middleware.oaipmh.Resource.Subjects; +import info.textgrid.middleware.oaipmh.Resource.Subjects.Subject; +import info.textgrid.middleware.oaipmh.Resource.Titles; +import info.textgrid.middleware.oaipmh.Resource.Titles.Title; + +/** + * @author Maximilian Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + * @version 2021-09-10 + * @since 2020-06-13 + */ +@Component +public class RecordDelivererDATACITE extends RecordDelivererAbstract { + + // Logger for errors and info + private static Log log = LogFactory.getLog(RecordDelivererDATACITE.class); + + // Container object for the result of the elasticsearch request. This object contains the source + // of the response. + private JSONObject jsonObj = new JSONObject(); + + // This variables contains the field requested in the ElasticSearch Index. The content will be + // given by a configuration file + private String oarIdentifierField; + private String oarSizeField; + private String[] oarTitleFields; + private String[] oarDateFields; + private String[] oarContributorFields; + private String[] oarCreatorFields; + private String[] oarLanguageFields; + private String[] oarAlternateIdentifierFields; + private String[] oarFormatFields; + private String[] oarRightsFields; + private String[] oarDescriptionFields; + private String[] oarRelatedIdentifierFields; + private String[] oarGeoLocationFields; + private String[] oarVersionFields; + private String[] oarSubjectFields; + + private String relationToWorkObject; + private String handle; + + // // This variable contains the XML-content for a whole OpenAire file + // private Resource resource = new Resource(); + + /** + * @param textgrid flag to indicate that the content of the record is context of the TextGrid repo + * @param dariah flag to indicate that the content of the record is context of the DARIAH repo + * @throws IOException + */ + public RecordDelivererDATACITE(boolean textgrid, boolean dariah) throws IOException { + super(textgrid, dariah); + } + + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) + */ + public GetRecordType getRecordById(final String idInElasticSearchIndex) + throws ParseException, DatatypeConfigurationException, IOException { + + String replacedID = idInElasticSearchIndex.replace(this.repositoryObjectURIPrefix, ""); + + log.debug("idInElasticSearchIndex: " + idInElasticSearchIndex + " = " + replacedID); + + GetRecordType getRecordType = new GetRecordType(); + + // Get ES object. + this.jsonObj = + new JSONObject(OAIPMHUtilities.getRcordByIDFromElasticSearch(OAI_ESClient.getEsIndex(), + replacedID, this.fields, Strings.EMPTY_ARRAY).getSource()); + + if (this.jsonObj == null || this.jsonObj.isEmpty()) { + throw new IOException( + "No data could be retrieved from ElasticSearch for ID: " + idInElasticSearchIndex); + } + + log.debug("jsonObject: " + this.jsonObj); + + // Set response header. + String datestamp = OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(this.jsonObj, this.dateOfObjectCreation)); + + String identifier = ""; + if (!idInElasticSearchIndex.startsWith(this.repositoryObjectURIPrefix)) { + identifier = this.repositoryObjectURIPrefix + idInElasticSearchIndex; + } else { + identifier = idInElasticSearchIndex; + } + + log.debug("specField: " + this.specField); + + String setSpec = OAIPMHUtilities.fieldLoader(this.jsonObj, this.specField); + String setSpecValue = OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + + log.debug("setSpec: " + setSpec); + + HeaderType header = + OAIPMHUtilities.computeTheF______Header(datestamp, identifier, setSpecValue); + getRecordType = OAIPMHUtilities.getRecordType(this.setOpenAireRecord(), header); + + return getRecordType; + } + + /** + * Adding the openaire record fields to the openaire record object + * + * @return + * @throws ParseException + * @throws DatatypeConfigurationException + * @throws IOException + */ + private Resource setOpenAireRecord() + throws ParseException, DatatypeConfigurationException, IOException { + + Resource result = new Resource(); + + result.setTitles(this.addTitles()); + result.setPublisher(addPublisher()); + result.setPublicationYear(this.addPublicationYear()); + result.setDates(this.addDates()); + result.setContributors(this.addContributors()); + result.setLanguage(this.addLanguae()); + result.setAlternateIdentifiers(this.addAlternateIdentifier()); + result.setFormats(this.addFormats()); + result.setRightsList(this.addRights()); + result.setDescriptions(this.addDescriptions()); + result.setRelatedIdentifiers(this.addRelatedIdentifiers()); + result.setIdentifier(this.addIdentifier()); + result.setCreators(this.addCreators()); + // FIXME Check if we can have empty elements here! Was: Check for null in this.addGeoLocation() + // method!) + result.setGeoLocations(this.addGeoLocation()); + result.setResourceType(addResourceType()); + result.setVersion(this.addVersion()); + // FIXME Check if we can have empty elements here! Was: Check for null in this.addSubjects() + // method!) + result.setSubjects(this.addSubjects()); + result.setSizes(this.addSize()); + + return result; + } + + /** + * @return + */ + private Sizes addSize() { + Sizes sizes = new Sizes(); + + log.debug("sizeField: " + this.oarSizeField); + + String size = OAIPMHUtilities.fieldLoader(this.jsonObj, this.oarSizeField) + " Bytes"; + + log.debug("size: " + size); + + sizes.getSize().add(size); + + return sizes; + } + + /** + * @return + */ + private Subjects addSubjects() { + + Subjects subjects = new Subjects(); + + // ** + // TextGrid + // ** + + if (this.textgrid) { + for (String subjectField : this.oarSubjectFields) { + Subject subject = new Subject(); + subject.setValue(OAIPMHUtilities.fieldLoader(this.jsonObj, subjectField + ".value")); + subject.setSchemeURI(OAIPMHUtilities.fieldLoader(this.jsonObj, subjectField + ".id.type")); + subject.setSubjectScheme( + OAIPMHUtilities.fieldLoader(this.jsonObj, subjectField + ".id.value")); + subjects.getSubject().add(subject); + } + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + for (String subjectField : this.oarSubjectFields) { + List<String> sList = OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {subjectField}); + for (String s : sList) { + Subject subject = new Subject(); + + log.debug("subject: " + s); + + subject.setValue(s); + // TODO Extract subject schema and schema URI somehow? + // subject.setSchemeURI(); + // subject.setSubjectScheme(); + subjects.getSubject().add(subject); + } + } + } + + return subjects; + } + + /** + * @return + */ + private String addVersion() { + + String version = ""; + + for (String versionField : this.oarVersionFields) { + version = OAIPMHUtilities.fieldLoader(this.jsonObj, versionField); + } + + return version; + } + + /** + * @return + */ + private ResourceType addResourceType() { + + ResourceType resourceType = new ResourceType(); + + // ** + // TextGrid + // ** + + if (this.textgrid) { + for (String format : this.oarFormatFields) { + String resourceValue = OAIPMHUtilities.fieldLoader(this.jsonObj, format); + // TODO Set resource value here? + resourceType.setValue(resourceValue); + // Set collection for all aggregation types, take also into account: images and text. + if (TextGridMimetypes.AGGREGATION_SET.contains(format)) { + resourceType + .setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.COLLECTION); + } else if (TextGridMimetypes.IMAGE_SET.contains(format)) { + resourceType + .setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.IMAGE); + } else if (TextGridMimetypes.ORIGINAL_SET.contains(format)) { + resourceType + .setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.TEXT); + } + // Use dataset for everything else. + else { + resourceType.setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.DATASET); + } + // We take only the first of all the resource types! + if (resourceType.getValue() != null && !resourceType.getValue().isEmpty()) { + break; + } + } + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + + log.debug("oarFormatFields: " + this.oarFormatFields.length); + + for (String format : this.oarFormatFields) { + // Only the first value is taken here! We do not need to create a list! + // TODO Please see addLanguage(), maybe do it as done there to use the other fielsLoader() + // method! + String resourceValue = OAIPMHUtilities.fieldLoader(this.jsonObj, format); + + log.debug("resourceType/value: " + format + "/" + resourceValue); + + resourceType.setValue(resourceValue); + // Set collection for DARIAH collection type here, data object for everything else. + if (TextGridMimetypes.DARIAH_COLLECTION.equals(format)) { + resourceType + .setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.COLLECTION); + } + // Use dataset for everything else. + else { + resourceType.setResourceTypeGeneral(info.textgrid.middleware.oaipmh.ResourceType.DATASET); + } + // We take only the first of all the resource types! + if (resourceType.getValue() != null && !resourceType.getValue().isEmpty()) { + break; + } + } + } + + return resourceType; + } + + /** + * + */ + private GeoLocations addGeoLocation() { + + GeoLocations geoLocations = new GeoLocations(); + + for (String geoLocationField : this.oarGeoLocationFields) { + GeoLocation geoLocation = new GeoLocation(); + geoLocation.setGeoLocationPlace( + OAIPMHUtilities.fieldLoader(this.jsonObj, geoLocationField + ".value")); + geoLocations.getGeoLocation().add(geoLocation); + } + + // if (geoLocations.getGeoLocation().get(0).getGeoLocationPlace() != null) { + // this.resource.setGeoLocations(geoLocations); + // } + + return geoLocations; + } + + /** + * @return + * @throws IOException + */ + private RelatedIdentifiers addRelatedIdentifiers() throws IOException { + + RelatedIdentifiers relatedIdentifiers = new RelatedIdentifiers(); + + for (String relatedIdentifierField : this.oarRelatedIdentifierFields) { + + log.debug("relatedIdentifierField: " + relatedIdentifierField); + + // ** + // TextGrid + // * + + if (this.textgrid) { + String[] workFields = {this.handle}; + RelatedIdentifier relatedIdentifier = new RelatedIdentifier(); + relatedIdentifier.setRelatedIdentifierType(RelatedIdentifierType.HANDLE); + // relatedIdentifier.setRelatedMetadataScheme(TGConstants.TEXTGRID_METADATASCHEME); + relatedIdentifier.setRelationType(RelationType.IS_PART_OF); + // relatedIdentifier.setSchemeType("XSD"); + // relatedIdentifier.setSchemeURI(TGConstants.TEXTGRID_METADATASCHEME_URI); + + String uriForWork = OAIPMHUtilities.fieldLoader(this.jsonObj, relatedIdentifierField) + .replace(this.repositoryObjectURIPrefix, ""); + + relatedIdentifier + .setValue( + OAIPMHUtilities.fieldLoader( + new JSONObject( + OAIPMHUtilities.getRcordByIDFromElasticSearch(OAI_ESClient.getEsIndex(), + uriForWork, workFields, Strings.EMPTY_ARRAY).getSource()), + this.handle)); + relatedIdentifiers.getRelatedIdentifier().add(relatedIdentifier); + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + List<String> relatedIdentiferList = + OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {relatedIdentifierField}); + for (String i : relatedIdentiferList) { + + log.debug("i: " + i); + + RelatedIdentifier relatedID = new RelatedIdentifier(); + if (i.startsWith(RDFConstants.HDL_PREFIX)) { + relatedID.setRelatedIdentifierType(RelatedIdentifierType.HANDLE); + relatedID.setValue(LTPUtils.omitHdlPrefix(i)); + } else if (i.startsWith(RDFConstants.DOI_PREFIX)) { + relatedID.setRelatedIdentifierType(RelatedIdentifierType.DOI); + relatedID.setValue(LTPUtils.omitDoiPrefix(i)); + } else if (i.startsWith("http")) { + relatedID.setRelatedIdentifierType(RelatedIdentifierType.URL); + } + // TODO Check other prefixes and add other values, too? + else { + // TODO No type OTHER existing! Value is mandatory, so we chose URL, what else can we + // do? + relatedID.setRelatedIdentifierType(RelatedIdentifierType.URL); + relatedID.setValue(i); + } + // Relation type is REFERENCES for the time being (coming from dc:relation at the moment). + relatedID.setRelationType(RelationType.REFERENCES); + relatedIdentifiers.getRelatedIdentifier().add(relatedID); + } + } + } + + return relatedIdentifiers; + } + + /** + * @return + * @throws IOException + */ + private Descriptions addDescriptions() throws IOException { + + Descriptions descriptions = new Descriptions(); + + for (String descriptionField : this.oarDescriptionFields) { + + // ** + // TextGrid + // ** + + if (this.textgrid) { + + String idForWorkObject = + OAIPMHUtilities.fieldLoader(this.jsonObj, this.relationToWorkObject); + if (idForWorkObject != null) { + idForWorkObject = idForWorkObject.replace(this.repositoryObjectURIPrefix, ""); + JSONObject resultOfFurtherObject = new JSONObject( + OAIPMHUtilities.getRcordByIDFromElasticSearch(OAI_ESClient.getEsIndex(), + idForWorkObject, this.workFields, Strings.EMPTY_ARRAY).getSource()); + // Create abstract for every dc:description. + List<String> abstractsFromWork = + OAIPMHUtilities.fieldLoader(resultOfFurtherObject, new String[] {descriptionField}); + for (String d : abstractsFromWork) { + Description description = new Description(); + description.setDescriptionType(OpenaireDescriptionType.ABSTRACT); + + log.debug("description: " + descriptionField); + log.debug("relationToWorkObject: " + this.relationToWorkObject); + log.debug("abstract for work: " + d); + + description.getContent().add(d); + descriptions.getDescription().add(description); + } + } + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + // Here the version of fieldLoader() is used, that delivers a LIST of strings! + // TODO Check if you can adapt the other method to only have ONE method left! + List<String> descriptionsFromMetadata = + OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {descriptionField}); + + log.debug("descriptions: " + descriptionsFromMetadata); + + // Create abstract for every dc:description. + for (String d : descriptionsFromMetadata) { + Description description = new Description(); + description.setDescriptionType(OpenaireDescriptionType.ABSTRACT); + description.getContent().add(d); + descriptions.getDescription().add(description); + } + } + } + + return descriptions; + } + + /** + * @return + */ + private RightsList addRights() { + + RightsList rightsList = new RightsList(); + + // ** + // Textgrid + // ** + + if (this.textgrid) { + for (String rightsField : this.oarRightsFields) { + Rights rights = new Rights(); + rights.setRightsURI(OAIPMHUtilities.fieldLoader(this.jsonObj, rightsField + ".licenseUri")); + rights.setValue(OAIPMHUtilities.fieldLoader(this.jsonObj, rightsField + ".value")); + rightsList.getRights().add(rights); + } + if (rightsList.getRights().get(0).getValue() != null) { + Rights openAccesRight = new Rights(); + openAccesRight.setRightsURI("info:eu-repo/semantics/openAccess"); + rightsList.getRights().add(openAccesRight); + } + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + for (String rightsField : this.oarRightsFields) { + Rights rights = new Rights(); + + List<String> rList = OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {rightsField}); + + for (String r : rList) { + + log.debug("right: " + r); + + // Set rights URI assuming every "http://" or "https://" really IS an URI. + if (r.startsWith("http")) { + rights.setRightsURI(r); + } + // Set value in every case, even if doubled with URI. + rights.setValue(r); + } + + rightsList.getRights().add(rights); + } + } + + return rightsList; + } + + /** + * @return + */ + private Formats addFormats() { + + Formats formats = new Formats(); + + for (String formatField : this.oarFormatFields) { + formats.getFormat().add(OAIPMHUtilities.fieldLoader(this.jsonObj, formatField)); + } + + return formats; + } + + /** + * @return + */ + private AlternateIdentifiers addAlternateIdentifier() { + + AlternateIdentifiers alternateIdentifiers = new AlternateIdentifiers(); + + for (String alternateIdentifierField : this.oarAlternateIdentifierFields) { + + // ** + // TextGrid + // ** + + if (this.textgrid) { + AlternateIdentifier alternateIdentifier = new AlternateIdentifier(); + alternateIdentifier + .setValue(OAIPMHUtilities.fieldLoader(this.jsonObj, alternateIdentifierField)); + alternateIdentifier.setAlternateIdentifierType(OAIPMHConstants.URI_IDENTIIER_TYPE); + alternateIdentifiers.getAlternateIdentifier().add(alternateIdentifier); + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + List<String> alternateIdentifierList = + OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {alternateIdentifierField}); + for (String i : alternateIdentifierList) { + AlternateIdentifier alternateID = new AlternateIdentifier(); + if (i.startsWith(RDFConstants.HDL_PREFIX)) { + alternateID.setAlternateIdentifierType("HANDLE"); + alternateID.setValue(LTPUtils.omitHdlPrefix(i)); + } else if (i.startsWith(RDFConstants.DOI_PREFIX)) { + alternateID.setAlternateIdentifierType("DOI"); + alternateID.setValue(LTPUtils.omitDoiPrefix(i)); + } else { + alternateID.setAlternateIdentifierType("OTHER"); + alternateID.setValue(i); + } + alternateIdentifiers.getAlternateIdentifier().add(alternateID); + } + } + } + + return alternateIdentifiers; + } + + /** + * @return + */ + private String addLanguae() { + + String language = null; + + // TODO Only ONE language is permitted in Datacite schema? What if we have more then one in + // DARIAH DC data? Take only first one for the moment! + for (String languageField : this.oarLanguageFields) { + List<String> langs = OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {languageField}); + if (!langs.isEmpty()) { + language = langs.get(0); + } + } + + return language; + } + + /** + * @return + */ + private Contributors addContributors() { + + Contributors contributors = new Contributors(); + + for (String contributorField : this.oarContributorFields) { + + // ** + // TextGrid + // ** + + if (this.textgrid) { + + Contributor contributorInOpenAireRecord = new Contributor(); + + if (contributorField.equals("project")) { + String fieldContent = + OAIPMHUtilities.fieldLoader(this.jsonObj, contributorField + ".value"); + if (fieldContent != null && !fieldContent.isEmpty()) { + contributorInOpenAireRecord.setContributorName(fieldContent); + contributorInOpenAireRecord.setContributorType(ContributorType.OTHER); + info.textgrid.middleware.oaipmh.Resource.Contributors.Contributor.NameIdentifier name = + new info.textgrid.middleware.oaipmh.Resource.Contributors.Contributor.NameIdentifier(); + name.setNameIdentifierScheme("textgrid"); + name.setValue(OAIPMHUtilities.fieldLoader(this.jsonObj, contributorField + ".id")); + name.setSchemeURI("https://textgridlab.org/schema/textgrid-metadata_2010.xsd"); + contributorInOpenAireRecord.setNameIdentifier(name); + contributors.getContributor().add(contributorInOpenAireRecord); + } + } else { + String fieldContent = OAIPMHUtilities.fieldLoader(this.jsonObj, contributorField); + if (fieldContent != null && !fieldContent.isEmpty()) { + contributorInOpenAireRecord.setContributorName(fieldContent); + contributorInOpenAireRecord.setContributorType(ContributorType.DATA_MANAGER); + contributors.getContributor().add(contributorInOpenAireRecord); + /* + * info.textgrid.middleware.oaipmh.Resource.Contributors.Contributor.NameIdentifier name + * = new + * info.textgrid.middleware.oaipmh.Resource.Contributors.Contributor.NameIdentifier(); + * name.setNameIdentifierScheme("textgrid"); name.setValue(""); + * name.setSchemeURI("http://www.textgridlab.org/schema/textgrid-metadata_2010.xsd"); + * contributorInOpenAireRecord.setNameIdentifier(name); + */ + } + } + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + + log.debug("field: " + contributorField); + log.debug("entry: " + OAIPMHUtilities.fieldLoader(this.jsonObj, contributorField)); + + List<String> contributorList = + OAIPMHUtilities.fieldLoader(this.jsonObj, new String[] {contributorField}); + for (String i : contributorList) { + Contributor contributorInOpenAireRecord = new Contributor(); + if (i != null && !i.isEmpty()) { + contributorInOpenAireRecord.setContributorName(i); + if (contributorField.equals("administrativeMetadata.dcterms:creator")) { + contributorInOpenAireRecord.setContributorType(ContributorType.DATA_MANAGER); + } else { + contributorInOpenAireRecord.setContributorType(ContributorType.OTHER); + } + contributors.getContributor().add(contributorInOpenAireRecord); + } + } + } + } + + return contributors; + } + + /** + * @return + */ + private Dates addDates() { + + Dates dates = new Dates(); + + for (String dateField : this.oarDateFields) { + + log.debug("dateField: " + dateField); + + Date dateInOpenAireRecord = new Date(); + + // NOTE Date must be taken from oar date fields, not from dateOfObjectCration! That only must + // be used in the record's header! + // String date = OAIPMHUtilities.convertDateFormat(OAIPMHUtilities.fieldLoader(this.jsonObj, + // this.dateOfObjectCreation).toString()).toXMLFormat(); + // dateInOpenAireRecord.setValue(date); + + try { + // Only one value per field is needed here (I think). + String dateValue = OAIPMHUtilities + .convertDateFormat(OAIPMHUtilities.fieldLoader(this.jsonObj, dateField).toString()) + .toXMLFormat(); + dateInOpenAireRecord.setValue(dateValue); + + log.debug("dateValue: " + dateValue); + + // TODO Use extra created, issued, and updated fields in configuration! + + // Filter TextGrid values for date type. + if (dateField.equals("created")) { + dateInOpenAireRecord.setDateType(DateType.CREATED); + } + if (dateField.equals("issued")) { + dateInOpenAireRecord.setDateType(DateType.ISSUED); + } + if (dateField.equals("lastModified")) { + dateInOpenAireRecord.setDateType(DateType.UPDATED); + } + + // Filter DARIAH values for date type. + if (dateField.equals("administrativeMetadata.dcterms:created")) { + dateInOpenAireRecord.setDateType(DateType.CREATED); + } + if (dateField.equals("administrativeMetadata.dcterms:modified")) { + dateInOpenAireRecord.setDateType(DateType.UPDATED); + } + } catch (ParseException | DatatypeConfigurationException e) { + log.error("Could not parse date field: " + e.getMessage()); + } + + dates.getDate().add(dateInOpenAireRecord); + } + + return dates; + } + + /** + * @return + */ + private Identifier addIdentifier() { + + Identifier identifier = new Identifier(); + String idValue = OAIPMHUtilities.fieldLoader(this.jsonObj, this.oarIdentifierField); + + // ** + // TextGrid + // ** + + if (this.textgrid) { + // We must set Handle here for TG, cause we do not have a DOI! So this is not valid due to + // Datacite schema validation! + // TODO Please check some time! + identifier.setIdentifierType("Handle"); + identifier.setValue(LTPUtils.omitHdlPrefix(idValue)); + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + // We set DOI for DH, 'cause we HAVE it! :-D + identifier.setIdentifierType("DOI"); + identifier.setValue(LTPUtils.omitDoiPrefix(idValue)); + } + + return identifier; + } + + /** + * @return + */ + private Creators addCreators() { + + Creators creators = new Creators(); + + // ** + // TextGrid + // ** + + if (this.textgrid) { + + // TODO: Fields from configFile + + Creator creator = new Creator(); + creator.setCreatorName(OAIPMHUtilities.fieldLoader(this.jsonObj, "edition.agent.value")); + NameIdentifier nameIdentifier = new NameIdentifier(); + // TODO: creatorID Field from config file + String creatorID = OAIPMHUtilities.fieldLoader(this.jsonObj, + "edition.source.bibliographicCitation.author.id"); + + if (creatorID != null && creatorID.contains(":")) { + nameIdentifier.setValue(creatorID.split(":")[1]); + nameIdentifier.setNameIdentifierScheme(creatorID.split(":")[0]); + // TODO Check if the scheme URI is correct + nameIdentifier.setSchemeURI("https://ref.de.dariah.eu/pndsearch/pndquery.xql?id="); + } else { + nameIdentifier.setValue(creatorID); + } + creator.setNameIdentifier(nameIdentifier); + nameIdentifier.setSchemeURI("https://ref.de.dariah.eu/pndsearch/pndquery.xql?id="); + creators.getCreator().add(creator); + } + + // ** + // DARIAH + // ** + + else if (this.dariah) { + + log.debug("oarCreatorFields: " + this.oarCreatorFields); + + for (String cFields : this.oarCreatorFields) { + + log.debug("creator fields: " + cFields); + + List<String> creatorsList = + OAIPMHUtilities.fieldLoader(this.jsonObj, this.oarCreatorFields); + for (String c : creatorsList) { + Creator creator = new Creator(); + + log.debug("creator: " + c); + + creator.setCreatorName(c); + creators.getCreator().add(creator); + } + } + + } + + return creators; + } + + /** + * @return + */ + private Titles addTitles() { + + Titles titles = new Titles(); + + log.debug("oarTitleFields: " + this.oarTitleFields); + + for (String titleField : this.oarTitleFields) { + + log.debug("titleField: " + titleField); + + List<String> titleList = OAIPMHUtilities.fieldLoader(this.jsonObj, this.oarTitleFields); + for (String title : titleList) { + Title tileInOpenAireRecord = new Title(); + tileInOpenAireRecord.setValue(title); + // Title type OTHER is not permitted, leave type out for the moment! + // tileInOpenAireRecord.setTitleType(TitleType.OTHER); + titles.getTitle().add(tileInOpenAireRecord); + } + } + + return titles; + } + + /** + * @return + */ + private String addPublisher() { + + String result = ""; + + /** + * Publisher fields + */ + // TODO: fields from config file + // TODO: for each field + // TODO: Adapt to DARIAH! + // return OAIPMHUtilities.fieldLoader(jsonObj, + // "edition.source.bibliographicCitation.publisher.value"); + + if (this.textgrid) { + result = "TextGrid"; + } else if (this.dariah) { + result = "DARIAH-DE"; + } + + return result; + } + + /** + * @return + * @throws ParseException + * @throws DatatypeConfigurationException + */ + private String addPublicationYear() throws ParseException, DatatypeConfigurationException { + return Integer.toString(OAIPMHUtilities + .convertDateFormat(OAIPMHUtilities.fieldLoader(this.jsonObj, this.dateOfObjectCreation)) + .getYear()); + } + + // ** + // GETTERS & SETTERS + // ** + + /** + * <p> + * Set all the props from config file, if bean can not be configured by spring if doing a new + * RecordDelivererDATACITE(). + * </p> + * + * @throws IOException + */ + protected void setConfigFileProps() throws IOException { + + // FIXME Let spring configure this anyhow! We have all settings in our beans.xml anyway! + // FIXME Configure config file name differently! + InputStream input = new FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); + + Properties p = new Properties(); + p.load(input); + + // Set basic fields. + this.fields = OAIPMHUtilities.fetchFieldsFromPropFile("fields", p); + this.setWorkFields(OAIPMHUtilities.fetchFieldsFromPropFile("workFields", p)); + + this.setFormatField(p.getProperty("formatField")); + this.setFormatToFilter(p.getProperty("formatToFilter")); + this.setDateOfObjectCreation(p.getProperty("dateOfObjectCreation")); + this.setRelationToFurtherMetadataObject(p.getProperty("relationToFurtherMetadataObject")); + this.setRepositoryObjectURIPrefix(p.getProperty("repositoryObjectURIPrefix")); + this.setIdentifierField(p.getProperty("identifierField")); + + // Set DC fields. + this.setContributor(OAIPMHUtilities.fetchFieldsFromPropFile("contributorList", p)); + this.setCoverage(OAIPMHUtilities.fetchFieldsFromPropFile("coverageList", p)); + this.setCreator(OAIPMHUtilities.fetchFieldsFromPropFile("creatorList", p)); + this.setDates(OAIPMHUtilities.fetchFieldsFromPropFile("dateList", p)); + this.setDescriptions(OAIPMHUtilities.fetchFieldsFromPropFile("descriptionList", p)); + this.setFormats(OAIPMHUtilities.fetchFieldsFromPropFile("formatList", p)); + this.setIdentifiers(OAIPMHUtilities.fetchFieldsFromPropFile("identifierList", p)); + this.setLanguages(OAIPMHUtilities.fetchFieldsFromPropFile("languageList", p)); + this.setPublishers(OAIPMHUtilities.fetchFieldsFromPropFile("publisherList", p)); + this.setRelations(OAIPMHUtilities.fetchFieldsFromPropFile("relationList", p)); + this.setRights(OAIPMHUtilities.fetchFieldsFromPropFile("rightsList", p)); + this.setSources(OAIPMHUtilities.fetchFieldsFromPropFile("sourceList", p)); + this.setSubjects(OAIPMHUtilities.fetchFieldsFromPropFile("subjectList", p)); + this.setTitles(OAIPMHUtilities.fetchFieldsFromPropFile("titleList", p)); + this.setTypes(OAIPMHUtilities.fetchFieldsFromPropFile("typeList", p)); + + // Set OpenAire config fields. + this.setOarIdentifierField(p.getProperty("oar.identifierField")); + this.setOarSizeField(p.getProperty("oar.sizeField")); + this.setOarTitleFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.titleFields", p)); + this.setOarDateFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.dateFields", p)); + this.setOarContributorFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.contributorFields", p)); + this.setOarCreatorFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.creatorFields", p)); + this.setOarLanguageFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.languageFields", p)); + this.setOarAlternateIdentifierFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.alternateIdentifierFields", p)); + this.setOarFormatFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.formatFields", p)); + this.setOarRightsFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.rightsFields", p)); + this.setOarDescriptionFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.descriptionFields", p)); + this.setOarRelatedIdentifierFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.relatedIdentifierFields", p)); + this.setOarGeoLocationFields( + OAIPMHUtilities.fetchFieldsFromPropFile("oar.geoLocationFields", p)); + this.setOarVersionFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.versionFields", p)); + this.setOarSubjectFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.subjectFields", p)); + + // Set more fields. + this.setRelationToWorkObject(p.getProperty("oar.relationToWorkObject")); + this.setHandle(p.getProperty("oar.handle")); + this.setSpecFieldPrefix(p.getProperty("specFieldPrefix")); + this.setSpecField(p.getProperty("specField")); + + input.close(); + } + + /** + * @return + */ + public String[] getOarTitleFields() { + return this.oarTitleFields; + } + + /** + * @param oarTitleFields + */ + public void setOarTitleFields(String[] oarTitleFields) { + this.oarTitleFields = oarTitleFields; + } + + /** + * @return + */ + public String getOarIdentifierField() { + return this.oarIdentifierField; + } + + /** + * @param oarIdentifierField + */ + public void setOarIdentifierField(String oarIdentifierField) { + this.oarIdentifierField = oarIdentifierField; + } + + /** + * @return + */ + public String[] getOarDateFields() { + return this.oarDateFields; + } + + /** + * @param oarDateFields + */ + public void setOarDateFields(String[] oarDateFields) { + this.oarDateFields = oarDateFields; + } + + /** + * @return + */ + public String[] getOarCreatorFields() { + return this.oarCreatorFields; + } + + /** + * @param oarCreatorFields + */ + public void setOarCreatorFields(String[] oarCreatorFields) { + this.oarCreatorFields = oarCreatorFields; + } + + /** + * @return + */ + public String[] getOarContributorFields() { + return this.oarContributorFields; + } + + /** + * @param oarContributorFields + */ + public void setOarContributorFields(String[] oarContributorFields) { + this.oarContributorFields = oarContributorFields; + } + + /** + * @return + */ + public String[] getOarLanguageFields() { + return this.oarLanguageFields; + } + + /** + * @param oarLanguageFields + */ + public void setOarLanguageFields(String[] oarLanguageFields) { + this.oarLanguageFields = oarLanguageFields; + } + + /** + * @return + */ + public String[] getOarAlternateIdentifierFields() { + return this.oarAlternateIdentifierFields; + } + + /** + * @param oarAlternateIdentifierFields + */ + public void setOarAlternateIdentifierFields(String[] oarAlternateIdentifierFields) { + this.oarAlternateIdentifierFields = oarAlternateIdentifierFields; + } + + /** + * @return + */ + public String[] getOarFormatFields() { + return this.oarFormatFields; + } + + /** + * @param oarFormatFields + */ + public void setOarFormatFields(String[] oarFormatFields) { + this.oarFormatFields = oarFormatFields; + } + + /** + * @return + */ + public String[] getOarRightsFields() { + return this.oarRightsFields; + } + + /** + * @param oarRightsFields + */ + public void setOarRightsFields(String[] oarRightsFields) { + this.oarRightsFields = oarRightsFields; + } + + /** + * @return + */ + public String[] getOarDescriptionFields() { + return this.oarDescriptionFields; + } + + /** + * @param oarDescriptionFields + */ + public void setOarDescriptionFields(String[] oarDescriptionFields) { + this.oarDescriptionFields = oarDescriptionFields; + } + + /** + * @return + */ + public String[] getOarRelatedIdentifierFields() { + return this.oarRelatedIdentifierFields; + } + + /** + * @param oarRelatedIdentifierFields + */ + public void setOarRelatedIdentifierFields(String[] oarRelatedIdentifierFields) { + this.oarRelatedIdentifierFields = oarRelatedIdentifierFields; + } + + /** + * @return + */ + public String getRelationToWorkObject() { + return this.relationToWorkObject; + } + + /** + * @param relationToWorkObject + */ + public void setRelationToWorkObject(String relationToWorkObject) { + this.relationToWorkObject = relationToWorkObject; + } + + /** + * @return + */ + public String[] getOarGeoLocationFields() { + return this.oarGeoLocationFields; + } + + /** + * @param oarGeoLocationFields + */ + public void setOarGeoLocationFields(String[] oarGeoLocationFields) { + this.oarGeoLocationFields = oarGeoLocationFields; + } + + /** + * @return + */ + public String getHandle() { + return this.handle; + } + + /** + * @param handle + */ + public void setHandle(String handle) { + this.handle = handle; + } + + /** + * @return + */ + public String[] getOarVersionFields() { + return this.oarVersionFields; + } + + /** + * @param oarVersionFields + */ + public void setOarVersionFields(String[] oarVersionFields) { + this.oarVersionFields = oarVersionFields; + } + + /** + * @return + */ + public String[] getOarSubjectFields() { + return this.oarSubjectFields; + } + + /** + * @param oarSubjectFields + */ + public void setOarSubjectFields(String[] oarSubjectFields) { + this.oarSubjectFields = oarSubjectFields; + } + + /** + * @return + */ + public String getOarSizeField() { + return this.oarSizeField; + } + + /** + * @param oarSize + */ + public void setOarSizeField(String oarSize) { + this.oarSizeField = oarSize; + } + +} 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..ec828f669e986faba5f33e3bf57ca152fd80cd72 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java @@ -1,56 +1,27 @@ 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.Log; +import org.apache.commons.logging.LogFactory; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.common.Strings; +import org.json.JSONObject; +import org.springframework.stereotype.Component; import info.textgrid.middleware.oaipmh.GetRecordType; -import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.RecordType; /** - * FIXME - * - * @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 2021-07-06 + * @since 2014-02-17 */ - +@Component public class RecordDelivererDC extends RecordDelivererAbstract { - private String[] fields; - private String[] workFields; - - private String formatField; - private String formatToFilter; - private String dateOfObjectCreation; - private String relationToFurtherMetadataObject; - private String repositoryObjectURIPrefix; - private String identifierField; - - /* - * Lists for the Dublin Core elements. Lists are needed since each DC fields is possible to occur - * several times - */ - - private String[] contributorList; - private String[] coverageList; - private String[] creatorList; - private String[] dateList; - private String[] descriptionList; - private String[] formatList; - private String[] identifierList; - private String[] languageList; - private String[] publisherList; - private String[] relationList; - private String[] relationForWorkList; - private String[] rightList; - private String[] sourceList; - private String[] subjectList; - private String[] titleList; - private String[] typeList; - - private OAI_ESClient oaiEsClient; + private static Log log = LogFactory.getLog(RecordDelivererDC.class); /** * @param textgrid @@ -65,43 +36,52 @@ 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 { GetRecordType getRecordType = new GetRecordType(); RecordType record = new RecordType(); - String changedId = id; DublinCoreBuilder dublinCoreBuilder; + String changedId = id; if (id.startsWith(this.repositoryObjectURIPrefix)) { + // FIXME Why do we need changeID? Where is it used? 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); + // Get ES response, get record for given ID. + GetResponse esResultObject = null; + try { + String[] includes = this.fields; + String[] excludes = Strings.EMPTY_ARRAY; - GetResponse esResultObject = recordById.execute().actionGet(); + esResultObject = OAIPMHUtilities.getRcordByIDFromElasticSearch(OAI_ESClient.getEsIndex(), id, + includes, excludes); - if (esResultObject.isExists()) { + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + log.error("Could not fetch the result of ElasticSearch"); + } + if (esResultObject.isExists()) { String identifier; + // ** + // DARIAH + // ** + if (this.dariah == true) { - dublinCoreBuilder = putContentIntoDCFieldLists(esResultObject); - identifier = esResultObject.getField(this.identifierField).getValue().toString(); - String dateOfCreation = "NO_DATE_SET!"; + dublinCoreBuilder = putContentIntoDCFieldListsDH(esResultObject); + JSONObject json = new JSONObject(esResultObject.getSourceAsMap()); + identifier = OAIPMHUtilities.fieldLoader(json, this.identifierField); - if (esResultObject.getField(this.dateOfObjectCreation) != null) { + String dateOfCreation = "NO_DATE_SET!"; + if (OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation) != null) { try { dateOfCreation = OAIPMHUtilities .convertDateFormat( - esResultObject.getField(this.dateOfObjectCreation).getValue().toString()) + OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation).toString()) .toXMLFormat(); } catch (ParseException e) { // TODO Auto-generated catch block @@ -110,30 +90,48 @@ public class RecordDelivererDC extends RecordDelivererAbstract { // TODO Auto-generated catch block e.printStackTrace(); } - record.setMetadata(dublinCoreBuilder.getDC()); } - setRecordHeader(dateOfCreation, identifier, record, dublinCoreBuilder); + String setSpec = OAIPMHUtilities.fieldLoader(json, this.specField); + String setSpecValue = OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + + record.setHeader( + OAIPMHUtilities.computeTheF______Header(dateOfCreation, identifier, setSpecValue)); + record.setMetadata(dublinCoreBuilder.getDC()); } - if (this.textgrid == true && esResultObject.getField(this.formatField).getValue().toString() - .equals(this.formatToFilter)) { + // ** + // TEXTGRID + // ** + + if (this.textgrid == true + && esResultObject.getSourceAsMap().get(this.formatField).equals(this.formatToFilter)) { - String workUri = - esResultObject.getField(this.relationToFurtherMetadataObject).getValue().toString(); + String workUri = DublinCoreFieldLoader + .fillListFromTGWorkValues(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(); + dublinCoreBuilder = + putContentIntoDCFieldListsTG(esResultObject, furtherDCElements(workUri)); + 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 = DublinCoreFieldLoader + .fillListFromTGWorkValues(esResultObject, TGConstants.RELATIONS_LIST).get(0); + String setSpecValue = OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + + record.setHeader(OAIPMHUtilities.computeTheF______Header( + OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, + setSpecValue)); record.setMetadata(dublinCoreBuilder.getDC()); } getRecordType.setRecord(record); } else { - getRecordType = null; + return null; } return getRecordType; @@ -143,32 +141,6 @@ public class RecordDelivererDC extends RecordDelivererAbstract { // PRIVATE METHODS // ** - /** - * @param dateOfCreation - * @param identifier - * @param record - * @param dbc - * @return - */ - private static RecordType setRecordHeader(String dateOfCreation, String identifier, - RecordType record, DublinCoreBuilder dbc) { - - HeaderType recordHeader = new HeaderType(); - - recordHeader.setIdentifier(identifier); - recordHeader.setDatestamp(dateOfCreation); - - // FIXME Do add set spec here! - // if (set != null) { - // recordHeader.getSetSpec().add(set); - // } - - record.setMetadata(dbc.getDC()); - record.setHeader(recordHeader); - - return record; - } - /** * @param id * @return @@ -179,332 +151,126 @@ public class RecordDelivererDC extends RecordDelivererAbstract { 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); - // } + GetResponse responseWorkValues = null; + try { + String[] includes = this.workFields; + String[] excludes = Strings.EMPTY_ARRAY; + + responseWorkValues = OAIPMHUtilities.getRcordByIDFromElasticSearch(OAI_ESClient.getEsIndex(), + id, includes, excludes); + + } 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) { + private DublinCoreBuilder putContentIntoDCFieldListsTG(GetResponse responseWorkValues, + 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.fillListFromTGWorkValues(responseWorkValues, this.contributorList)); + result.setCoverage( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.coverageList)); + result.setCreator( + DublinCoreFieldLoader.fillListFromTGWorkValues(relatedWorkObject, this.creatorList)); + result + .setDate(DublinCoreFieldLoader.fillListFromTGWorkValues(relatedWorkObject, this.dateList)); result.setDescription( - DublinCoreFieldLoader.setDescription(relatedWorkObject, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(responseWorkValues, this.formatList)); + DublinCoreFieldLoader.fillListFromTGWorkValues(relatedWorkObject, this.descriptionList)); + result.setFormat( + DublinCoreFieldLoader.fillListFromTGWorkValues(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.fillListFromTGWorkValues(responseWorkValues, this.identifierList)); + result.setLanguage( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.languageList)); + result.setPublisher( + DublinCoreFieldLoader.fillListFromTGWorkValues(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.fillListFromTGWorkValues(responseWorkValues, this.relationList)); + result.setRights( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.rightsList)); + result.setSource( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.sourceList)); + result.setSubject( + DublinCoreFieldLoader.fillListFromTGWorkValues(relatedWorkObject, this.subjectList)); + result.setTitle( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.titleList)); + result + .setType(DublinCoreFieldLoader.fillListFromTGWorkValues(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 putContentIntoDCFieldListsDH(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)); + result.setContributor(OAIPMHUtilities + .fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), this.contributorList)); + result.setCoverage( + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.coverageList)); + result + .setCreator(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.creatorList)); + result.setDate(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.dateList)); result.setDescription( - DublinCoreFieldLoader.setDescription(responseWorkValues, this.descriptionList)); - result.setFormat(DublinCoreFieldLoader.setFormat(responseWorkValues, this.formatList)); + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.descriptionList)); + result + .setFormat(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.formatList)); result.setIdentifier( - DublinCoreFieldLoader.setIdentifier(responseWorkValues, this.identifierList)); - result.setLanguage(DublinCoreFieldLoader.setLanguage(responseWorkValues, this.languageList)); - result.setPublisher(DublinCoreFieldLoader.setPublisher(responseWorkValues, this.publisherList)); + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.identifierList)); + result.setLanguage( + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.languageList)); + result.setPublisher( + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + 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)); + OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.relationList)); + result + .setRights(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.rightsList)); + result + .setSource(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.sourceList)); + result.setSubject(OAIPMHUtilities + .fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), this.subjectList)); + result.setTitle(OAIPMHUtilities + .fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), this.titleList)); + result.setType(OAIPMHUtilities.fieldLoader(new JSONObject(responseWorkValues.getSourceAsMap()), + this.typeList)); return result; } - // ** - // GETTERS AND SETTERS - // ** - - /** - * @param formatToFilter - */ - public void setFormatToFilter(String formatToFilter) { - this.formatToFilter = formatToFilter; - } - - /** - * @param formatField - */ - public void setFormatField(String formatField) { - this.formatField = formatField; - } - - /** - * @return - */ - public String getDateOfObjectCreation() { - return this.dateOfObjectCreation; - } - - /** - * @param dateOfObjectCreation - */ - public void setDateOfObjectCreation(String dateOfObjectCreation) { - this.dateOfObjectCreation = dateOfObjectCreation; - } - - /** - * @return - */ - public String getRelationToFurtherMetadataObject() { - return this.relationToFurtherMetadataObject; - } - - /** - * @param relationToFurtherMetadataObject - */ - public void setRelationToFurtherMetadataObject(String relationToFurtherMetadataObject) { - this.relationToFurtherMetadataObject = relationToFurtherMetadataObject; - } - - /** - * @return - */ - public String getRepositoryObjectURIPrefix() { - return this.repositoryObjectURIPrefix; - } - - /** - * @param repositoryObjectURIPrefix - */ - public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { - this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; - } - - /** - * @return - */ - public String getIdentifierField() { - return this.identifierField; - } - - /** - * @param identifierPrefix - */ - public void setIdentifierField(String identifierPrefix) { - this.identifierField = identifierPrefix; - } - - /** - * @param contributorList - */ - public void setContributor(String[] contributorList) { - this.contributorList = contributorList; - } - - /** - * @return - */ - public String[] getContributor() { - return this.contributorList; - } - - /** - * @param coveragesList - */ - public void setCoverage(String[] coveragesList) { - this.coverageList = coveragesList; - } - - /** - * @param creatorsList - */ - public void setCreator(String[] creatorsList) { - this.creatorList = creatorsList; - } - - /** - * @param datesList - */ - public void setDates(String[] datesList) { - this.dateList = datesList; - } - - /** - * @param descriptionsList - */ - public void setDescriptions(String[] descriptionsList) { - this.descriptionList = descriptionsList; - } - - /** - * @param formatsList - */ - public void setFormats(String[] formatsList) { - this.formatList = formatsList; - } - - /** - * @param identifiersList - */ - public void setIdentifiers(String[] identifiersList) { - this.identifierList = identifiersList; - } - - /** - * @param languagesList - */ - public void setLanguages(String[] languagesList) { - this.languageList = languagesList; - } - - /** - * @param publishersList - */ - public void setPublishers(String[] publishersList) { - this.publisherList = publishersList; - } - - /** - * @param relationsList - */ - public void setRelations(String[] relationsList) { - this.relationList = relationsList; - } - - /** - * @param relationsList - */ - public void setRelationsForWork(String[] relationsList) { - this.relationForWorkList = relationsList; - } - - /** - * @param rightsList - */ - public void setRights(String[] rightsList) { - this.rightList = rightsList; - } - - /** - * @param sourcesList - */ - public void setSources(String[] sourcesList) { - this.sourceList = sourcesList; - } - - /** - * @param subjectsList - */ - public void setSubjects(String[] subjectsList) { - this.subjectList = subjectsList; - } - - /** - * @param titlesList - */ - public void setTitles(String[] titlesList) { - this.titleList = titlesList; - } - - /** - * @param typesList - */ - public void setTypes(String[] typesList) { - this.typeList = typesList; - } - - /** - * @return - */ - public OAI_ESClient getOaiEsClient() { - return this.oaiEsClient; - } - - /** - * @param oaiEsClient - */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { - this.oaiEsClient = oaiEsClient; - } - - /** - * @return - */ - public String[] getWorkFields() { - return this.workFields; - } - - /** - * @param workFields - */ - public void setWorkFields(String[] workFields) { - this.workFields = workFields; - } - - /** - * @param fields - */ - public void setFields(String[] fields) { - this.fields = fields; - } - - /** - * @return - */ - public String[] getFields() { - return this.fields; - } - } 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 e14a05110e965234284ff5aa9b148314f5bfd583..238a3aef81b72ff77f92a194dcde7d44ddbbe773 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java @@ -1,40 +1,42 @@ 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.Log; 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.json.JSONObject; +import org.springframework.stereotype.Component; +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; -import info.textgrid.middleware.oaipmh.StatusType; /** - * * @author Maximilian Brodhun, SUB Göttingen - * @since 2019-03-08 + * @author Stefan E. Funk, SUB Göttingen + * @since 2021-09-09 * @version 2019-03-12 - * */ - +@Component public class RecordDelivererIDIOM extends RecordDelivererAbstract { - private String dateOfObjectCreation; + private static Log log = LogFactory.getLog(RecordDelivererIDIOM.class); + private String dateOfLastOblectModification; - private OAI_ESClient oaiEsClient; - RecordType record = new RecordType(); - //ClassicMayanMetsMods metsmods; - - private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDelivererIDIOM.class); + ClassicMayanMetsMods metsmods; /** * @param textgrid @@ -44,61 +46,70 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { super(textgrid, dariah); } - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) - */ - /** + * <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 + * @throws ParseException + * @throws IOException */ + public void setDatestamps(String idInDatabase) throws ParseException, IOException { - 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()); } if (!idInDatabase.contains(".0")) { - - //changedId = changedId.substring(0,changedId.length() - 1) + "0"; + // changedId = changedId.substring(0,changedId.length() - 1) + "0"; changedId = changedId + ".0"; - } - if(changedId.contains(".1")) { - changedId = changedId.replace(".1", ""); + + GetRequest getRequest = + new GetRequest("textgrid-nonpublic", 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); - 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(); - - - this.dateOfObjectCreation = - objectInDatabase.getField(TGConstants.CREATED).getValue().toString(); - - this.dateOfLastOblectModification = - objectInDatabase.getField(TGConstants.MODIFIED_FIELD).getValue().toString(); + JSONObject json = new JSONObject(); + String[] fields = {TGConstants.CREATED, TGConstants.MODIFIED_FIELD}; + json = new JSONObject(OAIPMHUtilities + .getRcordByIDFromElasticSearch("textgrid-nonpublic", changedId, fields, Strings.EMPTY_ARRAY) + .getSource()); + + log.debug("id in elasticsearch is: " + OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED))); + log.debug(json); + + this.dateOfObjectCreation = OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED)); + + this.dateOfLastOblectModification = OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.MODIFIED_FIELD)); + // objectInDatabase.getField(TGConstants.MODIFIED_FIELD).getValue().toString(); } /** * building the record XML object for the OAI-PMH response + * + * @throws ParseException + * @throws IOException */ + public GetRecordType getRecordById(String id) throws ParseException, IOException { - public GetRecordType getRecordById(String id) { - ClassicMayanMetsMods metsmods; GetRecordType grt = new GetRecordType(); setDatestamps(id); @@ -109,22 +120,25 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { textgridBaseURI_FromID = id; } log.info("ID for generating the METS/MODS file is: " + textgridBaseURI_FromID); - metsmods = new ClassicMayanMetsMods( + this.metsmods = new ClassicMayanMetsMods( textgridBaseURI_FromID, this.dateOfObjectCreation, this.dateOfLastOblectModification); - this.record.setMetadata(idiomMets(metsmods)); - try { - if (!id.startsWith("textgrid:")) { - setRecordHeader(this.dateOfObjectCreation, "textgrid:" + id); - } else { - setRecordHeader(this.dateOfObjectCreation, id); - } - } catch (ParseException e) { - e.printStackTrace(); - log.error(e.toString()); + this.record.setMetadata(idiomMets()); + + String identifierToSet = ""; + if (!id.startsWith("textgrid:")) { + identifierToSet = "textgrid:" + id; + } else { + identifierToSet = id; } + // No setSpec needed here! + String setSpec = ""; + HeaderType header = OAIPMHUtilities.computeTheF______Header(this.dateOfObjectCreation, + identifierToSet, setSpec); + this.record.setHeader(header); + grt.setRecord(this.record); return grt; @@ -135,21 +149,22 @@ 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() { - private MetadataType idiomMets(ClassicMayanMetsMods metsmods) { - - MetadataType metadataMets = new MetadataType(); + MetadataType metadataMets = new MetadataType(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); - Document doc = builder.parse(new InputSource(new StringReader(metsmods.getMets()))); + Document doc = builder.parse(new InputSource(new StringReader(this.metsmods.getMets()))); metadataMets.setAny(doc.getDocumentElement()); } catch (Exception e) { e.printStackTrace(); @@ -158,31 +173,4 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { return metadataMets; } - - - /** - * @param dateOfCreation - * @param identifier - * @return - * @throws ParseException - */ - private void setRecordHeader(String dateOfCreation, String identifier) throws ParseException { - - HeaderType recordHeader = new HeaderType(); - recordHeader.setIdentifier(identifier); - recordHeader.setDatestamp(OAIPMHUtilities.datestampAsString(dateOfCreation)); - this.record.setHeader(recordHeader); - - //recordHeader.setStatus(StatusType.DELETED); - // return recordHeader; - } - - public OAI_ESClient getOaiEsClient() { - return this.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..8f1f3b6a4aa66e6d82e1c08c2ea43263c0ef8efc 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java @@ -1,11 +1,15 @@ package info.textgrid.middleware; +import java.io.IOException; +import java.text.ParseException; +import javax.xml.datatype.DatatypeConfigurationException; import info.textgrid.middleware.oaipmh.GetRecordType; +import info.textgrid.middleware.oaipmh.HeaderType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2019-03-07 + * @version 2021-09-09 * @since 2019-03-07 */ @@ -18,7 +22,11 @@ public interface RecordDelivererInterface { * * @param id identifier within database * @return Get the GetRecord response for the request + * @throws DatatypeConfigurationException + * @throws ParseException + * @throws IOException */ - GetRecordType getRecordById(String id); + GetRecordType getRecordById(String id) + throws ParseException, DatatypeConfigurationException, IOException; } 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..f43cc365a522328d303364b217a98550920d3f8e 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java @@ -1,17 +1,60 @@ package info.textgrid.middleware; +import java.io.IOException; import java.util.ArrayList; +import java.util.Hashtable; import java.util.List; +import java.util.Map; +import org.apache.commons.logging.Log; +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.client.RequestOptions; +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 info.textgrid.middleware.oaipmh.RequestType; +import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** * */ public abstract class RecordListDelivererAbstract implements RecordListDelivererInterface { + protected OAI_ESClient oaiEsClient; + protected boolean textgrid; protected boolean dariah; + protected String[] fields; + protected String[] workFields; + + protected String dateOfObjectCreation; + protected String relationToFurtherMetadataObject; + protected String repositoryObjectURIPrefix; + protected String modifiedField; + protected String identifierField; + protected String rangeField; + protected String formatField; + protected String formatToFilter; + protected int searchResponseSize; + protected String specField; + protected String specFieldPrefix; + + protected String modifiedValue; + private long resultSize; + private boolean foundItems; + + public ResumptionTokenType resTokenForResponse; + + // private static final int LIFETIME_RES_TOKEN = 600; + protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + + private static Log log = LogFactory.getLog(RecordListDelivererAbstract.class); + /** * @param textgrid * @param dariah @@ -21,6 +64,108 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer this.dariah = dariah; } + /** + * @param query + * @param resumptionToken + * @param set + * @return + */ + protected List<String> getFieldsFromESIndex(QueryBuilder query, String resumptionToken, + String set) { + + List<String> uriList = new ArrayList<String>(); + + QueryBuilder recordFilter; + if (this.textgrid) { + // We filter out all editions here! + recordFilter = QueryBuilders.boolQuery().must(query) + .must(QueryBuilders.matchPhraseQuery("format", this.formatToFilter)); + } else { + // Do not filter at all in DH. We need every ID! + recordFilter = QueryBuilders.boolQuery().must(query); + } + + SearchRequest searchRequest = new SearchRequest(OAI_ESClient.getEsIndex()); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + + searchSourceBuilder.query(recordFilter); + searchSourceBuilder.size(100); + searchRequest.source(searchSourceBuilder); + + SearchResponse scrollResp = new SearchResponse(); + + if (resumptionToken != null) { + + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueHours(24L)); + + try { + scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueHours(24L)); + try { + scrollResp = OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + String scrollID = scrollResp.getScrollId(); + long completeListSize = scrollResp.getHits().totalHits; + setResultSize(completeListSize); + + if (completeListSize > 0) { + + setFoundItems(true); + int i = 0; + + for (SearchHit hit : scrollResp.getHits().getHits()) { + i++; + if (hit != null && hit.getFields() != null) { + String id2add; + // FIXME Could we not use hit.getId() also for TG hits? Where is the difference? + if (this.textgrid) { + id2add = hit.getSourceAsMap().get(TGConstants.URI).toString(); + } else { + id2add = hit.getId(); + } + uriList.add(id2add); + } + } + if (resumptionToken != null + && this.resTokenForResponse.getCursor().intValue() >= completeListSize) { + try { + cursorCollector.remove(resumptionToken); + } catch (NullPointerException couldNotRemove) { + log.info("Could not remove hash value: " + resumptionToken + " from hash map"); + } + this.resTokenForResponse.setValue(""); + } else { + this.resTokenForResponse = OAIPMHUtilities.getResumptionToken( + completeListSize, resumptionToken, cursorCollector, scrollID, this.searchResponseSize, + i); + } + + log.debug("cursorCollector: " + cursorCollector); + + } else { + setFoundItems(false); + } + + if (this.resTokenForResponse != null) { + log.debug("restok value: " + this.resTokenForResponse.getValue()); + log.debug("restok cursor: " + this.resTokenForResponse.getCursor()); + } + + return uriList; + } + /** * @param request * @return @@ -31,9 +176,10 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer // Check if metadata prefix is existing and valid. if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) - && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - result.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, + && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX) + && !request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { + result.setError(OAIPMHConstants.OAI_METADATA_FORMAT_ERROR, "The value of the metadataPrefix: " + request.getMetadataPrefix() + " is not supported by the item identified by the value of: " + request.getIdentifier()); @@ -41,12 +187,16 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer // Check if resumptionToken is invalid or existing. if (request.getResumptionToken() != null) { - boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null + boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); - boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null + + boolean restokDCExisting = RecordListDelivererDC.cursorCollector != null && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); - if (restokDCExisting || restokIDIOMExisting) { - result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " + boolean restok = cursorCollector != null + && cursorCollector.containsKey(request.getResumptionToken()); + + if (!restokDCExisting && !restokIDIOMExisting && !restok) { + result.setError(OAIPMHConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " + request.getResumptionToken() + " argument is invalid or expired."); } } @@ -54,21 +204,349 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer // 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 " + result.setError(OAIPMHConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + "or is missing required arguments: " + errorValues); } return result; } + // /* + // * (non-Javadoc) + // * + // * @see info.textgrid.middleware.RecordListDelivererInterface#setHeader(java.lang.String, + // * java.lang.String, java.lang.String) + // */ + // public HeaderType setHeader(final String set, final String headerIdentifier, + // String modifiedDate) { + // + // HeaderType header = new HeaderType(); + // String identifierForHeader = headerIdentifier; + // + // System.out.println("header identifier: " + headerIdentifier); + // System.out.println("modified value: " + modifiedDate); + // + // // Set date in XML format. + // try { + // header.setDatestamp(OAIPMHUtilities.convertDateFormat(modifiedDate).toXMLFormat()); + // } catch (ParseException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (DatatypeConfigurationException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // + // // Set header specific for TextGrid objects (remove URL). + // if (this.textgrid == true) { + // identifierForHeader = identifierForHeader.replaceFirst("https://textgridrep.org/", ""); + // } + // + // header.setIdentifier(identifierForHeader); + // + // // Set set :-) + // if (set != null) { + // header.getSetSpec().add(this.specFieldPrefix + set); + // } + // + // return header; + // } + + // ** + // GETTER AND SETTER + // ** + + /** + * @return + */ + public String getRangeField() { + return this.rangeField; + } + + /** + * @param rangeField + */ + public void setRangeField(String rangeField) { + this.rangeField = rangeField; + } + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public int getSearchResponseSize() { + return this.searchResponseSize; + } + + /** + * @param searchResponseSize + */ + public void setSearchResponseSize(int searchResponseSize) { + this.searchResponseSize = searchResponseSize; + } + + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + + /** + * @return + */ + public boolean isFoundItems() { + return this.foundItems; + } + + /** + * @param foundItems + */ + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } + + /** + * @return + */ + public OAI_ESClient getOaiEsClient() { + return this.oaiEsClient; + } + + /** + * @param oaiEsClient + */ + public void setOaiEsClient(OAI_ESClient oaiEsClient) { + this.oaiEsClient = oaiEsClient; + } + + /** + * @return + */ + public ResumptionTokenType getResTokenForResponse() { + return this.resTokenForResponse; + } + + /** + * @param resTokenForResponse + */ + public void setResTokenForResponse(ResumptionTokenType resTokenForResponse) { + this.resTokenForResponse = resTokenForResponse; + } + + + /** + * @return + */ + public String getModifiedField() { + return this.modifiedField; + } + + /** + * @param modifiedField + */ + public void setModifiedField(String modifiedField) { + this.modifiedField = modifiedField; + } + + + /** + * @return + */ + public String getDateOfObjectCreation() { + return this.dateOfObjectCreation; + } + + /** + * @param dateOfObjectCreation + */ + public void setDateOfObjectCreation(String dateOfObjectCreation) { + this.dateOfObjectCreation = dateOfObjectCreation; + } + + /** + * @return + */ + public String getRelationToFurtherMetadataObject() { + return this.relationToFurtherMetadataObject; + } + + /** + * @param relationToFurtherMetadataObject + */ + public void setRelationToFurtherMetadataObject(String relationToFurtherMetadataObject) { + this.relationToFurtherMetadataObject = relationToFurtherMetadataObject; + } + + /** + * @return + */ + public String getRepositoryObjectURIPrefix() { + return this.repositoryObjectURIPrefix; + } + + /** + * @param repositoryObjectURIPrefix + */ + public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { + this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; + } + + /** + * @param textgrid + */ + public void setTextgrid(boolean textgrid) { + this.textgrid = textgrid; + } + + /** + * @return + */ + public boolean isDariah() { + return this.dariah; + } + + /** + * @param dariah + */ + public void setDariah(boolean dariah) { + this.dariah = dariah; + } + + /** + * @return + */ + public String getIdentifierField() { + return this.identifierField; + } + + /** + * @param identifierField + */ + public void setIdentifierField(String identifierField) { + this.identifierField = identifierField; + } + + /** + * @return + */ + public String getModifiedValue() { + return this.modifiedValue; + } + + /** + * @param modifiedValue + */ + public void setModifiedValue(String modifiedValue) { + this.modifiedValue = modifiedValue; + } + + /** + * @return + */ + public String getFormatField() { + return this.formatField; + } + + /** + * @return + */ + public String getFormatToFilter() { + return this.formatToFilter; + } + + + /** + * @return + */ + public String[] getWorkFields() { + return this.workFields; + } + + /** + * @param workFields + */ + public void setWorkFields(String[] workFields) { + this.workFields = workFields; + } + + /** + * @param fields + */ + public void setFields(String[] fields) { + this.fields = fields; + } + + /** + * @return + */ + public String[] getFields() { + return this.fields; + } + + /** + * @return + */ + public String getSpecField() { + return this.specField; + } + + /** + * @param specField + */ + public void setSpecField(String specField) { + this.specField = specField; + } + + /** + * @return + */ + public String getSpecFieldPrefix() { + return this.specFieldPrefix; + } + + /** + * @param specFieldPrefix + */ + public void setSpecFieldPrefix(String specFieldPrefix) { + this.specFieldPrefix = specFieldPrefix; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java new file mode 100644 index 0000000000000000000000000000000000000000..e1b396a1ab6ac111178cdcde56a4203f0d69d044 --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java @@ -0,0 +1,162 @@ +package info.textgrid.middleware; + +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import javax.xml.datatype.DatatypeConfigurationException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import info.textgrid.middleware.oaipmh.GetRecordType; +import info.textgrid.middleware.oaipmh.ListRecordsType; +import info.textgrid.middleware.oaipmh.RecordType; + +/** + * @author Maximilian Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + * @version 2021-09-10 + * @since 2020-06-13 + */ +public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { + + private static Log log = LogFactory.getLog(RecordListDelivererDATACITE.class); + + /** + * @param textgrid + * @param dariah + */ + public RecordListDelivererDATACITE(boolean textgrid, boolean dariah) { + super(textgrid, dariah); + } + + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) + throws ParseException, IOException { + + ListRecordsType openAireRecordList = new ListRecordsType(); + + // Create one RecordDeliverer only, to configure all fields only ONCE. + // FIYME May be solved using spring configuration, but I do not know how! + RecordDelivererDATACITE openAireRecord = + new RecordDelivererDATACITE(this.textgrid, this.dariah); + // Must be done here, as spring does not configure this bean if instantiated with "new". + openAireRecord.setConfigFileProps(); + + List<String> URIList = getUriList(from, to, set, resumptionToken); + for (String uri : URIList) { + + String eventuallyChangedUri = uri; + + // ** + // TextGrid + // ** + + if (this.textgrid) { + // We must remove the prefix, as ElasticSearch is storing the IDs without it. + eventuallyChangedUri = uri.replace("textgrid:", ""); + } + + // ** + // DARIAH + // ** + + // else if (this.dariah) { + // Nothing to remove for DARIAH IDs here. + // } + + log.debug("uri: " + uri + " | eventuallyChangedUri: " + eventuallyChangedUri); + + try { + + GetRecordType grt = openAireRecord.getRecordById(eventuallyChangedUri); + RecordType record = grt.getRecord(); + // Header is already set by getRecordById(). + + openAireRecordList.getRecord().add(record); + + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + openAireRecordList.setResumptionToken(getResTokenForResponse()); + + return openAireRecordList; + } + + /** + * @param from + * @param to + * @param set + * @param resumptionToken + * @return + */ + private List<String> getUriList(String from, String to, String set, String resumptionToken) { + + List<String> result = new ArrayList<String>(); + + QueryBuilder query; + + log.debug("rangefield: " + this.dateOfObjectCreation); + log.debug("set: " + set); + + QueryBuilder rangeQuery = QueryBuilders.rangeQuery(this.dateOfObjectCreation).from(from).to(to); + QueryBuilder tgFilterSandBox = QueryBuilders.matchPhraseQuery("nearlyPublished", "true"); + + if (set != null && !set.equals("openaire_data")) { + + String queryField = ""; + String valueField = ""; + + if (this.dariah == true) { + // FIXME Put query field into config! + queryField = "administrativeMetadata.dcterms:relation"; + valueField = set; + + // Add new record with set metadata in it (to also find collection metadata in Repository + // Search!) + + } + + if (this.textgrid == true) { + String[] setParts = set.split(":"); + if (setParts[0].equals("project")) { + // FIXME Put query field into config! + queryField = "project.id"; + valueField = setParts[1]; + } + } + + QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); + if (this.textgrid) { + query = + QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery).mustNot(tgFilterSandBox); + } else { + query = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); + } + } else { + if (this.textgrid) { + query = QueryBuilders.boolQuery().must(rangeQuery).mustNot(tgFilterSandBox); + } else { + query = QueryBuilders.boolQuery().must(rangeQuery); + } + } + + log.debug("query:\n" + query); + + result = getFieldsFromESIndex(query, resumptionToken, set); + + log.debug("URI list result: " + result); + + 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..0530c9e489079b7778042e0b7dd49277b2ceeaf1 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java @@ -1,20 +1,27 @@ package info.textgrid.middleware; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.text.ParseException; -import java.util.Hashtable; -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.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 org.json.JSONObject; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListRecordsType; import info.textgrid.middleware.oaipmh.MetadataType; @@ -27,27 +34,16 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; public class RecordListDelivererDC extends RecordListDelivererAbstract { // ** - // STATICS + // FINALS // ** - private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + private static final int LIFETIME_RES_TOKEN = 600; // ** - // CLASS VARIABLES + // STATICS // ** - private OAI_ESClient oaiEsClient; - private String[] fields; - private String[] workFields; - private String formatField; - private String formatToFilter; - private String dateOfObjectCreation; - private String relationToFurtherMetadataObject; - private String repositoryObjectURIPrefix; - private String rangeField; - private String modifiedField; - private String identifierField; - private boolean foundItems; + private static Log log = LogFactory.getLog(RecordListDelivererDC.class); // ** // DC-Field Lists @@ -63,18 +59,12 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { private String[] languageList; private String[] publisherList; private String[] relationList; - private String[] relationForWorkList; - private String[] rightList; + private String[] relationsForWorkList; + private String[] rightsList; 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,24 +84,29 @@ 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 { id = URLDecoder.decode(id, "UTF-8"); } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + 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(); } - - GetRequestBuilder getWorkValues = - OAI_ESClient.getOaiESClient() - .prepareGet() - .setIndex(OAI_ESClient.getEsIndex()) - .setType(OAI_ESClient.getEsType()) - .setId(id) - .setFields(this.workFields); - - GetResponse responseWorkValues = getWorkValues.execute().actionGet(); return responseWorkValues; } @@ -121,7 +116,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { /** * <p> - * The fetchFields function filters all edition and fetch the specified fields + * The fetchFields function filters all edition and fetch the specified fields. * </p> * * @param query @@ -137,189 +132,166 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { SearchResponse scrollResp; QueryBuilder recordFilter; DublinCoreBuilder dublinCoreBuilder = new DublinCoreBuilder(); + + log.debug("formatField: " + (this.formatField == null ? "NULL" : this.formatField)); + log.debug("formatToFilter: " + (this.formatToFilter == null ? "NULL" : this.formatToFilter)); + if (this.dariah == true) { + // All objects! recordFilter = query; } else { + // All editions only! recordFilter = QueryBuilders.boolQuery().must(query) .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(100); + 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); int i = 0; - for (SearchHit hit : scrollResp.getHits().getHits()) { i++; if (hit != null && hit.getFields() != null) { - try { - if (hit.getFields().get(this.dateOfObjectCreation) != null) { - String datestamp = - hit.getFields().get(this.dateOfObjectCreation).getValue().toString(); - datestamp = OAIPMHUtilities.convertDateFormat(datestamp).toXMLFormat(); - } - } catch (ParseException e1) { - log.debug(e1); - } catch (DatatypeConfigurationException e1) { - log.debug(e1); - } + JSONObject json = new JSONObject(hit.getSourceAsMap()); + this.modifiedValue = OAIPMHUtilities.fieldLoader(json, this.modifiedField); + + // ** + // TEXTGRID SEARCH + // ** + + if (this.textgrid) { + String workUri = ""; + String[] relationFields = new String[] {this.relationToFurtherMetadataObject}; + + if (hit.getSourceAsMap().get(this.formatField).toString().equals(this.formatToFilter)) { + String setSpec = this.specFieldPrefix + + DublinCoreFieldLoader.fillList(hit, TGConstants.RELATIONS_LIST).get(0); + if (DublinCoreFieldLoader.fillList(hit, relationFields).get(0) != null) { + workUri = DublinCoreFieldLoader.fillList(hit, relationFields).get(0) + .substring(this.repositoryObjectURIPrefix.length()); + + if (!workUri.endsWith(".0")) { + workUri = workUri.concat(".0"); + } + } + try { + dublinCoreBuilder = putContentIntoDCFieldListsTG(hit, + furtherDCElements(workUri, OAI_ESClient.getEsClient())); + + log.debug( + "ID field: " + (this.identifierField == null ? "NULL" : this.identifierField)); - this.modifiedValue = hit.getFields().get(this.modifiedField).getValue().toString(); + String identifier = hit.getSourceAsMap().get(this.identifierField).toString(); - // TextGrid search! - String workUri = ""; + log.debug("identifier (tgrep): " + identifier); + log.debug("setSpec: " + setSpec); - if (this.textgrid == true && hit.getFields().get(this.formatField).values().get(0) - .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()); + HeaderType header = OAIPMHUtilities.computeTheF______Header( + OAIPMHUtilities.convertDateFormat(this.modifiedValue).toString(), identifier, + setSpec); + buildRecord(recordList, header, dublinCoreBuilder); - if (!workUri.endsWith(".0")) { - workUri = workUri.concat(".0"); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } + } - dublinCoreBuilder = putContentIntoDCFieldLists(hit, - furtherDCElements(workUri, OAI_ESClient.getOaiESClient())); + // ** + // DARIAH SEARCH + // ** - buildRecord(recordList, set, - hit.getFields().get(this.identifierField).getValue().toString(), dublinCoreBuilder); - } + else if (this.dariah) { + + // Get identifier and setSpec field, add setSpec prefix if not already set. + String identifier = OAIPMHUtilities.fieldLoader(json, this.identifierField); + String setSpec = OAIPMHUtilities.getSetSpec(set, this.specFieldPrefix, identifier); - if (this.dariah == true) { - dublinCoreBuilder = putContentIntoDCFieldLists2(hit, - furtherDCElements(hit.getId(), OAI_ESClient.getOaiESClient())); - buildRecord(recordList, set, - hit.getFields().get(this.identifierField).getValue().toString(), dublinCoreBuilder); + log.debug("identifier (dhrep): " + identifier); + log.debug("setSpec: " + set); + + try { + dublinCoreBuilder = putContentIntoDCFieldListsDH(hit); + + HeaderType header = OAIPMHUtilities.computeTheF______Header( + OAIPMHUtilities.convertDateFormat(this.modifiedValue).toString(), identifier, + setSpec); + buildRecord(recordList, header, dublinCoreBuilder); + + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } } // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( - completeListSize, resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i); - if (resTokenForResponse != null) { - recordList.setResumptionToken(resTokenForResponse); - } + ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, + resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i); + recordList.setResumptionToken(resTokenForResponse); + + log.debug("RESTOK: " + recordList.getResumptionToken()); } else { setFoundItems(false); } } - /** - * @param hit - * @param responseWorkValues - * @return - */ - public DublinCoreBuilder putContentIntoDCFieldLists(SearchHit hit, - GetResponse responseWorkValues) { - - 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.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)); - 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)); - - return result; - } - - /** - * @param hit - * @param responseWorkValues - * @return - */ - public DublinCoreBuilder putContentIntoDCFieldLists2(SearchHit hit, - GetResponse responseWorkValues) { - - 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)); - - return result; - } - - /** - * @param recordList - * @param set - * @param headerIdentifier - * @param dublinCoreBuilder - * @return - */ - public RecordType buildRecord(ListRecordsType recordList, String set, String headerIdentifier, - DublinCoreBuilder dublinCoreBuilder) { - - MetadataType metadata = new MetadataType(); - RecordType record = new RecordType(); - - metadata = dublinCoreBuilder.getDC(); - record.setMetadata(metadata); - record.setHeader(setHeader(set, headerIdentifier)); - recordList.getRecord().add(record); - - return record; - } - /* * (non-Javadoc) * * @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ - public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) { + public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) + throws ParseException, IOException { log.info("Started List Records with booleans for DARIAH: " + this.dariah + " and TextGrid: " + this.textgrid); @@ -329,18 +301,27 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { QueryBuilder rangeQuery = QueryBuilders.rangeQuery(this.rangeField).from(from).to(to); if (set != null) { - String queryField = ""; String valueField = ""; + // ** + // DARIAH + // ** + if (this.dariah == true) { - queryField = "descriptiveMetadata.dc:relation"; + // FIXME Put query field into config! + queryField = "administrativeMetadata.dcterms:relation"; valueField = set; } + // ** + // TEXTGRID + // ** + if (this.textgrid == true) { String[] setParts = set.split(":"); if (setParts[0].equals("project")) { + // FIXME Put query field into config! queryField = "project.id"; valueField = setParts[1]; } @@ -353,136 +334,159 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { } else { query = rangeQuery; } + try { - fetchFields(query, recordList, resumptionToken, set); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return recordList; - } + log.debug("getRecords(): " + (query != null ? "queryName=" + query.getName() : "query=NULL") + + " | " + (recordList != null ? recordList : "recordList=NULL") + " | " + + (resumptionToken != null ? resumptionToken : "resumptionToken=NULL") + " | " + + (set != null ? set : "set=NULL")); - /** - * @param set - * @param headerIdentifier - * @return - */ - public HeaderType setHeader(final String set, final String headerIdentifier) { + fetchFields(query, recordList, resumptionToken, set); - HeaderType header = new HeaderType(); - String identifierForHeader = headerIdentifier; + // FOR DHREP ONLY: Add record with set metadata in it (to also find collection metadata in + // Repository Search!) + // FIXME Put query field into config! + if (this.dariah && set != null && !set.isEmpty()) { + QueryBuilder setQuery = QueryBuilders + .matchQuery("administrativeMetadata.dcterms:identifier", this.specFieldPrefix + set); - // Set date in XML format. - try { - header.setDatestamp(OAIPMHUtilities.convertDateFormat(this.modifiedValue).toXMLFormat()); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DatatypeConfigurationException e) { + fetchFields(QueryBuilders.boolQuery().must(setQuery), recordList, resumptionToken, set); + } + + } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } - // Set header specific for TextGrid objects (remove URL). - if (this.textgrid == true) { - identifierForHeader = identifierForHeader.replaceFirst("https://textgridrep.org/", ""); - } - - header.setIdentifier(identifierForHeader); - - // Set set :-) - if (set != null) { - header.getSetSpec().add(set); - } - - return header; + return recordList; } - /** - * @param formatToFilter - */ - public void setFormatToFilter(String formatToFilter) { - this.formatToFilter = formatToFilter; - } + // ** + // PRIVATE METHIODS + // ** /** - * @param formatField + * @param recordList + * @param header + * @param dublinCoreBuilder */ - public void setFormatField(String formatField) { - this.formatField = formatField; - } + private static void buildRecord(ListRecordsType recordList, HeaderType header, + DublinCoreBuilder dublinCoreBuilder) { - /** - * @return - */ - public String getDateOfObjectCreation() { - return this.dateOfObjectCreation; - } + // Get metadata. + MetadataType metadata = new MetadataType(); + metadata = dublinCoreBuilder.getDC(); - /** - * @param dateOfObjectCreation - */ - public void setDateOfObjectCreation(String dateOfObjectCreation) { - this.dateOfObjectCreation = dateOfObjectCreation; + // Build record, set header and metadata. + RecordType record = new RecordType(); + record.setHeader(header); + record.setMetadata(metadata); + + // Add record to the given list. + recordList.getRecord().add(record); } /** + * @param hit + * @param responseWorkValues * @return + * @throws DatatypeConfigurationException + * @throws ParseException */ - public String getRelationToFurtherMetadataObject() { - return this.relationToFurtherMetadataObject; - } + private DublinCoreBuilder putContentIntoDCFieldListsTG(SearchHit hit, + GetResponse responseWorkValues) throws ParseException, DatatypeConfigurationException { - /** - * @param relationToFurtherMetadataObject - */ - public void setRelationToFurtherMetadataObject(String relationToFurtherMetadataObject) { - this.relationToFurtherMetadataObject = relationToFurtherMetadataObject; - } + DublinCoreBuilder result = new DublinCoreBuilder(); - /** - * @return - */ - public String getRepositoryObjectURIPrefix() { - return this.repositoryObjectURIPrefix; - } + result.setContributor( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.contributorList)); + result.setCoverage( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.coverageList)); + result.setCreator( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.creatorList)); + result + .setDate(DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.dateList)); + result.setDescription( + DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.descriptionList)); + result.setFormat(DublinCoreFieldLoader.fillList(hit, this.formatList)); + result.setIdentifier( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), 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.fillListFromTGWorkValues(responseWorkValues, + this.relationsForWorkList)); + result.setRights(DublinCoreFieldLoader.fillList(hit, this.rightsList)); + result.setSource(DublinCoreFieldLoader.fillList(hit, this.sourceList)); + result.setSubject(DublinCoreFieldLoader.fillList(hit, this.subjectList)); + result.setTitle(DublinCoreFieldLoader.fillList(hit, this.titleList)); + result + .setType(DublinCoreFieldLoader.fillListFromTGWorkValues(responseWorkValues, this.typeList)); - /** - * @param repositoryObjectURIPrefix - */ - public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { - this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; + return result; } /** + * @param hit * @return + * @throws ParseException + * @throws DatatypeConfigurationException */ - public String getFieldForRange() { - return this.rangeField; - } + private DublinCoreBuilder putContentIntoDCFieldListsDH(SearchHit hit) + throws ParseException, DatatypeConfigurationException { - /** - * @param fieldForRange - */ - public void setFieldForRange(String fieldForRange) { - this.rangeField = fieldForRange; + DublinCoreBuilder result = new DublinCoreBuilder(); + + result.setContributor( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.contributorList)); + result.setCoverage( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.coverageList)); + result.setCreator( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.creatorList)); + result + .setDate(OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.dateList)); + result.setDescription( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.descriptionList)); + result.setFormat( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.formatList)); + result.setIdentifier( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.identifierList)); + result.setLanguage( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.languageList)); + result.setPublisher( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.publisherList)); + result.setRelation( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.relationList)); + result.setRights( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.rightsList)); + result.setSource( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.sourceList)); + result.setSubject( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.subjectList)); + result.setTitle( + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.titleList)); + result + .setType(OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), this.typeList)); + + return result; } - /* - * Setter for DublinCore Lists - */ + // ** + // GETTERS AND SETTERS for DublinCore Lists + // ** /** * @param contributorList */ - public void setContributor(String[] contributorList) { + public void setContributors(String[] contributorList) { this.contributorList = contributorList; } /** * @param coveragesList */ - public void setCoverage(String[] coveragesList) { + public void setCoverages(String[] coveragesList) { this.coverageList = coveragesList; } @@ -535,25 +539,11 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { this.publisherList = publishersList; } - /** - * @param relationsList - */ - public void setRelations(String[] relationsList) { - this.relationList = relationsList; - } - - /** - * @param relationsList - */ - public void setRelationsForWork(String[] relationsList) { - this.relationForWorkList = relationsList; - } - /** * @param rightsList */ public void setRights(String[] rightsList) { - this.rightList = rightsList; + this.rightsList = rightsList; } /** @@ -585,108 +575,17 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { } /** - * @return - */ - public boolean isFoundItems() { - return this.foundItems; - } - - /** - * @param foundItems - */ - public void setFoundItems(boolean foundItems) { - this.foundItems = foundItems; - } - - /** - * @return - */ - public String getModifiedField() { - return this.modifiedField; - } - - /** - * @param modifiedField - */ - public void setModifiedField(String modifiedField) { - this.modifiedField = modifiedField; - } - - /** - * @return - */ - public String getIdentifierField() { - return this.identifierField; - } - - /** - * @param identifierField - */ - public void setIdentifierField(String identifierField) { - this.identifierField = identifierField; - } - - /** - * @return - */ - public int getSearchResponseSize() { - return this.searchResponseSize; - } - - /** - * @param searchResponseSize - */ - public void setSearchResponseSize(String searchResponseSize) { - this.searchResponseSize = Integer.parseInt(searchResponseSize); - } - - /** - * @return - */ - public boolean getTextGrid() { - return this.textgrid; - } - - /** - * @return - */ - public String[] getWorkFields() { - return this.workFields; - } - - /** - * @param workFields - */ - public void setWorkFields(String[] workFields) { - this.workFields = workFields; - } - - /** - * @param fields - */ - public void setFields(String[] fields) { - this.fields = fields; - } - - /** - * @return - */ - public String[] getFields() { - return this.fields; - } - - /** - * @return + * @param relationsList */ - public OAI_ESClient getOaiEsClient() { - return this.oaiEsClient; + public void setRelations(String[] relationsList) { + this.relationList = relationsList; } /** - * @param oaiEsClient + * @param relationsForWorkList */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { - this.oaiEsClient = oaiEsClient; + public void setRelationsForWork(String[] relationsForWorkList) { + this.relationsForWorkList = relationsForWorkList; } } 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 28b1d2c560cf59ee260ddd605e88eb1b5c3fc5d6..1c38debd22987a3acee23d45514d0afa711d1651 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -1,18 +1,21 @@ package info.textgrid.middleware; -import java.util.Hashtable; -import java.util.Map; +import java.io.IOException; +import java.text.ParseException; +import org.apache.commons.logging.Log; 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.client.RequestOptions; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.search.SearchHit; - -import info.textgrid.middleware.oaipmh.HeaderType; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.json.JSONObject; import info.textgrid.middleware.oaipmh.ListRecordsType; -import info.textgrid.middleware.oaipmh.MetadataType; -import info.textgrid.middleware.oaipmh.RecordType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** @@ -20,142 +23,105 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; */ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { - private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); - static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - - private OAI_ESClient oaiEsClient; - private boolean foundItems; + private static Log log = LogFactory.getLog(RecordListDelivererIDIOM.class); /** * @param textgrid * @param dariah */ public RecordListDelivererIDIOM(boolean textgrid, boolean dariah) { - super(textgrid, dariah); } - /** - * @param recordList - * @param set - * @param headerIdentifier - * @return - */ - public RecordType buildRecord(ListRecordsType recordList, String set, String headerIdentifier) { - - MetadataType metadata = new MetadataType(); - RecordType record = new RecordType(); - - record.setMetadata(metadata); - recordList.getRecord().add(record); - - return null; - } - /* * (non-Javadoc) * * @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ - - @Override public ListRecordsType getRecords(final String from, final String to, final String set, - final String resumptionToken) { - System.out.println("BUFF"); - ListRecordsType recordList = new ListRecordsType(); - - QueryBuilder recordFilterForClassicMayan; - QueryBuilder rangeQuery; - //Queries queries = new Queries(); - //List<String> artefactURIs = queries.getArtefactList(); - - rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); - recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery) - .must(QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) - .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) - .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); - - SearchResponse scrollResp; - - if (resumptionToken == null) { - - scrollResp = OAI_ESClient.getOaiESClient() - .prepareSearch("textgrid-nonpublic") - .setScroll(TimeValue.timeValueHours(24L)) - .setTypes(OAI_ESClient.getEsType()) - .addFields("lastModified", "textgridUri", "project.id") - .setQuery(recordFilterForClassicMayan) - .setSize(30) - .execute() - .actionGet(); - }else { - scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); - } - - String scrollID = scrollResp.getScrollId(); - - long completeListSize = scrollResp.getHits().totalHits(); - //long completeListSize = 45; - //System.out.println(completeListSize); - //System.out.println(completeListSize + " || " + artefactURIs.size()); - if (completeListSize > 0) { - setFoundItems(true); - int i = 0; - //System.out.println("inside "); - for (SearchHit hit : scrollResp.getHits().getHits()) { - i++; - String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); - System.out.println("Processing: " + textgridURI); - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); - recordList.getRecord().add(idiomRecord.getRecordById(textgridURI).getRecord()); - } - - // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( - completeListSize, resumptionToken, cursorCollector, scrollID, 30, i); - if (resTokenForResponse != null) { - recordList.setResumptionToken(resTokenForResponse); - } - }else { - setFoundItems(false); - } - - return recordList; + final String resumptionToken) throws ParseException, IOException { + + ListRecordsType recordList = new ListRecordsType(); + + BoolQueryBuilder recordFilterForClassicMayan; + RangeQueryBuilder rangeQuery; + + rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); + + recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery) + .must(QueryBuilders.matchPhraseQuery("project.id", + "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) + .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) + .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); + + SearchResponse scrollResp; + + SearchRequest searchRequest = new SearchRequest("textgrid-nonpublic"); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + + scrollResp = null; + + searchSourceBuilder.query(recordFilterForClassicMayan); + searchSourceBuilder.size(30); + searchRequest.source(searchSourceBuilder); + + if (resumptionToken != null) { + SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + scrollRequest.scroll(TimeValue.timeValueHours(24L)); + try { + scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + searchRequest.source(searchSourceBuilder); + searchRequest.scroll(TimeValue.timeValueHours(24L)); + try { + scrollResp = OAI_ESClient.getEsClient().search(searchRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + String scrollID = scrollResp.getScrollId(); + + long completeListSize = scrollResp.getHits().totalHits; + // long completeListSize = 45; + + if (completeListSize > 0) { + setFoundItems(true); + int i = 0; + + for (SearchHit hit : scrollResp.getHits().getHits()) { + i++; + + String textgridURI = + OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), "textgridUri"); + + log.debug("IDIOM URIs: " + textgridURI); + + // hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); + + log.debug("Processing: " + textgridURI); + + RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); + recordList.getRecord() + .add(idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord()); + } + // Check the need for a resumption token! + ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( + completeListSize, resumptionToken, cursorCollector, scrollID, 30, i); + if (resTokenForResponse != null) { + recordList.setResumptionToken(resTokenForResponse); + } + } else { + setFoundItems(false); + } + + return recordList; } - - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.RecordListDelivererInterface#setHeader(java.lang.String, - * java.lang.String) - */ - @Override - public HeaderType setHeader(String set, String headerIdentifier) { - return null; - } - - /** - * @return - */ - public OAI_ESClient getOaiEsClient() { - return this.oaiEsClient; - } - - /** - * @param oaiEsClient - */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { - this.oaiEsClient = oaiEsClient; - } - -public boolean isFoundItems() { - return foundItems; -} - -public void setFoundItems(boolean foundItems) { - this.foundItems = foundItems; -} } 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..b79343d8158fd6400f52105d8ac9318a9b87231b 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java @@ -1,6 +1,7 @@ package info.textgrid.middleware; -import info.textgrid.middleware.oaipmh.HeaderType; +import java.io.IOException; +import java.text.ParseException; import info.textgrid.middleware.oaipmh.ListRecordsType; /** @@ -8,20 +9,17 @@ import info.textgrid.middleware.oaipmh.ListRecordsType; */ public interface RecordListDelivererInterface { + /** * @param from * @param to * @param set * @param resumptionToken * @return + * @throws ParseException + * @throws IOException */ - public ListRecordsType getRecords(String from, String to, String set, String resumptionToken); - - /** - * @param set - * @param headerIdentifier - * @return - */ - public HeaderType setHeader(String set, String headerIdentifier); + public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) + throws ParseException, IOException; } 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 deleted file mode 100644 index c7be36a580bdb4a27532d830aa45300ab090eed6..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/SetDeliverer.java +++ /dev/null @@ -1,272 +0,0 @@ -package info.textgrid.middleware; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import org.elasticsearch.action.get.GetRequestBuilder; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import info.textgrid.middleware.oaipmh.ListSetsType; -import info.textgrid.middleware.oaipmh.RequestType; -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 Set<String> identifier = new LinkedHashSet<String>(); - private String formatField; - private String formatToFilter; - private String identifierField; - private String repositoryObjectURIPrefix; - private String specField; - private String specFieldPrefix; - private boolean textgrid; - private boolean dariah; - - /** - * @param oaiEsClient - * @param textgrid - * @param dariah - */ - public SetDeliverer(boolean textgrid, boolean dariah) { - this.textgrid = textgrid; - this.dariah = dariah; - } - - /** - * @return - */ - 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(); - - for (SearchHit hit : getRecordListItems.getHits().getHits()) { - if (this.dariah == true && hit.getFields().get(this.identifierField).values().get(0) - .toString().startsWith("hdl:")) { - String pid = hit.getFields().get(this.identifierField).values().get(0).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; - try { - id = URLDecoder.decode(id, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - 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); - - 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(); - } - } - - SetType set = new SetType(); - set.setSetName(setName); - set.setSetSpec(this.specFieldPrefix + id); - setList.getSet().add(set); - } - } - - this.identifier.clear(); - - return setList; - } - - /** - * <p> - * Checking the request if all necessary values are set or not allowed values are not set. - * </p> - * - * @param request the initially request from the OAIPMG client - * @return a boolean indicating the correctness of the request - */ - public boolean requestChecker(RequestType request) { - - boolean noArguments; - - if (request.getFrom() != null || - request.getIdentifier() != null || - request.getMetadataPrefix() != null) { - noArguments = false; - } else if (request.getResumptionToken() != null || - request.getSet() != null || - request.getUntil() != null) { - - noArguments = false; - } else { - noArguments = true; - } - return noArguments; - } - - /** - * @return - */ - public String getFormatField() { - return this.formatField; - } - - /** - * @param formatField - */ - public void setFormatField(String formatField) { - this.formatField = formatField; - } - - public String getFormatToFilter() { - return this.formatToFilter; - } - - /** - * @param formatToFilter - */ - public void setFormatToFilter(String formatToFilter) { - this.formatToFilter = formatToFilter; - } - - /** - * @return - */ - public String getIdentifierField() { - return this.identifierField; - } - - /** - * @param identifierField - */ - public void setIdentifierField(String identifierField) { - this.identifierField = identifierField; - } - - /** - * @return - */ - public String getRepositoryObjectURIPrefix() { - return this.repositoryObjectURIPrefix; - } - - /** - * @param repositoryObjectURIPrefix - */ - public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { - this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; - } - - /** - * @return - */ - public String getSpecField() { - return this.specField; - } - - /** - * @param titleField - */ - public void setSpecField(String titleField) { - this.specField = titleField; - } - - /** - * @return - */ - public String getSpecFieldPrefix() { - return this.specFieldPrefix; - } - - /** - * @param specFieldPrefix - */ - public void setSpecFieldPrefix(String specFieldPrefix) { - this.specFieldPrefix = specFieldPrefix; - } - - /** - * @return - */ - public boolean isTextgrid() { - return this.textgrid; - } - - /** - * @param textgrid - */ - public void setTextgrid(boolean textgrid) { - this.textgrid = textgrid; - } - - /** - * @return - */ - public boolean isDariah() { - return this.dariah; - } - - /** - * @param dariah - */ - public void setDariah(boolean dariah) { - this.dariah = dariah; - } - -} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java new file mode 100644 index 0000000000000000000000000000000000000000..f7c12dbaf8bcd1d8e5356c418d0f1616d54ebb2b --- /dev/null +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java @@ -0,0 +1,331 @@ +package info.textgrid.middleware; + +import java.io.IOException; +import java.util.Map.Entry; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.Aggregation; +import org.elasticsearch.search.aggregations.AggregationBuilder; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.filter.Filter; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import info.textgrid.clients.tgauth.AuthClientException; +import info.textgrid.middleware.common.TextGridMimetypes; +import info.textgrid.middleware.oaipmh.ListSetsType; +import info.textgrid.middleware.oaipmh.RequestType; +import info.textgrid.middleware.oaipmh.SetType; + +/** + * + */ +public class SetListDeliverer { + + private static Log log = LogFactory.getLog(SetListDeliverer.class); + + private static final int DH_SIZE = 100000; + + private static final String DH_COLLECTION_FILTER_NAME = "collectionFilter"; + private static final String DH_COLLECTION_FILTER_TERM_NAME = "collectionFilterTerm"; + private static final String DH_FIELD_DIVIDER = "&"; + + // FIXME Do we need all the vars and getters/setters here? Why don't we use them? + + private String formatField; + private String formatToFilter; + private String identifierField; + private String repositoryObjectURIPrefix; + private String specFieldPrefix; + private boolean textgrid; + private boolean dariah; + + /** + * @param oaiEsClient + * @param textgrid + * @param dariah + */ + public SetListDeliverer(boolean textgrid, boolean dariah) { + this.textgrid = textgrid; + this.dariah = dariah; + } + + /** + * @return + * @throws AuthClientException + * @throws IOException + */ + public ListSetsType setListBuilder() { + + ListSetsType setList = new ListSetsType(); + + SearchRequest request = new SearchRequest(OAI_ESClient.getEsIndex()); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + searchSourceBuilder.size(0); + + // Assemble TG ES request. + if (this.textgrid) { + Script mergeProjectIDandProjectName = + new Script("doc['project.id'].value + '&' + doc['project.value.untouched'].value"); + + AggregationBuilder filterPublicProjects = AggregationBuilders.filter("projectsPublic", + QueryBuilders.boolQuery() + .mustNot(QueryBuilders.existsQuery("nearlyPublished")) + .must(QueryBuilders.matchPhraseQuery("format", TextGridMimetypes.EDITION))); + + AggregationBuilder projectNameAndID = AggregationBuilders.terms("projects") + .script(mergeProjectIDandProjectName) + .size(1000); + + filterPublicProjects.subAggregation(projectNameAndID); + + searchSourceBuilder.aggregation(filterPublicProjects); + // searchSourceBuilder.aggregation(projectNameAndID); + } + + // Assemble DH ES request. + else if (this.dariah) { + + Script mergeCollectionIDAndTitle = new Script( + "doc['administrativeMetadata.dcterms:identifier'].value + '" + DH_FIELD_DIVIDER + + "' + doc['descriptiveMetadata.dc:title'].value"); + + // Do filter all collections (via descriptiveMetadata.dc:format) AND get out all the child + // objects and collections (NO descriptiveMetadata.dc:relation), so we get exactly one set per + // root collection only! + AggregationBuilder collectionFilter = AggregationBuilders.filter(DH_COLLECTION_FILTER_NAME, + QueryBuilders.boolQuery() + .mustNot(QueryBuilders.existsQuery("descriptiveMetadata.dc:relation")) + .must(QueryBuilders.matchPhraseQuery("descriptiveMetadata.dc:format", + TextGridMimetypes.DARIAH_COLLECTION))); + AggregationBuilder collectionFilterTerm = AggregationBuilders + .terms(DH_COLLECTION_FILTER_TERM_NAME).script(mergeCollectionIDAndTitle).size(DH_SIZE); + + collectionFilter.subAggregation(collectionFilterTerm); + searchSourceBuilder.aggregation(collectionFilter); + } + + request.source(searchSourceBuilder); + + log.debug("request: " + request); + + // Get items with TG or DH request. + SearchResponse getRecordListItems = null; + try { + getRecordListItems = OAI_ESClient.getEsClient().search(request, RequestOptions.DEFAULT); + + log.debug("list item count: " + getRecordListItems.getHits().totalHits); + + } catch (IOException e) { + // TODO Auto-generated catch block + log.error(e.getMessage()); + e.printStackTrace(); + } + + // Fill ListSets request... + if (getRecordListItems.getAggregations() != null) { + + // ...for TG + if (this.textgrid) { + 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()) { + String projectName = bentry.getKey().toString(); + String[] projectInfos = projectName.split("&"); + SetType setsForTextGrid = new SetType(); + setsForTextGrid.setSetSpec(this.specFieldPrefix + projectInfos[0]); + setsForTextGrid.setSetName(projectInfos[1]); + setList.getSet().add(setsForTextGrid); + } + } + } + } + + // ...for DH + else if (this.dariah) { + for (Entry<String, Aggregation> entry : getRecordListItems.getAggregations().asMap() + .entrySet()) { + + String name = entry.getKey(); + + log.debug("entry key: " + entry.getKey()); + + if (name.equals(DH_COLLECTION_FILTER_NAME)) { + Filter filterCollection = + getRecordListItems.getAggregations().get(DH_COLLECTION_FILTER_NAME); + Terms collectionTerms = + filterCollection.getAggregations().get(DH_COLLECTION_FILTER_TERM_NAME); + for (Bucket b : collectionTerms.getBuckets()) { + // Divide ID and title. + String combined = b.getKeyAsString(); + + log.debug("combined: " + combined); + + int indexOf = combined.indexOf(DH_FIELD_DIVIDER); + // ID already contains the setSpecPrefix! + String id = combined.substring(0, indexOf); + + log.debug("id: " + id); + + String title = combined.substring(indexOf + 1); + + log.debug("title: " + title); + + // Set set. + SetType newSet = new SetType(); + newSet.setSetSpec(id); + newSet.setSetName(title); + setList.getSet().add(newSet); + } + } + } + } + } + + // Add OpenAIRE data set for OpenAIRE. + // TODO Document for what this is used or necessary! + SetType setOpenAire = new SetType(); + setOpenAire.setSetName("OpenAIRE"); + setOpenAire.setSetSpec("openaire_data"); + setList.getSet().add(setOpenAire); + + return setList; + } + + /** + * <p> + * Checking the request if all necessary values are set or not allowed values are not set. + * </p> + * + * @param request the initially request from the OAIPMG client + * @return a boolean indicating the correctness of the request + */ + public boolean requestChecker(RequestType request) { + + boolean noArguments; + + if (request.getFrom() != null || + request.getIdentifier() != null || + request.getMetadataPrefix() != null) { + noArguments = false; + } else if (request.getResumptionToken() != null || + request.getSet() != null || + request.getUntil() != null) { + noArguments = false; + } else { + noArguments = true; + } + + return noArguments; + } + + + /** + * @return + */ + public String getFormatField() { + return this.formatField; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public String getFormatToFilter() { + return this.formatToFilter; + } + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @return + */ + public String getIdentifierField() { + return this.identifierField; + } + + /** + * @param identifierField + */ + public void setIdentifierField(String identifierField) { + this.identifierField = identifierField; + } + + /** + * @return + */ + public String getRepositoryObjectURIPrefix() { + return this.repositoryObjectURIPrefix; + } + + /** + * @param repositoryObjectURIPrefix + */ + public void setRepositoryObjectURIPrefix(String repositoryObjectURIPrefix) { + this.repositoryObjectURIPrefix = repositoryObjectURIPrefix; + } + + /** + * @return + */ + public String getSpecFieldPrefix() { + return this.specFieldPrefix; + } + + /** + * @param specFieldPrefix + */ + public void setSpecFieldPrefix(String specFieldPrefix) { + this.specFieldPrefix = specFieldPrefix; + } + + /** + * @return + */ + public boolean isTextgrid() { + return this.textgrid; + } + + /** + * @param textgrid + */ + public void setTextgrid(boolean textgrid) { + this.textgrid = textgrid; + } + + /** + * @return + */ + public boolean isDariah() { + return this.dariah; + } + + /** + * @param dariah + */ + public void setDariah(boolean dariah) { + this.dariah = dariah; + } + +} 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..2db94e96994a207f74bfd49a571c7a0636269949 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/TGConstants.java @@ -1,48 +1,19 @@ package info.textgrid.middleware; -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 REPOSITORY_BASEURL = "textgridrep.org"; public static final String ITEM_IDENTIFIER_PREFIX = "textgrid:"; - public static final List<String> TEXTGRID_REP_ADMIN_CONTACT = - Arrays.asList("textgrid-support@gwdg.de"); - - /* - * Repository Identification String Constants - */ - - public static final String TG_REP_BASEURL = "www.textgridrep.de"; - public static final String METADATA_DC_PREFIX = "oai_dc"; - public static final String METADATA_IDIOM_PREFIX = "oai_idiom_mets"; - - /* - * 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"; - - /* - * 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"; @@ -51,6 +22,7 @@ public final class TGConstants { public static final String PROJECT_ID = "project.id"; public static final String IS_DERIVED_FROM = "relations.isDerivedFrom"; public static final String TITLE = "title"; + public static final String ADDITIONAL_TITLE = "edition.source.editionTitle"; // Just for OpenAire public static final String PID = "pid.value"; public static final String EDITION_ISEDITIONOF = "edition.isEditionOf"; public static final String EDITION_AGENT = "edition.agent.value"; @@ -78,27 +50,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 +69,15 @@ 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/openaire/include/datacite-contributorType-v3.1.xsd b/oaipmh-core/src/main/openaire/include/datacite-contributorType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..c472076af44c0e2a6c30d8e1f7183d6be6ba5e36 --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-contributorType-v3.1.xsd @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, added values "ResearchGroup" & "Other" + 2014-08-20 v3.1: Addition of value "DataCurator" + 2015-05-14 v4.0 dropped value "Funder", use new "funderReference" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="contributorType" id="contributorType"> + <xs:annotation> + <xs:documentation>The type of contributor of the resource.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="ContactPerson"/> + <xs:enumeration value="DataCollector"/> + <xs:enumeration value="DataCurator"/> + <xs:enumeration value="DataManager"/> + <xs:enumeration value="Distributor"/> + <xs:enumeration value="Editor"/> + <xs:enumeration value="HostingInstitution"/> + <xs:enumeration value="Other"/> + <xs:enumeration value="Producer"/> + <xs:enumeration value="ProjectLeader"/> + <xs:enumeration value="ProjectManager"/> + <xs:enumeration value="ProjectMember"/> + <xs:enumeration value="RegistrationAgency"/> + <xs:enumeration value="RegistrationAuthority"/> + <xs:enumeration value="RelatedPerson"/> + <xs:enumeration value="ResearchGroup"/> + <xs:enumeration value="RightsHolder"/> + <xs:enumeration value="Researcher"/> + <xs:enumeration value="Sponsor"/> + <xs:enumeration value="Supervisor"/> + <xs:enumeration value="WorkPackageLeader"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-dateType-v3.xsd b/oaipmh-core/src/main/openaire/include/datacite-dateType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..0455f8ac57344bd75fa5119603293297b33353a5 --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-dateType-v3.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; addition of value "Collected"; deleted "StartDate" & "EndDate"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="dateType" id="dateType"> + <xs:annotation> + <xs:documentation>The type of date. Use RKMSâ€ISO8601 standard for depicting date ranges.To indicate the end of an embargo period, use Available. To indicate the start of an embargo period, use Submitted or Accepted, as appropriate.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Accepted"/> + <xs:enumeration value="Available"/> + <xs:enumeration value="Collected"/> + <xs:enumeration value="Copyrighted"/> + <xs:enumeration value="Created"/> + <xs:enumeration value="Issued"/> + <xs:enumeration value="Submitted"/> + <xs:enumeration value="Updated"/> + <xs:enumeration value="Valid"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-descriptionType-v3.xsd b/oaipmh-core/src/main/openaire/include/datacite-descriptionType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..881a4dfddd66bf3421e93cb4845f17bde757e81b --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-descriptionType-v3.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, addition of value "Methods" + 2015-02-12 v4.0: Addition of value "TechnicalInfo"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="openaireDescriptionType" id="openaireDescriptionType"> + <xs:annotation> + <xs:documentation>The type of the description.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Abstract"/> + <xs:enumeration value="Methods"/> + <xs:enumeration value="SeriesInformation"/> + <xs:enumeration value="TableOfContents"/> + <xs:enumeration value="TechnicalInfo"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-relatedIdentifierType-v3.1.xsd b/oaipmh-core/src/main/openaire/include/datacite-relatedIdentifierType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..a300456d93c1fad4d5bc96f73d9f526b9270db5e --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-relatedIdentifierType-v3.1.xsd @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; addition of value "PMID" + 2014-08-20 v3.1: Addition of values "arxiv" and "bibcode"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="relatedIdentifierType" id="relatedIdentifierType"> + <xs:annotation> + <xs:documentation>The type of the RelatedIdentifier.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="ARK"/> + <xs:enumeration value="arXiv"/> + <xs:enumeration value="bibcode"/> + <xs:enumeration value="DOI"/> + <xs:enumeration value="EAN13"/> + <xs:enumeration value="EISSN"/> + <xs:enumeration value="Handle"/> + <xs:enumeration value="ISBN"/> + <xs:enumeration value="ISSN"/> + <xs:enumeration value="ISTC"/> + <xs:enumeration value="LISSN"/> + <xs:enumeration value="LSID"/> + <xs:enumeration value="PMID"/> + <xs:enumeration value="PURL"/> + <xs:enumeration value="UPC"/> + <xs:enumeration value="URL"/> + <xs:enumeration value="URN"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-relationType-v3.1.xsd b/oaipmh-core/src/main/openaire/include/datacite-relationType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..ed8516b52bdd3a92220946e2b22b630de2fa55f3 --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-relationType-v3.1.xsd @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, addition of values "IsIdenticalTo", "HasMetadata" & "IsMetadataFor" + 2014-08-20 v3.1: Addition of values "Reviews" & "IsReviewedBy" and "IsDerivedFrom" & "IsSourceOf"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="relationType" id="relationType"> + <xs:annotation> + <xs:documentation>Description of the relationship of the resource being registered (A) and the related resource (B).</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="IsCitedBy"/> + <xs:enumeration value="Cites"/> + <xs:enumeration value="IsSupplementTo"/> + <xs:enumeration value="IsSupplementedBy"/> + <xs:enumeration value="IsContinuedBy"/> + <xs:enumeration value="Continues"/> + <xs:enumeration value="IsNewVersionOf"/> + <xs:enumeration value="IsPreviousVersionOf"/> + <xs:enumeration value="IsPartOf"/> + <xs:enumeration value="HasPart"/> + <xs:enumeration value="IsReferencedBy"/> + <xs:enumeration value="References"/> + <xs:enumeration value="IsDocumentedBy"/> + <xs:enumeration value="Documents"/> + <xs:enumeration value="IsCompiledBy"/> + <xs:enumeration value="Compiles"/> + <xs:enumeration value="IsVariantFormOf"/> + <xs:enumeration value="IsOriginalFormOf"/> + <xs:enumeration value="IsIdenticalTo"/> + <xs:enumeration value="HasMetadata"/> + <xs:enumeration value="IsMetadataFor"/> + <xs:enumeration value="Reviews"/> + <xs:enumeration value="IsReviewedBy"/> + <xs:enumeration value="IsDerivedFrom"/> + <xs:enumeration value="IsSourceOf"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-resourceType-v3.xsd b/oaipmh-core/src/main/openaire/include/datacite-resourceType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..3205a0cd3df8975b6b142061d67fe63622cda082 --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-resourceType-v3.xsd @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; added values "Audiovisual", "Workflow" & "Other"; deleted value "Film" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="resourceType" id="resourceType"> + <xs:annotation> + <xs:documentation>The general type of a resource.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Audiovisual"/> + <xs:enumeration value="Collection"/> + <xs:enumeration value="Dataset"/> + <xs:enumeration value="Event"/> + <xs:enumeration value="Image"/> + <xs:enumeration value="InteractiveResource"/> + <xs:enumeration value="Model"/> + <xs:enumeration value="PhysicalObject"/> + <xs:enumeration value="Service"/> + <xs:enumeration value="Software"/> + <xs:enumeration value="Sound"/> + <xs:enumeration value="Text"/> + <xs:enumeration value="Workflow"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/include/datacite-titleType-v3.xsd b/oaipmh-core/src/main/openaire/include/datacite-titleType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..ed2508ad8a9e8da913dbf77ea8763ccff13fe1cf --- /dev/null +++ b/oaipmh-core/src/main/openaire/include/datacite-titleType-v3.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element + 2015-02-12 v4.0 Added value "Other" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="titleType" id="titleType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="AlternativeTitle"/> + <xs:enumeration value="Subtitle"/> + <xs:enumeration value="TranslatedTitle"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..952ae31ddbf10d640b11c920f116bb400f07f257 --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-1.0.xsd @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema describes the XML serialization of the OpenAIRE Research Graph. + For an overview of the model, please check the OpenAIRE Research Graph Data Model at https://doi.org/10.5281/zenodo.2643199 + </xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-result-1.0.xsd"/> + <xs:include schemaLocation="oaf-org-1.0.xsd"/> + <xs:include schemaLocation="oaf-datasource-1.0.xsd"/> + <xs:include schemaLocation="oaf-project-1.0.xsd"/> + + <xs:element name="entity"> + <xs:complexType> + <xs:sequence> + <xs:choice> + <xs:element ref="result"/> + <xs:element ref="organization"/> + <xs:element ref="datasource"/> + <xs:element ref="project"/> + </xs:choice> + </xs:sequence> + </xs:complexType> + </xs:element> + +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-common-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-common-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..8c52e22a3732c42d8f782bb065f7acfd7e525e0a --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-common-1.0.xsd @@ -0,0 +1,298 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns="http://namespace.openaire.eu/oaf" targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema defines common types that can be re-used.</xs:documentation> + </xs:annotation> + + <xs:simpleType name="emptyType"> + <xs:restriction base="xs:string"> + <xs:length value="0"/> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="boolOrEmptyType"> + <xs:union memberTypes="emptyType xs:boolean"/> + </xs:simpleType> + + <xs:simpleType name="stringOrEmptyType"> + <xs:union memberTypes="emptyType xs:string"/> + </xs:simpleType> + + <xs:attributeGroup name="dataInfoAttributeGroup"> + <xs:attribute name="inferred" use="optional" type="xs:boolean"> + <xs:annotation> + <xs:documentation>True if this information has been inferred by the automatic + inference algorithms run by OpenAIRE. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="trust" use="optional" type="xs:string"> + <xs:annotation> + <xs:documentation>Value of trust of this information in the range [0,1]. More the + value, more trustworthy is the information. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="inferenceprovenance" use="optional" type="xs:string"> + <xs:annotation> + <xs:documentation>Which algorithm inferred the current property. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attributeGroup ref="qualifierAttributeGroup"></xs:attributeGroup> + </xs:attributeGroup> + + <xs:attributeGroup name="qualifierAttributeGroup"> + <xs:attribute name="classid" use="required" type="xs:string"/> + <xs:attribute name="classname" use="required" type="xs:string"/> + <xs:attribute name="schemeid" use="required" type="xs:string"/> + <xs:attribute name="schemename" use="required" type="xs:string"/> + </xs:attributeGroup> + + <xs:complexType name="fieldType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="qualifierType"> + <xs:attributeGroup ref="qualifierAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="dataInfoType"> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="structuredPropertyElementType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attributeGroup ref="qualifierAttributeGroup"/> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="labeledIdElementType"> + <xs:attribute name="id" use="required"/> + <xs:attribute name="label" use="required"/> + </xs:complexType> + + <!-- <oaf:context id="egi" label="EGI" type="community"> + <oaf:category id="egi::virtual" label="EGI virtual organizations"> + <oaf:concept id="egi::virtual::2" label="alice"/> + </oaf:category> + </oaf:context> + <oaf:community id="{@id}" label="{@label}"> + <xsl:apply-templates/> + </oaf:community> + --> + <xs:complexType name="contextType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence maxOccurs="unbounded"> + <xs:element name="category" type="categoryType"/> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="categoryType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence minOccurs="0" maxOccurs="unbounded"> + <xs:element name="concept" type="conceptType"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="conceptType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence maxOccurs="unbounded" minOccurs="0"> + <xs:element name="concept" type="conceptType"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="namedIdElementType"> + <xs:attribute name="id" use="required"/> + <xs:attribute name="name" use="required"/> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities.</xs:documentation> + </xs:annotation> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element name="rel" type="relType" minOccurs="0"/> + </xs:choice> + </xs:complexType> + + <xs:complexType name="relType"> + <xs:sequence> + <xs:choice maxOccurs="unbounded"> + <xs:element name="to" type="relToType"/> + <xs:element name="title" type="xs:string"/> + <xs:element name="websiteurl"/> + <xs:choice> + <xs:group ref="relDataSourceGroup"/> + <xs:group ref="relResultGroup"/> + <xs:group ref="relProjectGroup"/> + <xs:group ref="relOrganizationGroup"/> + <xs:group ref="fundingGroup"/> + </xs:choice> + </xs:choice> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:group name="relDataSourceGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="officialname" type="xs:string"/> + <xs:element name="datasourcetype" type="qualifierType"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relResultGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="collectedfrom" type="namedIdElementType"/> + <xs:element name="url" type="xs:string"/> + <xs:element name="pid" type="structuredPropertyElementType"/> + <xs:element name="dateofacceptance" type="xs:string"/> + <xs:element name="publisher" type="xs:string"/> + <xs:element name="resulttype" type="xs:string"> + <xs:annotation> + <xs:documentation> Tells if the related record is about a publication or a + dataset. </xs:documentation> + </xs:annotation> + </xs:element> + <!-- the following fields are available only for similarity relations --> + <xs:element name="similarity" type="xs:double"> + <xs:annotation> + <xs:documentation>The similarity degree expressed in the range (0,1]. This + field is avaiable only when the to/@class is one of + {hasAmongTopNSimilarDocuments, + isAmongTopNSimilarDocuments}</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="type"> + <xs:annotation> + <xs:documentation>The similarity degree expressed in the range (0,1]. This + field is avaiable only when the to/@class is one of + {hasAmongTopNSimilarDocuments, + isAmongTopNSimilarDocuments}</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="STANDARD"/> + <xs:enumeration value="WEBUSAGE"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relProjectGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="code" type="xs:string"/> + <xs:element name="acronym" type="xs:string"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="fundingGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="contracttype" type="qualifierType"/> + <xs:element name="funding" type="fundingFlatType"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relOrganizationGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="legalname" type="xs:string"/> + <xs:element name="legalshortname" type="xs:string"/> + <xs:element name="country" type="xs:string"/> + </xs:choice> + </xs:sequence> + </xs:group> + + + <xs:complexType name="relToType"> + <xs:annotation> + <xs:documentation>Information about the related entity. <p>The semantics of the + relationships is expressed by the attributes class and scheme. </p> + </xs:documentation> + </xs:annotation> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="class" use="required" type="xs:string"/> + <xs:attribute name="type" use="required" type="xs:string"> + <xs:annotation> + <xs:documentation>The type of the related entity. <p>Allowed values are: + project, organization, datasource, result, person.</p> + </xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="fundingFlatType"> + <xs:sequence> + <xs:element name="funder" type="funderFlatType" minOccurs="1" maxOccurs="1"/> + <xs:element name="funding_level_0" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + <xs:element name="funding_level_1" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + <xs:element name="funding_level_2" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="funderFlatType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="id" use="required" type="xs:string"/> + <xs:attribute name="shortname" use="required" type="xs:string"/> + <xs:attribute name="name" use="required" type="xs:string"/> + <xs:attribute name="jurisdiction" use="optional" type="xs:string"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="namedFundingLevel"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="name" use="required" type="xs:string"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="externalreferenceType"> + <xs:sequence> + <xs:element name="sitename" type="xs:string" minOccurs="0" maxOccurs="1"/> + <!--<xs:element name="label" type="xs:string" minOccurs="0" maxOccurs="1"/>--> + <xs:element name="url" type="xs:string" minOccurs="0" maxOccurs="1"/> + <xs:element name="qualifier" type="qualifierType" minOccurs="0" maxOccurs="1"/> + <xs:element name="refidentifier" type="xs:string" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + + <!-- REMOVE FROM HERE TO THE END --> + +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-datasource-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-datasource-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..c84ec2531dafd7151cd00ac15f6b15aa1fd579af --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-datasource-1.0.xsd @@ -0,0 +1,76 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE datasources: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_datasource</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="datasource"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="namespaceprefix" type="xs:string" /> + <xs:element name="officialname" type="xs:string" /> + <xs:element name="englishname" type="xs:string" /> + <xs:element name="websiteurl" type="xs:string" /> + <xs:element name="logourl" type="xs:string" /> + <xs:element name="contactemail" type="xs:string" /> + <xs:element name="datasourcetype" type="qualifierType"> + <xs:annotation> + <xs:documentation>For allowed values check terms in:http://api.openaire.eu/vocabularies/dnet:datasource_typologies</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="openairecompatibility" type="qualifierType"> + <xs:annotation> + <xs:documentation> + Level of compatibility of this datasource with regards to the + guidelines. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:datasourceCompatibilityLevel + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="dateofvalidation" type="xs:string"> + <xs:annotation> + <xs:documentation>When this datasource has been validated by the + OpenAire + Validator. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="latitude" type="xs:string" /> + <xs:element name="longitude" type="xs:string" /> + <xs:element name="description" type="xs:string" /> + <xs:element name="subjects" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> + Subjects and keywords. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:result_subjects + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="originalId" type="xs:string" /> + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which + this datasource has + been collected from. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="structuredPropertyElementType" /> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. + </xs:documentation> + </xs:annotation> + </xs:element> + + </xs:choice> + </xs:complexType> + </xs:element> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-org-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-org-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..3c46fca44b6462be5fb51d116555cac23ea9d016 --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-org-1.0.xsd @@ -0,0 +1,41 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE entities of type organization: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_organization</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="organization"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="legalname" type="xs:string"/> + <xs:element name="legalshortname" type="xs:string"/> + <xs:element name="logourl" type="xs:string"/> + <xs:element name="originalId" type="xs:string"/> + <xs:element name="websiteurl" type="xs:string"/> + <xs:element name="country" type="qualifierType"> + <xs:annotation> + <xs:documentation>Countries in ISO 3166-1 alpha-2. </xs:documentation> + </xs:annotation> + </xs:element> + + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + organization has been collected from. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="structuredPropertyElementType"/> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + <!-- If we decide not to show deduplicated org, then we have to remove this field --> + <!-- <xs:element name="duplicates" type="mergedOrgs"/> --> + </xs:choice> + </xs:complexType> + </xs:element> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-project-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-project-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..abcba4d9f63f31996226f01a18ab575541e32827 --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-project-1.0.xsd @@ -0,0 +1,111 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE project entity: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_project</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="project"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="code" type="xs:string"> + <xs:annotation> + <xs:documentation>Project code as assigned by the project's funder.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="title" type="xs:string"/> + <xs:element name="acronym" type="xs:string"/> + <xs:element name="callidentifier" type="xs:string"> + <xs:annotation> + <xs:documentation> Identifier of the call for proposal.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="contactfullname" type="xs:string"/> + <xs:element name="contactfax" type="xs:string"/> + <xs:element name="contactphone" type="xs:string"/> + <xs:element name="contactemail" type="xs:string"/> + <xs:element name="contracttype" type="qualifierType"/> + <xs:element name="keywords" type="xs:string"/> + <xs:element name="websiteurl" type="xs:string"/> + <xs:element name="startdate" type="xs:string"/> + <xs:element name="enddate" type="xs:string"/> + <xs:element name="duration" type="xs:string"/> + <xs:element name="ecsc39" type="boolOrEmptyType"> + <xs:annotation> + <xs:documentation>True if the project has the special clause 39. Available + only for EC FP7 funded projects. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="oamandatepublications" type="xs:boolean"> + <xs:annotation> + <xs:documentation>True if the project's funding mandates the availability of project's publications in Open Access.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="ecarticle29_3" type="boolOrEmptyType"> + <xs:annotation> + <xs:documentation>True if the project is under the EC Open Data Pilot. Available only for EC H2020 funded projects. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="subjects" type="qualifierType"/> + + <xs:element name="fundingtree" type="fundingTreeType"/> + <xs:element name="originalId" type="xs:string"/> + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + project has been collected from. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="qualifierType"/> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + </xs:choice> + </xs:complexType> + </xs:element> + + <!-- to be removed, and replaced by ContextType --> + <xs:complexType name="fundingTreeType"> + <xs:sequence> + <xs:element name="funder" type="funderType"/> + <xs:choice maxOccurs="unbounded"> + <!-- Three-tier funding hierarchies --> + <xs:element name="funding_level_2" type="fundingType"/> + <!-- Two-tier funding hierarchies --> + <xs:element name="funding_level_1" type="fundingType"/> + <!-- No funding hierarchy --> + <xs:element name="funding_level_0" type="fundingType"/> + </xs:choice> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="fundingType"> + <xs:all> + <xs:element name="id" type="xs:string"/> + <xs:element name="description" type="xs:string"/> + <xs:element name="name" type="xs:string"/> + <xs:element name="class" type="xs:string"/> + <xs:element name="parent" type="fundingParentType"/> + </xs:all> + </xs:complexType> + + <xs:complexType name="fundingParentType"> + <xs:choice minOccurs="0"> + <xs:element name="funding_level_1" type="fundingType"/> + <xs:element name="funding_level_0" type="fundingType"/> + </xs:choice> + </xs:complexType> + + <xs:complexType name="funderType"> + <xs:all> + <xs:element name="id" type="xs:string"/> + <xs:element name="shortname" type="xs:string"/> + <xs:element name="name" type="xs:string"/> + <xs:element name="jurisdiction" type="xs:string"/> + </xs:all> + </xs:complexType> +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/oaf-result-1.0.xsd b/oaipmh-core/src/main/openaire/oaf-result-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..2ffd39849cbb1f5da2ebfa5d7cba94ae8d21185f --- /dev/null +++ b/oaipmh-core/src/main/openaire/oaf-result-1.0.xsd @@ -0,0 +1,242 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns="http://namespace.openaire.eu/oaf" targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of the OpenAIRE Result entity. For an overview of the model, please check the OpenAIRE Research Graph Data Model at https://doi.org/10.5281/zenodo.2643199</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="result"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="creator"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="surname" type="xs:string"/> + <xs:attribute name="ORCID" type="xs:string"/> + <xs:attribute name="rank" type="xs:int"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="resulttype" type="qualifierType"> + <xs:annotation> + <xs:documentation> Tells if this record is about a publication or a dataset. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:result_typologies </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="language" type="qualifierType"/> + <xs:element name="country" type="dataInfoType"/> + <xs:element name="subject" type="structuredPropertyElementType"/> + <xs:element name="title" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> Title of this research result. <p>Different types of + titles are allowed: see http://api.openaire.eu/vocabularies/dnet:dataCite_title</p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="relevantdate" type="structuredPropertyElementType"/> + <xs:element name="description" type="xs:string"/> + <xs:element name="dateofacceptance" type="xs:string"/> + <xs:element name="publisher" type="xs:string"/> + <xs:element name="embargoenddate" type="xs:string"/> + <xs:element name="source" type="xs:string"> + <xs:annotation> + <xs:documentation>The semantics of this field is inherited from dc:source in + Dublin Core. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="format" type="xs:string"/> + <xs:element name="contributor" type="xs:string"/> + <xs:element name="resourcetype" type="qualifierType"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + expresses the nature of the dataset. <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:publication_resource </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="coverage" type="xs:string"/> + <xs:element name="bestaccessright" type="qualifierType"> + <xs:annotation> + <xs:documentation> The best access right available for this result among the + available licenses of its children elements. <p>For allowed values + check: http://api.openaire.eu/vocabularies/dnet:access_modes </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="journal" type="journalType"/> + <xs:element name="pid" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> Persistent identifier. <p>For allowed pid systems check: + http://api.openaire.eu/vocabularies/dnet:pid_types </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="device" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the device used to generate the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="size" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the size of the dataset. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="version" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the version of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="lastmetadataupdate" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + is the last update date of the metadata of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="metadataversionnumber" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the version of the metadata of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="originalId" type="xs:string" maxOccurs="unbounded"/> + <xs:element name="collectedfrom" type="namedIdElementType" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + result has been collected from (e.g., "OpenDOAR"). </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="context" type="contextType"> + <xs:annotation> + <xs:documentation>Research community, initiative, infrastructure or funding agency related to this result.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="instances" type="instancesType" minOccurs="1" maxOccurs="1"/> + <xs:element name="citations" type="citationsType" maxOccurs="1" minOccurs="0"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:complexType name="citationsType"> + <xs:sequence> + <xs:element name="citation" maxOccurs="unbounded" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="rawText"/> + <xs:element name="id" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="value"/> + <xs:attribute name="type"/> + <xs:attribute name="confidenceLevel"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="provenance" type="xs:string"/> + <xs:attribute name="trust" type="xs:string"/> + </xs:complexType> + + <xs:complexType name="journalType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="eissn" use="optional"/> + <xs:attribute name="issn" use="optional"/> + <xs:attribute name="lissn" use="optional"/> + <xs:attribute name="ep" use="optional"/> + <xs:attribute name="iss" use="optional"/> + <xs:attribute name="sp" use="optional"/> + <xs:attribute name="vol" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="instancesType"> + <xs:sequence> + <xs:element name="instance" type="instanceType" minOccurs="1" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Actual digital representation of the publication or dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="externalreference" type="externalreferenceType" minOccurs="0" + maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="instanceType"> + <xs:choice maxOccurs="unbounded"> + <xs:element name="license" type="fieldType"> + <xs:annotation> + <xs:documentation> License to access this actual manifestation of the + result. Typically it is a URL. OpenAIRE does not yet attempt any harmonization and reflect the original values that are available in the collected metadata records. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="accessright" type="qualifierType"/> + <xs:element name="instancetype" type="qualifierType"> + <xs:annotation> + <xs:documentation> Type of the instance, for example: article, thesis, etc. + <p>For allowed values check: http://api.openaire.eu/vocabularies/dnet:publication_resource + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="collectedfrom" type="namedIdElementType" maxOccurs="1"> + <xs:annotation> + <xs:documentation>Datasource from which OpenAIRE collected the description of this instance.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="hostedby" type="namedIdElementType" maxOccurs="1"> + <xs:annotation> + <xs:documentation>Datasource hosting this file. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="webresource" type="webresourceType" minOccurs="1" + maxOccurs="unbounded"/> + <xs:element name="distributionlocation" type="xs:string" minOccurs="0"/> + <xs:element name="dateofacceptance" type="xs:string" minOccurs="0"/> + <xs:element name="processingchargeamount" type="fieldType"> + <xs:annotation> + <xs:documentation> Article/Book Processing Charge </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="processingchargecurrency" type="fieldType"> + <xs:annotation> + <xs:documentation>Currency for the value in processingchargeamount </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="refereed" type="fieldType"> + <xs:annotation> + <xs:documentation>Peer-review status</xs:documentation> + </xs:annotation> + </xs:element> + </xs:choice> + <xs:attribute name="id" use="required"/> + </xs:complexType> + + <xs:complexType name="webresourceType"> + <xs:sequence> + <xs:element name="url" type="xs:string" minOccurs="1" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + +</xs:schema> diff --git a/oaipmh-core/src/main/openaire/openaire.xsd b/oaipmh-core/src/main/openaire/openaire.xsd new file mode 100644 index 0000000000000000000000000000000000000000..a88a5f0456d1bbad63edf7eef754d1362d41f11d --- /dev/null +++ b/oaipmh-core/src/main/openaire/openaire.xsd @@ -0,0 +1,380 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Revision history + 2010-08-26 Complete revision according to new common specification by the metadata work group after review. AJH, DTIC + 2010-11-17 Revised to current state of kernel review, FZ, TIB + 2011-01-17 Complete revsion after community review. FZ, TIB + 2011-03-17 Release of v2.1: added a namespace; mandatory properties got minLength; changes in the definitions of relationTypes + IsDocumentedBy/Documents and isCompiledBy/Compiles; changes type of property "Date" from xs:date to xs:string. FZ, TIB + 2011-06-27 v2.2: namespace: kernel-2.2, additions to controlled lists "resourceType", "contributorType", "relatedIdentifierType", and "descriptionType". Removal of intermediate include-files. + 2013-05 v3.0: namespace: kernel-3.0; delete LastMetadataUpdate & MetadateVersionNumber; additions to controlled lists "contributorType", "dateType", "descriptionType", "relationType", "relatedIdentifierType" & "resourceType"; deletion of "StartDate" & "EndDate" from list "dateType" and "Film" from "resourceType"; allow arbitrary order of elements; allow optional wrapper elements to be empty; include openaire:lang attribute for title, subject & description; include attribute schemeURI for nameIdentifier of creator, contributor & subject; added new attributes "relatedMetadataScheme", "schemeURI" & "schemeType" to relatedIdentifier; included new property "geoLocation" + 2014-08-20 v3.1: additions to controlled lists "relationType", contributorType" and "relatedIdentifierType"; introduction of new child element "affiliation" to "creator" and "contributor"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified" > + + <xs:include schemaLocation="include/datacite-titleType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-contributorType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-dateType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-resourceType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-relationType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-relatedIdentifierType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-descriptionType-v3.xsd"/> + <xs:element name="resource"> + <xs:annotation> + <xs:documentation> + Root element of a single record. This wrapper element is for XML implementation only and is not defined in the DataCite DOI standard. + Note: This is the case for all wrapper elements within this schema!</xs:documentation> + <xs:documentation>No content in this wrapper element.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:all> + <!--REQUIRED FIELDS--> + <xs:element name="identifier"> + <xs:annotation> + <xs:documentation>A persistent identifier that identifies a resource.</xs:documentation> + <xs:documentation>Currently, only DOI is allowed.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="doiType"> + <xs:attribute name="identifierType" use="required" fixed="DOI"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="creators"> + <xs:complexType> + <xs:sequence> + <xs:element name="creator" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>The main researchers involved working on the data, or the authors of the publication in priority order. May be a corporate/institutional or personal name.</xs:documentation> + <xs:documentation>Format: Family, Given.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="creatorName"> + <xs:simpleType> + <xs:restriction base="nonemptycontentStringType"/> + </xs:simpleType> + </xs:element> + <xs:element name="nameIdentifier" minOccurs="0"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="nonemptycontentStringType"> + <xs:attribute name="nameIdentifierScheme" use="required"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="affiliation" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="titles"> + <xs:complexType> + <xs:sequence> + <xs:element name="title" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>A name or title by which a resource is known.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="nonemptycontentStringType"> + <xs:attribute name="titleType" type="titleType" use="optional"/> + <xs:attribute name="lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="publisher"> + <xs:annotation> + <xs:documentation>The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource. This property will be used to formulate the citation, so consider the prominence of the role.</xs:documentation> + <xs:documentation>In the case of datasets, "publish" is understood to mean making the data available to the community of researchers.</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="nonemptycontentStringType"/> + </xs:simpleType> + </xs:element> + <xs:element name="publicationYear"> + <xs:annotation> + <xs:documentation>Year when the data is made publicly available. If an embargo period has been in effect, use the date when the embargo period ends.</xs:documentation> + <xs:documentation>In the case of datasets, "publish" is understood to mean making the data available on a specific date to the community of researchers. If there is no standard publication year value, use the date that would be preferred from a citation perspective.</xs:documentation> + <xs:documentation>YYYY</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="yearType"/> + </xs:simpleType> + </xs:element> + <!--OPTIONAL FIELDS--> + <xs:element name="subjects" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="subject" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Subject, keywords, classification codes, or key phrases describing the resource.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="subjectScheme" use="optional"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + <xs:attribute name="lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="contributors" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="contributor" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>The institution or person responsible for collecting, creating, or otherwise contributing to the developement of the dataset.</xs:documentation> + <xs:documentation>The personal name format should be: Family, Given.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="contributorName"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:minLength value="1"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="nameIdentifier" minOccurs="0"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="nameIdentifierScheme" use="required"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="affiliation" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="contributorType" type="contributorType" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="dates" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="date" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Different dates relevant to the work.</xs:documentation> + <xs:documentation>YYYY,YYYY-MM-DD, YYYY-MM-DDThh:mm:ssTZD or any other format or level of granularity described in W3CDTF. Use RKMS-ISO8601 standard for depicting date ranges.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="dateType" type="dateType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="language" type="xs:language" minOccurs="0"> + <xs:annotation> + <xs:documentation>Primary language of the resource. Allowed values are taken from IETF BCP 47, ISO 639-1 language codes.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="resourceType" minOccurs="0"> + <xs:annotation> + <xs:documentation>The type of a resource. You may enter an additional free text description.</xs:documentation> + <xs:documentation>The format is open, but the preferred format is a single term of some detail so that a pair can be formed with the sub-property.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="resourceTypeGeneral" type="resourceType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="alternateIdentifiers" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="alternateIdentifier" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>An identifier or identifiers other than the primary Identifier applied to the resource being registered. This may be any alphanumeric string which is unique within its domain of issue. May be used for local identifiers. AlternateIdentifier should be used for another identifier of the same instance (same location, same file).</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="alternateIdentifierType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="relatedIdentifiers" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="relatedIdentifier" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Identifiers of related resources. Use this property to indicate subsets of properties, as appropriate.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="relatedIdentifierType" type="relatedIdentifierType" use="required"/> + <xs:attribute name="relationType" type="relationType" use="required"/> + <xs:attribute name="relatedMetadataScheme" use="optional"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + <xs:attribute name="schemeType" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="sizes" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="size" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Unstructures size information about the resource.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="formats" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="format" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Technical format of the resource.</xs:documentation> + <xs:documentation>Use file extension or MIME type where possible.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="version" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Version number of the resource. If the primary resource has changed the version number increases.</xs:documentation> + <xs:documentation>Register a new identifier for a major version change. Individual stewards need to determine which are major vs. minor versions. May be used in conjunction with properties 11 and 12 (AlternateIdentifier and RelatedIdentifier) to indicate various information updates. May be used in conjunction with property 17 (Description) to indicate the nature and file/record range of version.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="rightsList" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="rights" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Any rights information for this resource. Provide a rights management statement for the resource or reference a service providing such information. Include embargo information if applicable. +Use the complete title of a license and include version information if applicable.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="rightsURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="descriptions" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="description" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>All additional information that does not fit in any of the other categories. May be used for technical information. It is a best practice to supply a description.</xs:documentation> + </xs:annotation> + <xs:complexType mixed="true"> + <xs:choice> + <xs:element name="br" minOccurs="0" maxOccurs="unbounded"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:length value="0"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + </xs:choice> + <xs:attribute name="openaireDescriptionType" type="openaireDescriptionType" use="required"/> + <xs:attribute name="lang"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="geoLocations" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="geoLocation" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Spatial region or named place where the data was gathered or about which the data is focused.</xs:documentation> + <xs:documentation>A point contains a single latitude-longitude pair, separated by whitespace.</xs:documentation> + <xs:documentation>A box contains two white space separated latitude-longitude pairs, with each pair separated by whitespace. The first pair is the lower corner, the second is the upper corner.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="geoLocationPoint" type="point" minOccurs="0"/> + <xs:element name="geoLocationBox" type="box" minOccurs="0"/> + <xs:element name="geoLocationPlace" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:all> + </xs:complexType> + </xs:element> + <!-- TYPE DECLARATIONS --> + <!-- defines the value for a DOI: DOI must start with "10." --> + <xs:simpleType name="doiType"> + <xs:restriction base="xs:token"> + <xs:pattern value="10\..+/.+"/> + </xs:restriction> + </xs:simpleType> + <!-- defines value for mandatory fields --> + <xs:simpleType name="nonemptycontentStringType"> + <xs:restriction base="xs:string"> + <xs:minLength value="1"/> + </xs:restriction> + </xs:simpleType> + <xs:attributeGroup name="nameId"> + <xs:attribute name="nameIdentifier" type="xs:string" use="optional"/> + <xs:attribute name="nameIdentifierScheme" type="xs:string" use="optional"/> + </xs:attributeGroup> + <!-- defines the value for a year --> + <xs:simpleType name="yearType"> + <xs:restriction base="xs:token"> + <xs:pattern value="[\d]{4}"/> + </xs:restriction> + <!-- definitions for geoLocation --> + </xs:simpleType> + <xs:simpleType name="point"> + <xs:restriction base="listOfDoubles"> + <xs:minLength value="2"/> + <xs:maxLength value="2"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="box"> + <xs:restriction base="listOfDoubles"> + <xs:minLength value="4"/> + <xs:maxLength value="4"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="listOfDoubles"> + <xs:list itemType="xs:double"/> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/bindings.xjb b/oaipmh-core/src/main/resources/bindings.xjb index a85bd2428058235ab071d54921f098ec53819781..4d1a426b65b80c36f69349980626c0439d7b80b0 100644 --- a/oaipmh-core/src/main/resources/bindings.xjb +++ b/oaipmh-core/src/main/resources/bindings.xjb @@ -2,9 +2,12 @@ <jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix" xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb https://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd http://jaxb2-commons.dev.java.net/namespace-prefix https://raw.githubusercontent.com/Siggen/jaxb2-namespace-prefix/master/src/main/resources/prefix-namespace-schema.xsd"> + <jxb:bindings schemaLocation="oai_pmh.xsd"> <jxb:schemaBindings> <jxb:package name="info.textgrid.middleware.oaipmh" /> @@ -20,6 +23,49 @@ name="oai_dc" /> <namespace:prefix namespaceURI="http://purl.org/dc/elements/1.1/" name="dc" /> + <namespace:prefix + namespaceURI="http://datacite.org/schema/kernel-3" name="datacite" /> + <namespace:prefix + namespaceURI="http://namespace.openaire.eu/oaf" name="open_aire" /> </jxb:bindings> + + + </jxb:bindings> + + <jxb:bindings schemaLocation="openaire.xsd"> + <jxb:schemaBindings> + <jxb:package + name="info.textgrid.middleware.oaipmh.openaire" /> + </jxb:schemaBindings> </jxb:bindings> + + + + + <!-- MIT DIESEM HIER EINKOMMENTIERT, benennt er die Klassen um, scheint + sie aber irgendwo NOCHMAL zu definieren?? --> + + <jxb:bindings schemaLocation="oaf-common-1.0.xsd" multiple="true" node="/xs:schema"> + <jxb:schemaBindings> + <jxb:package name="info.textgrid.middleware.oaipmh.oaf.common" /> + </jxb:schemaBindings> + <jxb:bindings node="//xs:attribute[@name='classname']" multiple="true" > + <jxb:property name="OAFClassnameProperty" /> + </jxb:bindings> + <jxb:bindings node="//xs:attribute[@name='classid']" multiple="true" > + <jxb:property name="OAFClassidProperty" /> + </jxb:bindings> + <jxb:bindings node="//xs:attribute[@name='schemeid']" multiple="true" > + <jxb:property name="OAFSchemeidProperty" /> + </jxb:bindings> + <jxb:bindings node="//xs:attribute[@name='schemename']" multiple="true" > + <jxb:property name="OAFSchemenameProperty" /> + </jxb:bindings> + + </jxb:bindings> + + + + + </jxb:bindings> diff --git a/oaipmh-core/src/main/resources/include/datacite-contributorType-v3.1.xsd b/oaipmh-core/src/main/resources/include/datacite-contributorType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..c472076af44c0e2a6c30d8e1f7183d6be6ba5e36 --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-contributorType-v3.1.xsd @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, added values "ResearchGroup" & "Other" + 2014-08-20 v3.1: Addition of value "DataCurator" + 2015-05-14 v4.0 dropped value "Funder", use new "funderReference" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="contributorType" id="contributorType"> + <xs:annotation> + <xs:documentation>The type of contributor of the resource.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="ContactPerson"/> + <xs:enumeration value="DataCollector"/> + <xs:enumeration value="DataCurator"/> + <xs:enumeration value="DataManager"/> + <xs:enumeration value="Distributor"/> + <xs:enumeration value="Editor"/> + <xs:enumeration value="HostingInstitution"/> + <xs:enumeration value="Other"/> + <xs:enumeration value="Producer"/> + <xs:enumeration value="ProjectLeader"/> + <xs:enumeration value="ProjectManager"/> + <xs:enumeration value="ProjectMember"/> + <xs:enumeration value="RegistrationAgency"/> + <xs:enumeration value="RegistrationAuthority"/> + <xs:enumeration value="RelatedPerson"/> + <xs:enumeration value="ResearchGroup"/> + <xs:enumeration value="RightsHolder"/> + <xs:enumeration value="Researcher"/> + <xs:enumeration value="Sponsor"/> + <xs:enumeration value="Supervisor"/> + <xs:enumeration value="WorkPackageLeader"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-dateType-v3.xsd b/oaipmh-core/src/main/resources/include/datacite-dateType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..0455f8ac57344bd75fa5119603293297b33353a5 --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-dateType-v3.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; addition of value "Collected"; deleted "StartDate" & "EndDate"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="dateType" id="dateType"> + <xs:annotation> + <xs:documentation>The type of date. Use RKMSâ€ISO8601 standard for depicting date ranges.To indicate the end of an embargo period, use Available. To indicate the start of an embargo period, use Submitted or Accepted, as appropriate.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Accepted"/> + <xs:enumeration value="Available"/> + <xs:enumeration value="Collected"/> + <xs:enumeration value="Copyrighted"/> + <xs:enumeration value="Created"/> + <xs:enumeration value="Issued"/> + <xs:enumeration value="Submitted"/> + <xs:enumeration value="Updated"/> + <xs:enumeration value="Valid"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-descriptionType-v3.xsd b/oaipmh-core/src/main/resources/include/datacite-descriptionType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..881a4dfddd66bf3421e93cb4845f17bde757e81b --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-descriptionType-v3.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, addition of value "Methods" + 2015-02-12 v4.0: Addition of value "TechnicalInfo"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="openaireDescriptionType" id="openaireDescriptionType"> + <xs:annotation> + <xs:documentation>The type of the description.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Abstract"/> + <xs:enumeration value="Methods"/> + <xs:enumeration value="SeriesInformation"/> + <xs:enumeration value="TableOfContents"/> + <xs:enumeration value="TechnicalInfo"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-relatedIdentifierType-v3.1.xsd b/oaipmh-core/src/main/resources/include/datacite-relatedIdentifierType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..a300456d93c1fad4d5bc96f73d9f526b9270db5e --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-relatedIdentifierType-v3.1.xsd @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; addition of value "PMID" + 2014-08-20 v3.1: Addition of values "arxiv" and "bibcode"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="relatedIdentifierType" id="relatedIdentifierType"> + <xs:annotation> + <xs:documentation>The type of the RelatedIdentifier.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="ARK"/> + <xs:enumeration value="arXiv"/> + <xs:enumeration value="bibcode"/> + <xs:enumeration value="DOI"/> + <xs:enumeration value="EAN13"/> + <xs:enumeration value="EISSN"/> + <xs:enumeration value="Handle"/> + <xs:enumeration value="ISBN"/> + <xs:enumeration value="ISSN"/> + <xs:enumeration value="ISTC"/> + <xs:enumeration value="LISSN"/> + <xs:enumeration value="LSID"/> + <xs:enumeration value="PMID"/> + <xs:enumeration value="PURL"/> + <xs:enumeration value="UPC"/> + <xs:enumeration value="URL"/> + <xs:enumeration value="URN"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-relationType-v3.1.xsd b/oaipmh-core/src/main/resources/include/datacite-relationType-v3.1.xsd new file mode 100644 index 0000000000000000000000000000000000000000..ed8516b52bdd3a92220946e2b22b630de2fa55f3 --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-relationType-v3.1.xsd @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element, addition of values "IsIdenticalTo", "HasMetadata" & "IsMetadataFor" + 2014-08-20 v3.1: Addition of values "Reviews" & "IsReviewedBy" and "IsDerivedFrom" & "IsSourceOf"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="relationType" id="relationType"> + <xs:annotation> + <xs:documentation>Description of the relationship of the resource being registered (A) and the related resource (B).</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="IsCitedBy"/> + <xs:enumeration value="Cites"/> + <xs:enumeration value="IsSupplementTo"/> + <xs:enumeration value="IsSupplementedBy"/> + <xs:enumeration value="IsContinuedBy"/> + <xs:enumeration value="Continues"/> + <xs:enumeration value="IsNewVersionOf"/> + <xs:enumeration value="IsPreviousVersionOf"/> + <xs:enumeration value="IsPartOf"/> + <xs:enumeration value="HasPart"/> + <xs:enumeration value="IsReferencedBy"/> + <xs:enumeration value="References"/> + <xs:enumeration value="IsDocumentedBy"/> + <xs:enumeration value="Documents"/> + <xs:enumeration value="IsCompiledBy"/> + <xs:enumeration value="Compiles"/> + <xs:enumeration value="IsVariantFormOf"/> + <xs:enumeration value="IsOriginalFormOf"/> + <xs:enumeration value="IsIdenticalTo"/> + <xs:enumeration value="HasMetadata"/> + <xs:enumeration value="IsMetadataFor"/> + <xs:enumeration value="Reviews"/> + <xs:enumeration value="IsReviewedBy"/> + <xs:enumeration value="IsDerivedFrom"/> + <xs:enumeration value="IsSourceOf"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-resourceType-v3.xsd b/oaipmh-core/src/main/resources/include/datacite-resourceType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..3205a0cd3df8975b6b142061d67fe63622cda082 --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-resourceType-v3.xsd @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element; added values "Audiovisual", "Workflow" & "Other"; deleted value "Film" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="resourceType" id="resourceType"> + <xs:annotation> + <xs:documentation>The general type of a resource.</xs:documentation> + </xs:annotation> + <xs:restriction base="xs:string"> + <xs:enumeration value="Audiovisual"/> + <xs:enumeration value="Collection"/> + <xs:enumeration value="Dataset"/> + <xs:enumeration value="Event"/> + <xs:enumeration value="Image"/> + <xs:enumeration value="InteractiveResource"/> + <xs:enumeration value="Model"/> + <xs:enumeration value="PhysicalObject"/> + <xs:enumeration value="Service"/> + <xs:enumeration value="Software"/> + <xs:enumeration value="Sound"/> + <xs:enumeration value="Text"/> + <xs:enumeration value="Workflow"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/include/datacite-titleType-v3.xsd b/oaipmh-core/src/main/resources/include/datacite-titleType-v3.xsd new file mode 100644 index 0000000000000000000000000000000000000000..ed2508ad8a9e8da913dbf77ea8763ccff13fe1cf --- /dev/null +++ b/oaipmh-core/src/main/resources/include/datacite-titleType-v3.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Version 1.0 - Created 2011-01-13 - FZ, TIB, Germany + 2013-05 v3.0: Addition of ID to simpleType element + 2015-02-12 v4.0 Added value "Other" --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified"> + <xs:simpleType name="titleType" id="titleType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="AlternativeTitle"/> + <xs:enumeration value="Subtitle"/> + <xs:enumeration value="TranslatedTitle"/> + <xs:enumeration value="Other"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-1.0.xsd b/oaipmh-core/src/main/resources/oaf-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..952ae31ddbf10d640b11c920f116bb400f07f257 --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-1.0.xsd @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema describes the XML serialization of the OpenAIRE Research Graph. + For an overview of the model, please check the OpenAIRE Research Graph Data Model at https://doi.org/10.5281/zenodo.2643199 + </xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-result-1.0.xsd"/> + <xs:include schemaLocation="oaf-org-1.0.xsd"/> + <xs:include schemaLocation="oaf-datasource-1.0.xsd"/> + <xs:include schemaLocation="oaf-project-1.0.xsd"/> + + <xs:element name="entity"> + <xs:complexType> + <xs:sequence> + <xs:choice> + <xs:element ref="result"/> + <xs:element ref="organization"/> + <xs:element ref="datasource"/> + <xs:element ref="project"/> + </xs:choice> + </xs:sequence> + </xs:complexType> + </xs:element> + +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-common-1.0.xsd b/oaipmh-core/src/main/resources/oaf-common-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..b3ffcbbedd1cc20a5401229dbbb30c20d68f5ee6 --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-common-1.0.xsd @@ -0,0 +1,305 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns="http://namespace.openaire.eu/oaf" targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema defines common types that can be re-used.</xs:documentation> + </xs:annotation> + + <xs:simpleType name="emptyType"> + <xs:restriction base="xs:string"> + <xs:length value="0"/> + </xs:restriction> + </xs:simpleType> + + <xs:simpleType name="boolOrEmptyType"> + <xs:union memberTypes="emptyType xs:boolean"/> + </xs:simpleType> + + <xs:simpleType name="stringOrEmptyType"> + <xs:union memberTypes="emptyType xs:string"/> + </xs:simpleType> + + <xs:attributeGroup name="dataInfoAttributeGroup"> + <xs:attribute name="inferred" use="optional" type="xs:boolean"> + <xs:annotation> + <xs:documentation>True if this information has been inferred by the automatic + inference algorithms run by OpenAIRE. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="trust" use="optional" type="xs:string"> + <xs:annotation> + <xs:documentation>Value of trust of this information in the range [0,1]. More the + value, more trustworthy is the information. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="inferenceprovenance" use="optional" type="xs:string"> + <xs:annotation> + <xs:documentation>Which algorithm inferred the current property. </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attributeGroup ref="qualifierAttributeGroup"></xs:attributeGroup> + </xs:attributeGroup> + + <xs:attributeGroup name="qualifierAttributeGroup"> + <xs:attribute name="classid" use="required" type="xs:string"/> + <xs:attribute name="classname" use="required" type="xs:string"/> + <xs:attribute name="schemeid" use="required" type="xs:string"/> + <xs:attribute name="schemename" use="required" type="xs:string"/> + </xs:attributeGroup> + + <xs:attributeGroup name="qualifierAttributeGroupAlternative"> + <xs:attribute name="classid_alt" use="required" type="xs:string"/> + <xs:attribute name="classname_alt" use="required" type="xs:string"/> + <xs:attribute name="schemeid_alt" use="required" type="xs:string"/> + <xs:attribute name="schemename_alt" use="required" type="xs:string"/> + </xs:attributeGroup> + + <xs:complexType name="fieldType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="qualifierType"> + <xs:attributeGroup ref="qualifierAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="dataInfoType"> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="structuredPropertyElementType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attributeGroup ref="qualifierAttributeGroupAlternative"/> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="labeledIdElementType"> + <xs:attribute name="id" use="required"/> + <xs:attribute name="label" use="required"/> + </xs:complexType> + + <!-- <oaf:context id="egi" label="EGI" type="community"> + <oaf:category id="egi::virtual" label="EGI virtual organizations"> + <oaf:concept id="egi::virtual::2" label="alice"/> + </oaf:category> + </oaf:context> + <oaf:community id="{@id}" label="{@label}"> + <xsl:apply-templates/> + </oaf:community> + --> + <xs:complexType name="contextType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence maxOccurs="unbounded"> + <xs:element name="category" type="categoryType"/> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="categoryType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence minOccurs="0" maxOccurs="unbounded"> + <xs:element name="concept" type="conceptType"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="conceptType"> + <xs:complexContent> + <xs:extension base="labeledIdElementType"> + <xs:sequence maxOccurs="unbounded" minOccurs="0"> + <xs:element name="concept" type="conceptType"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="namedIdElementType"> + <xs:attribute name="id" use="required"/> + <xs:attribute name="name" use="required"/> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:complexType name="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities.</xs:documentation> + </xs:annotation> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element name="rel" type="relType" minOccurs="0"/> + </xs:choice> + </xs:complexType> + + <xs:complexType name="relType"> + <xs:sequence> + <xs:choice maxOccurs="unbounded"> + <xs:element name="to" type="relToType"/> + <xs:element name="title" type="xs:string"/> + <xs:element name="websiteurl"/> + <xs:choice> + <xs:group ref="relDataSourceGroup"/> + <xs:group ref="relResultGroup"/> + <xs:group ref="relProjectGroup"/> + <xs:group ref="relOrganizationGroup"/> + <xs:group ref="fundingGroup"/> + </xs:choice> + </xs:choice> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + <xs:group name="relDataSourceGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="officialname" type="xs:string"/> + <xs:element name="datasourcetype" type="qualifierType"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relResultGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="collectedfrom" type="namedIdElementType"/> + <xs:element name="url" type="xs:string"/> + <xs:element name="pid" type="structuredPropertyElementType"/> + <xs:element name="dateofacceptance" type="xs:string"/> + <xs:element name="publisher" type="xs:string"/> + <xs:element name="resulttype" type="xs:string"> + <xs:annotation> + <xs:documentation> Tells if the related record is about a publication or a + dataset. </xs:documentation> + </xs:annotation> + </xs:element> + <!-- the following fields are available only for similarity relations --> + <xs:element name="similarity" type="xs:double"> + <xs:annotation> + <xs:documentation>The similarity degree expressed in the range (0,1]. This + field is avaiable only when the to/@class is one of + {hasAmongTopNSimilarDocuments, + isAmongTopNSimilarDocuments}</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="type"> + <xs:annotation> + <xs:documentation>The similarity degree expressed in the range (0,1]. This + field is avaiable only when the to/@class is one of + {hasAmongTopNSimilarDocuments, + isAmongTopNSimilarDocuments}</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="STANDARD"/> + <xs:enumeration value="WEBUSAGE"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relProjectGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="code" type="xs:string"/> + <xs:element name="acronym" type="xs:string"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="fundingGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="contracttype" type="qualifierType"/> + <xs:element name="funding" type="fundingFlatType"/> + </xs:choice> + </xs:sequence> + </xs:group> + + <xs:group name="relOrganizationGroup"> + <xs:sequence> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element name="legalname" type="xs:string"/> + <xs:element name="legalshortname" type="xs:string"/> + <xs:element name="country" type="xs:string"/> + </xs:choice> + </xs:sequence> + </xs:group> + + + <xs:complexType name="relToType"> + <xs:annotation> + <xs:documentation>Information about the related entity. <p>The semantics of the + relationships is expressed by the attributes class and scheme. </p> + </xs:documentation> + </xs:annotation> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="class" use="required" type="xs:string"/> + <xs:attribute name="type" use="required" type="xs:string"> + <xs:annotation> + <xs:documentation>The type of the related entity. <p>Allowed values are: + project, organization, datasource, result, person.</p> + </xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="fundingFlatType"> + <xs:sequence> + <xs:element name="funder" type="funderFlatType" minOccurs="1" maxOccurs="1"/> + <xs:element name="funding_level_0" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + <xs:element name="funding_level_1" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + <xs:element name="funding_level_2" type="namedFundingLevel" minOccurs="0" + maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="funderFlatType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="id" use="required" type="xs:string"/> + <xs:attribute name="shortname" use="required" type="xs:string"/> + <xs:attribute name="name" use="required" type="xs:string"/> + <xs:attribute name="jurisdiction" use="optional" type="xs:string"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="namedFundingLevel"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="name" use="required" type="xs:string"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + + <xs:complexType name="externalreferenceType"> + <xs:sequence> + <xs:element name="sitename" type="xs:string" minOccurs="0" maxOccurs="1"/> + <!--<xs:element name="label" type="xs:string" minOccurs="0" maxOccurs="1"/>--> + <xs:element name="url" type="xs:string" minOccurs="0" maxOccurs="1"/> + <xs:element name="qualifier" type="qualifierType" minOccurs="0" maxOccurs="1"/> + <xs:element name="refidentifier" type="xs:string" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + <xs:attributeGroup ref="dataInfoAttributeGroup"/> + </xs:complexType> + + + <!-- REMOVE FROM HERE TO THE END --> + +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-datasource-1.0.xsd b/oaipmh-core/src/main/resources/oaf-datasource-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..c84ec2531dafd7151cd00ac15f6b15aa1fd579af --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-datasource-1.0.xsd @@ -0,0 +1,76 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE datasources: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_datasource</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="datasource"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="namespaceprefix" type="xs:string" /> + <xs:element name="officialname" type="xs:string" /> + <xs:element name="englishname" type="xs:string" /> + <xs:element name="websiteurl" type="xs:string" /> + <xs:element name="logourl" type="xs:string" /> + <xs:element name="contactemail" type="xs:string" /> + <xs:element name="datasourcetype" type="qualifierType"> + <xs:annotation> + <xs:documentation>For allowed values check terms in:http://api.openaire.eu/vocabularies/dnet:datasource_typologies</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="openairecompatibility" type="qualifierType"> + <xs:annotation> + <xs:documentation> + Level of compatibility of this datasource with regards to the + guidelines. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:datasourceCompatibilityLevel + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="dateofvalidation" type="xs:string"> + <xs:annotation> + <xs:documentation>When this datasource has been validated by the + OpenAire + Validator. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="latitude" type="xs:string" /> + <xs:element name="longitude" type="xs:string" /> + <xs:element name="description" type="xs:string" /> + <xs:element name="subjects" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> + Subjects and keywords. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:result_subjects + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="originalId" type="xs:string" /> + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which + this datasource has + been collected from. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="structuredPropertyElementType" /> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. + </xs:documentation> + </xs:annotation> + </xs:element> + + </xs:choice> + </xs:complexType> + </xs:element> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-org-1.0.xsd b/oaipmh-core/src/main/resources/oaf-org-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..3c46fca44b6462be5fb51d116555cac23ea9d016 --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-org-1.0.xsd @@ -0,0 +1,41 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE entities of type organization: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_organization</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="organization"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="legalname" type="xs:string"/> + <xs:element name="legalshortname" type="xs:string"/> + <xs:element name="logourl" type="xs:string"/> + <xs:element name="originalId" type="xs:string"/> + <xs:element name="websiteurl" type="xs:string"/> + <xs:element name="country" type="qualifierType"> + <xs:annotation> + <xs:documentation>Countries in ISO 3166-1 alpha-2. </xs:documentation> + </xs:annotation> + </xs:element> + + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + organization has been collected from. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="structuredPropertyElementType"/> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + <!-- If we decide not to show deduplicated org, then we have to remove this field --> + <!-- <xs:element name="duplicates" type="mergedOrgs"/> --> + </xs:choice> + </xs:complexType> + </xs:element> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-project-1.0.xsd b/oaipmh-core/src/main/resources/oaf-project-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..abcba4d9f63f31996226f01a18ab575541e32827 --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-project-1.0.xsd @@ -0,0 +1,111 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namespace.openaire.eu/oaf" + targetNamespace="http://namespace.openaire.eu/oaf" elementFormDefault="qualified"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of OpenAIRE project entity: https://issue.openaire.research-infrastructures.eu/projects/openaire2020-wiki/wiki/Core_entity_project</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="project"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="code" type="xs:string"> + <xs:annotation> + <xs:documentation>Project code as assigned by the project's funder.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="title" type="xs:string"/> + <xs:element name="acronym" type="xs:string"/> + <xs:element name="callidentifier" type="xs:string"> + <xs:annotation> + <xs:documentation> Identifier of the call for proposal.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="contactfullname" type="xs:string"/> + <xs:element name="contactfax" type="xs:string"/> + <xs:element name="contactphone" type="xs:string"/> + <xs:element name="contactemail" type="xs:string"/> + <xs:element name="contracttype" type="qualifierType"/> + <xs:element name="keywords" type="xs:string"/> + <xs:element name="websiteurl" type="xs:string"/> + <xs:element name="startdate" type="xs:string"/> + <xs:element name="enddate" type="xs:string"/> + <xs:element name="duration" type="xs:string"/> + <xs:element name="ecsc39" type="boolOrEmptyType"> + <xs:annotation> + <xs:documentation>True if the project has the special clause 39. Available + only for EC FP7 funded projects. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="oamandatepublications" type="xs:boolean"> + <xs:annotation> + <xs:documentation>True if the project's funding mandates the availability of project's publications in Open Access.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="ecarticle29_3" type="boolOrEmptyType"> + <xs:annotation> + <xs:documentation>True if the project is under the EC Open Data Pilot. Available only for EC H2020 funded projects. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="subjects" type="qualifierType"/> + + <xs:element name="fundingtree" type="fundingTreeType"/> + <xs:element name="originalId" type="xs:string"/> + <xs:element name="collectedfrom" type="namedIdElementType"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + project has been collected from. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="pid" type="qualifierType"/> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + </xs:choice> + </xs:complexType> + </xs:element> + + <!-- to be removed, and replaced by ContextType --> + <xs:complexType name="fundingTreeType"> + <xs:sequence> + <xs:element name="funder" type="funderType"/> + <xs:choice maxOccurs="unbounded"> + <!-- Three-tier funding hierarchies --> + <xs:element name="funding_level_2" type="fundingType"/> + <!-- Two-tier funding hierarchies --> + <xs:element name="funding_level_1" type="fundingType"/> + <!-- No funding hierarchy --> + <xs:element name="funding_level_0" type="fundingType"/> + </xs:choice> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="fundingType"> + <xs:all> + <xs:element name="id" type="xs:string"/> + <xs:element name="description" type="xs:string"/> + <xs:element name="name" type="xs:string"/> + <xs:element name="class" type="xs:string"/> + <xs:element name="parent" type="fundingParentType"/> + </xs:all> + </xs:complexType> + + <xs:complexType name="fundingParentType"> + <xs:choice minOccurs="0"> + <xs:element name="funding_level_1" type="fundingType"/> + <xs:element name="funding_level_0" type="fundingType"/> + </xs:choice> + </xs:complexType> + + <xs:complexType name="funderType"> + <xs:all> + <xs:element name="id" type="xs:string"/> + <xs:element name="shortname" type="xs:string"/> + <xs:element name="name" type="xs:string"/> + <xs:element name="jurisdiction" type="xs:string"/> + </xs:all> + </xs:complexType> +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oaf-result-1.0.xsd b/oaipmh-core/src/main/resources/oaf-result-1.0.xsd new file mode 100644 index 0000000000000000000000000000000000000000..2ffd39849cbb1f5da2ebfa5d7cba94ae8d21185f --- /dev/null +++ b/oaipmh-core/src/main/resources/oaf-result-1.0.xsd @@ -0,0 +1,242 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + xmlns="http://namespace.openaire.eu/oaf" targetNamespace="http://namespace.openaire.eu/oaf"> + + <xs:annotation> + <xs:documentation>This schema describes elements and properties of the OpenAIRE Result entity. For an overview of the model, please check the OpenAIRE Research Graph Data Model at https://doi.org/10.5281/zenodo.2643199</xs:documentation> + </xs:annotation> + + <xs:include schemaLocation="oaf-common-1.0.xsd"/> + + <xs:element name="result"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element name="creator"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="surname" type="xs:string"/> + <xs:attribute name="ORCID" type="xs:string"/> + <xs:attribute name="rank" type="xs:int"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="resulttype" type="qualifierType"> + <xs:annotation> + <xs:documentation> Tells if this record is about a publication or a dataset. + <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:result_typologies </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="language" type="qualifierType"/> + <xs:element name="country" type="dataInfoType"/> + <xs:element name="subject" type="structuredPropertyElementType"/> + <xs:element name="title" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> Title of this research result. <p>Different types of + titles are allowed: see http://api.openaire.eu/vocabularies/dnet:dataCite_title</p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="relevantdate" type="structuredPropertyElementType"/> + <xs:element name="description" type="xs:string"/> + <xs:element name="dateofacceptance" type="xs:string"/> + <xs:element name="publisher" type="xs:string"/> + <xs:element name="embargoenddate" type="xs:string"/> + <xs:element name="source" type="xs:string"> + <xs:annotation> + <xs:documentation>The semantics of this field is inherited from dc:source in + Dublin Core. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="format" type="xs:string"/> + <xs:element name="contributor" type="xs:string"/> + <xs:element name="resourcetype" type="qualifierType"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + expresses the nature of the dataset. <p>For allowed values check: + http://api.openaire.eu/vocabularies/dnet:publication_resource </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="coverage" type="xs:string"/> + <xs:element name="bestaccessright" type="qualifierType"> + <xs:annotation> + <xs:documentation> The best access right available for this result among the + available licenses of its children elements. <p>For allowed values + check: http://api.openaire.eu/vocabularies/dnet:access_modes </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="journal" type="journalType"/> + <xs:element name="pid" type="structuredPropertyElementType"> + <xs:annotation> + <xs:documentation> Persistent identifier. <p>For allowed pid systems check: + http://api.openaire.eu/vocabularies/dnet:pid_types </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="device" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the device used to generate the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="size" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the size of the dataset. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="version" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the version of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="lastmetadataupdate" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + is the last update date of the metadata of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="metadataversionnumber" type="xs:string"> + <xs:annotation> + <xs:documentation> This field is valid only if resulttype is "dataset". It + contains information about the version of the metadata of the dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="originalId" type="xs:string" maxOccurs="unbounded"/> + <xs:element name="collectedfrom" type="namedIdElementType" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Identifier and name of the datasource from which this + result has been collected from (e.g., "OpenDOAR"). </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="context" type="contextType"> + <xs:annotation> + <xs:documentation>Research community, initiative, infrastructure or funding agency related to this result.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="rels" type="relsType"> + <xs:annotation> + <xs:documentation>Relationships to other entities. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="instances" type="instancesType" minOccurs="1" maxOccurs="1"/> + <xs:element name="citations" type="citationsType" maxOccurs="1" minOccurs="0"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:complexType name="citationsType"> + <xs:sequence> + <xs:element name="citation" maxOccurs="unbounded" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="rawText"/> + <xs:element name="id" minOccurs="0" maxOccurs="unbounded"> + <xs:complexType> + <xs:attribute name="value"/> + <xs:attribute name="type"/> + <xs:attribute name="confidenceLevel"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="provenance" type="xs:string"/> + <xs:attribute name="trust" type="xs:string"/> + </xs:complexType> + + <xs:complexType name="journalType"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="eissn" use="optional"/> + <xs:attribute name="issn" use="optional"/> + <xs:attribute name="lissn" use="optional"/> + <xs:attribute name="ep" use="optional"/> + <xs:attribute name="iss" use="optional"/> + <xs:attribute name="sp" use="optional"/> + <xs:attribute name="vol" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="instancesType"> + <xs:sequence> + <xs:element name="instance" type="instanceType" minOccurs="1" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Actual digital representation of the publication or dataset. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="externalreference" type="externalreferenceType" minOccurs="0" + maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="instanceType"> + <xs:choice maxOccurs="unbounded"> + <xs:element name="license" type="fieldType"> + <xs:annotation> + <xs:documentation> License to access this actual manifestation of the + result. Typically it is a URL. OpenAIRE does not yet attempt any harmonization and reflect the original values that are available in the collected metadata records. + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="accessright" type="qualifierType"/> + <xs:element name="instancetype" type="qualifierType"> + <xs:annotation> + <xs:documentation> Type of the instance, for example: article, thesis, etc. + <p>For allowed values check: http://api.openaire.eu/vocabularies/dnet:publication_resource + </p> + </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="collectedfrom" type="namedIdElementType" maxOccurs="1"> + <xs:annotation> + <xs:documentation>Datasource from which OpenAIRE collected the description of this instance.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="hostedby" type="namedIdElementType" maxOccurs="1"> + <xs:annotation> + <xs:documentation>Datasource hosting this file. </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="webresource" type="webresourceType" minOccurs="1" + maxOccurs="unbounded"/> + <xs:element name="distributionlocation" type="xs:string" minOccurs="0"/> + <xs:element name="dateofacceptance" type="xs:string" minOccurs="0"/> + <xs:element name="processingchargeamount" type="fieldType"> + <xs:annotation> + <xs:documentation> Article/Book Processing Charge </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="processingchargecurrency" type="fieldType"> + <xs:annotation> + <xs:documentation>Currency for the value in processingchargeamount </xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="refereed" type="fieldType"> + <xs:annotation> + <xs:documentation>Peer-review status</xs:documentation> + </xs:annotation> + </xs:element> + </xs:choice> + <xs:attribute name="id" use="required"/> + </xs:complexType> + + <xs:complexType name="webresourceType"> + <xs:sequence> + <xs:element name="url" type="xs:string" minOccurs="1" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + +</xs:schema> diff --git a/oaipmh-core/src/main/resources/oai_dc.xsd b/oaipmh-core/src/main/resources/oai_dc.xsd index 88479d78648ab89020b97d1d347cfabc4972e79b..da2b49c8bb402faffb9700b4262c9b3f84b98e7b 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> @@ -14,8 +13,12 @@ </documentation> </annotation> + <!--import namespace="http://purl.org/dc/elements/1.1/" + schemaLocation="file:///home/max/Dokumente/simpledc20021212.xsd"/--> + <import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="https://dublincore.org/schemas/xmls/simpledc20021212.xsd"/> + <element name="dc" type="oai_dc:oai_dcType"/> 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/main/resources/openaire.xsd b/oaipmh-core/src/main/resources/openaire.xsd new file mode 100644 index 0000000000000000000000000000000000000000..496a435cba5b75d82bf8c16bf236014d401e71ae --- /dev/null +++ b/oaipmh-core/src/main/resources/openaire.xsd @@ -0,0 +1,380 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Revision history + 2010-08-26 Complete revision according to new common specification by the metadata work group after review. AJH, DTIC + 2010-11-17 Revised to current state of kernel review, FZ, TIB + 2011-01-17 Complete revsion after community review. FZ, TIB + 2011-03-17 Release of v2.1: added a namespace; mandatory properties got minLength; changes in the definitions of relationTypes + IsDocumentedBy/Documents and isCompiledBy/Compiles; changes type of property "Date" from xs:date to xs:string. FZ, TIB + 2011-06-27 v2.2: namespace: kernel-2.2, additions to controlled lists "resourceType", "contributorType", "relatedIdentifierType", and "descriptionType". Removal of intermediate include-files. + 2013-05 v3.0: namespace: kernel-3.0; delete LastMetadataUpdate & MetadateVersionNumber; additions to controlled lists "contributorType", "dateType", "descriptionType", "relationType", "relatedIdentifierType" & "resourceType"; deletion of "StartDate" & "EndDate" from list "dateType" and "Film" from "resourceType"; allow arbitrary order of elements; allow optional wrapper elements to be empty; include openaire:lang attribute for title, subject & description; include attribute schemeURI for nameIdentifier of creator, contributor & subject; added new attributes "relatedMetadataScheme", "schemeURI" & "schemeType" to relatedIdentifier; included new property "geoLocation" + 2014-08-20 v3.1: additions to controlled lists "relationType", contributorType" and "relatedIdentifierType"; introduction of new child element "affiliation" to "creator" and "contributor"--> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://datacite.org/schema/kernel-3" targetNamespace="http://datacite.org/schema/kernel-3" elementFormDefault="qualified" > + + <xs:include schemaLocation="include/datacite-titleType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-contributorType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-dateType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-resourceType-v3.xsd"/> + <xs:include schemaLocation="include/datacite-relationType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-relatedIdentifierType-v3.1.xsd"/> + <xs:include schemaLocation="include/datacite-descriptionType-v3.xsd"/> + <xs:element name="resource"> + <xs:annotation> + <xs:documentation> + Root element of a single record. This wrapper element is for XML implementation only and is not defined in the DataCite DOI standard. + Note: This is the case for all wrapper elements within this schema!</xs:documentation> + <xs:documentation>No content in this wrapper element.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:all> + <!--REQUIRED FIELDS--> + <xs:element name="identifier"> + <xs:annotation> + <xs:documentation>A persistent identifier that identifies a resource.</xs:documentation> + <xs:documentation>Currently, only DOI is allowed.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="doiType"> + <xs:attribute name="identifierType" use="required" fixed="DOI"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="creators"> + <xs:complexType> + <xs:sequence> + <xs:element name="creator" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>The main researchers involved working on the data, or the authors of the publication in priority order. May be a corporate/institutional or personal name.</xs:documentation> + <xs:documentation>Format: Family, Given.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="creatorName"> + <xs:simpleType> + <xs:restriction base="nonemptycontentStringType"/> + </xs:simpleType> + </xs:element> + <xs:element name="nameIdentifier" minOccurs="0"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="nonemptycontentStringType"> + <xs:attribute name="nameIdentifierScheme" use="required"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="affiliation" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="titles"> + <xs:complexType> + <xs:sequence> + <xs:element name="title" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>A name or title by which a resource is known.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="nonemptycontentStringType"> + <xs:attribute name="titleType" type="titleType" use="optional"/> + <xs:attribute name="lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="publisher"> + <xs:annotation> + <xs:documentation>The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource. This property will be used to formulate the citation, so consider the prominence of the role.</xs:documentation> + <xs:documentation>In the case of datasets, "publish" is understood to mean making the data available to the community of researchers.</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="nonemptycontentStringType"/> + </xs:simpleType> + </xs:element> + <xs:element name="publicationYear"> + <xs:annotation> + <xs:documentation>Year when the data is made publicly available. If an embargo period has been in effect, use the date when the embargo period ends.</xs:documentation> + <xs:documentation>In the case of datasets, "publish" is understood to mean making the data available on a specific date to the community of researchers. If there is no standard publication year value, use the date that would be preferred from a citation perspective.</xs:documentation> + <xs:documentation>YYYY</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="yearType"/> + </xs:simpleType> + </xs:element> + <!--OPTIONAL FIELDS--> + <xs:element name="subjects" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="subject" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Subject, keywords, classification codes, or key phrases describing the resource.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="subjectScheme" use="optional"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + <xs:attribute name="lang"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="contributors" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="contributor" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>The institution or person responsible for collecting, creating, or otherwise contributing to the developement of the dataset.</xs:documentation> + <xs:documentation>The personal name format should be: Family, Given.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="contributorName"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:minLength value="1"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="nameIdentifier" minOccurs="0"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="nameIdentifierScheme" use="required"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="affiliation" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="contributorType" type="contributorType" use="required"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="dates" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="date" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Different dates relevant to the work.</xs:documentation> + <xs:documentation>YYYY,YYYY-MM-DD, YYYY-MM-DDThh:mm:ssTZD or any other format or level of granularity described in W3CDTF. Use RKMS-ISO8601 standard for depicting date ranges.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="dateType" type="dateType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="language" type="xs:language" minOccurs="0"> + <xs:annotation> + <xs:documentation>Primary language of the resource. Allowed values are taken from IETF BCP 47, ISO 639-1 language codes.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="resourceType" minOccurs="0"> + <xs:annotation> + <xs:documentation>The type of a resource. You may enter an additional free text description.</xs:documentation> + <xs:documentation>The format is open, but the preferred format is a single term of some detail so that a pair can be formed with the sub-property.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="resourceTypeGeneral" type="resourceType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="alternateIdentifiers" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="alternateIdentifier" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>An identifier or identifiers other than the primary Identifier applied to the resource being registered. This may be any alphanumeric string which is unique within its domain of issue. May be used for local identifiers. AlternateIdentifier should be used for another identifier of the same instance (same location, same file).</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="alternateIdentifierType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="relatedIdentifiers" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="relatedIdentifier" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Identifiers of related resources. Use this property to indicate subsets of properties, as appropriate.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="relatedIdentifierType" type="relatedIdentifierType" use="required"/> + <xs:attribute name="relationType" type="relationType" use="required"/> + <xs:attribute name="relatedMetadataScheme" use="optional"/> + <xs:attribute name="schemeURI" type="xs:anyURI" use="optional"/> + <xs:attribute name="schemeType" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="sizes" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="size" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Unstructures size information about the resource.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="formats" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="format" type="xs:string" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Technical format of the resource.</xs:documentation> + <xs:documentation>Use file extension or MIME type where possible.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="version" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Version number of the resource. If the primary resource has changed the version number increases.</xs:documentation> + <xs:documentation>Register a new identifier for a major version change. Individual stewards need to determine which are major vs. minor versions. May be used in conjunction with properties 11 and 12 (AlternateIdentifier and RelatedIdentifier) to indicate various information updates. May be used in conjunction with property 17 (Description) to indicate the nature and file/record range of version.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="rightsList" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="rights" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Any rights information for this resource. Provide a rights management statement for the resource or reference a service providing such information. Include embargo information if applicable. +Use the complete title of a license and include version information if applicable.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="rightsURI" type="xs:anyURI" use="optional"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="descriptions" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="description" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>All additional information that does not fit in any of the other categories. May be used for technical information. It is a best practice to supply a description.</xs:documentation> + </xs:annotation> + <xs:complexType mixed="true"> + <xs:choice> + <xs:element name="br" minOccurs="0" maxOccurs="unbounded"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:length value="0"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + </xs:choice> + <xs:attribute name="descriptionType" type="openaireDescriptionType" use="required"/> + <xs:attribute name="lang"/> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="geoLocations" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="geoLocation" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Spatial region or named place where the data was gathered or about which the data is focused.</xs:documentation> + <xs:documentation>A point contains a single latitude-longitude pair, separated by whitespace.</xs:documentation> + <xs:documentation>A box contains two white space separated latitude-longitude pairs, with each pair separated by whitespace. The first pair is the lower corner, the second is the upper corner.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="geoLocationPoint" type="point" minOccurs="0"/> + <xs:element name="geoLocationBox" type="box" minOccurs="0"/> + <xs:element name="geoLocationPlace" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:all> + </xs:complexType> + </xs:element> + <!-- TYPE DECLARATIONS --> + <!-- defines the value for a DOI: DOI must start with "10." --> + <xs:simpleType name="doiType"> + <xs:restriction base="xs:token"> + <xs:pattern value="10\..+/.+"/> + </xs:restriction> + </xs:simpleType> + <!-- defines value for mandatory fields --> + <xs:simpleType name="nonemptycontentStringType"> + <xs:restriction base="xs:string"> + <xs:minLength value="1"/> + </xs:restriction> + </xs:simpleType> + <xs:attributeGroup name="nameId"> + <xs:attribute name="nameIdentifier" type="xs:string" use="optional"/> + <xs:attribute name="nameIdentifierScheme" type="xs:string" use="optional"/> + </xs:attributeGroup> + <!-- defines the value for a year --> + <xs:simpleType name="yearType"> + <xs:restriction base="xs:token"> + <xs:pattern value="[\d]{4}"/> + </xs:restriction> + <!-- definitions for geoLocation --> + </xs:simpleType> + <xs:simpleType name="point"> + <xs:restriction base="listOfDoubles"> + <xs:minLength value="2"/> + <xs:maxLength value="2"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="box"> + <xs:restriction base="listOfDoubles"> + <xs:minLength value="4"/> + <xs:maxLength value="4"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="listOfDoubles"> + <xs:list itemType="xs:double"/> + </xs:simpleType> +</xs: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 deleted file mode 100644 index 669b00f968e423e7c0a74aee7efdee9770c0316a..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDARIAHTest.java +++ /dev/null @@ -1,182 +0,0 @@ -package info.textgrid.middleware; - -import java.text.ParseException; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import info.textgrid.middleware.oaipmh.DeletedRecordType; -import info.textgrid.middleware.oaipmh.GranularityType; -import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; - -/** - * - */ -@Ignore -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; - private static IdentifierListDelivererDC identifierList; - private static MetadataFormatListDeliverer metadataFormatList = new MetadataFormatListDeliverer(); - private static SetDeliverer setListDARIAH = new SetDeliverer(false, true); - - private RepIdentification rep = new RepIdentification("DARIAH-DE Repository", - "http://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", - this.granularityType, "2.0", "funk@sub.uni-goettingen.de"); - - /** - * FIXME: it should not be necessary to put idiom record variables for a DARIAH test case - */ - private static RecordDelivererIDIOM recordIDIOM; - private static RecordListDelivererIDIOM recordListIDIOM; - private static IdentifierListDelivererIDIOM identifierListIDIOM = - new IdentifierListDelivererIDIOM(true, false); - - private OAIPMHImpl request = new OAIPMHImpl(this.rep, OaiPmhDARIAHTest.record, - OaiPmhDARIAHTest.recordIDIOM, OaiPmhDARIAHTest.recordList, OaiPmhDARIAHTest.recordListIDIOM, - OaiPmhDARIAHTest.metadataFormatList, OaiPmhDARIAHTest.setListDARIAH, - OaiPmhDARIAHTest.identifierList, OaiPmhDARIAHTest.identifierListIDIOM); - - /** - * @throws Exception - */ - @BeforeClass - public static void setUp() throws Exception { - - oaiEsClient = new OAI_ESClient("localhost", "9302", "dhrep-dariah-dev-public"); - OAI_ESClient.setEsIndex("dariah-public"); - OAI_ESClient.setEsType("metadata"); - - record = new RecordDelivererDC(false, true); - record.setOaiEsClient(oaiEsClient); - record.setWorkFields(DARIAHConstants.DARIAHFields); - } - - /** - * @throws ParseException - */ - @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); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testGetRequestGetRecordDariah() throws ParseException { - - OaiPmhDARIAHTest.record.setContributor(DARIAHConstants.CONTRIBUTOR_LIST); - OaiPmhDARIAHTest.record.setCoverage(DARIAHConstants.COVERAGE_LIST); - OaiPmhDARIAHTest.record.setCreator(DARIAHConstants.CREATOR_LIST); - OaiPmhDARIAHTest.record.setDates(DARIAHConstants.DATE_LIST); - OaiPmhDARIAHTest.record.setDescriptions(DARIAHConstants.DESCRIPTION_LIST); - OaiPmhDARIAHTest.record.setFormats(DARIAHConstants.FORMAT_LIST); - OaiPmhDARIAHTest.record.setIdentifiers(DARIAHConstants.IDENTIFIER_LIST); - OaiPmhDARIAHTest.record.setLanguages(DARIAHConstants.LANGUAGE_LIST); - OaiPmhDARIAHTest.record.setPublishers(DARIAHConstants.PUBLISHER_LIST); - OaiPmhDARIAHTest.record.setRelations(DARIAHConstants.RELATIONS_LIST); - OaiPmhDARIAHTest.record.setRights(DARIAHConstants.RIGHTS_LIST); - OaiPmhDARIAHTest.record.setSources(DARIAHConstants.SOURCE_LIST); - OaiPmhDARIAHTest.record.setSubjects(DARIAHConstants.SUBJECT_LIST); - OaiPmhDARIAHTest.record.setTitles(DARIAHConstants.TITLE_LIST); - OaiPmhDARIAHTest.record.setTypes(DARIAHConstants.TYPE_LIST); - OaiPmhDARIAHTest.record.setFields(DARIAHConstants.DARIAHFields); - OaiPmhDARIAHTest.record.setFormatField(DARIAHConstants.FORMAT); - OaiPmhDARIAHTest.record.setFormatToFilter("metadata"); - OaiPmhDARIAHTest.record.setDateOfObjectCreation(DARIAHConstants.MODIFIED_FIELD); - OaiPmhDARIAHTest.record.setRepositoryObjectURIPrefix(DARIAHConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhDARIAHTest.record.setIdentifierField("administrativeMetadata.dcterms:identifier"); - - System.out.println("Test for the verb \"GetRecord\" for DARIAH with succesfull response"); - String p = this.request.getRequest("GetRecord", "hdl:21.T11991/0000-0005-E1AA-D", "oai_dc", "", - "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListRecordsDariah() throws ParseException { - - OaiPmhDARIAHTest.recordList.setContributor(DARIAHConstants.CONTRIBUTOR_LIST); - OaiPmhDARIAHTest.recordList.setCoverage(DARIAHConstants.COVERAGE_LIST); - OaiPmhDARIAHTest.recordList.setCreators(DARIAHConstants.CREATOR_LIST); - OaiPmhDARIAHTest.recordList.setDates(DARIAHConstants.DATE_LIST); - OaiPmhDARIAHTest.recordList.setDescriptions(DARIAHConstants.DESCRIPTION_LIST); - OaiPmhDARIAHTest.recordList.setFormats(DARIAHConstants.FORMAT_LIST); - OaiPmhDARIAHTest.recordList.setIdentifiers(DARIAHConstants.IDENTIFIER_LIST); - OaiPmhDARIAHTest.recordList.setLanguages(DARIAHConstants.LANGUAGE_LIST); - OaiPmhDARIAHTest.recordList.setPublishers(DARIAHConstants.PUBLISHER_LIST); - OaiPmhDARIAHTest.recordList.setRelations(DARIAHConstants.RELATIONS_LIST); - OaiPmhDARIAHTest.recordList.setRights(DARIAHConstants.RIGHTS_LIST); - OaiPmhDARIAHTest.recordList.setSources(DARIAHConstants.SOURCE_LIST); - OaiPmhDARIAHTest.recordList.setSubjects(DARIAHConstants.SUBJECT_LIST); - OaiPmhDARIAHTest.recordList.setTitles(DARIAHConstants.TITLE_LIST); - OaiPmhDARIAHTest.recordList.setTypes(DARIAHConstants.TYPE_LIST); - OaiPmhDARIAHTest.recordList.setFormatField(DARIAHConstants.FORMAT); - OaiPmhDARIAHTest.recordList.setDateOfObjectCreation(DARIAHConstants.CREATED); - OaiPmhDARIAHTest.recordList.setFieldForRange(DARIAHConstants.MODIFIED_FIELD); - OaiPmhDARIAHTest.recordList.setDateOfObjectCreation(DARIAHConstants.RANGE_FIELD); - OaiPmhDARIAHTest.recordList.setIdentifierField(DARIAHConstants.IDENTIFIER); - OaiPmhDARIAHTest.recordList.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); - OaiPmhDARIAHTest.recordList.setModifiedField(DARIAHConstants.MODIFIED_FIELD); - OaiPmhDARIAHTest.recordList - .setRelationToFurtherMetadataObject("descriptiveMetadata.dc:relation"); - OaiPmhDARIAHTest.recordList.setSearchResponseSize("100"); - - String r = this.request.getRequest("ListRecords", "", "oai_dc", "21.T11991/0000-0003-718E-E", - "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListSetsDARIAH() throws ParseException { - - OaiPmhDARIAHTest.setListDARIAH.setFormatField(DARIAHConstants.FORMAT); - OaiPmhDARIAHTest.setListDARIAH.setFormatToFilter(DARIAHConstants.COLLECTION_MIMETYPE); - OaiPmhDARIAHTest.setListDARIAH.setIdentifierField(DARIAHConstants.IDENTIFIER); - OaiPmhDARIAHTest.setListDARIAH - .setRepositoryObjectURIPrefix(DARIAHConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhDARIAHTest.setListDARIAH.setIdentifierField("administrativeMetadata.dcterms:identifier"); - OaiPmhDARIAHTest.setListDARIAH.setSpecField("descriptiveMetadata.dc:title"); - OaiPmhDARIAHTest.setListDARIAH.setSpecFieldPrefix(DARIAHConstants.COLLECTIONREGISTRY_PREFIX); - String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListIdentifiersDARIAH() throws ParseException { - - OaiPmhDARIAHTest.identifierList.setFieldForRange(DARIAHConstants.RANGE_FIELD); - OaiPmhDARIAHTest.identifierList.setIdentifierListFields(DARIAHConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhDARIAHTest.identifierList - .setDateOfObjectCreation("administrativeMetadata.dcterms:modified"); - OaiPmhDARIAHTest.identifierList - .setRepositoryObjectURIPrefix(DARIAHConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhDARIAHTest.identifierList.setIdentifierField("administrativeMetadata.dcterms:identifier"); - OaiPmhDARIAHTest.identifierList.setSearchResponseSize("100"); - String r = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - -} 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..09851b073e3c503c7fb44a63e04f42a403a942bb 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,19 +21,23 @@ import info.textgrid.utils.httpclient.TGHttpResponse; * * @author Stefan E. Funk, SUB Göttingen */ +@Ignore public class OaiPmhDariahdeOnlineTests { + // TODO Configure config files for all the different OAI-PMH service instances! + // The OAIPMH host to be tested. - private static String host = "http://trep.de.dariah.eu/1.0/oaipmh/"; // private static String host = "https://repository.de.dariah.eu/1.0/oaipmh/"; + // private static String host = "https://dhrepworkshop.de.dariah.eu/1.0/oaipmh/"; + private static String host = "http://trep.de.dariah.eu/1.0/oaipmh/"; + // private static String host = "http://vm1.dariah.local/1.0/oaipmh/"; // Some output finals. private static final String ERROR = ">>> ERROR"; private static final String OK = ">>> OKIDO"; private static final String TESTING = "\n>>> TESTING "; - // Time to wait between the single queries using resumption tokens in - // milliseconds. + // Time to wait between the single queries using resumption tokens in milliseconds. private static final Long TIME = 1000l; // ** @@ -98,25 +103,36 @@ public class OaiPmhDariahdeOnlineTests { * @throws IOException */ @Test - public void testRootUrl() throws IOException { + public void testRootWithSlash() throws IOException { - String shouldContain = "repository.de.dariah.eu"; + String url = "oai/"; + String shouldContain = "DARIAH-DE Repository"; - System.out.println(TESTING + "#ROOTURL"); + testRootURL(url, shouldContain); + } - TGHttpResponse httpResponse = getHttpResponse(host + "oai"); - int status = httpResponse.getStatusCode(); + /** + * @throws IOException + */ + @Test + public void testRootWithoutSlash() throws IOException { - String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + String url = "oai"; + String shouldContain = "DARIAH-DE Repository"; - if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { - System.err.println("\tstatus: " + status); - System.err.println(ERROR + ": response should contain '" + shouldContain + "'"); - assertTrue(false); - } + testRootURL(url, shouldContain); + } - System.out.println("\tresponse: " + response); - System.out.println(OK); + /** + * @throws IOException + */ + @Test + public void testBlubbVerb() throws IOException { + + String url = "oai?verb=BLUBB"; + String shouldContain = "Illegal OAI verb"; + + testRootURL(url, shouldContain); } /** @@ -126,7 +142,7 @@ public class OaiPmhDariahdeOnlineTests { public void testIdentify() throws IOException { String verb = "Identify"; - String shouldContain = "repository.de.dariah.eu"; + String shouldContain = "DARIAH-DE Repository"; System.out.println(TESTING + "#IDENTIFY"); @@ -151,36 +167,82 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListSets() throws IOException { - String verb = "ListSets"; - // Testing for set: Bahnsen 1670_Erschließung_20161017.xlsx - String shouldContainREPOSITORY = "<setSpec>hdl:21.11113/0000-000B-CAD1-5</setSpec>"; - String shouldContainTREP = "<setSpec>hdl:21.T11991/0000-0008-4C20-F</setSpec>"; + // repository.de.dariah.eu + String set = "hdl:21.11113/0000-000B-CADD-9"; + + if (host.contains("vm1")) { + // VM1: <setSpec>hdl:21.T11991/0000-001B-4CE2-F</setSpec> + // VM1: <setName>DUNGEON MASTER images</setName> + set = "hdl:21.T11991/0000-001B-4CE2-F"; + } else if (host.contains("trep")) { + set = "hdl:21.T11991/0000-0008-C3AC-A"; + } else if (host.contains("dhrepworkshop")) { + set = "hdl:21.T11991/0000-0013-8FEE-F"; + } - System.out.println(TESTING + "#LISTSETS"); + String expected = set; + testListSet(set, expected); + } - TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + verb); - int status = httpResponse.getStatusCode(); + /** + * @throws IOException + */ + @Test + public void testListRecordsSinglePageDC() throws IOException { - String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println(TESTING + "#LISTRECORDS with expected single page (without token)"); - if (status != HttpStatus.SC_OK - || !response.contains(shouldContainREPOSITORY) && !response.contains(shouldContainTREP)) { - System.err.println("\tstatus: " + status); - System.err.println(ERROR + ": response should contain (repository) '" - + shouldContainREPOSITORY + "' or (trep) '" + shouldContainTREP + "'"); - System.err.println(response); + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + int pageAmount = testList("ListRecords", "oai_dc", set); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsMorePagesDC() throws IOException { + + System.out.println(TESTING + "#LISTRECORDS with expected resumption token usage"); + + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + int pageAmount = testList("ListRecords", "oai_dc", set); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsMorePagesDCFromUntil() throws IOException { + + System.out.println(TESTING + "#LISTRECORDS with expected resumption token usage"); + + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + // FIXME Values for vm1 only! + String from = "2016-03-03"; + String until = "2018-05-04"; + int expectedPages = 5; + + int pageAmount = testList("ListRecords", "oai_dc", set, from, until); + + if (pageAmount != expectedPages) { assertTrue(false); } - - System.out.println("\tresponse: " + response); - System.out.println(OK); } /** * @throws IOException */ @Test - public void testListRecordsSinglePage() throws IOException { + public void testListRecordsSinglePageDATACITE() throws IOException { System.out.println(TESTING + "#LISTRECORDS with expected single page (without token)"); @@ -188,14 +250,29 @@ public class OaiPmhDariahdeOnlineTests { // String set = "21.11113/0000-000B-CAD1-5"; String set = ""; - testList("ListRecords", set); + int pageAmount = testList("ListRecords", "oai_datacite", set); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsMorePagesDATASITE() throws IOException { + + System.out.println(TESTING + "#LISTRECORDS with expected resumption token usage"); + + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + int pageAmount = testList("ListRecords", "oai_datacite", set); } /** * @throws IOException */ @Test - public void testListRecordsMorePages() throws IOException { + public void testListRecordsMorePagesDATASITEFromUntil() throws IOException { System.out.println(TESTING + "#LISTRECORDS with expected resumption token usage"); @@ -203,14 +280,86 @@ public class OaiPmhDariahdeOnlineTests { // String set = "21.11113/0000-000B-CAD1-5"; String set = ""; - testList("ListRecords", set); + // FIXME Values for vm1 only! + String from = "2016-03-03"; + String until = "2018-05-04"; + int expectedPages = 5; + + int pageAmount = testList("ListRecords", "oai_datacite", set, from, until); + + if (pageAmount != expectedPages) { + assertTrue(false); + } + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordDC() throws IOException { + + System.out.println(TESTING + "#GETRECORD with expected single page (without token)"); + + String identifier = ""; + String shouldContain = ""; + + String url = host + "oai?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=oai_dc"; + + // FIXME Complete test! + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordDATASITE() throws IOException { + + System.out.println(TESTING + "#GETRECORD with expected single page (without token)"); + + String identifier = ""; + String shouldContain = ""; + + String url = + host + "oai?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=oai_datacite"; + + // FIXME Complete test! + } + + /** + * @throws IOException + */ + @Test + public void testListIdentifierSinglePageDC() throws IOException { + + System.out.println(TESTING + "#LISTIDENTIFIERS with expected single page (without token)"); + + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + int pageAmount = testList("ListIdentifiers", "oai_dc", set); + } + + /** + * @throws IOException + */ + @Test + public void testListIdentifiersMorePagesDC() throws IOException { + + System.out.println(TESTING + "#LISTIDENTIFIERS with expected resumption token usage"); + + // Testing set: Bahnsen 1670_Erschließung_20161017.xlsx + // String set = "21.11113/0000-000B-CAD1-5"; + String set = ""; + + int pageAmount = testList("ListIdentifiers", "oai_dc", set); } /** * @throws IOException */ @Test - public void testListIdentifierSinglePage() throws IOException { + public void testListIdentifierSinglePageDATACITE() throws IOException { System.out.println(TESTING + "#LISTIDENTIFIERS with expected single page (without token)"); @@ -218,14 +367,14 @@ public class OaiPmhDariahdeOnlineTests { // String set = "21.11113/0000-000B-CAD1-5"; String set = ""; - testList("ListIdentifiers", set); + int pageAmount = testList("ListIdentifiers", "oai_datacite", set); } /** * @throws IOException */ @Test - public void testListIdentifiersMorePages() throws IOException { + public void testListIdentifiersMorePagesDATASITE() throws IOException { System.out.println(TESTING + "#LISTIDENTIFIERS with expected resumption token usage"); @@ -233,7 +382,7 @@ public class OaiPmhDariahdeOnlineTests { // String set = "21.11113/0000-000B-CAD1-5"; String set = ""; - testList("ListIdentifiers", set); + int pageAmount = testList("ListIdentifiers", "oai_datacite", set); } // ** @@ -306,6 +455,8 @@ public class OaiPmhDariahdeOnlineTests { i = res.indexOf("<" + recordOrHeader + ">", i); } + System.out.println("recordCount: " + recordCount); + System.out.println("\t" + recordOrHeader + "s: " + recordCount); // Check if token tag is existing. @@ -389,9 +540,30 @@ public class OaiPmhDariahdeOnlineTests { /** * @param theVerb + * @param theMetadataPrefix + * @param theSet + * @return + * @throws IOException + */ + private static int testList(String theVerb, String theMetadataPrefix, String theSet) + throws IOException { + return testList(theVerb, theMetadataPrefix, theSet, null, null); + } + + /** + * @param theVerb + * @param theMetadataPrefix + * @param theSet + * @param from + * @param until + * @return How many pages were delivered * @throws IOException */ - private static void testList(String theVerb, String theSet) throws IOException { + private static int testList(String theVerb, String theMetadataPrefix, String theSet, String from, + String until) + throws IOException { + + int result; long startTime = System.currentTimeMillis(); @@ -400,13 +572,16 @@ public class OaiPmhDariahdeOnlineTests { testOccurance = "record"; } - String prefix = "oai_dc"; + String url = host + "oai?verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; - String url = host + "oai?verb=" + theVerb + "&metadataPrefix=" + prefix; - if (theSet != null && !theSet.equals("")) { + if (theSet != null && !theSet.isEmpty()) { url += "&set=" + theSet; } + if (from != null && until != null) { + url += "&from=" + from + "&until=" + until; + } + TGHttpResponse httpResponse = getHttpResponse(url); int status = httpResponse.getStatusCode(); @@ -415,14 +590,69 @@ public class OaiPmhDariahdeOnlineTests { String restok = examineResumptionTokenTag(httpResponse, testOccurance, ""); + result = 1; while (status == HttpStatus.SC_OK && !restok.equals("-1")) { url = host + "/oai?verb=" + theVerb + "&resumptionToken=" + restok; httpResponse = getHttpResponse(url); timeRunning = System.currentTimeMillis() - startTime; System.out.println("\ttime: " + getDurationInSecs(timeRunning)); restok = examineResumptionTokenTag(httpResponse, testOccurance, restok); + result++; + } + + System.out.println(OK); + + return result; + } + + /** + * @param theSet + * @throws IOException + */ + private static void testListSet(String theSet, String theExpectedResponse) throws IOException { + + String verb = "ListSets"; + + System.out.println(TESTING + "#LISTSETS"); + + TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + verb); + int status = httpResponse.getStatusCode(); + + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + + if (status != HttpStatus.SC_OK || !response.contains(theExpectedResponse)) { + System.err.println("\tstatus: " + status); + System.err.println(ERROR + ": response should contain '" + theExpectedResponse + "'"); + System.err.println(response); + assertTrue(false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OK); + + } + + /** + * @param theURL + * @param shouldContain + * @throws IOException + */ + private static void testRootURL(String theURL, String shouldContain) throws IOException { + + System.out.println(TESTING + "#ROOTURL"); + + TGHttpResponse httpResponse = getHttpResponse(host + theURL); + int status = httpResponse.getStatusCode(); + + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + + if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { + System.err.println("\tstatus: " + status); + System.err.println(ERROR + ": response should contain '" + shouldContain + "'"); + assertTrue(false); } + System.out.println("\tresponse: " + response); System.out.println(OK); } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java deleted file mode 100644 index 75713ab5f8127478a9e82368125467ee9adfcb00..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ /dev/null @@ -1,478 +0,0 @@ -package info.textgrid.middleware; - -import java.text.ParseException; -import java.util.Map; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.XMLGregorianCalendar; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import info.textgrid.middleware.oaipmh.DeletedRecordType; -import info.textgrid.middleware.oaipmh.GranularityType; -import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; - -/** - * @author Maximilian Brodhun, SUB Göttingen - * @author Stefan E. Funk, SUB Göttingen - */ - -public class OaiPmhTest { - - // ** - // STATICS - // ** - - public static OAI_ESClient oaiEsClient; - - private static RecordDelivererDC record; - private static RecordDelivererIDIOM recordIDIOM; - private static RecordListDelivererDC recordList; - private static RecordListDelivererIDIOM recordListIDIOM; - private static IdentifierListDelivererDC identifierList = - new IdentifierListDelivererDC(true, false); - private static IdentifierListDelivererIDIOM identifierListIDIOM = - new IdentifierListDelivererIDIOM(true, false); - - // ** - // CLASS - // ** - - private DeletedRecordType bla = DeletedRecordType.NO; - private GranularityType bla2 = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; - 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); - - /** - * @throws Exception - */ - @BeforeClass - public static void setUp() throws Exception { - oaiEsClient = new OAI_ESClient("localhost", "9302", "tg-esx2-instance"); - OAI_ESClient.setEsIndex("textgrid-public"); - OAI_ESClient.setEsType("metadata"); - - record = new RecordDelivererDC(true, false); - record.setOaiEsClient(oaiEsClient); - record.setWorkFields(TGConstants.TGWorkFields); - - recordIDIOM = new RecordDelivererIDIOM(true, false); - recordIDIOM.setOaiEsClient(oaiEsClient); - - recordList = new RecordListDelivererDC(true, false); - recordList.setFields(TGConstants.TGFields); - recordList.setWorkFields(TGConstants.TGWorkFields); - recordList.setOaiEsClient(oaiEsClient); - recordList.setSearchResponseSize("100"); - - recordListIDIOM = new RecordListDelivererIDIOM(true, false); - recordListIDIOM.setOaiEsClient(oaiEsClient); - - identifierList = new IdentifierListDelivererDC(true, false); - identifierList.setOaiEsClient(oaiEsClient); - identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - } - - /** - * @throws DatatypeConfigurationException - */ - @Test - @Ignore - public void testDateNow() throws DatatypeConfigurationException { - System.out.println("---------------Test Datestamp Parsing with now date -----------------"); - XMLGregorianCalendar nowTest = OAIPMHUtilities.getXMLGregorianCalendarNow(); - System.out.println(nowTest); - System.out.println("-------------------------------------------"); - } - - /** - * @throws ParseException - * @throws DatatypeConfigurationException - */ - @Test - @Ignore - public void testDateGregorianType() throws ParseException, DatatypeConfigurationException { - String dateformatbefore = "2012-02-06T20:48:39.614+01:00"; - System.out.println("--------- Test Datestamp Parsing with a given date ---------------"); - System.out.println("Original date: " + dateformatbefore); - XMLGregorianCalendar testDate = OAIPMHUtilities.convertDateFormat(dateformatbefore); - System.out.println("Date after conversion: " + testDate); - System.out.println("---------------------------------------------"); - } - - /** - * @throws ParseException - * @throws DatatypeConfigurationException - */ - @Test - @Ignore - public void testDateStringType() throws ParseException, DatatypeConfigurationException { - String dateformatbefore = "2012-02-06T20:48:39.614+01:00"; - System.out.println("------------String Version-------------------"); - System.out.println("Original date: " + dateformatbefore); - String testDate = OAIPMHUtilities.datestampAsString(dateformatbefore); - System.out.println("Date after conversion: " + testDate); - System.out.println("---------------------------------------------"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - 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); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testGetRequestIdentifyVerbError() throws ParseException { - System.out.println("Test for the verb \"Identify\" with error response (MetadaFormat)"); - String t = this.request.getRequest("Identify", "", "a", "", "", "", ""); - System.out.println(t); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testGetRequestIdentifyArgumentError() throws ParseException { - System.out.println("Test for the verb \"Identify\" with error response (Until and Identifier)"); - String z = this.request.getRequest("Identify", "a", "", "", "", "a", ""); - System.out.println(z); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testGetRequestGetRecordTextGrid() throws ParseException { - record.setContributor(TGConstants.CONTRIBUTOR_LIST); - record.setCoverage(TGConstants.COVERAGE_LIST); - record.setCreator(TGConstants.CREATOR_LIST); - record.setDates(TGConstants.DATE_LIST); - record.setDescriptions(TGConstants.DESCRIPTION_LIST); - record.setFormats(TGConstants.FORMAT_LIST); - record.setIdentifiers(TGConstants.IDENTIFIER_LIST); - record.setLanguages(TGConstants.LANGUAGE_LIST); - record.setPublishers(TGConstants.PUBLISHER_LIST); - record.setRelations(TGConstants.RELATIONS_LIST); - record.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); - record.setRights(TGConstants.RIGHTS_LIST); - record.setSources(TGConstants.SOURCE_LIST); - record.setSubjects(TGConstants.SUBJECT_LIST); - record.setTitles(TGConstants.TITLE_LIST); - record.setTypes(TGConstants.TYPE_LIST); - record.setFields(TGConstants.TGFields); - record.setFormatField(TGConstants.FORMAT); - record.setFormatToFilter(TextGridMimetypes.EDITION); - record.setDateOfObjectCreation(TGConstants.CREATED); - record.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); - record.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - 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", "", "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testGetRequestGetRecordIDIOM() throws ParseException { - System.out.println("Test for the verb \"GetRecord\" with succesfull response"); - String p = this.request.getRequest("GetRecord", "textgrid:2rcj2", - TGConstants.METADATA_IDIOM_PREFIX, "", "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testGetRequestGetRecordErrorIdentifierMissing() throws ParseException { - System.out.println("Test for the verb \"GetRecord\" with errpr response (Identifier Missing)"); - String p = this.request.getRequest("GetRecord", "", "", "", "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListIdentifierSetsDC() throws ParseException { - OaiPmhTest.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTest.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTest.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTest.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - 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", "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListIdentifierWithResumptionTokenDC() throws ParseException { - OaiPmhTest.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTest.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTest.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTest.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - 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", "", "", "", ""); - System.out.println(p); - String resToken = ""; - for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.cursorCollector.entrySet()) { - resToken = entry.getKey(); - } - System.out.println("HASH MAP BEFORE: "); - System.out.println(IdentifierListDelivererDC.cursorCollector); - System.out.println(resToken); - String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); - System.out.println(p2); - System.out.println("HASH MAP AFTER: "); - System.out.println(IdentifierListDelivererDC.cursorCollector); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListIdentifierIDIOMInvalidResumptionToken() throws ParseException { - System.out - .println("Test for the verb \"ListIdentifiers\" in IDIOM with an invalid resumption token"); - String p = this.request.getRequest("ListIdentifiers", "", "", "", "", "", - "45d8b524-b69e-44e8-81a9-a3634005a430"); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListIdentifierIDIOMWithResumptionToken() throws ParseException { - System.out.println("Test for the verb \"ListIdentifiers\" in IDIOM with successfull response"); - String p = this.request.getRequest("ListIdentifiers", "", TGConstants.METADATA_IDIOM_PREFIX, "", - "", "", ""); - System.out.println(p); - String resToken = ""; - for (Map.Entry<String, Integer> entry : IdentifierListDelivererIDIOM.cursorCollector - .entrySet()) { - resToken = entry.getKey(); - } - String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); - System.out.println(p2); - System.out.println("HASH MAP AFTER: "); - System.out.println(IdentifierListDelivererIDIOM.cursorCollector); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListRecordSets() throws ParseException { - OaiPmhTest.recordList.setContributor(TGConstants.CONTRIBUTOR_LIST); - OaiPmhTest.recordList.setCoverage(TGConstants.COVERAGE_LIST); - OaiPmhTest.recordList.setCreators(TGConstants.CREATOR_LIST); - OaiPmhTest.recordList.setDates(TGConstants.DATE_LIST); - OaiPmhTest.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); - OaiPmhTest.recordList.setFormats(TGConstants.FORMAT_LIST); - OaiPmhTest.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); - OaiPmhTest.recordList.setLanguages(TGConstants.LANGUAGE_LIST); - OaiPmhTest.recordList.setPublishers(TGConstants.PUBLISHER_LIST); - OaiPmhTest.recordList.setRelations(TGConstants.RELATIONS_LIST); - OaiPmhTest.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); - OaiPmhTest.recordList.setRights(TGConstants.RIGHTS_LIST); - OaiPmhTest.recordList.setSources(TGConstants.SOURCE_LIST); - OaiPmhTest.recordList.setSubjects(TGConstants.SUBJECT_LIST); - OaiPmhTest.recordList.setTitles(TGConstants.TITLE_LIST); - OaiPmhTest.recordList.setTypes(TGConstants.TYPE_LIST); - OaiPmhTest.recordList.setFormatField(TGConstants.FORMAT); - OaiPmhTest.recordList.setFormatToFilter(TextGridMimetypes.EDITION); - OaiPmhTest.recordList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTest.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); - OaiPmhTest.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTest.recordList.setFieldForRange(TGConstants.CREATED); - OaiPmhTest.recordList.setModifiedField(TGConstants.MODIFIED_FIELD); - 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", "", "", "", ""); - System.out.println(p); - 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"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListRecordWithResumptionTokenForIDIOM() throws ParseException { - System.out.println("Test for the verb \"ListRecords\" for IDIOM with succesfull response"); - String p = this.request.getRequest("ListRecords", "", TGConstants.METADATA_IDIOM_PREFIX, "", "", - "", ""); - System.out.println(p); - String resToken = ""; - for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.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(RecordListDelivererIDIOM.cursorCollector); - System.out.println("-----------------------------------\n"); - } - - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListRecords() throws ParseException { - String r = - this.request.getRequest("ListRecords", "", "oai_dc", "", "2011-02-06T20:48:39", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListRecords2() throws ParseException { - OaiPmhTest.recordList.setContributor(TGConstants.CONTRIBUTOR_LIST); - OaiPmhTest.recordList.setCoverage(TGConstants.COVERAGE_LIST); - OaiPmhTest.recordList.setCreators(TGConstants.CREATOR_LIST); - OaiPmhTest.recordList.setDates(TGConstants.DATE_LIST); - OaiPmhTest.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); - OaiPmhTest.recordList.setFormats(TGConstants.FORMAT_LIST); - OaiPmhTest.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); - OaiPmhTest.recordList.setLanguages(TGConstants.LANGUAGE_LIST); - OaiPmhTest.recordList.setPublishers(TGConstants.PUBLISHER_LIST); - OaiPmhTest.recordList.setRelations(TGConstants.RELATIONS_LIST); - OaiPmhTest.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); - OaiPmhTest.recordList.setRights(TGConstants.RIGHTS_LIST); - OaiPmhTest.recordList.setSources(TGConstants.SOURCE_LIST); - OaiPmhTest.recordList.setSubjects(TGConstants.SUBJECT_LIST); - OaiPmhTest.recordList.setTitles(TGConstants.TITLE_LIST); - OaiPmhTest.recordList.setTypes(TGConstants.TYPE_LIST); - OaiPmhTest.recordList.setFormatField(TGConstants.FORMAT); - OaiPmhTest.recordList.setFormatToFilter(TextGridMimetypes.EDITION); - OaiPmhTest.recordList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTest.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); - OaiPmhTest.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTest.recordList.setFieldForRange(TGConstants.CREATED); - 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"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListMetadataFormatsForIdentifier() throws ParseException { - String r = this.request.getRequest("ListMetadataFormats", "7t.0", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testListMetadataFormatsWithoutID() throws ParseException { - String r = this.request.getRequest("ListMetadataFormats", "", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @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:"); - - String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - @Ignore - public void testEmptyRequest() throws ParseException { - OaiPmhTest.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTest.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTest.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - 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"); - } - -} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java new file mode 100644 index 0000000000000000000000000000000000000000..02c4532da06b860652dc8f7fba635387cf8eb0f5 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java @@ -0,0 +1,200 @@ +package info.textgrid.middleware; + +import java.text.ParseException; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.oaipmh.DeletedRecordType; +import info.textgrid.middleware.oaipmh.GranularityType; +import info.textgrid.middleware.common.TextGridMimetypes; + +/** + * FIXME: Add documentation how to use this class, use SSH tunneling? + */ +@Ignore +public class OaiPmhTestDH { + + public static OAI_ESClient oaiEsClient; + + private static RecordDelivererDC record; + private static RecordListDelivererDC recordList; + private static IdentifierListDelivererDC identifierList; + private static MetadataFormatListDelivererInterface metadataFormatList = + new MetadataFormatListDelivererDH(); + private static SetListDeliverer setListDARIAH = new SetListDeliverer(false, true); + + // private static OpenAireRecord openAireRecord; + private static RecordDelivererDATACITE recordDATACITE; + // private static OpenAireRecordList openAireRecordList; + private static RecordListDelivererDATACITE recordListDATACITE; + // private static OpenAireIdentifierList openAireIdentifierList; + private static IdentifierListDelivererDATACITE identifierListDATACITE; + + private DeletedRecordType deletedRecordType = DeletedRecordType.NO; + private GranularityType granularityType = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; + private RepIdentification rep = new RepIdentification("DARIAH-DE Repository", + "https://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", + this.granularityType, "2.0", "funk@sub.uni-goettingen.de"); + + /** + * FIXME: it should not be necessary to put idiom record variables for a DARIAH test case + */ + private static RecordDelivererIDIOM recordIDIOM; + private static RecordListDelivererIDIOM recordListIDIOM; + private static IdentifierListDelivererIDIOM identifierListIDIOM = + new IdentifierListDelivererIDIOM(true, false); + + private OAIPMHImpl request = + new OAIPMHImpl(this.rep, + OaiPmhTestDH.record, + OaiPmhTestDH.recordIDIOM, + OaiPmhTestDH.recordDATACITE, + OaiPmhTestDH.recordList, + OaiPmhTestDH.recordListIDIOM, + OaiPmhTestDH.recordListDATACITE, + OaiPmhTestDH.metadataFormatList, + OaiPmhTestDH.setListDARIAH, + OaiPmhTestDH.identifierList, + OaiPmhTestDH.identifierListIDIOM, + // OaiPmhTestDH.openAireIdentifierList); + OaiPmhTestDH.identifierListDATACITE); + + OAIPMHUtilities settings = new OAIPMHUtilities(); + + /** + * @throws Exception + */ + @BeforeClass + public static void setUp() throws Exception { + int[] ports = new int[] {9202}; + oaiEsClient = new OAI_ESClient("localhost", ports, 100); + OAI_ESClient.setEsIndex("dariah-public"); + OAI_ESClient.setEsType("metadata"); + + record = new RecordDelivererDC(false, true); + record.setOaiEsClient(oaiEsClient); + record.setWorkFields(OAIPMHConstants.TEST_DARIAH_FIELDS); + } + + /** + * @throws ParseException + */ + @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); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testGetRequestGetRecordDariah() throws ParseException { + + OaiPmhTestDH.record.setContributor(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); + OaiPmhTestDH.record.setCoverage(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); + OaiPmhTestDH.record.setCreator(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); + OaiPmhTestDH.record.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); + OaiPmhTestDH.record.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); + OaiPmhTestDH.record.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); + OaiPmhTestDH.record.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); + OaiPmhTestDH.record.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); + OaiPmhTestDH.record.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); + OaiPmhTestDH.record.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); + OaiPmhTestDH.record.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); + OaiPmhTestDH.record.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); + OaiPmhTestDH.record.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); + OaiPmhTestDH.record.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); + OaiPmhTestDH.record.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); + OaiPmhTestDH.record.setFields(OAIPMHConstants.TEST_DARIAH_FIELDS); + OaiPmhTestDH.record.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + OaiPmhTestDH.record.setFormatToFilter("metadata"); + OaiPmhTestDH.record.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + OaiPmhTestDH.record.setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + OaiPmhTestDH.record.setIdentifierField("administrativeMetadata.dcterms:identifier"); + + System.out.println("Test for the verb \"GetRecord\" for DARIAH with succesfull response"); + String p = this.request.getRequest("GetRecord", "hdl:21.T11991/0000-0005-E1AA-D", "oai_dc", "", + "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListRecordsDariah() throws ParseException { + + OaiPmhTestDH.recordList.setContributors(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); + OaiPmhTestDH.recordList.setCoverages(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); + OaiPmhTestDH.recordList.setCreators(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); + OaiPmhTestDH.recordList.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); + OaiPmhTestDH.recordList.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); + OaiPmhTestDH.recordList.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); + OaiPmhTestDH.recordList.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); + OaiPmhTestDH.recordList.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); + OaiPmhTestDH.recordList.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); + OaiPmhTestDH.recordList.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); + OaiPmhTestDH.recordList.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); + OaiPmhTestDH.recordList.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); + OaiPmhTestDH.recordList.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); + OaiPmhTestDH.recordList.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); + OaiPmhTestDH.recordList.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); + OaiPmhTestDH.recordList.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + OaiPmhTestDH.recordList.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_CREATED); + OaiPmhTestDH.recordList.setRangeField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + OaiPmhTestDH.recordList.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); + OaiPmhTestDH.recordList.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); + OaiPmhTestDH.recordList.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); + OaiPmhTestDH.recordList.setModifiedField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + OaiPmhTestDH.recordList + .setRelationToFurtherMetadataObject("descriptiveMetadata.dc:relation"); + OaiPmhTestDH.recordList.setSearchResponseSize(100); + + String r = this.request.getRequest("ListRecords", "", "oai_dc", "21.T11991/0000-0003-718E-E", + "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListSetsDARIAH() throws ParseException { + + OaiPmhTestDH.setListDARIAH.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + OaiPmhTestDH.setListDARIAH.setFormatToFilter(OAIPMHConstants.TEST_DARIAH_COLLECTION_MIMETYPE); + OaiPmhTestDH.setListDARIAH.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); + OaiPmhTestDH.setListDARIAH + .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + OaiPmhTestDH.setListDARIAH.setIdentifierField("administrativeMetadata.dcterms:identifier"); + OaiPmhTestDH.setListDARIAH.setSpecFieldPrefix(OAIPMHConstants.TEST_DARIAH_COLLECTIONREGISTRY_PREFIX); + String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListIdentifiersDARIAH() throws ParseException { + + OaiPmhTestDH.identifierList.setFieldForRange(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); + OaiPmhTestDH.identifierList.setIdentifierListFields(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST_FIELDS); + OaiPmhTestDH.identifierList + .setDateOfObjectCreation("administrativeMetadata.dcterms:modified"); + OaiPmhTestDH.identifierList + .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + OaiPmhTestDH.identifierList.setIdentifierField("administrativeMetadata.dcterms:identifier"); + OaiPmhTestDH.identifierList.setSearchResponseSize("100"); + String r = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java new file mode 100644 index 0000000000000000000000000000000000000000..bd04384489b75da9a83a5047183b835e401b3603 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java @@ -0,0 +1,689 @@ +package info.textgrid.middleware; + +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBException; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.XMLGregorianCalendar; +import org.json.JSONObject; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.common.TextGridMimetypes; +import info.textgrid.middleware.oaipmh.DeletedRecordType; +import info.textgrid.middleware.oaipmh.GranularityType; + +/** + * @author Maximilian Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + */ + +public class OaiPmhTestTG { + + // ** + // STATICS + // ** + + public static OAI_ESClient oaiEsClient; + private static RecordDelivererDC record; + private static RecordDelivererIDIOM recordIDIOM; + // private static OpenAireRecord openAireRecord; + private static RecordDelivererDATACITE recordDATACITE; + // private static OpenAireRecordList openAireRecordList; + private static RecordListDelivererDATACITE recordListDATACITE; + // private static OpenAireIdentifierList openAireIdentifierList; + private static IdentifierListDelivererDATACITE identifierListDATACITE; + private static RecordListDelivererDC recordList; + private static RecordListDelivererIDIOM recordListIDIOM; + private static IdentifierListDelivererDC identifierList = + new IdentifierListDelivererDC(true, false); + private static IdentifierListDelivererIDIOM identifierListIDIOM = + new IdentifierListDelivererIDIOM(true, false); + private static SetListDeliverer setListTextGrid; + + // ** + // CLASS + // ** + + private DeletedRecordType bla = DeletedRecordType.NO; + private GranularityType bla2 = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; + 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 MetadataFormatListDelivererInterface metadataFormatList = + new MetadataFormatListDelivererTG(); + private OAIPMHImpl request = new OAIPMHImpl(this.rep, + OaiPmhTestTG.record, + OaiPmhTestTG.recordIDIOM, + OaiPmhTestTG.recordDATACITE, + OaiPmhTestTG.recordList, + OaiPmhTestTG.recordListIDIOM, + OaiPmhTestTG.recordListDATACITE, + this.metadataFormatList, + OaiPmhTestTG.setListTextGrid, + OaiPmhTestTG.identifierList, + OaiPmhTestTG.identifierListIDIOM, + // OaiPmhTestTG.openAireIdentifierList); + OaiPmhTestTG.identifierListDATACITE); + + OAIPMHUtilities settings = new OAIPMHUtilities(); + + /** + * @throws Exception + */ + @BeforeClass + public static void setUp() throws Exception { + 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); + + recordIDIOM = new RecordDelivererIDIOM(true, false); + recordIDIOM.setOaiEsClient(oaiEsClient); + + /* + * openAireRecord = new OpenAireRecord(true, false); openAireRecord.setOaiEsClient(oaiEsClient); + * + * openAireRecordList = new OpenAireRecordList(true, false); + * + * openAireIdentifierList = new OpenAireIdentifierList(true, false); + */ + + recordList = new RecordListDelivererDC(true, false); + recordList.setFields(TGConstants.TGFields); + recordList.setWorkFields(TGConstants.TGWorkFields); + recordList.setOaiEsClient(oaiEsClient); + recordList.setSearchResponseSize(100); + + recordListIDIOM = new RecordListDelivererIDIOM(true, false); + recordListIDIOM.setOaiEsClient(oaiEsClient); + + identifierList = new IdentifierListDelivererDC(true, false); + identifierList.setOaiEsClient(oaiEsClient); + identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + + setListTextGrid = new SetListDeliverer(true, false); + } + + + /** + * + */ + @Test + public void testGetArrayFromESIndex() { + String jsonAsString = + "{\"administrativeMetadata\":{\"dcterms:identifier\":\"hdl:21.T11991/0000-001B-4C02-C\",\"dcterms:modified\":\"2021-06-08T11:03:37.448\"},\"descriptiveMetadata\":{\"dc:creator\":\"fu\",\"dc:format\":\"text/vnd.dariah.dhrep.collection+turtle\",\"dc:rights\":\"free\",\"dc:title\":\"First ES6 Tests for DH-rep using Publikator\",\"dc:identifier\":[\"hdl:21.T11991/0000-001B-4C02-C\",\"doi:10.20375/0000-001B-4C02-C\"]}}"; + + JSONObject json = new JSONObject(jsonAsString); + // System.out.println(json); + DublinCoreBuilder result = new DublinCoreBuilder(); + List<String> identifier = new ArrayList<String>(); + String[] fieldsForIdentifier = {"descriptiveMetadata.dc:identifier"}; + System.out.println(OAIPMHUtilities.fieldLoader(json, OAIPMHConstants.TEST_DARIAH_IDENTIFIER)); + identifier = OAIPMHUtilities.fieldLoader(json, fieldsForIdentifier); + for (String id : identifier) { + System.out.println(id); + } + + result.setIdentifier(identifier); + } + + /** + * + */ + @Test + public void testGetArrayFromESIndexForListRecords() { + String jsonAsString = "{\r\n" + + " \"administrativeMetadata\": {\r\n" + + " \"dcterms:created\": \"2021-06-16T17:15:48.689\",\r\n" + + " \"dcterms:creator\": \"StefanFunk@dariah.eu\",\r\n" + + " \"dcterms:extent\": 154064,\r\n" + + " \"dcterms:identifier\": \"hdl:21.T11991/0000-001B-4D41-4\",\r\n" + + " \"dcterms:modified\": \"2021-06-16T17:15:48.689\"\r\n" + + " },\r\n" + + " \"descriptiveMetadata\": {\r\n" + + " \"dc:creator\": \"fu\",\r\n" + + " \"dc:description\": \"just some ictures\",\r\n" + + " \"dc:format\": \"image/jpeg\",\r\n" + + " \"dc:identifier\": [\r\n" + + " \"hdl:21.T11991/0000-001B-4D41-4\",\r\n" + + " \"doi:10.20375/0000-001B-4D41-4\"\r\n" + + " ],\r\n" + + " \"dc:relation\": \"hdl:21.T11991/0000-001B-4D28-1\",\r\n" + + " \"dc:rights\": \"free\",\r\n" + + " \"dc:title\": \"2017-07-12-Waffel copy 2.jpeg\"\r\n" + + " },\r\n" + + " \"technicalMetadata\": {\r\n" + + " \"externalIdentifier\": \"fmt/43\",\r\n" + + " \"externalIdentifierType\": \"puid\",\r\n" + + " \"format\": \"JPEG File Interchange Format\",\r\n" + + " \"mimetype\": \"image/jpeg\",\r\n" + + " \"valid\": \"true\",\r\n" + + " \"version\": \"1.01\",\r\n" + + " \"well-formed\": \"true\"\r\n" + + " }\r\n" + + " }"; + + JSONObject json = new JSONObject(jsonAsString); + // System.out.println(json); + DublinCoreBuilder result = new DublinCoreBuilder(); + List<String> identifier = new ArrayList<String>(); + String[] fieldsForIdentifier = {"descriptiveMetadata.dc:identifier"}; + System.out.println(OAIPMHUtilities.fieldLoader(json, OAIPMHConstants.TEST_DARIAH_IDENTIFIER)); + identifier = OAIPMHUtilities.fieldLoader(json, fieldsForIdentifier); + for (String id : identifier) { + System.out.println(id); + } + + result.setIdentifier(identifier); + + System.out.println(result); + } + + /** + * + */ + @Test + @Ignore + public void testOpenAireIdentifierList() { + + this.settings.setRangeField(TGConstants.RANGE_FIELD); + this.settings.setFormatField(TGConstants.FORMAT); + this.settings.setFormatToFilter(TextGridMimetypes.EDITION); + this.settings.setSearchResponseSize(100); + + String p = + this.request.getRequest("ListIdentifiers", "", "oai_datacite", "", "2013", "2014", ""); + + System.out.println(p); + } + + /** + * @throws DatatypeConfigurationException + */ + @Test + @Ignore + public void testDateNow() throws DatatypeConfigurationException { + System.out.println("---------------Test Datestamp Parsing with now date -----------------"); + XMLGregorianCalendar nowTest = OAIPMHUtilities.getXMLGregorianCalendarNow(); + System.out.println(nowTest); + System.out.println("-------------------------------------------"); + } + + /** + * @throws ParseException + * @throws DatatypeConfigurationException + */ + @Test + @Ignore + public void testDateGregorianType() throws ParseException, DatatypeConfigurationException { + String dateformatbefore = "2012-02-06T20:48:39.614+01:00"; + System.out.println("--------- Test Datestamp Parsing with a given date ---------------"); + System.out.println("Original date: " + dateformatbefore); + XMLGregorianCalendar testDate = OAIPMHUtilities.convertDateFormat(dateformatbefore); + System.out.println("Date after conversion: " + testDate); + System.out.println("---------------------------------------------"); + } + + /** + * @throws ParseException + * @throws DatatypeConfigurationException + */ + @Test + @Ignore + public void testDateStringType() throws ParseException, DatatypeConfigurationException { + String dateformatbefore = "2012-02-06T20:48:39.614+01:00"; + System.out.println("------------String Version-------------------"); + System.out.println("Original date: " + dateformatbefore); + String testDate = OAIPMHUtilities.datestampAsString(dateformatbefore); + System.out.println("Date after conversion: " + testDate); + System.out.println("---------------------------------------------"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + 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); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testGetRequestIdentifyVerbError() throws ParseException { + System.out.println("Test for the verb \"Identify\" with error response (MetadaFormat)"); + String t = this.request.getRequest("Identify", "", "a", "", "", "", ""); + System.out.println(t); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testGetRequestIdentifyArgumentError() throws ParseException { + System.out.println("Test for the verb \"Identify\" with error response (Until and Identifier)"); + String z = this.request.getRequest("Identify", "a", "", "", "", "a", ""); + System.out.println(z); + 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 + */ + @Test + @Ignore + public void testGetRequestGetRecordTextGrid() throws ParseException { + record.setContributor(TGConstants.CONTRIBUTOR_LIST); + record.setCoverage(TGConstants.COVERAGE_LIST); + record.setCreator(TGConstants.CREATOR_LIST); + record.setDates(TGConstants.DATE_LIST); + record.setDescriptions(TGConstants.DESCRIPTION_LIST); + record.setFormats(TGConstants.FORMAT_LIST); + record.setIdentifiers(TGConstants.IDENTIFIER_LIST); + record.setLanguages(TGConstants.LANGUAGE_LIST); + record.setPublishers(TGConstants.PUBLISHER_LIST); + record.setRelations(TGConstants.RELATIONS_LIST); + // record.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + record.setRights(TGConstants.RIGHTS_LIST); + record.setSources(TGConstants.SOURCE_LIST); + record.setSubjects(TGConstants.SUBJECT_LIST); + record.setTitles(TGConstants.TITLE_LIST); + record.setTypes(TGConstants.TYPE_LIST); + record.setFields(TGConstants.TGFields); + record.setFormatField(TGConstants.FORMAT); + record.setFormatToFilter(TextGridMimetypes.EDITION); + record.setDateOfObjectCreation(TGConstants.CREATED); + record.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); + record.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + record.setIdentifierField("textgridUri"); + + System.out.println("Test for the verb \"GetRecord\" with succesfull response"); + String p = this.request.getRequest("GetRecord", "textgrid:11hp0.0", "oai_dc", "", "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testGetRequestGetRecordIDIOM() throws ParseException { + System.out.println("Test for the verb \"GetRecord\" with succesfull response"); + String p = this.request.getRequest("GetRecord", "textgrid:2rcj2", + OAIPMHConstants.METADATA_IDIOM_PREFIX, "", "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + * @throws JAXBException + * @throws DatatypeConfigurationException + * @throws IOException + */ + @Test + @Ignore + public void testGetRequestGetRecordOpenAire() + throws ParseException, JAXBException, DatatypeConfigurationException, IOException { + System.out.println("Test for OpenAire get record"); + + System.out.println("-----------------------------------\n"); + // OAIPMHUtilities.marshal(oar.getResource()); + // System.out.println(OAIPMHImpl.getStringFromJAXBOAIElement("GetRecord", + // oar.getRecord("24gv8.0"))); + + // OAIPMHUtilities.marshal(oar.getRecord("24gv8.0")); + + String p = this.request.getRequest("GetRecord", "mk7j.0", + OAIPMHConstants.METADATA_OPENAIRE_PREFIX, "", "", "", ""); + + System.out.println(p); + } + + /** + * @throws IOException + */ + @Test + @Ignore + public void testLIstRecordsOpenAire() throws IOException { + + recordListDATACITE.setOaiEsClient(oaiEsClient); + recordListDATACITE.setRangeField(TGConstants.RANGE_FIELD); + recordListDATACITE.setFormatField(TGConstants.FORMAT); + recordListDATACITE.setFormatToFilter(TextGridMimetypes.EDITION); + recordListDATACITE.setSearchResponseSize(100); + + String p = this.request.getRequest("ListRecords", "", OAIPMHConstants.METADATA_OPENAIRE_PREFIX, + "", "", "", ""); + + System.out.println(p); + + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testGetRequestGetRecordErrorIdentifierMissing() throws ParseException { + System.out.println("Test for the verb \"GetRecord\" with errpr response (Identifier Missing)"); + String p = this.request.getRequest("GetRecord", "", "", "", "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListIdentifierSetsDC() throws ParseException { + OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); + OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); + String p = + this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "2000-02-05", "", "junk"); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListIdentifierWithResumptionTokenDC() throws ParseException { + OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); + OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); + String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); + System.out.println(p); + String resToken = ""; + for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.cursorCollector.entrySet()) { + resToken = entry.getKey(); + } + System.out.println("HASH MAP BEFORE: "); + System.out.println(IdentifierListDelivererDC.cursorCollector); + System.out.println(resToken); + String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); + System.out.println(p2); + System.out.println("HASH MAP AFTER: "); + System.out.println(IdentifierListDelivererDC.cursorCollector); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListIdentifierIDIOMInvalidResumptionToken() throws ParseException { + System.out + .println("Test for the verb \"ListIdentifiers\" in IDIOM with an invalid resumption token"); + String p = this.request.getRequest("ListIdentifiers", "", "", "", "", "", + "45d8b524-b69e-44e8-81a9-a3634005a430"); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @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 + */ + @Test + @Ignore + public void testListIdentifierIDIOMWithResumptionToken() throws ParseException { + System.out.println("Test for the verb \"ListIdentifiers\" in IDIOM with successfull response"); + String p = this.request.getRequest("ListIdentifiers", "", OAIPMHConstants.METADATA_IDIOM_PREFIX, + "", "", "", ""); + System.out.println(p); + String resToken = ""; + for (Map.Entry<String, Integer> entry : IdentifierListDelivererIDIOM.cursorCollector + .entrySet()) { + resToken = entry.getKey(); + } + String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); + System.out.println(p2); + System.out.println("HASH MAP AFTER: "); + System.out.println(IdentifierListDelivererIDIOM.cursorCollector); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListRecordSets() throws ParseException { + OaiPmhTestTG.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); + OaiPmhTestTG.recordList.setCoverages(TGConstants.COVERAGE_LIST); + OaiPmhTestTG.recordList.setCreators(TGConstants.CREATOR_LIST); + OaiPmhTestTG.recordList.setDates(TGConstants.DATE_LIST); + OaiPmhTestTG.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); + OaiPmhTestTG.recordList.setFormats(TGConstants.FORMAT_LIST); + OaiPmhTestTG.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); + OaiPmhTestTG.recordList.setLanguages(TGConstants.LANGUAGE_LIST); + OaiPmhTestTG.recordList.setPublishers(TGConstants.PUBLISHER_LIST); + OaiPmhTestTG.recordList.setRelations(TGConstants.RELATIONS_LIST); + OaiPmhTestTG.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + OaiPmhTestTG.recordList.setRights(TGConstants.RIGHTS_LIST); + OaiPmhTestTG.recordList.setSources(TGConstants.SOURCE_LIST); + OaiPmhTestTG.recordList.setSubjects(TGConstants.SUBJECT_LIST); + OaiPmhTestTG.recordList.setTitles(TGConstants.TITLE_LIST); + OaiPmhTestTG.recordList.setTypes(TGConstants.TYPE_LIST); + OaiPmhTestTG.recordList.setFormatField(TGConstants.FORMAT); + OaiPmhTestTG.recordList.setFormatToFilter(TextGridMimetypes.EDITION); + OaiPmhTestTG.recordList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTestTG.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); + OaiPmhTestTG.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + OaiPmhTestTG.recordList.setRangeField(TGConstants.CREATED); + OaiPmhTestTG.recordList.setModifiedField(TGConstants.MODIFIED_FIELD); + OaiPmhTestTG.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 = ""; 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"); } + */ + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListRecordWithResumptionTokenForIDIOM() throws ParseException { + System.out.println("Test for the verb \"ListRecords\" for IDIOM with succesfull response"); + String p = this.request.getRequest("ListRecords", "", OAIPMHConstants.METADATA_IDIOM_PREFIX, "", + "", "", ""); + System.out.println(p); + String resToken = ""; + for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.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(RecordListDelivererIDIOM.cursorCollector); + System.out.println("-----------------------------------\n"); + } + + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListRecords() throws ParseException { + String r = + this.request.getRequest("ListRecords", "", "oai_dc", "", "2011-02-06T20:48:39", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListRecords2() throws ParseException { + System.out.println("HU"); + OaiPmhTestTG.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); + OaiPmhTestTG.recordList.setCoverages(TGConstants.COVERAGE_LIST); + OaiPmhTestTG.recordList.setCreators(TGConstants.CREATOR_LIST); + OaiPmhTestTG.recordList.setDates(TGConstants.DATE_LIST); + OaiPmhTestTG.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); + OaiPmhTestTG.recordList.setFormats(TGConstants.FORMAT_LIST); + OaiPmhTestTG.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); + OaiPmhTestTG.recordList.setLanguages(TGConstants.LANGUAGE_LIST); + OaiPmhTestTG.recordList.setPublishers(TGConstants.PUBLISHER_LIST); + OaiPmhTestTG.recordList.setRelations(TGConstants.RELATIONS_LIST); + OaiPmhTestTG.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + OaiPmhTestTG.recordList.setRights(TGConstants.RIGHTS_LIST); + OaiPmhTestTG.recordList.setSources(TGConstants.SOURCE_LIST); + OaiPmhTestTG.recordList.setSubjects(TGConstants.SUBJECT_LIST); + OaiPmhTestTG.recordList.setTitles(TGConstants.TITLE_LIST); + OaiPmhTestTG.recordList.setTypes(TGConstants.TYPE_LIST); + OaiPmhTestTG.recordList.setFormatField(TGConstants.FORMAT); + OaiPmhTestTG.recordList.setFormatToFilter(TextGridMimetypes.EDITION); + OaiPmhTestTG.recordList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTestTG.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); + OaiPmhTestTG.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + OaiPmhTestTG.recordList.setRangeField(TGConstants.CREATED); + OaiPmhTestTG.recordList.setModifiedField(TGConstants.CREATED); + OaiPmhTestTG.recordList.setIdentifierField(TGConstants.URI); + OaiPmhTestTG.recordList.setSearchResponseSize(100); + String r = this.request.getRequest("ListRecords", "", "oai_dc", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListMetadataFormatsForIdentifier() throws ParseException { + String r = + this.request.getRequest("ListMetadataFormats", "textgrid:125x1.0", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListMetadataFormatsWithoutID() throws ParseException { + String r = this.request.getRequest("ListMetadataFormats", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testListSetsTG() throws ParseException { + OaiPmhTestTG.setListTextGrid.setFormatField("format"); + OaiPmhTestTG.setListTextGrid.setFormatToFilter(TextGridMimetypes.EDITION); + OaiPmhTestTG.setListTextGrid.setIdentifierField("textgridUri"); + OaiPmhTestTG.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 { + OaiPmhTestTG.setListTextGrid.setFormatField("format"); + OaiPmhTestTG.setListTextGrid.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); + OaiPmhTestTG.setListTextGrid.setIdentifierField("textgridUri"); + OaiPmhTestTG.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); + String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + @Ignore + public void testEmptyRequest() throws ParseException { + OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); + OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix("textgrid:"); + OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + String r = this.request.getRequest("", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + +} 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..c9ae47d8d4b01e2b9729c5f5c2aa431fa4f0a352 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,9 +26,11 @@ 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"; + private static final String OAI_DATACITE_PREFIX = "oai_datacite"; private static final String OAI_IDIOMMETS_PREFIX = "oai_idiom_mets"; private static final String NO_SET = null; private static final String ERROR = " >>> ERROR"; @@ -35,6 +38,7 @@ public class OaiPmhTextgridOnlineTests { private static final String TESTING = "\n >>> TESTING "; private static final String NO_THREAD_NAME = ""; private static final String NOT_TESTED = " >>> NOT_TESTED"; + private static final String NO_TOKEN = "-1"; private static final String VERB_LIST_IDENTIFIERS = "ListIdentifiers"; private static final String VERB_LIST_RECORDS = "ListRecords"; @@ -44,8 +48,8 @@ public class OaiPmhTextgridOnlineTests { private static final String VERB_LIST_SETS = "ListSets"; // The OAIPMH host to be tested. - // private static String host = "http://dev.textgridlab.org/1.0/tgoaipmh/"; - private static String host = "http://textgridlab.org/1.0/tgoaipmh/"; + private static String host = "http://dev.textgridlab.org/1.0/tgoaipmh/"; + // private static String host = "http://textgridlab.org/1.0/tgoaipmh/"; // NOTE Test with "mvn jetty:run" in oaipmh-webapp module folder and SSH tunneling "ssh -L // 9302:localhost:9302 -l username textgrid-esx2.gwdg.de", please use original OAIPMH config file @@ -56,7 +60,7 @@ public class OaiPmhTextgridOnlineTests { // private static String host = "http://localhost:8080/oaipmh-webapp/"; // Time to wait between the single queries using resumption tokens in milliseconds. - private static final Long TIME = 50l; + private static final Long TIME = 275l; // ** // PREPARATIONS @@ -125,7 +129,7 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testRootUrl()"); - String shouldContain = "www.textgridrep.de"; + String shouldContain = "textgridrep.org"; TGHttpResponse httpResponse = getHttpResponse(host + "oai", NO_THREAD_NAME); int status = httpResponse.getStatusCode(); @@ -150,7 +154,7 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testIdentify()"); - String shouldContain = "www.textgridrep.de"; + String shouldContain = "textgridrep.org"; TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + VERB_IDENTIFY, NO_THREAD_NAME); @@ -205,7 +209,7 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListSets()"); - // Testing for set: Digital Bibliothek. + // Testing for set: TextGrid Digitale Bibliothek. String shouldContainTEXTGRIDLABORG = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; String shouldContainDEFTEXTGRIDLABORG = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; @@ -237,27 +241,50 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testGetRecordOAIDC()"); - String identifier = "textgrid:mq05.0"; - String shouldContain = "tvitt@textgrid.de"; + String identifier = "textgrid:vqn0.0"; + String shouldContain = "Heidi"; String url = host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + OAI_DC_PREFIX; - if (!host.contains("dev.textgridlab.org")) { - TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); - int status = httpResponse.getStatusCode(); - String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); - System.out.println("\tresponse: " + response); + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); - if (!response.contains(shouldContain)) { - assertTrue(false); - } + if (!response.contains(shouldContain)) { + assertTrue(false); + } - System.out.println(OK); - } else { - System.out.println(NOT_TESTED); + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordOAIDCNoPrefix() throws IOException { + + System.out.println(TESTING + "testGetRecordOAIDCNoPrefix()"); + + String identifier = "mq05.0"; + String shouldContain = "tvitt@textgrid.de"; + + String url = + host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + + OAI_DC_PREFIX; + + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); + + if (!response.contains(shouldContain)) { + assertTrue(false); } + + System.out.println(OK); } /** @@ -268,34 +295,111 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testGetRecordIDIOMMETS()"); - String identifier = "textgrid:254w6"; - String shouldContain = "Tikal"; + String identifier = "textgrid:2sg18.0"; + String shouldContain = "Aguateca"; String url = host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + OAI_IDIOMMETS_PREFIX; - if (!host.contains("dev.textgridlab.org")) { - TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); - int status = httpResponse.getStatusCode(); - String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); - System.out.println("\tresponse: " + response); + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); - if (!response.contains(shouldContain)) { - assertTrue(false); - } + if (!response.contains(shouldContain)) { + assertTrue(false); + } - System.out.println(OK); - } else { - System.err.println(NOT_TESTED); + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordIDIOMMETSNoPrefix() throws IOException { + + System.out.println(TESTING + "testGetRecordIDIOMMETSNoPrefix()"); + + String identifier = "2sg18.0"; + String shouldContain = "Aguateca"; + + String url = + host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + + OAI_IDIOMMETS_PREFIX; + + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); + + if (!response.contains(shouldContain)) { + assertTrue(false); + } + + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordDATACITE() throws IOException { + + System.out.println(TESTING + "testGetRecordDATACITE()"); + + String identifier = "textgrid:mq05.0"; + String shouldContain = "Spraach-en Höfflichkeit"; + + String url = + host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + + OAI_DATACITE_PREFIX; + + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); + + if (!response.contains(shouldContain)) { + assertTrue(false); } + + System.out.println(OK); } /** * @throws IOException */ @Test - public void testListRecordsOAIDCSinglePage() throws IOException { + public void testGetRecordDATACITENoPrefix() throws IOException { + + System.out.println(TESTING + "testGetRecordDATACITENoPrefix()"); + + String identifier = "mq05.0"; + String shouldContain = "Spraach-en Höfflichkeit"; + + String url = + host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + identifier + "&metadataPrefix=" + + OAI_DATACITE_PREFIX; + + TGHttpResponse httpResponse = getHttpResponse(url, NO_THREAD_NAME); + int status = httpResponse.getStatusCode(); + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + System.out.println("\tresponse: " + response); + + if (!response.contains(shouldContain)) { + assertTrue(false); + } + + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsWithSetOAIDCSinglePage() throws IOException { System.out.println(TESTING + "testListRecordsOAIDCSinglePage()"); @@ -315,19 +419,32 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListRecordsOAIDCMorePages()"); - // Testing set: Digitale Bibliothek (TODO Find another project with less records for testing!). + // Testing set: Digitale Bibliothek (on prod and dev available only...) String set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; - if (host.contains("dev.textgridlab.org")) { - // Use fu's test project, if test instance used in host name. - // Testing set: fu's shakespeare. - set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d"; - } testList(VERB_LIST_RECORDS, set, OAI_DC_PREFIX, 0, 100, NO_THREAD_NAME); System.out.println(OK); } + /** + * @throws IOException + */ + @Test + public void testListRecordsOAIDCMorePagesFromUntil() throws IOException { + + System.out.println(TESTING + "testListRecordsOAIDCMorePagesFromUntil()"); + + // Testing set: Digitale Bibliothek (on prod and dev available only...) + String set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; + String from = "2012-01-04T01:00:00"; + String until = "2012-01-04T12:00:00"; + + testList(VERB_LIST_RECORDS, set, OAI_DC_PREFIX, 0, 100, NO_THREAD_NAME, from, until); + + System.out.println(OK); + } + /** * @throws IOException */ @@ -336,10 +453,52 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListRecordsIDIOMMETSMorePages()"); - // Do not test on dev.textgridlab.org. - if (!host.contains("dev.textgridlab.org")) { - testList(VERB_LIST_RECORDS, NO_SET, OAI_IDIOMMETS_PREFIX, 100, 30, NO_THREAD_NAME); - } + testList(VERB_LIST_RECORDS, NO_SET, OAI_IDIOMMETS_PREFIX, 100, 30, NO_THREAD_NAME); + + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsIDIOMMETSMorePagesFromUntil() throws IOException { + + System.out.println(TESTING + "testListRecordsIDIOMMETSMorePagesFromUntil()"); + + String from = "2012-01-04T01:00:00"; + String until = "2012-01-04T12:00:00"; + + testList(VERB_LIST_RECORDS, NO_SET, OAI_IDIOMMETS_PREFIX, 100, 30, NO_THREAD_NAME, from, until); + + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsDATACITEMorePages() throws IOException { + + System.out.println(TESTING + "testListRecordsDATACITEMorePages()"); + + testList(VERB_LIST_RECORDS, NO_SET, OAI_DATACITE_PREFIX, 15, 100, NO_THREAD_NAME); + + System.out.println(OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsDATACITEMorePagesFromUntil() throws IOException { + + System.out.println(TESTING + "testListRecordsDATACITEMorePagesFromUntil()"); + + String from = "2012-01-04T01:00:00"; + String until = "2012-01-04T12:00:00"; + + testList(VERB_LIST_RECORDS, NO_SET, OAI_DATACITE_PREFIX, 15, 100, NO_THREAD_NAME, from, until); System.out.println(OK); } @@ -368,15 +527,10 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListIdentifiersOAIDCMorePages()"); - // Testing set: Digitale Bibliothek (TODO Find another project with less records for testing!). + // Testing set: Digitale Bibliothek (on prod and dev available only...) String set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; - if (host.contains("dev.textgridlab.org")) { - // Use fu's test project, if test instance used in host name. - // Testing set: fu's shakespeare. - set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d"; - } - testList(VERB_LIST_IDENTIFIERS, set, OAI_DC_PREFIX, 0, 100, NO_THREAD_NAME); + testList(VERB_LIST_IDENTIFIERS, set, OAI_DC_PREFIX, 30, 100, NO_THREAD_NAME); System.out.println(OK); } @@ -394,6 +548,19 @@ public class OaiPmhTextgridOnlineTests { System.out.println(OK); } + /** + * @throws IOException + */ + @Test + public void testListIdentifiersDATACITEMorePages() throws IOException { + + System.out.println(TESTING + "testListIdentifiersDATACITEMorePages()"); + + testList(VERB_LIST_IDENTIFIERS, NO_SET, OAI_DATACITE_PREFIX, 44, 100, NO_THREAD_NAME); + + System.out.println(OK); + } + /** * @throws IOException * @throws ExecutionException @@ -405,7 +572,7 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListIdentifiersConcurrentlyIDIOMMETSMorePages()"); - // Do not test on dev.textgridlab.org. + // Do not test on dev.textgridlab.org. We only do have ONE IDIOM page yet! if (!host.contains("dev.textgridlab.org")) { ExecutorService executor = Executors.newFixedThreadPool(3); @@ -438,24 +605,68 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testListRecordsConcurrentlyIDIOMMETSMorePages()"); - // Do not test on dev.textgridlab.org. - if (!host.contains("dev.textgridlab.org")) { - ExecutorService executor = Executors.newFixedThreadPool(3); + ExecutorService executor = Executors.newFixedThreadPool(3); - Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30, "[D1]")); - Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30, "[D2]")); - Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30, "[D3]")); + Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_IDIOMMETS_PREFIX, 1, 30, "[D1]")); + Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_IDIOMMETS_PREFIX, 1, 30, "[D2]")); + Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_IDIOMMETS_PREFIX, 1, 30, "[D3]")); - executor.shutdown(); + executor.shutdown(); - System.out.println(OK + ": [D1]=" + f1.get() + ", [D2]=" + f2.get() + ", [D3]=" + f3.get()); + System.out.println(OK + ": [D1]=" + f1.get() + ", [D2]=" + f2.get() + ", [D3]=" + f3.get()); + } - } else { - System.out.println(NOT_TESTED); - } + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersDC() + throws InterruptedException, ExecutionException { + + System.out.println(TESTING + "testRestokConcurrentlyListIdentifiersDC()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_DC_PREFIX, 36, 100, "[A1]")); + Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_DC_PREFIX, 27, 100, "[A2]")); + Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_DC_PREFIX, 19, 100, "[A3]")); + + executor.shutdown(); + + System.out.println(OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + ", [A3]=" + f3.get()); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersIDIOM() + throws InterruptedException, ExecutionException { + + System.out.println(TESTING + "testRestokConcurrentlyListIdentifiersIDIOM()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_IDIOMMETS_PREFIX, 13, 30, "[A1]")); + Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_IDIOMMETS_PREFIX, 35, 30, "[A2]")); + Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, + NO_SET, OAI_IDIOMMETS_PREFIX, 11, 30, "[A3]")); + + executor.shutdown(); + + System.out.println(OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + ", [A3]=" + f3.get()); } /** @@ -464,19 +675,19 @@ public class OaiPmhTextgridOnlineTests { * @throws ExecutionException */ @Test - public void testRestokConcurrentlyListIdentifiers() + public void testRestokConcurrentlyListIdentifiersDATACITE() throws InterruptedException, ExecutionException { - System.out.println(TESTING + "testRestokConcurrentlyListIdentifiers()"); + System.out.println(TESTING + "testRestokConcurrentlyListIdentifiersDATACITE()"); ExecutorService executor = Executors.newFixedThreadPool(3); Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_DC_PREFIX, 200, 100, "[A1]")); + NO_SET, OAI_DATACITE_PREFIX, 13, 100, "[A1]")); Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_DC_PREFIX, 201, 100, "[A2]")); + NO_SET, OAI_DATACITE_PREFIX, 35, 100, "[A2]")); Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_DC_PREFIX, 210, 100, "[A3]")); + NO_SET, OAI_DATACITE_PREFIX, 11, 100, "[A3]")); executor.shutdown(); @@ -493,20 +704,54 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testRestokConcurrentlyListIdentifiersDCAndIDIOMMets()"); + int idiomPagesToTest = 3; + int idiomRecordsPerPage = 30; + if (!host.contains("dev.textgridlab.org")) { + idiomPagesToTest = 1; + idiomRecordsPerPage = 1; + } + ExecutorService executor = Executors.newFixedThreadPool(3); Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_DC_PREFIX, 201, 100, "[DC1]")); + NO_SET, OAI_DC_PREFIX, 53, 100, "[DC1]")); Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_DC_PREFIX, 199, 100, "[DC2]")); + NO_SET, OAI_DC_PREFIX, 28, 100, "[DC2]")); Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_IDENTIFIERS, - NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30, "[IDIOM3]")); + NO_SET, OAI_IDIOMMETS_PREFIX, idiomPagesToTest, idiomRecordsPerPage, "[IDIOM3]")); executor.shutdown(); System.out.println(OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + ", [A3]=" + f3.get()); } + /** + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListRecordsDC() + throws InterruptedException, ExecutionException { + + System.out.println(TESTING + "testRestokConcurrentlyListRecordsDC()"); + + ExecutorService executor = Executors.newFixedThreadPool(4); + + Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_DC_PREFIX, 44, 100, "[DC1]")); + Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_DC_PREFIX, 33, 100, "[DC2]")); + Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_DC_PREFIX, 66, 100, "[DC3]")); + Future<Boolean> f4 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_DC_PREFIX, 28, 100, "[DC4]")); + + executor.shutdown(); + + System.out.println(OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + ", [A3]=" + f3.get() + + ", [A4]=" + f4.get()); + } + /** * @throws IOException * @throws InterruptedException @@ -520,15 +765,18 @@ public class OaiPmhTextgridOnlineTests { ExecutorService executor = Executors.newFixedThreadPool(3); Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_DC_PREFIX, 33, 100, "[B1]")); + NO_SET, OAI_DC_PREFIX, 6, 100, "[B1]")); Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_DC_PREFIX, 33, 100, "[B2]")); + NO_SET, OAI_DC_PREFIX, 7, 100, "[B2]")); Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_DC_PREFIX, 33, 100, "[B3]")); + NO_SET, OAI_DC_PREFIX, 8, 100, "[B3]")); + Future<Boolean> f4 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, + NO_SET, OAI_DC_PREFIX, 9, 100, "[B4]")); executor.shutdown(); - System.out.println(OK + ": [B1]=" + f1.get() + ", [B2]=" + f2.get() + ", [B3]=" + f3.get()); + System.out.println(OK + ": [B1]=" + f1.get() + ", [B2]=" + f2.get() + ", [B3]=" + f3.get() + + ", [B4]=" + f4.get()); } /** @@ -541,14 +789,21 @@ public class OaiPmhTextgridOnlineTests { System.out.println(TESTING + "testRestokConcurrentlyListRecordsAndIDIOMMets()"); + int idiomPagesToTest = 3; + int idiomRecordsPerPage = 30; + if (!host.contains("dev.textgridlab.org")) { + idiomPagesToTest = 1; + idiomRecordsPerPage = 1; + } + ExecutorService executor = Executors.newFixedThreadPool(3); Future<Boolean> f1 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_DC_PREFIX, 66, 100, "[DC1]")); + NO_SET, OAI_DC_PREFIX, 34, 100, "[DC1]")); Future<Boolean> f2 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_DC_PREFIX, 77, 100, "[DC2]")); + NO_SET, OAI_DC_PREFIX, 27, 100, "[DC2]")); Future<Boolean> f3 = executor.submit(new OaiPmhResumptionTokenTestThread(VERB_LIST_RECORDS, - NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30, "[IDIOM1]")); + NO_SET, OAI_IDIOMMETS_PREFIX, idiomPagesToTest, idiomRecordsPerPage, "[IDIOM1]")); executor.shutdown(); @@ -723,7 +978,7 @@ public class OaiPmhTextgridOnlineTests { if (tokStart == -1 && tokEnd == -1) { System.out.println("\t" + theThreadName + " token: no token"); - return "-1"; + return NO_TOKEN; } String restokTmp = res.substring(tokStart, tokEnd); @@ -779,7 +1034,7 @@ public class OaiPmhTextgridOnlineTests { } // No resumption token available in response. - return "-1"; + return NO_TOKEN; } return restok; @@ -800,15 +1055,34 @@ public class OaiPmhTextgridOnlineTests { /** * @param theVerb * @param theSet - * @param metadataPrefix - * @param numberOfPagesToTest + * @param theMetadataPrefix + * @param maxNumberOfPagesToTest * @param recordsExpectedPerRequest - * @param threadName + * @param theThreadName * @throws IOException */ protected static void testList(final String theVerb, final String theSet, - final String theMetadataPrefix, final int numberOfPagesToTest, + final String theMetadataPrefix, final int maxNumberOfPagesToTest, final int recordsExpectedPerRequest, final String theThreadName) throws IOException { + testList(theVerb, theSet, theMetadataPrefix, maxNumberOfPagesToTest, recordsExpectedPerRequest, + theThreadName, null, null); + } + + /** + * @param theVerb + * @param theSet + * @param theMetadataPrefix + * @param maxNumberOfPagesToTest + * @param recordsExpectedPerRequest + * @param theThreadName + * @param from + * @param until + * @throws IOException + */ + protected static void testList(final String theVerb, final String theSet, + final String theMetadataPrefix, final int maxNumberOfPagesToTest, + final int recordsExpectedPerRequest, final String theThreadName, final String from, + final String until) throws IOException { long startTime = System.currentTimeMillis(); @@ -823,6 +1097,10 @@ public class OaiPmhTextgridOnlineTests { url += "&set=" + theSet; } + if (from != null && until != null) { + url += "&from=" + from + "&until=" + until; + } + TGHttpResponse httpResponse = getHttpResponse(url, theThreadName); int status = httpResponse.getStatusCode(); @@ -830,17 +1108,18 @@ public class OaiPmhTextgridOnlineTests { long timeRunning = System.currentTimeMillis() - startTime; System.out .println("\t" + theThreadName + " time: " + getDurationInSecs(timeRunning) + " (loop " - + loopCount + (numberOfPagesToTest != 0 ? "/" + numberOfPagesToTest : "") + ")"); + + loopCount + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + ")"); String restok = examineResumptionTokenTag(httpResponse, testOccurance, "", recordsExpectedPerRequest, loopCount, theThreadName); - while (status == HttpStatus.SC_OK && !restok.equals("-1")) { + while (status == HttpStatus.SC_OK && !restok.equals(NO_TOKEN)) { loopCount += 1; synchronized (theThreadName) { - if (numberOfPagesToTest > 0 && loopCount > numberOfPagesToTest) { + if (maxNumberOfPagesToTest > 0 && loopCount > maxNumberOfPagesToTest) { System.out - .println("\t" + theThreadName + " TESTING ONLY " + numberOfPagesToTest + " pages!"); + .println( + "\t" + theThreadName + " TESTING ONLY " + maxNumberOfPagesToTest + " pages!"); break; } url = host + "oai?verb=" + theVerb + "&resumptionToken=" + restok; @@ -849,15 +1128,17 @@ public class OaiPmhTextgridOnlineTests { System.out .println("\t" + theThreadName + " time: " + getDurationInSecs(timeRunning) + " (loop " - + loopCount + (numberOfPagesToTest != 0 ? "/" + numberOfPagesToTest : "") + ")"); + + loopCount + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + + ")"); restok = examineResumptionTokenTag(httpResponse, testOccurance, restok, recordsExpectedPerRequest, loopCount, theThreadName); - } } - if (loopCount < numberOfPagesToTest) { - System.out.println(theThreadName + ERROR + ": " + "Must have done " + numberOfPagesToTest + // Only check for max loops, if we do have less loops and nmo resumption token, it will be fine, + // too! + if (!restok.equals(NO_TOKEN) && loopCount < maxNumberOfPagesToTest) { + System.out.println(theThreadName + ERROR + ": " + "Must have done " + maxNumberOfPagesToTest + " loops, but did only " + loopCount); assertTrue(false); } @@ -944,14 +1225,13 @@ public class OaiPmhTextgridOnlineTests { */ public Boolean call() throws IOException { - String url = host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + this.identifier + String url = host + "oai?verb=" + this.verb + "&identifier=" + this.identifier + "&metadataPrefix=" + this.metadataPrefix; TGHttpResponse httpResponse = getHttpResponse(url, this.threadName); return true; } - } } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java b/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java new file mode 100644 index 0000000000000000000000000000000000000000..56cb8ef77b9bc3e3302899455d99a56e8651d876 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java @@ -0,0 +1,104 @@ +package info.textgrid.middleware; + +import static org.junit.Assert.assertTrue; +import java.text.ParseException; +import org.junit.Test; + +/** + */ +public class TestOAIPMHUtilities { + + /** + * @throws ParseException + */ + @Test + public void testOmitPrefixFromIdentifier() { + + // Check Handle IDs (dhrep). + String id1 = "hdl:21.11113/0000-000B-C8EF-7"; + String exp1 = "21.11113/0000-000B-C8EF-7"; + String res1 = OAIPMHUtilities.omitPrefixFromIdentifier(id1); + if (!res1.equals(exp1)) { + System.out.println(res1 + "!=" + exp1); + assertTrue(false); + } + + // Check tgrep set IDs (do not filter project: prefix!). + String id2 = "project:TGPR-2c283391-6ed5-70b4-2e5e-5501c856bca9"; + String exp2 = "project:TGPR-2c283391-6ed5-70b4-2e5e-5501c856bca9"; + String res2 = OAIPMHUtilities.omitPrefixFromIdentifier(id2); + if (!res2.equals(exp2)) { + System.out.println(res2 + "!=" + exp2); + assertTrue(false); + } + + // Check tgrep identifier. + String id3 = "textgrid:24gv8.0"; + String exp3 = "24gv8.0"; + String res3 = OAIPMHUtilities.omitPrefixFromIdentifier(id3); + if (!res3.equals(exp3)) { + System.out.println(res3 + "!=" + exp3); + assertTrue(false); + } + + // Check unknown prefix. + String id4 = "urgli:furgli"; + String exp4 = "urgli:furgli"; + String res4 = OAIPMHUtilities.omitPrefixFromIdentifier(id4); + if (!res4.equals(exp4)) { + System.out.println(res4 + "!=" + exp4); + assertTrue(false); + } + + // Check no prefix. + String id5 = "URGLARGLAUA"; + String exp5 = "URGLARGLAUA"; + String res5 = OAIPMHUtilities.omitPrefixFromIdentifier(id5); + if (!res5.equals(exp5)) { + System.out.println(res5 + "!=" + exp5); + assertTrue(false); + } + } + + /** + * + */ + @Test + public void testGetSetSpec() { + + String id = "hdl:21.T11991/0000-001B-4C00-E"; + + // Set is empty. + String set = ""; + String exp = "hdl:21.T11991/0000-001B-4C00-E"; + String setSpec = OAIPMHUtilities.getSetSpec(set, "hdl:", id); + + if (!setSpec.equals(exp)) { + System.out.println(setSpec + " != " + exp); + assertTrue(false); + } + + // Set is prefix only. + set = "hdl:"; + exp = "hdl:21.T11991/0000-001B-4C00-E"; + setSpec = OAIPMHUtilities.getSetSpec(set, "hdl:", id); + + if (!setSpec.equals(exp)) { + System.out.println(setSpec + " != " + exp); + assertTrue(false); + } + + // Set is NOT empty. + set = "project:53281-3452-34-5"; + exp = "project:53281-3452-34-5"; + setSpec = OAIPMHUtilities.getSetSpec(set, "project:", id); + + if (!setSpec.equals(exp)) { + System.out.println(setSpec + " != " + exp); + assertTrue(false); + } + + + } + +} diff --git a/oaipmh-webapp/pom.xml b/oaipmh-webapp/pom.xml index b8baaed17335e109728387cef59790d983cfac89..6b3f65e599cf2c52ae21b9236acc1d02f8df0a9e 100644 --- a/oaipmh-webapp/pom.xml +++ b/oaipmh-webapp/pom.xml @@ -5,13 +5,13 @@ <parent> <artifactId>oaipmh</artifactId> <groupId>info.textgrid.middleware</groupId> - <version>3.3.16</version> + <version>4.0.0</version> </parent> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh-webapp</artifactId> <packaging>war</packaging> <name>DARIAHDE :: OAI-PMH DataProvider :: Webapp</name> - <url>http://maven.apache.org</url> + <url>https://projects.gwdg.de/projects/oai-pmh</url> <profiles> <profile> <id>dhrep.deb</id> @@ -62,11 +62,6 @@ <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>${spring.version}</version> - </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> @@ -77,12 +72,11 @@ <artifactId>oaipmh-core</artifactId> <version>${project.version}</version> </dependency> - </dependencies> <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..37c18fa1c597e735e6fb0e2921d5ecac00907ad4 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,40 +31,88 @@ <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}" /> + <!-- ES client bean --> + + <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> + <!-- Main class bean --> + + <bean id="oai" class="info.textgrid.middleware.OAIPMHImpl"> + <constructor-arg ref="RepIdentification" /> + <constructor-arg ref="RecordDC" /> + <constructor-arg ref="RecordIDIOM" /> + <constructor-arg ref="RecordDATACITE" /> + <constructor-arg ref="RecordListDC" /> + <constructor-arg ref="RecordListIDIOM" /> + <constructor-arg ref="RecordListDATACITE" /> + <constructor-arg ref="${metadataFormatListInstance}" /> + <constructor-arg ref="ListSet" /> + <constructor-arg ref="ListIdentifierDC" /> + <constructor-arg ref="ListIdentifierIDIOM" /> + <constructor-arg ref="ListIdentifierDATACITE" /> + <property name="textGrid" value="${textgrid}" /> + <property name="dariah" value="${dariah}" /> + </bean> + <!--bean id="drc" class="info.textgrid.middleware.oaipmh.${DeletedRecordInfo}" --> - <bean id="RepIdentification" class="info.textgrid.middleware.RepIdentification"> + <!-- Define all implementing classes here, chose needed class in main config + file! --> + <bean id="MetadataFormatListDelivererDH" + class="info.textgrid.middleware.MetadataFormatListDelivererDH"> + </bean> + <bean id="MetadataFormatListDelivererTG" + class="info.textgrid.middleware.MetadataFormatListDelivererTG"> + </bean> + + <!-- Bean for verb=Identify --> + + <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"> + <!-- Beans for verb=GetRecord --> + + <bean scope="prototype" id="RecordDC" + class="info.textgrid.middleware.RecordDelivererDC"> <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="FieldForRange" value="${rangeField}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="identifierField" value="${identifierField}" /> + <property name="contributor" value="${contributorList}" /> <property name="coverage" value="${coverageList}" /> - <property name="creators" value="${creatorList}" /> + <property name="creator" value="${creatorList}" /> <property name="dates" value="${dateList}" /> <property name="descriptions" value="${descriptionList}" /> <property name="formats" value="${formatList}" /> @@ -70,33 +120,70 @@ <property name="languages" value="${languageList}" /> <property name="publishers" value="${publisherList}" /> <property name="relations" value="${relationList}" /> - <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}" /> - <property name="modifiedField" value="${modifiedField}" /> - <property name="identifierField" value="${identifierField}" /> - <property name="searchResponseSize" value="${searchResponseSize}" /> + + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> </bean> - <bean id="RecordListIDIOM" class="info.textgrid.middleware.RecordListDelivererIDIOM"> + <bean id="RecordIDIOM" + class="info.textgrid.middleware.RecordDelivererIDIOM"> <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="identifierField" value="${identifierField}" /> + + <property name="contributor" value="${contributorList}" /> + <property name="coverage" value="${coverageList}" /> + <property name="creator" value="${creatorList}" /> + <property name="dates" value="${dateList}" /> + <property name="descriptions" value="${descriptionList}" /> + <property name="formats" value="${formatList}" /> + <property name="identifiers" value="${identifierList}" /> + <property name="languages" value="${languageList}" /> + <property name="publishers" value="${publisherList}" /> + <property name="relations" value="${relationList}" /> + <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}" /> + + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> </bean> - <bean scope="prototype" id="RecordDC" class="info.textgrid.middleware.RecordDelivererDC"> + <bean id="RecordDATACITE" + class="info.textgrid.middleware.RecordDelivererDATACITE"> <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="identifierField" value="${identifierField}" /> - <property name="fields" value="${fields}" /> - <property name="workFields" value="${workFields}" /> <property name="contributor" value="${contributorList}" /> <property name="coverage" value="${coverageList}" /> <property name="creator" value="${creatorList}" /> @@ -107,74 +194,207 @@ <property name="languages" value="${languageList}" /> <property name="publishers" value="${publisherList}" /> <property name="relations" value="${relationList}" /> - <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}" /> + <property name="oarIdentifierField" + value="${oar.identifierField}" /> + <property name="oarSizeField" value="${oar.sizeField}" /> + <property name="oarTitleFields" value="${oar.titleFields}" /> + <property name="oarDateFields" value="${oar.dateFields}" /> + <property name="oarContributorFields" + value="${oar.contributorFields}" /> + <property name="oarCreatorFields" + value="${oar.creatorFields}" /> + <property name="oarLanguageFields" + value="${oar.languageFields}" /> + <property name="oarAlternateIdentifierFields" + value="${oar.alternateIdentifierFields}" /> + <property name="oarFormatFields" value="${oar.formatFields}" /> + <property name="oarRightsFields" value="${oar.rightsFields}" /> + <property name="oarDescriptionFields" + value="${oar.descriptionFields}" /> + <property name="oarRelatedIdentifierFields" + value="${oar.relatedIdentifierFields}" /> + <property name="oarGeoLocationFields" + value="${oar.geoLocationFields}" /> + <property name="oarVersionFields" + value="${oar.versionFields}" /> + <property name="oarSubjectFields" + value="${oar.subjectFields}" /> + <property name="relationToWorkObject" + value="${oar.relationToWorkObject}" /> + <property name="handle" value="${oar.handle}" /> + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> </bean> - - <bean id="RecordIDIOM" class="info.textgrid.middleware.RecordDelivererIDIOM"> + + <!-- Beans for verb=ListRecords --> + + <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="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="modifiedField" value="${modifiedField}" /> + <property name="identifierField" value="${identifierField}" /> + <property name="rangeField" value="${rangeField}" /> + <property name="formatField" value="${formatField}" /> + <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> + + <property name="contributors" value="${contributorList}" /> + <property name="coverages" value="${coverageList}" /> + <property name="creators" value="${creatorList}" /> + <property name="dates" value="${dateList}" /> + <property name="descriptions" value="${descriptionList}" /> + <property name="formats" value="${formatList}" /> + <property name="identifiers" value="${identifierList}" /> + <property name="languages" value="${languageList}" /> + <property name="publishers" value="${publisherList}" /> + <property name="relations" value="${relationList}" /> + <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="ListIdentifierDC" class="info.textgrid.middleware.IdentifierListDelivererDC"> + <bean scope="prototype" id="RecordListIDIOM" + class="info.textgrid.middleware.RecordListDelivererIDIOM"> <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="FieldForRange" value="${rangeField}" /> - <property name="identifierField" value="${identifierField}" /> - <property name="searchResponseSize" value="${searchResponseSize}" /> + + <!-- TODO Why we don't need any property definitions here? --> </bean> - - <bean id="ListIdentifierIDIOM" class="info.textgrid.middleware.IdentifierListDelivererIDIOM"> + + <bean id="RecordListDATACITE" + class="info.textgrid.middleware.RecordListDelivererDATACITE"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> + + <property name="fields" value="${fields}" /> + <property name="workFields" value="${workFields}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="modifiedField" value="${modifiedField}" /> + <property name="identifierField" value="${identifierField}" /> + <property name="rangeField" value="${rangeField}" /> + <property name="formatField" value="${formatField}" /> + <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> </bean> - <bean id="SetDeliverer" class="info.textgrid.middleware.SetDeliverer"> + <!-- Beans for verb=ListIdentifiers --> + + <bean id="ListIdentifierDC" + class="info.textgrid.middleware.IdentifierListDelivererDC"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> - <property name="formatField" value="${formatField}" /> + + <property name="fieldForRange" value="${rangeField}" /> <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="identifierListFields" + value="${identifierListFields}"></property> <property name="identifierField" value="${identifierField}" /> - <property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" /> + + <property name="specFieldPrefix" value="${specFieldPrefix}" /> <property name="specField" value="${specField}" /> + </bean> + + <bean id="ListIdentifierIDIOM" + class="info.textgrid.middleware.IdentifierListDelivererIDIOM"> + <constructor-arg index="0" value="${textgrid}" /> + <constructor-arg index="1" value="${dariah}" /> + + <property name="fieldForRange" value="${rangeField}" /> + <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="identifierListFields" + value="${identifierListFields}"></property> + <property name="identifierField" value="${identifierField}" /> <property name="specFieldPrefix" value="${specFieldPrefix}" /> </bean> - <bean id="MetadataFormatList" class="info.textgrid.middleware.MetadataFormatListDeliverer"> + <bean id="ListIdentifierDATACITE" + class="info.textgrid.middleware.IdentifierListDelivererDATACITE"> + <constructor-arg index="0" value="${textgrid}" /> + <constructor-arg index="1" value="${dariah}" /> + <property name="fieldForRange" value="${rangeField}" /> + <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="identifierListFields" + value="${identifierListFields}"></property> + <property name="identifierField" value="${identifierField}" /> + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + </bean> + + <!-- Bean for verb=ListSets --> + + <bean id="ListSet" + class="info.textgrid.middleware.SetListDeliverer"> + <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="specFieldPrefix" value="${specFieldPrefix}" /> </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> </bean> - <bean id="oai" class="info.textgrid.middleware.OAIPMHImpl"> - <constructor-arg ref="RepIdentification" /> - <constructor-arg ref="RecordDC" /> - <constructor-arg ref="RecordIDIOM" /> - <constructor-arg ref="RecordListDC" /> - <constructor-arg ref="RecordListIDIOM" /> - <constructor-arg ref="MetadataFormatList" /> - <constructor-arg ref="SetDeliverer" /> - <constructor-arg ref="ListIdentifierDC" /> - <constructor-arg ref="ListIdentifierIDIOM" /> - <property name="textGrid" value="${textgrid}" /> - <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 +403,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/log4j.properties b/oaipmh-webapp/src/main/webapp/WEB-INF/log4j.properties index 4c065ca2c693a215927b31a42733f6f06dd7e79a..e1fd2d9ad20b247b751bc9ec6096f079a5c2949e 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/log4j.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/log4j.properties @@ -19,9 +19,9 @@ # <http://www.gnu.org/licenses/lgpl-3.0.html>. # #L% ### -log4j.rootLogger=ERROR, console -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n +log4j.rootLogger = DEBUG, console +log4j.appender.console = org.apache.log4j.ConsoleAppender +log4j.appender.console.layout = org.apache.log4j.PatternLayout +log4j.appender.console.layout.conversionPattern = %5p [%t] (%F:%L) - %m%n -log4j.logger.info.textgrid.middleware=DEBUG +log4j.logger.info.textgrid.middleware = DEBUG, console 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..e9827e77fa02451eb06131b7237f078cf1570ebf 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.dariah.properties @@ -1,18 +1,18 @@ -############################## -## ElasticSearch Endpoint ## -############################## +############################################################################### +## OAI-PMH Configuration File ## +############################################################################### -RS_ENDPOINT = http://trep.de.dariah.eu/oaipmh +RS_ENDPOINT = https://repository.de.dariah.eu/1.0/oaipmh ############################ ## ElasticSearch Config ## ############################ elasticSearch.url = 127.0.0.1 -elasticSearch.port = 9302 -elasticSearch.clusterName = dariah-repository-prototype -elasticSearch.index = textgrid-public +elasticSearch.port = 9202 9203 +elasticSearch.clusterName = *** elasticSearch.type = metadata +elasticSearch.itemLimit = 100 ######################## ## Project Choosing ## @@ -26,20 +26,48 @@ 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 + +###################### +## Instantiations ## +###################### + +metadataFormatListInstance = MetadataFormatListDelivererDH ###################### ## Field Settings ## ###################### -fields = descriptiveMetadata.dc:contributor, descriptiveMetadata.dc:coverage, descriptiveMetadata.dc:creator, descriptiveMetadata.dc:date, administrativeMetadata.dcterms:modified, descriptiveMetadata.dc:description, descriptiveMetadata.dc:format, descriptiveMetadata.dc:identifier, administrativeMetadata.dcterms:identifier, descriptiveMetadata.dc:language, descriptiveMetadata.dc:publisher, descriptiveMetadata.dc:relation, descriptiveMetadata.dc:rights, descriptiveMetadata.dc:source, descriptiveMetadata.dc:subject, descriptiveMetadata.dc:title, descriptiveMetadata.dc:type +fields = administrativeMetadata.dcterms:creator, administrativeMetadata.datacite:identifier, administrativeMetadata.dcterms:modified, administrativeMetadata.dcterms:created, administrativeMetadata.dcterms:identifier, administrativeMetadata.dcterms:extent, administrativeMetadata.dcterms:relation, administrativeMetadata.dcterms:format, descriptiveMetadata.dc:contributor, descriptiveMetadata.dc:coverage, descriptiveMetadata.dc:creator, descriptiveMetadata.dc:date, descriptiveMetadata.dc:description, descriptiveMetadata.dc:format, descriptiveMetadata.dc:identifier, descriptiveMetadata.dc:language, descriptiveMetadata.dc:publisher, descriptiveMetadata.dc:relation, descriptiveMetadata.dc:rights, descriptiveMetadata.dc:source, descriptiveMetadata.dc:subject, descriptiveMetadata.dc:title, descriptiveMetadata.dc:type, descriptiveMetadata.dc:relation workFields = descriptiveMetadata.dc:title +###################### +## OpenAireRecords ### +###################### + +oar.identifierField = administrativeMetadata.datacite:identifier +oar.titleFields = descriptiveMetadata.dc:title +oar.dateFields = administrativeMetadata.dcterms:created, administrativeMetadata.dcterms:modified +oar.contributorFields = administrativeMetadata.dcterms:creator, descriptiveMetadata.dc:contributor +oar.creatorFields = descriptiveMetadata.dc:creator +oar.languageFields = descriptiveMetadata.dc:language +oar.alternateIdentifierFields = descriptiveMetadata.dc:identifier +oar.formatFields = administrativeMetadata.dcterms:format +oar.rightsFields = descriptiveMetadata.dc:rights +oar.descriptionFields = descriptiveMetadata.dc:description +oar.relatedIdentifierFields = descriptiveMetadata.dc:relation +oar.relationToWorkObject = +oar.geoLocationFields = descriptiveMetadata.dc:coverage +oar.handle = administrativeMetadata.dcterms:identifier +oar.versionFields = +oar.subjectFields = descriptiveMetadata.dc:subject +oar.sizeField = administrativeMetadata.dcterms:extent + ########################## ## Dublin Core Fields ## ########################## @@ -68,11 +96,16 @@ rangeField = administrativeMetadata.dcterms:modified identifierListFields = descriptiveMetadata.dc:identifier, descriptiveMetadata.dc:date, descriptiveMetadata.dc:format, administrativeMetadata.dcterms:identifier, administrativeMetadata.dcterms:modified formatField = descriptiveMetadata.dc:format formatToFilter = text/vnd.dariah.dhrep.collection+turtle -dateOfObjectCreation = administrativeMetadata.dcterms:modified +dateOfObjectCreation = administrativeMetadata.dcterms:created relationToFurtherMetadataObject = descriptiveMetadata.dc:relation repositoryObjectURIPrefix = hdl: identifierField = administrativeMetadata.dcterms:identifier -specFieldPrefix = dariah:collection: -specField = descriptiveMetadata.dc:title modifiedField = administrativeMetadata.dcterms:modified searchResponseSize = 100 + +####################### +### More Settings ### +####################### + +specField = administrativeMetadata.dcterms:relation +specFieldPrefix = hdl: 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 0e733f528141eb0b7b09fef86df5b2e5143f1cf5..43ec7f52a1053ed6030ea68624bf9588a09a2b1e 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties @@ -9,10 +9,10 @@ RS_ENDPOINT = https://textgridlab.org/1.0/tgoaipmh ############################ elasticSearch.url = 127.0.0.1 -elasticSearch.port = 9302 -elasticSearch.clusterName = tg-esx2-instance -elasticSearch.index = textgrid-public +elasticSearch.ports = 9202 9203 +elasticSearch.index = *** elasticSearch.type = metadata +elasticSearch.itemLimit = 100 ######################## ## Project Choosing ## @@ -33,20 +33,28 @@ Granularity = YYYY_MM_DD_THH_MM_SS_Z ProtocolVersion = 2.0 AdminMail = support@de.dariah.eu +###################### +## Instantiations ## +###################### + +metadataFormatListInstance = MetadataFormatListDelivererTG + ###################### ## Field Settings ## ###################### -fields = created, format, identifier, dataContributor, textgridUri, project.id, relations.isDerivedFrom, title, pid.value, edition.isEditionOf, edition.agent.value, edition.license.licenseUri, edition.language, edition.source.bibliographicCitation.author.value, edition.source.bibliographicCitation.editor.value, edition.source.bibliographicCitation.editionTitle, edition.source.bibliographicCitation.placeOfPublication.value, edition.source.bibliographicCitation.publisher.value, edition.source.bibliographicCitation.editionNo, edition.source.bibliographicCitation.series, edition.source.bibliographicCitation.volume, edition.source.bibliographicCitation.issue, edition.source.bibliographicCitation.epage, edition.source.bibliographicCitation.spage, edition.source.bibliographicCitation.bibidentifier, work.abstract, work.genre, work.type, work.spatial.value, work.temporal.value, work.agent.value, work.subject.id.value, lastModified -workFields = created, work.abstract, relations.isDerivedFrom, textgridUri, work.genre, title, work.type, work.spatial.value, work.temporal.spatial, work.agent.value, work.subject.id.value +fields = revision,edition.source.bibliographicCitation,edition.license,created,issued,format,identifier,dataContributor,textgridUri,project,project.id,relations.isDerivedFrom,title,pid.value,edition.isEditionOf,edition.agent.value,edition.license.licenseUri,edition.language,edition.source.bibliographicCitation.author.value,edition.source.bibliographicCitation.editor.value,edition.source.bibliographicCitation.editionTitle,edition.source.bibliographicCitation.placeOfPublication.value,edition.source.bibliographicCitation.publisher.value,edition.source.bibliographicCitation.editionNo,edition.source.bibliographicCitation.series,edition.source.bibliographicCitation.volume,edition.source.bibliographicCitation.issue,edition.source.bibliographicCitation.epage,edition.source.bibliographicCitation.spage,edition.source.bibliographicCitation.bibidentifier,work.abstract,work.genre,work.type,work.spatial.value,work.temporal.value,work.agent.value,work.subject.id.value,lastModified +workFields = created,work.abstract,relations.isDerivedFrom,textgridUri,work.genre,title,work.type,work.spatial.value,work.temporal.spatial,work.agent.value,work.subject.id.value ###################### ## OpenAireRecords ### ###################### +oar.identifierField = pid.value oar.titleFields = title,edition.source.bibliographicCitation.editionTitle oar.dateFields = created,issued,lastModified -oar.contributorFields = dataContributor +oar.contributorFields = dataContributor,project +oar.creatorFields = TODO oar.languageFields = edition.language oar.alternateIdentifierFields = textgridUri oar.formatFields = format @@ -54,36 +62,39 @@ oar.rightsFields = edition.license oar.descriptionFields = work.abstract oar.relatedIdentifierFields = edition.isEditionOf oar.relationToWorkObject = edition.isEditionOf - - +oar.geoLocationFields = edition.source.bibliographicCitation.placeOfPublication +oar.handle = pid.value +oar.versionFields = revision +oar.subjectFields = work.subject +oar.sizeField = extent ########################## ## Dublin Core Fields ## ########################## contributorList = dataContributor -coverageList = work.spatial.value, work.temporal.value +coverageList = work.spatial.value,work.temporal.value creatorList = work.agent.value dateList = created descriptionList = work.abstract formatList = format -identifierList = textgridUri, pid.value, identifier +identifierList = textgridUri,pid.value,identifier languageList = edition.language publisherList = edition.source.bibliographicCitation.publisher.value -relationList = project.id, relations.isDerivedFrom -relationsForWorkList = relations.isDerivedFrom, title, textgridUri +relationList = project.id,relations.isDerivedFrom +relationsForWorkList = relations.isDerivedFrom,title,textgridUri rightsList = edition.license.licenseUri -sourceList = edition.source.bibliographicCitation.author.value, edition.source.bibliographicCitation.editor.value, edition.source.bibliographicCitation.editionTitle, edition.source.bibliographicCitation.placeOfPublication.value, edition.source.bibliographicCitation.publisher.value, edition.source.bibliographicCitation.editionNo, edition.source.bibliographicCitation.series, edition.source.bibliographicCitation.volume, edition.source.bibliographicCitation.issue, edition.source.bibliographicCitation.epage, edition.source.bibliographicCitation.spage +sourceList = edition.source.bibliographicCitation.author.value,edition.source.bibliographicCitation.editor.value,edition.source.bibliographicCitation.editionTitle,edition.source.bibliographicCitation.placeOfPublication.value,edition.source.bibliographicCitation.publisher.value,edition.source.bibliographicCitation.editionNo,edition.source.bibliographicCitation.series,edition.source.bibliographicCitation.volume,edition.source.bibliographicCitation.issue,edition.source.bibliographicCitation.epage,edition.source.bibliographicCitation.spage subjectList = work.subject.id.value titleList = title -typeList = work.genre, work.type +typeList = work.genre,work.type ############################# ## ListIdentifierSetting ## ############################# rangeField = created -identifierListFields = textgridUri, created, format +identifierListFields = textgridUri,created,format formatField = format formatToFilter = text/tg.edition+tg.aggregation+xml dateOfObjectCreation = created @@ -91,6 +102,12 @@ relationToFurtherMetadataObject = edition.isEditionOf repositoryObjectURIPrefix = textgrid: identifierPrefix = textgridUri identifierField = textgridUri -specFieldPrefix = textgrid modifiedField = lastModified searchResponseSize = 100 + +####################### +### More Settings ### +####################### + +specField = project.id +specFieldPrefix = project: diff --git a/pom.xml b/pom.xml index a8e4ca91b69e91091f691b629213dfc6e3339d35..713cd91d5aa0714f78a1042096e61460ffa86c50 100644 --- a/pom.xml +++ b/pom.xml @@ -4,16 +4,15 @@ <modelVersion>4.0.0</modelVersion> <groupId>info.textgrid.middleware</groupId> <artifactId>oaipmh</artifactId> - <version>3.3.16</version> + <version>4.0.0</version> <packaging>pom</packaging> <name>DARIAHDE :: OAI-PMH DataProvider</name> <properties> - <tgcrud.version>10.2.0-SNAPSHOT</tgcrud.version> - <tghttpclients.version>3.3.1</tghttpclients.version> + <common.version>4.0.1</common.version> <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> @@ -28,15 +27,14 @@ <properties-maven-plugin.version>1.0-alpha-2</properties-maven-plugin.version> </properties> <url>https://projects.gwdg.de/projects/oai-pmh</url> - <scm> <connection>scm:git@git.projects.gwdg.de:oai-pmh.git</connection> <developerConnection>scm:git@git.projects.gwdg.de:oai-pmh.git</developerConnection> <url>https://projects.gwdg.de/projects/oai-pmh</url> </scm> <issueManagement> - <system>chili</system> - <url>https://projects.gwdg.de/projects/tg/issues</url> + <system>GWDG Project Management Service</system> + <url>https://projects.gwdg.de/projects/tg/work_packages</url> </issueManagement> <licenses> <license> @@ -47,7 +45,7 @@ </licenses> <organization> <name>SUB Göttingen</name> - <url>http://www.sub.uni-goettingen.de</url> + <url>https://sub.uni-goettingen.de</url> </organization> <build> <defaultGoal>package</defaultGoal>