Commit 2153f1d1 authored by Jens Kupferschmidt's avatar Jens Kupferschmidt
Browse files

fix bug(s)

parent b7e9aab4
......@@ -61,6 +61,14 @@ import org.mycore.solr.MCRSolrClientFactory;
* @author Jens Kupferschmidt
*/
/**
* @author dptadmin
*
*/
/**
* @author dptadmin
*
*/
public class MCRVIAFAuthorityFileUtils {
public static final MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
......@@ -150,6 +158,31 @@ public class MCRVIAFAuthorityFileUtils {
return obj;
}
/**
* replace a VIAF object with a new version from primary source like GND or LCNAF
* @param old_obj the current object in the system
* @param new_obj the new generated object
*/
public static final void replaceVIAF(MCRObject old_obj, MCRObject new_obj) {
// set old ID
new_obj.setId(old_obj.getId());
// createDate
MCRObjectService service = old_obj.getService();
Date date = service.getDate(MCRObjectService.DATE_TYPE_CREATEDATE);
new_obj.getService().setDate(MCRObjectService.DATE_TYPE_CREATEDATE, date);
// update
try {
MCRMetadataManager.update(new_obj);
} catch (MCRPersistenceException e) {
LOGGER.error("Error while update entry for VIAF with MCRObjectID " + old_obj.getId().toString());
e.printStackTrace();
} catch (MCRActiveLinkException e) {
LOGGER.error("Error while update entry for VIAF with MCRObjectID " + old_obj.getId().toString());
e.printStackTrace();
}
LOGGER.info("Update entry for VIAF with MCRObjectID " + old_obj.getId().toString());
}
public static final void updateVIAF(MCRObject old_obj, MCRObject new_obj) {
// set old ID
new_obj.setId(old_obj.getId());
......@@ -271,6 +304,24 @@ public class MCRVIAFAuthorityFileUtils {
return null;
}
/**
* Checks that an given identifier exists in database
*
* @param identifier
* the given identifier number
* @return <code>true</code>, if the authority file exists, <code>false</code>
* otherwise
*/
public static final QueryResponse existsIdentifier(String identifier) throws SolrServerException {
ModifiableSolrParams param = new ModifiableSolrParams();
param.set("q", "*:*");
param.set("fq", "objectType:viaf");
param.add("fq", MessageFormat.format("viaf_identifier:\"{0}\"", identifier));
param.set("rows", 1);
QueryResponse response = MCRSolrClientFactory.getSolrClient().query(param);
return response;
}
/**
* Checks whether a authority file with the given gnd exists or not
*
......
......@@ -232,7 +232,7 @@ public class MCRVIAFCommands extends MCRAbstractCommands {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a MyCoRe dataset. Continue.");
try {
MCRObject new_obj = MCRVIAFAuthorityFileUtils.getMCRObjectAsXML(null, viaf_id);
MCRVIAFAuthorityFileUtils.updateVIAF(viaf_obj, new_obj);
MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj);
} catch (Exception e) {
e.printStackTrace();
MCRVIAFAuthorityFileUtils.LOGGER.error("Error while update MCRObject " + viaf_id + ". Continue.");
......@@ -261,7 +261,7 @@ public class MCRVIAFCommands extends MCRAbstractCommands {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a gnd dataset");
try {
MCRObject new_obj = MCRVIAFAuthorityFileUtils.getGNDAsMarc21XML(null, viaf_text.getText());
MCRVIAFAuthorityFileUtils.updateVIAF(viaf_obj, new_obj);
MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj);
} catch (Exception e) {
e.printStackTrace();
MCRVIAFAuthorityFileUtils.LOGGER
......@@ -272,7 +272,7 @@ public class MCRVIAFCommands extends MCRAbstractCommands {
MCRVIAFAuthorityFileUtils.LOGGER.info("Object " + viaf_id + " is a lcnaf dataset");
try {
MCRObject new_obj = MCRVIAFAuthorityFileUtils.getLCNAFAsMarc21XML(null, viaf_text.getText());
MCRVIAFAuthorityFileUtils.updateVIAF(viaf_obj, new_obj);
MCRVIAFAuthorityFileUtils.replaceVIAF(viaf_obj, new_obj);
} catch (Exception e) {
e.printStackTrace();
MCRVIAFAuthorityFileUtils.LOGGER
......@@ -319,7 +319,9 @@ public class MCRVIAFCommands extends MCRAbstractCommands {
// get identifier
MCRMetaElement viaf_def_identifier = viaf_obj.getMetadata().getMetadataElement("def.identifier");
if (viaf_def_identifier == null) {
MCRVIAFAuthorityFileUtils.LOGGER.error("Object " + viaf_id + " has not a identifier. Continue.");
if (!type.equals("local")) {
MCRVIAFAuthorityFileUtils.LOGGER.error("Object " + viaf_id + " has not a identifier. Continue.");
}
continue;
}
String current_id = null;
......
......@@ -7,21 +7,13 @@
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:variable name="gnd_url" select="'http://d-nb.info/gnd/'" />
<xsl:template match="/">
<xsl:variable name="mcrid" select="'a_viaf_1'" />
<xsl:variable name="identifier">
<xsl:for-each select="/marcxml:record/marcxml:controlfield[@tag='001']">
<xsl:choose>
<xsl:when test="contains(text(), '(588')">
<xsl:value-of select="substring-after(text(),')')" />
</xsl:when>
<xsl:when test="contains(text(), '(100')">
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:value-of
select="substring-after(/marcxml:record/marcxml:datafield[@tag='024']/marcxml:subfield[@code='a'],$gnd_url)" />
</xsl:variable>
<mycoreobject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"
label="{$identifier}" ID="{$mcrid}" version="2.0" xsi:noNamespaceSchemaLocation="datamodel-viaf.xsd">
......@@ -252,10 +244,58 @@
</identifier>
<xsl:for-each select="/marcxml:record/marcxml:datafield[@tag='035']/marcxml:subfield[@code='a']">
<xsl:choose>
<xsl:when test="contains(text(), '(DE-101)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="otherdma">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
<xsl:when test="contains(text(), '(DE-588)')">
<identifier inherited="0" xml:lang="de" type="oldgnd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="othergnd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="/marcxml:record/marcxml:datafield[@tag='035']/marcxml:subfield[@code='z']">
<xsl:choose>
<xsl:when test="contains(text(), '(DE-101c)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="otherdma">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
<xsl:when test="contains(text(), '(DE-588)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="othergnd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
<xsl:when test="contains(text(), '(DE-588a)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="otherpnd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
<xsl:when test="contains(text(), '(DE-588b)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="othergkd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
<xsl:when test="contains(text(), '(DE-588c)')">
<xsl:if test="not($identifier = substring-after(text(),')'))">
<identifier inherited="0" xml:lang="de" type="otherswd">
<xsl:value-of select="substring-after(text(),')')" />
</identifier>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
......
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