-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FSU040THUL-5393 #650 Allow to indicate actual affiliation of author a…
…t time of publication (#651) * FSU040THUL-5393 #650 Allow to indicate actual affiliation of author at time of publication * FSU040THUL-5393 #650 Disabled ThUniBibAffiliationEventHandler
- Loading branch information
Showing
7 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
common/src/main/java/de/uni_jena/thunibib/common/events/ThUniBibAffiliationEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package de.uni_jena.thunibib.common.events; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jdom2.Document; | ||
import org.jdom2.Element; | ||
import org.jdom2.filter.Filters; | ||
import org.jdom2.xpath.XPathExpression; | ||
import org.mycore.common.events.MCREvent; | ||
import org.mycore.common.events.MCREventHandlerBase; | ||
import org.mycore.datamodel.metadata.MCRMetaElement; | ||
import org.mycore.datamodel.metadata.MCRObject; | ||
|
||
import java.util.List; | ||
|
||
import static org.mycore.common.MCRConstants.MODS_NAMESPACE; | ||
import static org.mycore.common.MCRConstants.XPATH_FACTORY; | ||
|
||
/** | ||
* This event handler removes previously inserted <code>mods:nameIdentifier[@type='connection']</code> element from a | ||
* <code>mods:name</code> element when that element has a <code>mods:affiliation[@valueURI="isAffiliated#false"</code> | ||
* element. | ||
* | ||
* @author shermann (Silvio Hermann) | ||
*/ | ||
public class ThUniBibAffiliationEventHandler extends MCREventHandlerBase { | ||
|
||
private final static Logger LOGGER = LogManager.getLogger(ThUniBibAffiliationEventHandler.class); | ||
|
||
protected static final XPathExpression<Element> XPATH = XPATH_FACTORY.compile( | ||
"//mods:name[mods:affiliation[contains(@valueURI, 'isAffiliated#false')]]/mods:nameIdentifier[@type='connection']", | ||
Filters.element(), null, MODS_NAMESPACE); | ||
|
||
protected void processAffiliation(MCREvent evt, MCRObject obj) { | ||
Document xml = obj.createXML(); | ||
List<Element> connectionIDs = XPATH.evaluate(xml); | ||
|
||
if (connectionIDs.isEmpty()) { | ||
return; | ||
} | ||
|
||
// remove mods:nameIdentifier[@type = 'connection'] | ||
for (Element connectionID : connectionIDs) { | ||
LOGGER.info("Removing mods:nameIdentifier[type='connection'][text()='{}'] of mods:name element in {}", | ||
connectionID.getText(), obj.getId()); | ||
connectionID.detach(); | ||
} | ||
|
||
Element updatedMODSContainer = XPATH_FACTORY | ||
.compile("//def.modsContainer", Filters.element(), null, MODS_NAMESPACE) | ||
.evaluateFirst(xml); | ||
|
||
// update metadata element | ||
if (updatedMODSContainer != null) { | ||
MCRMetaElement e = new MCRMetaElement(); | ||
e.setFromDOM(updatedMODSContainer); | ||
obj.getMetadata().setMetadataElement(e); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param evt | ||
* @param obj | ||
*/ | ||
@Override | ||
protected void handleObjectUpdated(MCREvent evt, MCRObject obj) { | ||
this.processAffiliation(evt, obj); | ||
} | ||
|
||
/** | ||
* | ||
* @param evt | ||
* @param obj | ||
*/ | ||
@Override | ||
protected void handleObjectCreated(MCREvent evt, MCRObject obj) { | ||
this.processAffiliation(evt, obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
common/src/main/resources/setup/classifications/isAffiliated.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mycoreclass ID="isAffiliated" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MCRClassification.xsd"> | ||
|
||
<label xml:lang="de" text="Affiliation, der Einrichtung zugehörig. Ja oder Nein." /> | ||
<label xml:lang="en" text="Affiliation, affiliated to the institution. Yes or No." /> | ||
|
||
<categories> | ||
<category ID="true"> | ||
<label xml:lang="de" text="Ja" description="Autor gehörte im Publikationszeitraum der Einrichtung an"/> | ||
<label xml:lang="en" text="Yes" description="Author was a member of the institution during the publication period"/> | ||
</category> | ||
<category ID="false"> | ||
<label xml:lang="de" text="Nein" description="Autor gehörte im Publikationszeitraum nicht der Einrichtung an"/> | ||
<label xml:lang="en" text="No" description="Author was not a member of the institution during the publication period"/> | ||
</category> | ||
</categories> | ||
|
||
</mycoreclass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters