From 2122d0cc0c95092cf12c838fa8ea9b18880b175d Mon Sep 17 00:00:00 2001 From: Thomas Scheffler Date: Fri, 23 Feb 2024 10:38:32 +0100 Subject: [PATCH] MCR-3051 allow to configure classifications for MODS import --- .../main/java/org/mycore/mods/MCRMODSCommands.java | 12 ++++++++++++ .../components/mods/config/mycore.properties | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/mycore-mods/src/main/java/org/mycore/mods/MCRMODSCommands.java b/mycore-mods/src/main/java/org/mycore/mods/MCRMODSCommands.java index 201aa9759c..3160895ce7 100644 --- a/mycore-mods/src/main/java/org/mycore/mods/MCRMODSCommands.java +++ b/mycore-mods/src/main/java/org/mycore/mods/MCRMODSCommands.java @@ -47,7 +47,9 @@ import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.xml.MCRXMLHelper; import org.mycore.datamodel.common.MCRActiveLinkException; +import org.mycore.datamodel.classifications2.MCRCategoryID; import org.mycore.datamodel.metadata.MCRDerivate; +import org.mycore.datamodel.metadata.MCRMetaClassification; import org.mycore.datamodel.metadata.MCRMetaIFS; import org.mycore.datamodel.metadata.MCRMetaLinkID; import org.mycore.datamodel.metadata.MCRMetadataManager; @@ -157,6 +159,8 @@ private static MCRObjectID saveAsMyCoReObject(String projectID, Element modsRoot throws MCRActiveLinkException, MCRPersistenceException, MCRAccessException { MCRObject mcrObject = MCRMODSWrapper.wrapMODSDocument(modsRoot, projectID); mcrObject.setId(MCRObjectID.getNextFreeId(mcrObject.getId().getBase())); + MCRConfiguration2.getString("MCR.MODS.Import.Object.State") + .ifPresent(mcrObject.getService()::setState); MCRMetadataManager.create(mcrObject); return mcrObject.getId(); } @@ -195,6 +199,14 @@ private static MCRDerivate createDerivate(MCRObjectID documentID, File fileDir) firstRegularFile.ifPresent(ifs::setMainDoc); derivate.getDerivate().setInternals(ifs); } + MCRConfiguration2.getString("MCR.MODS.Import.Derivate.Categories") + .map(MCRConfiguration2::splitValue) + .ifPresent(s -> { + s.map(MCRCategoryID::fromString) + .forEach(categId -> derivate.getDerivate().getClassifications() + .add(new MCRMetaClassification("classification", 0, null, + categId))); + }); LOGGER.debug("Creating new derivate with ID {}", derivate.getId()); MCRMetadataManager.create(derivate); diff --git a/mycore-mods/src/main/resources/components/mods/config/mycore.properties b/mycore-mods/src/main/resources/components/mods/config/mycore.properties index da6adb66ae..c09c836285 100644 --- a/mycore-mods/src/main/resources/components/mods/config/mycore.properties +++ b/mycore-mods/src/main/resources/components/mods/config/mycore.properties @@ -239,3 +239,7 @@ MCR.ContentTransformer.migrate-extension-display.Class=org.mycore.common.content MCR.ContentTransformer.migrate-extension-display.TransformerFactoryClass=net.sf.saxon.TransformerFactoryImpl MCR.ContentTransformer.migrate-extension-display.Stylesheet=xsl/migrate-extension-display.xsl +#Import commands +MCR.MODS.Import.Derivate.Categories=derivate_types:content +MCR.MODS.Import.Object.State=submitted +