Commit 76c53246 authored by ki124fuzo's avatar ki124fuzo

some changes to handle preferredName

parent c9d2d485
...@@ -127,7 +127,7 @@ public class MCRVIAFAuthorityFileUpdateUtils { ...@@ -127,7 +127,7 @@ public class MCRVIAFAuthorityFileUpdateUtils {
MCRMetaElement clone_metadata_tag = old_metadata_tag.clone(); MCRMetaElement clone_metadata_tag = old_metadata_tag.clone();
for (int i = 0; i < clone_metadata_tag.size(); i++) { for (int i = 0; i < clone_metadata_tag.size(); i++) {
MCRMetaInterface clone_metadata_subtag = clone_metadata_tag.getElement(i); MCRMetaInterface clone_metadata_subtag = clone_metadata_tag.getElement(i);
if (clone_metadata_subtag.getType() == null || !clone_metadata_subtag.getType().equals("gnd")) { if (clone_metadata_subtag.getType() != null && clone_metadata_subtag.getType().equals("gnd")) {
clone_metadata_tag.removeElement(i); clone_metadata_tag.removeElement(i);
i--; i--;
} }
......
...@@ -104,6 +104,7 @@ public class MCRVIAFAuthorityFileUtils { ...@@ -104,6 +104,7 @@ public class MCRVIAFAuthorityFileUtils {
public static final String PREFERRED_PROVIDER = CONFIG.getString("MCR.Dptbase.Viaf.Metadata.PreferredProvider"); public static final String PREFERRED_PROVIDER = CONFIG.getString("MCR.Dptbase.Viaf.Metadata.PreferredProvider");
public static final MCRObject getGNDAsMarc21XML(MCRServletJob job, String gnd) throws Exception { public static final MCRObject getGNDAsMarc21XML(MCRServletJob job, String gnd) throws Exception {
MCRVIAFAuthorityFileUtils.LOGGER.debug("Read a GND Marc21 dataset and transform it to MyCoRe.");
Transformer trans = MCRVIAFAuthorityFileUtils.getTransformer(MCRVIAFAuthorityFileUtils.GND_TRANSFORMER); Transformer trans = MCRVIAFAuthorityFileUtils.getTransformer(MCRVIAFAuthorityFileUtils.GND_TRANSFORMER);
URL url = new URL("https://d-nb.info/gnd/" + gnd + "/about/marcxml"); URL url = new URL("https://d-nb.info/gnd/" + gnd + "/about/marcxml");
Document doc = new SAXBuilder().build(url); Document doc = new SAXBuilder().build(url);
...@@ -125,15 +126,20 @@ public class MCRVIAFAuthorityFileUtils { ...@@ -125,15 +126,20 @@ public class MCRVIAFAuthorityFileUtils {
JDOMSource source = new JDOMSource(doc2); JDOMSource source = new JDOMSource(doc2);
JDOMResult result = new JDOMResult(); JDOMResult result = new JDOMResult();
MCRObject obj = null;
try { try {
trans.transform(source, result); trans.transform(source, result);
(new MCRJDOMContent(result.getDocument())).sendTo(System.out); Document object_doc = result.getDocument();
obj = new MCRObject(object_doc);
if (MCRVIAFAuthorityFileUtils.LOGGER.isDebugEnabled()) {
(new MCRJDOMContent(object_doc)).sendTo(System.out);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
job.getResponse() job.getResponse()
.sendRedirect(job.getResponse().encodeRedirectURL(MCRVIAFAuthorityFileUtils.GND_IMPORT_ERROR_PAGE)); .sendRedirect(job.getResponse().encodeRedirectURL(MCRVIAFAuthorityFileUtils.GND_IMPORT_ERROR_PAGE));
} }
MCRObject obj = new MCRObject(result.getDocument()); MCRVIAFAuthorityFileUtils.LOGGER.debug("GND to MyCoRe transformation is finished.");
return obj; return obj;
} }
...@@ -250,12 +256,13 @@ public class MCRVIAFAuthorityFileUtils { ...@@ -250,12 +256,13 @@ public class MCRVIAFAuthorityFileUtils {
MCRMetaClassification record_source = (MCRMetaClassification) viaf_record_sources MCRMetaClassification record_source = (MCRMetaClassification) viaf_record_sources
.getElementByName("recordSource"); .getElementByName("recordSource");
String type = record_source.getCategId(); String type = record_source.getCategId();
MCRVIAFAuthorityFileUtils.LOGGER.debug("The type of object " + viaf_id + " is " + type);
// make update // make update
if (type.equals("local")) { if (type.equals("local")) {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a local dataset. Continue."); MCRVIAFAuthorityFileUtils.LOGGER.warn("Object " + viaf_id + " is a local dataset. Continue.");
return; return;
} else if (type.equals("mcrid")) { } else if (type.equals("mcrid")) {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a MyCoRe dataset. Continue."); MCRVIAFAuthorityFileUtils.LOGGER.warn("Object " + viaf_id + " is a MyCoRe dataset. Continue.");
try { try {
MCRObject new_obj = MCRVIAFAuthorityFileUtils.getMCRObjectAsXML(null, viaf_id); MCRObject new_obj = MCRVIAFAuthorityFileUtils.getMCRObjectAsXML(null, viaf_id);
MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj, "replace"); MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj, "replace");
...@@ -284,7 +291,7 @@ public class MCRVIAFAuthorityFileUtils { ...@@ -284,7 +291,7 @@ public class MCRVIAFAuthorityFileUtils {
return; return;
} }
if (type.equals("gnd")) { if (type.equals("gnd")) {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a gnd dataset"); MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a gnd dataset for action " + replace_or_update);
try { try {
MCRObject new_obj = MCRVIAFAuthorityFileUtils.getGNDAsMarc21XML(null, viaf_text.getText()); MCRObject new_obj = MCRVIAFAuthorityFileUtils.getGNDAsMarc21XML(null, viaf_text.getText());
MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj, replace_or_update); MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj, replace_or_update);
...@@ -320,6 +327,7 @@ public class MCRVIAFAuthorityFileUtils { ...@@ -320,6 +327,7 @@ public class MCRVIAFAuthorityFileUtils {
* @param replace_or_update replace a String 'replace' or 'update' * @param replace_or_update replace a String 'replace' or 'update'
*/ */
public static final void replaceVIAF(MCRObject old_obj, MCRObject new_obj, String replace_or_update) { public static final void replaceVIAF(MCRObject old_obj, MCRObject new_obj, String replace_or_update) {
MCRVIAFAuthorityFileUtils.LOGGER.debug("Replace or update oln MyCoRe object with newer from GND with action " + replace_or_update);
// set old ID // set old ID
new_obj.setId(old_obj.getId()); new_obj.setId(old_obj.getId());
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
xmlns:marc21="xalan://org.mycore.frontend.marc21.MCRGetIDForMarc21" xmlns:marc21="xalan://org.mycore.frontend.marc21.MCRGetIDForMarc21"
xmlns:ld="xalan://org.mycore.common.MCRLanguageDetector" xmlns:ld="xalan://org.mycore.common.MCRLanguageDetector"
xmlns:xalan="http://xml.apache.org/xalan" xmlns:xalan="http://xml.apache.org/xalan"
xmlns:marcxml="http://www.loc.gov/MARC21/slim" extension-element-prefixes="marc21 xlink xalan"> xmlns:marcxml="http://www.loc.gov/MARC21/slim" extension-element-prefixes="ld marcxml marc21 xlink xalan">
<xsl:output method="xml" encoding="UTF-8" indent="yes" /> <xsl:output method="xml" encoding="UTF-8" indent="yes" />
...@@ -129,6 +129,11 @@ ...@@ -129,6 +129,11 @@
<xsl:value-of select="marcxml:subfield[@code = 'c']/text()" /> <xsl:value-of select="marcxml:subfield[@code = 'c']/text()" />
</title> </title>
</xsl:if> </xsl:if>
<xsl:if test="@ind1 = '1' and marcxml:subfield[@code = 'c']">
<peerage>
<xsl:value-of select="marcxml:subfield[@code = 'c']/text()" />
</peerage>
</xsl:if>
</variantName> </variantName>
</xsl:if> </xsl:if>
<xsl:if test="@ind1 = '1' and marcxml:subfield[@code = 'a']"> <xsl:if test="@ind1 = '1' and marcxml:subfield[@code = 'a']">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment