Skip to content

Commit

Permalink
Transfer Fedora object state via METS RECORDSTATE
Browse files Browse the repository at this point in the history
  • Loading branch information
claussni committed Jan 26, 2016
1 parent 54f3c6f commit a48f705
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.purl.sword.server.fedora.fileHandlers;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
Expand Down Expand Up @@ -50,17 +51,19 @@ public class METSContainer {
private static final String DS_ID_QUCOSAXML_LABEL = "Pristine Qucosa XML Metadata";
private static final String DS_MODS_MIME_TYPE = "application/mods+xml";
private static final String METS_DMDSEC_PREFIX = "/mets:mets/mets:dmdSec";
private static final String METS_HDR_PREFIX = "/mets:mets/mets:metsHdr";
private static final String MODS_PREFIX = METS_DMDSEC_PREFIX + "/mets:mdWrap[@MDTYPE='MODS']/mets:xmlData/mods:mods";
private final XPathQuery XPATH_FILES = new XPathQuery("/mets:mets/mets:fileSec/mets:fileGrp/mets:file");
private final XPathQuery XPATH_IDENTIFIERS = new XPathQuery(MODS_PREFIX + "/mods:identifier");
private final XPathQuery XPATH_MODS = new XPathQuery(MODS_PREFIX);
private final XPathQuery XPATH_QUCOSA = new XPathQuery(METS_DMDSEC_PREFIX + "/mets:mdWrap[@MDTYPE='OTHER' and @OTHERMDTYPE='QUCOSA-XML']/mets:xmlData/Opus");
private final XPathQuery XPATH_RECORDSTATUS = new XPathQuery(METS_HDR_PREFIX + "/@RECORDSTATUS");
private final XPathQuery XPATH_RELATEDITEMS = new XPathQuery(MODS_PREFIX + "/mods:relatedItem");
private final XPathQuery XPATH_SLUB = new XPathQuery("/mets:mets/mets:amdSec/mets:techMD" + "/mets:mdWrap[@MDTYPE='OTHER' and @OTHERMDTYPE='SLUBINFO']/mets:xmlData/slub:info");
private final XPathQuery XPATH_TITLE = new XPathQuery(MODS_PREFIX + "/mods:titleInfo/mods:title[1]");

private final String md5;
private final Document metsDocument;
private State recordstatus;

public METSContainer(InputStream in) throws NoSuchAlgorithmException, JDOMException, IOException {
DigestInputStream din = new DigestInputStream(in, MessageDigest.getInstance("MD5"));
Expand Down Expand Up @@ -199,6 +202,26 @@ public List<Element> getModsRelatedItems() {
}
}

public State getRecordstatus() throws SWORDException {
try {
final Attribute attr = XPATH_RECORDSTATUS.selectAttribute(metsDocument);
if (attr != null) {
final String rs = attr.getValue();
if (rs != null) {
try {
return State.valueOf(rs);
} catch (IllegalArgumentException e) {
throw new SWORDException(
String.format("Unknown METS record state: %s (none of `ACTIVE`, `INACTIVE` or `DELETED`) ", rs));
}
}
}
} catch (JDOMException e) {
throw new SWORDException("Cannot obtain METS record status", e);
}
return null;
}

private String getPrimaryTitle() {
try {
return XPATH_TITLE.selectValue(metsDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public SWORDEntry ingestDeposit(DepositCollection deposit, ServiceDocument servi
fedoraObject.setRelsext(buildRelationships(deposit, metsContainer));
fedoraObject.setDatastreams(datastreams);
fedoraObject.setDc(metsContainer.getDublinCore());
fedoraObject.setState(metsContainer.getRecordstatus());

validateObject(fedoraObject);
final SWORDEntry swordEntry = getSWORDEntry(deposit, serviceDocument, fedoraObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.purl.sword.server.fedora.fileHandlers;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
Expand All @@ -35,6 +36,10 @@ public XPathQuery(String xp) throws JDOMException {
xpath.addNamespace(Namespaces.SLUB);
}

public Attribute selectAttribute(Document doc) throws JDOMException {
return (Attribute) xpath.selectSingleNode(doc);
}

public String selectValue(Document doc) throws JDOMException {
Element el = selectNode(doc);
if (el != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ abstract class QucosaMETSFileHandler_AbstractTest {
public static final String METS_JUST_SLUBINFO = "/mets_just_slubinfo.xml";
public static final String METS_JUST_SLUBINFO_WITHOUT_RIGHTS = "/mets_just_slubinfo_without_rights.xml";
public static final String METS_NO_FLOCAT = "/mets_no_flocat.xml";
public static final String METS_WITH_RECORDSTATE = "/mets_with_recordstate.xml";
public static final String SUBMITTER = "qucosa";
public static final String USERNAME = "fedoraAdmin";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ public void emits_IsDerivationOf_Relationship_for_preceding_type() throws Except
verifyRelationship(buildDeposit(METS_FILE_ALLREFS), "isDerivationOf", "urn:nbn:de:bsz:14-qucosa-25559");
}

@Test
public void emits_record_status() throws Exception {
ArgumentCaptor<FedoraObject> argument = verifyIngestExecution(buildDeposit(METS_WITH_RECORDSTATE));
FedoraObject fedoraObject = argument.getValue();
assertEquals("Record state should be `ACTIVE`", State.ACTIVE, fedoraObject.getState());
}

private void verifyRelationship(DepositCollection deposit, String relationshipName, String referenceUrn) throws Exception {
ArgumentCaptor<FedoraObject> argument = verifyIngestExecution(deposit);
FedoraObject fo = argument.getValue();
Expand Down
Loading

0 comments on commit a48f705

Please sign in to comment.