Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#614 Use class mapping for determining destatis from ORIGIN.xml #615

Merged
37 changes: 34 additions & 3 deletions common/src/main/java/de/uni_jena/thunibib/ThUniBibCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.mycore.access.MCRAccessException;
import org.mycore.backend.jpa.MCREntityManagerProvider;
import org.mycore.common.MCRConstants;
import org.mycore.common.MCRException;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.MCRJDOMContent;
import org.mycore.common.content.transformer.MCRXSLTransformer;
import org.mycore.common.xml.MCRXMLFunctions;
import org.mycore.common.xsl.MCRParameterCollector;
import org.mycore.datamodel.classifications2.MCRCategory;
import org.mycore.datamodel.classifications2.MCRCategoryID;
import org.mycore.datamodel.classifications2.impl.MCRCategoryDAOImpl;
Expand Down Expand Up @@ -60,16 +65,16 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static org.mycore.common.MCRConstants.*;
import static org.mycore.common.MCRConstants.MODS_NAMESPACE;
import static org.mycore.common.MCRConstants.XPATH_FACTORY;

@MCRCommandGroup(name = "ThUniBib Tools")
@MCRCommandGroup(name = "ThUniBib Commands")

public class ThUniBibCommands {
private static final Logger LOGGER = LogManager.getLogger(ThUniBibCommands.class);
Expand Down Expand Up @@ -612,4 +617,30 @@ public static List<String> renameUsernamesToLeadId(String realmId) {

return list;
}

@MCRCommand(syntax = "thunibib migrate fachreferate to destatis in object {0}",
help = "Replaces fachreferate classification by destatis classification in the given object")
public static void migratetoDestatis(String mcrid) {
if (!MCRObjectID.isValid(mcrid)) {
LOGGER.error("ID {} is invalid", mcrid);
return;
}
MCRObjectID mcrObjectID = MCRObjectID.getInstance(mcrid);
if (!MCRMetadataManager.exists(mcrObjectID)) {
LOGGER.warn("Object {} does not exist", mcrid);
return;
}

MCRObject mcrObject = MCRMetadataManager.retrieveMCRObject(mcrObjectID);
MCRXSLTransformer transformer = MCRXSLTransformer.getInstance(
"xsl/migration/xslt-migrate-fachreferate-to-destatis.xsl");

try {
MCRContent content = transformer.transform(new MCRJDOMContent(mcrObject.createXML()),
MCRParameterCollector.getInstanceFromUserSession());
MCRMetadataManager.update(new MCRObject(content.asXML()));
} catch (IOException | JDOMException | MCRAccessException e) {
LOGGER.error("Could not transform xml", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</xed:template>

<xed:template id="subject">
<xed:repeat xpath="mods:classification[@classID='fachreferate']">
<xed:repeat xpath="mods:classification[@classID='destatis']">
<div class="form-inline form-group ubo-repeat-group {$xed-validation-marker}">
<label for="{xed:generate-id()}" class="mycore-form-label ubo-mandatory">
<xed:output value="concat(i18n:translate('ubo.subject'), ': ')"/>
Expand All @@ -136,7 +136,7 @@
<option value="">
<xed:output i18n="search.select.autocomplete"/>
</option>
<xed:include uri="xslStyle:items2options:classification:editor:-1:children:fachreferate"/>
<xed:include uri="xslStyle:items2options:classification:editor:-1:children:destatis"/>
</select>
<xed:controls/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@
<tr class="background2">
<td>subject</td>
<td>ID</td>
<td>Fach, vgl.
<a href="fachreferate.xed">diese Liste</a>
</td>
<td>Fach</td>
<td>=, contains *</td>
</tr>
<tr class="background1">
Expand Down Expand Up @@ -547,9 +545,7 @@
<tr class="background1">
<td>subject</td>
<td>ID</td>
<td>subject, cf.
<a href="fachreferate.xed">attribute value in this list</a>
</td>
<td>subject, cf.</td>
<td>=, contains *</td>
</tr>
<tr class="background2">
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/META-INF/resources/search.xed
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<option value="">
<xed:output i18n="search.select"/>
</option>
<xed:include uri="xslStyle:items2options:classification:editor:-1:children:fachreferate"/>
<xed:include uri="xslStyle:items2options:classification:editor:-1:children:destatis"/>
</select>
</div>
</xed:bind>
Expand Down
Loading
Loading