Skip to content

Commit

Permalink
Ufal/synchronising cmdi outputs (#708)
Browse files Browse the repository at this point in the history
* work in progress

* only use first available value from demo uri

* reorder funding to be correct

* WIP

* remove forgotten script

* restore old version

* restore old version for real

* restore old version for real fr

* restore old version for real fr2

* comment of changed order

* add issues and todo comments

* use old and correct version

* comment change

* sacrifice to the checkstyle god

* reformat TODOs
  • Loading branch information
MajoBerger authored Jul 24, 2024
1 parent 6f6c7ae commit 4844f83
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
17 changes: 14 additions & 3 deletions dspace-oai/src/main/java/org/dspace/utils/SpecialItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,27 @@ public static Node getFunding(String mdValue) {
}
String[] values = mdValue
.split(DCInput.ComplexDefinitions.getSeparator(), -1);
// mind the order in input forms, org;code;projname;type
Element[] elements = {organization, code, projName, fundsType};
// ORIGINAL order of funding was org;code;projname;type
// Element[] elements = {organization, code, projName, fundsType};

// TODO 2024/07 - order was changed to fundsType, code, org, projName
Element[] elements = {fundsType, code, organization, projName};

for (int i = 0; i < elements.length; i++) {
if (values.length <= i) {
elements[i].appendChild(doc.createTextNode(""));
} else {
elements[i].appendChild(doc.createTextNode(values[i]));
}
el.appendChild(elements[i]);

}
// swap to original order to display correctly
Element[] correctOrder = {organization, code, projName, fundsType};

for (Element e : correctOrder) {
el.appendChild(e);
}

return doc;
} catch (ParserConfigurationException e) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import static org.dspace.xoai.services.impl.resources.functions.StringXSLFunction.BASE;

import java.util.Objects;
import javax.xml.transform.dom.DOMSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.ExtensionFunction;
Expand All @@ -25,10 +26,12 @@
import net.sf.saxon.s9api.XdmValue;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.util.Arrays;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;



/**
* Serves as proxy for call from XSL engine.
*
Expand All @@ -48,7 +51,7 @@ final public QName getName() {

@Override
final public SequenceType getResultType() {
return SequenceType.makeSequenceType(ItemType.ANY_NODE, OccurrenceIndicator.ZERO_OR_ONE);
return SequenceType.makeSequenceType(ItemType.ANY_NODE, OccurrenceIndicator.ZERO_OR_MORE);
}

@Override
Expand All @@ -75,11 +78,36 @@ final public XdmValue call(XdmValue[] xdmValues) throws SaxonApiException {


NodeList nodeList = getNodeList(val);
Node oneNode = nodeList.item(0);
// TODO: 2024/07 (mb) Below is attempted fix that does not work yet.
// see https://github.com/dataquest-dev/DSpace/issues/709
// Node oneNode = nodeList.item(0);

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
Document newDoc = db.newDocument();
Element rootElement = newDoc.createElement("root");
newDoc.appendChild(rootElement);

for (int i = 0; i < nodeList.getLength(); i++) {
try {
rootElement.appendChild(newDoc.importNode(nodeList.item(i), true));
} catch (Exception e) {
log.error("Error while importing node", e);
}

}
Processor processor = new Processor(false);
DocumentBuilder saxonDb = processor.newDocumentBuilder();
XdmValue xdmValue = saxonDb.wrap(newDoc);

return xdmValue;
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}



DocumentBuilder db = new Processor(false).newDocumentBuilder();
DOMSource sourceObj = new DOMSource(oneNode);
var res = db.wrap(sourceObj);
return res;
}
}
27 changes: 27 additions & 0 deletions dspace-oai/src/main/java/org/dspace/xoai/util/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.Utils;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.core.service.LicenseService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.xoai.data.DSpaceItem;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class ItemUtils {
private static final AuthorizeService authorizeService
= AuthorizeServiceFactory.getInstance().getAuthorizeService();


private static final LicenseService licenseService = CoreServiceFactory.getInstance().getLicenseService();

/**
* Default constructor
*/
Expand Down Expand Up @@ -153,6 +158,8 @@ private static Element createBundlesElement(Context context, Item item) throws S
bitstream.getField().add(createValue("checksum", cks));
bitstream.getField().add(createValue("checksumAlgorithm", cka));
bitstream.getField().add(createValue("sid", bit.getSequenceID() + ""));
bitstream.getField().add(createValue("id", bit.getID().toString()));

}
}

Expand Down Expand Up @@ -290,6 +297,26 @@ public static Metadata retrieveMetadata(Context context, Item item) {
other.getField().add(createValue("handle", item.getHandle()));
other.getField().add(createValue("identifier", DSpaceItem.buildIdentifier(item.getHandle())));
other.getField().add(createValue("lastModifyDate", item.getLastModified().toString()));
// TODO: 2024/07 (mb) this is taken from clarin, but restricted is never set correctly.
// see issue https://github.com/dataquest-dev/DSpace/issues/710
boolean restricted = false;
// if(!restricted){
// List<ClarinLicense> lds =
// for(LicenseDefinition ld : lds){
// if(ld.getRequiredInfo() != null && ld.getRequiredInfo().length() > 0){
// restricted = true;
// }
// if(restricted){
// break;
// }
// }
// }

if (restricted) {
other.getField().add(createValue("restrictedAccess", "true"));
}
other.getField().add(createValue("owningCollection", item.getOwningCollection().getName()));
other.getField().add(createValue("itemId", item.getID().toString()));
metadata.getElement().add(other);

// Repository Info
Expand Down
8 changes: 5 additions & 3 deletions dspace/config/crosswalks/oai/metadataFormats/metasharev2.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
<xsl:when test="doc:metadata/doc:element[@name='local']/doc:element[@name='demo']/doc:element[@name='uri']/doc:element/doc:field[@name='value']">
<ms:resourceDocumentationInfo>
<ms:samplesLocation>
<xsl:value-of select="doc:metadata/doc:element[@name='local']/doc:element[@name='demo']/doc:element[@name='uri']/doc:element/doc:field[@name='value']" />
<xsl:value-of select="doc:metadata/doc:element[@name='local']/doc:element[@name='demo']/doc:element[@name='uri']/doc:element/doc:field[@name='value'][1]" />
</ms:samplesLocation>
</ms:resourceDocumentationInfo>
</xsl:when>
Expand Down Expand Up @@ -285,10 +285,12 @@
<xsl:for-each select="doc:metadata/doc:element[@name='local']/doc:element[@name='sponsor']/doc:element/doc:field[@name='value']">
<ms:fundingProject>
<ms:projectName>
<xsl:value-of select="tokenize(., ';')[3]"/>
<!-- order of funding complex field was changed-->
<xsl:value-of select="tokenize(., ';')[4]"/>
</ms:projectName>
<ms:fundingType>
<xsl:value-of select="tokenize(., ';')[4]"/>
<!-- order of funding complex field was changed-->
<xsl:value-of select="tokenize(., ';')[1]"/>
</ms:fundingType>
</ms:fundingProject>
</xsl:for-each>
Expand Down

0 comments on commit 4844f83

Please sign in to comment.