Permalink
Browse files

Fix #598

  • Loading branch information...
Stastny
Stastny committed Oct 5, 2018
1 parent b89f766 commit bcd99dc5ed931b0c37f372587e5a5ac3451a7696
@@ -13,9 +13,9 @@
<errOs>lrErr</errOs>
<javaProcessParameters>-Xmx1024m -Xms256m</javaProcessParameters>
<parameters>one two</parameters>
<checkErrorStream>false</checkErrorStream>

<checkErrorStream>false</checkErrorStream>

</process>

<process>
@@ -421,7 +421,7 @@


<!-- Apply moving wall to subtree -->
<process>
<process>
<id>applymw</id>
<description>Apply moving wall</description>
<mainClass>cz.cas.lib.knav.ApplyMovingWall</mainClass>
@@ -14,7 +14,7 @@
import cz.incad.kramerius.document.model.DCConent;

/**
* Utility class for collecting dc contents
* Dublin core utilities
* @author pavels
*/
public class DCUtils {
@@ -49,40 +49,57 @@ public static DCConent contentFromDC(org.w3c.dom.Document doc) {

}

/**
* Rights from Dublin core
* @param doc
* @return
*/
public static String rightsFromDC(org.w3c.dom.Document doc) {
Element elm = findElement(doc.getDocumentElement(), "rights", DC_NAMESPACE_URI);
return rightsFromDC(doc.getDocumentElement());
}

/**
* Rights from Dublin core
* @param docElement
* @return
*/
public static String rightsFromDC(Element docElement) {
Element elm = findElement(docElement, "rights", DC_NAMESPACE_URI);
if (elm != null) {
String policy = elm.getTextContent().trim();
return policy;
} else return null;
}





/**
* Returns title from dc stream
* @param doc parsed DC stream
* @return
*/
public static String titleFromDC(org.w3c.dom.Document doc) {
Element elm = findElement(doc.getDocumentElement(), "title", DC_NAMESPACE_URI);
if (elm == null) elm = findElement(doc.getDocumentElement(), "identifier", DC_NAMESPACE_URI);
String title = elm.getTextContent();
return title;
}
/**
* Returns model from dc stream
* @param doc parsed DC stream
* @return
*/
public static String modelFromDC(org.w3c.dom.Document doc) {
List<Element> elements = XMLUtils.getElements(doc.getDocumentElement(), new XMLUtils.ElementsFilter() {
public static String titleFromDC(org.w3c.dom.Document doc) {
Element elm = findElement(doc.getDocumentElement(), "title", DC_NAMESPACE_URI);
if (elm == null) elm = findElement(doc.getDocumentElement(), "identifier", DC_NAMESPACE_URI);
String title = elm.getTextContent();
return title;
}

/**
* Returns model from dc stream
* @param doc parsed DC stream
* @return
*/
public static String modelFromDC(org.w3c.dom.Document doc) {
List<Element> elements = XMLUtils.getElements(doc.getDocumentElement(), new XMLUtils.ElementsFilter() {
@Override
public boolean acceptElement(Element element) {
return (element.getLocalName().equals("type") && element.getNamespaceURI().equals(DC_NAMESPACE_URI));
}
});
for (Element elm : elements) {

for (Element elm : elements) {
String type = elm.getTextContent();
if (type.contains(":")) {
StringTokenizer tokenizer = new StringTokenizer(type,":");
@@ -91,24 +108,24 @@ public boolean acceptElement(Element element) {
return model;
} else return null;
}
}
return null;
}
/**
* Returns publishers from DC stream
* @param doc parsed DC stream
* @return
*/
public static String[] publishersFromDC(org.w3c.dom.Document doc) {
}
return null;
}

/**
* Returns publishers from DC stream
* @param doc parsed DC stream
* @return
*/
public static String[] publishersFromDC(org.w3c.dom.Document doc) {
ArrayList<String> texts = findElmTexts(doc, "publisher");
return (String[]) texts.toArray(new String[texts.size()]);
}
public static String[] creatorsFromDC(org.w3c.dom.Document dc) {
ArrayList<String> texts = findElmTexts(dc, "creator");
return (String[]) texts.toArray(new String[texts.size()]);
}
}

public static String[] creatorsFromDC(org.w3c.dom.Document dc) {
ArrayList<String> texts = findElmTexts(dc, "creator");
return (String[]) texts.toArray(new String[texts.size()]);
}

public static String dateFromDC(org.w3c.dom.Document dc) {
ArrayList<String> dates = findElmTexts(dc, "date");
@@ -130,18 +147,18 @@ public static String languageFromDC(org.w3c.dom.Document dc) {

public static ArrayList<String> findElmTexts(org.w3c.dom.Document dc, String elmName) {
ArrayList<String> texts = new ArrayList<String>();
Element documentElement = dc.getDocumentElement();
NodeList childNodes = documentElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE) {
Element documentElement = dc.getDocumentElement();
NodeList childNodes = documentElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE) {
if (item.getLocalName().equals(elmName)) {
texts.add(item.getTextContent().trim());
}
}
}
texts.add(item.getTextContent().trim());
}
}
}
return texts;
}


}
@@ -18,13 +18,12 @@
import cz.incad.kramerius.service.impl.IndexerProcessStarter;
import cz.incad.kramerius.service.impl.SortingServiceImpl;
import cz.incad.kramerius.statistics.StatisticsAccessLog;
import cz.incad.kramerius.utils.DCUtils;
import cz.incad.kramerius.utils.FedoraUtils;
import cz.incad.kramerius.utils.IOUtils;
import cz.incad.kramerius.utils.RESTHelper;
import cz.incad.kramerius.utils.conf.KConfiguration;
import org.fedora.api.FedoraAPIM;
import org.fedora.api.FedoraAPIMService;
import org.fedora.api.ObjectFactory;
import org.fedora.api.RelationshipTuple;
import org.fedora.api.*;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

@@ -49,6 +48,9 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static cz.incad.kramerius.FedoraNamespaces.DC_NAMESPACE_URI;
import static cz.incad.kramerius.utils.XMLUtils.findElement;

public class Import {

static FedoraAPIMService service;
@@ -262,6 +264,19 @@ private static void visitAllDirsAndFiles(File importFile, Set<TitlePidTuple> roo
DatastreamVersionType dsversion = ds.getDatastreamVersion().get(0);
if (dsversion.getXmlContent() != null) {
Element element = dsversion.getXmlContent().getAny().get(0);
if (dsName.equals(FedoraUtils.DC_STREAM)) {
String rights = DCUtils.rightsFromDC(element);
if (rights != null) {
Element elm = findElement(element, "rights", DC_NAMESPACE_URI);
if (elm == null) {
elm = element.getOwnerDocument().createElementNS(DC_NAMESPACE_URI, "rights");
element.appendChild(elm);
}
elm.setTextContent(rights);
}
}


ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(element);
Result outputTarget = new StreamResult(outputStream);
@@ -284,7 +299,7 @@ private static void visitAllDirsAndFiles(File importFile, Set<TitlePidTuple> roo
if (roots != null) {
TitlePidTuple npt = new TitlePidTuple("", dobj.getPID());
roots.add(npt);
log.info("Added updated object for indexing:" + dobj.getPID());
log.info("Added updated object for indexing:" + dobj.getPID());
}
} else {
ingest(importFile, dobj.getPID(), sortRelations, roots, updateExisting);
@@ -78,6 +78,7 @@ private static String prepareFile(File importDirectory, Boolean replaceDC, Boole
File[] files = importDirectory.listFiles();
if (files != null) {
for (File f : files) {
if (!f.getName().endsWith("xml")) continue;
Document document = XMLUtils.parseDocument(new FileInputStream(f), true);
String pid = document.getDocumentElement().getAttribute("PID");
builder.append(pid);

0 comments on commit bcd99dc

Please sign in to comment.