Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ubo-cli/src/main/setup/classifications/state.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<mycoreclass ID="state" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MCRClassification.xsd">

<label xml:lang="de" text="Objektstatus"/>
<label xml:lang="en" text="Object state"/>
<label xml:lang="it" text="stato dell'oggetto"/>

<label xml:lang="x-uri" text="http://www.mycore.org/classifications/state"/>

<categories>
<category ID="confirmed">
<label xml:lang="de" text="freigegeben"/>
<label xml:lang="en" text="confirmed"/>
</category>
<category ID="submitted">
<label xml:lang="de" text="eingereicht"/>
<label xml:lang="en" text="submitted"/>
</category>
<category ID="review">
<label xml:lang="de" text="wird bearbeitet"/>
<label xml:lang="en" text="in review"/>
</category>
<category ID="imported">
<label xml:lang="de" text="importiert"/>
<label xml:lang="en" text="imported"/>
</category>
<category ID="deleted">
<label xml:lang="de" text="gelöscht"/>
<label xml:lang="en" text="deleted"/>
</category>
</categories>
</mycoreclass>
157 changes: 109 additions & 48 deletions ubo-common/src/main/java/org/mycore/ubo/DozBibCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.jdom2.filter.Filters;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.xpath.XPathExpression;
import org.mycore.access.MCRAccessException;
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.xml.MCRXMLHelper;
import org.mycore.datamodel.common.MCRXMLMetadataManager;
import org.mycore.datamodel.ifs2.MCRMetadataStore;
Expand All @@ -34,12 +36,14 @@
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.frontend.cli.MCRAbstractCommands;
import org.mycore.frontend.cli.MCRCommand;
import org.mycore.frontend.cli.annotation.MCRCommand;
import org.mycore.frontend.cli.annotation.MCRCommandGroup;
import org.mycore.mods.MCRMODSCommands;
import org.mycore.mods.MCRMODSWrapper;
import org.mycore.services.i18n.MCRTranslation;
import org.mycore.ubo.dedup.DeDupCommands;
import org.mycore.ubo.importer.scopus.ScopusInitialImporter;
import org.mycore.ubo.importer.scopus.ScopusUpdater;

import java.io.BufferedOutputStream;
import java.io.File;
Expand All @@ -60,52 +64,101 @@
import static org.mycore.common.MCRConstants.MODS_NAMESPACE;
import static org.mycore.common.MCRConstants.XPATH_FACTORY;

public class DozBibCommands extends MCRAbstractCommands {
@MCRCommandGroup(name = "DozBibCommands")
public class DozBibCommands {

private static final Logger LOGGER = LogManager.getLogger(DozBibCommands.class);
private static final Logger LOGGER = LogManager.getLogger();

private static final String PROJECT_ID = MCRConfiguration2.getString("UBO.projectid.default").get();

/** Commands for the MyCoRe Command Line Interface */
public DozBibCommands() {
addCommand(new MCRCommand("ubo mods export all entries to directory {0}",
"org.mycore.ubo.DozBibCommands.exportMODS String",
"exports all entries as MODS dump to a zipped xml file in local directory {0}"));
addCommand(new MCRCommand("ubo transform entries using xsl {0}",
"org.mycore.ubo.DozBibCommands.transformEntries String",
"Transforms persistent xml of all bibentries using XSL stylesheet"));
addCommand(new MCRCommand("ubo find gnds", "org.mycore.ubo.DozBibGNDCommands.findGNDs", "Find GNDs"));
addCommand(new MCRCommand("ubo migrate to mcrobject", "org.mycore.ubo.DozBibCommands.migrate2mcrobject",
"migrates all bibentries to mycoreobject persistence"));
addCommand(new MCRCommand("ubo build duplicates report to directory {0}",
"org.mycore.ubo.dedup.DeDupCommands.buildDuplicatesReport String",
"builds report on possibly duplicate entries and writes it as xml to file duplicates.xml in directory {0}"));
addCommand(new MCRCommand("print possible duplicates", "org.mycore.ubo.dedup.DeDupCommands.printDuplicates","Prints possible duplicate objects"));
addCommand(new MCRCommand("ubo import mods collection from file {0}",
"org.mycore.ubo.DozBibCommands.importMODSCollection String",
"import mods:modsCollection from xml file {0}"));
addCommand(new MCRCommand("ubo update from scopus for affiliation IDs {0} last {1} days max {2}",
"org.mycore.ubo.importer.scopus.ScopusUpdater.update String int int",
"Queries Scopus for new publications of comma-separated affiliation IDs {0} added within last {1} days," +
"retrieves max {2} publications and imports them if not already present"));
addCommand(new MCRCommand("ubo update from scopus for query {0}",
"org.mycore.ubo.importer.scopus.ScopusUpdater.update String",
"Queries Scopus and imports them if not already present"));
addCommand(new MCRCommand(ScopusInitialImporter.IMPORT_BATCH_COMMAND,
"org.mycore.ubo.importer.scopus.ScopusInitialImporter.initialImport String int",
"Queries all affiliation IDs and imports all documents {0} = afid {1} = start point should be 0"));
addCommand(new MCRCommand(ScopusInitialImporter.IMPORT_SINGLE_COMMAND,
"org.mycore.ubo.importer.scopus.ScopusInitialImporter.doImport String",
"{0] = ID of object"));
addCommand(
new MCRCommand("migrate http uris matching {0} to https in {1}",
"org.mycore.ubo.DozBibCommands.migrateURItoHttps String String",
"Migrates http protocol of uris to https if they match the pattern given in {0} "
+ "(xpath will be '//mods:identifier[@type = 'uri'][contains(text(), {0})]'). "
+ "The mycore object id must be provided in {1}"));
addCommand(new MCRCommand("ubo migrate mods:genre for object {0}",
"org.mycore.ubo.DozBibCommands.migrateGenre String",
"Migrates mods:genre to mods:genre with authorityURI and valueURI"));
private static XPathExpression<Element> SERVFLAG_XPATH = XPATH_FACTORY.compile("//servflag[@type='status']",
Filters.element(), null, MODS_NAMESPACE);

@MCRCommand(syntax = "migrate status to state classification of {0}", help = "Migrates the status servflag to a servstate")
public static void migrateState(String objectId) {
if (!MCRObjectID.isValid(objectId)) {
LOGGER.error("'{}' is not a valid MCRObjectID", objectId);
return;
}

MCRObjectID mcrObjectID = MCRObjectID.getInstance(objectId);
if (!MCRMetadataManager.exists(mcrObjectID)) {
LOGGER.error("'{}' does not exist", objectId);
return;
}

LOGGER.info("Migrating status servflag of '{}'", objectId);
Document xml = MCRMetadataManager.retrieveMCRObject(mcrObjectID).createXML();
List<Element> servflags = SERVFLAG_XPATH.evaluate(xml);

if (servflags.isEmpty()) {
LOGGER.info("No servflags found for '{}'", objectId);
return;
}

for (Element flag : servflags) {
flag.detach();
}

String value = servflags.get(0).getValue();
if (!MCRXMLFunctions.isCategoryID("state", value)) {
LOGGER.error("'state:{}' is not valid with respect to state classification", value);
return;
}

MCRObject mcrObject = new MCRObject(xml);
mcrObject.getService().setState(value);
try {
MCRMetadataManager.update(mcrObject);
} catch (MCRAccessException e) {
LOGGER.error("Error while updating MCRObject '{}'", objectId, e);
}
}

@MCRCommand(syntax = "migrate status to state classification", help = "Migrates the status servflag to a servstate for all objects")
public static List<String> migrateState() {
List<String> commandList = new ArrayList<>();
List<String> mcrids = MCRXMLMetadataManager.getInstance().listIDsOfType("mods");
for (String mcrid : mcrids) {
commandList.add("migrate status to state classification of " + mcrid);
}
return commandList;
}

@MCRCommand(syntax = ScopusInitialImporter.IMPORT_SINGLE_COMMAND, help = "{0} = ID of object")
public static void doImport(String s) throws Exception {
ScopusInitialImporter.doImport(s);
}

@MCRCommand(syntax = ScopusInitialImporter.IMPORT_BATCH_COMMAND, help="Queries all affiliation IDs and imports all documents {0} = afid {1} = start point should be 0")
public static void initialImport(String s, int i) throws Exception {
ScopusInitialImporter.initialImport(s, i);
}

@MCRCommand(syntax = "ubo update from scopus for query {0}", help = "Queries Scopus and imports them if not already present")
public static void update(String s) throws Exception {
ScopusUpdater.update(s);
}

@MCRCommand(syntax = "ubo update from scopus for affiliation IDs {0} last {1} days max {2}",
help = "Queries Scopus for new publications of comma-separated affiliation IDs {0} added within last {1} days, retrieves max {2} publications and imports them if not already present")
public static void update(String s, int int1, int int2) throws Exception {
ScopusUpdater.update(s, int1, int2);
}

@MCRCommand(syntax = "print possible duplicates", help = "Prints possible duplicate objects")
public static void printDuplicates() {
DeDupCommands.printDuplicates();
}

@MCRCommand(syntax = "ubo build duplicates report to directory {0}",help = "builds report on possibly duplicate entries and writes it as xml to file duplicates.xml in directory {0}")
public static void buildDuplicatesReport(String s) throws Exception {
DeDupCommands.buildDuplicatesReport(s);
}

@MCRCommand(syntax = "ubo find gnds", help = "Find GNDs")
public static void findGNDs() throws Exception {
DozBibGNDCommands.findGNDs();
}

/**
Expand All @@ -115,6 +168,7 @@ public DozBibCommands() {
*
* @return true if the migration was successful, false otherwise
* */
@MCRCommand(syntax = "ubo migrate mods:genre for object {0}", help="Migrates mods:genre to mods:genre with authorityURI and valueURI")
public static boolean migrateGenre(String objId) {
if (!MCRObjectID.isValid(objId)) {
LOGGER.error("ID {} is not a valid {} ", objId, MCRObjectID.class.getSimpleName());
Expand All @@ -139,7 +193,7 @@ public static boolean migrateGenre(String objId) {
}
}

/** Exports all entries as MODS dump to a zipped xml file in the given directory */
@MCRCommand(syntax = "ubo mods export all entries to directory {0}", help = "exports all entries as MODS dump to a zipped xml file in local directory {0}")
public static void exportMODS(String dir) throws Exception {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
Date now = new Date();
Expand All @@ -166,7 +220,7 @@ public static void exportMODS(String dir) throws Exception {
for (String oid : oids) {
MCRObject obj = MCRMetadataManager.retrieveMCRObject(MCRObjectID.getInstance(oid));
MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
if ("confirmed".equals(wrapper.getServiceFlag("status"))) {
if ("confirmed".equals(obj.getService().getState().getId())) {
MCRContent src = new MCRJDOMContent(obj.createXML());
MCRXSLTransformer transformer = new MCRXSLTransformer("xsl/mycoreobject-mods.xsl");
MCRContent mods = transformer.transform(src);
Expand All @@ -184,6 +238,7 @@ public static void exportMODS(String dir) throws Exception {
}

/** Transforms existing entries using XSL stylesheet **/
@MCRCommand(syntax="ubo transform entries using xsl {0}", help="Transforms persistent xml of all bibentries using XSL stylesheet")
public static List<String> transformEntries(String xslFile) throws Exception {
List<String> commands = new ArrayList<String>();
for (String oid : MCRXMLMetadataManager.getInstance().listIDsOfType("mods")) {
Expand All @@ -192,6 +247,7 @@ public static List<String> transformEntries(String xslFile) throws Exception {
return commands;
}

@MCRCommand(syntax = "ubo migrate to mcrobject", help = "migrates all bibentries to mycoreobject persistence")
public static void migrate2mcrobject() throws Exception {
MCRMetadataStore store = MCRStoreManager.createStore("ubo", MCRMetadataStore.class);
for (Iterator<Integer> IDs = store.listIDs(MCRStore.ASCENDING); IDs.hasNext(); ) {
Expand Down Expand Up @@ -235,15 +291,16 @@ public static void migrate2mcrobject() throws Exception {
}

MCRMODSWrapper wrapper = new MCRMODSWrapper();
wrapper.setServiceFlag("status", root.getAttributeValue("status"));
wrapper.setMODS(mods.detach());
MCRObject obj = wrapper.getMCRObject();
obj.getService().setState(root.getAttributeValue("status"));

obj.setId(oid);
MCRMetadataManager.create(obj);
}
}

@MCRCommand(syntax = "ubo import mods collection from file {0}", help = "import mods:modsCollection from xml file {0}")
public static void importMODSCollection(String fileName) throws Exception {
File file = new File(fileName);
if (!file.isFile()) {
Expand All @@ -263,15 +320,19 @@ public static void importMODSCollection(String fileName) throws Exception {
}
for (Element mods : root.getChildren("mods", MCRConstants.MODS_NAMESPACE)) {
MCRMODSWrapper wrapper = new MCRMODSWrapper();
wrapper.setServiceFlag("status", "imported");
wrapper.setMODS(mods.clone());
MCRObject obj = wrapper.getMCRObject();
obj.getService().setState("imported");

obj.setId(MCRMetadataManager.getMCRObjectIDGenerator().getNextFreeId(PROJECT_ID + "_mods"));
MCRMetadataManager.create(obj);
}
}

@MCRCommand(syntax = "migrate http uris matching {0} to https in {1}",
help = "Migrates http protocol of uris to https if they match the pattern given in {0} "
+ "(xpath will be '//mods:identifier[@type = 'uri'][contains(text(), {0})]'). "
+ "The mycore object id must be provided in {1}")
public static void migrateURItoHttps(String uriContains, String id) {
MCRObjectID mcrObjectID = MCRObjectID.getInstance(id);
if (!MCRMetadataManager.exists(mcrObjectID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void deleteEntry(HttpServletRequest req, HttpServletResponse res) throws
return;
}

new MCRMODSWrapper(obj).setServiceFlag("status", "deleted");
obj.getService().setState("deleted");
Document xml = obj.createXML();

MCRMetadataManager.deleteMCRObject(oid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ public void setStatus(Document publication) {
if (status == null || status.getText().isEmpty()) {
return;
}
Element statusElement = XPATH_FACTORY.compile("//service/servflags/servflag[@type='status']", Filters.element())
Element statusElement = XPATH_FACTORY
.compile("//service/servstates/servstate[@classid='state']", Filters.element())
.evaluateFirst(publication);

if(statusElement != null) {
statusElement.setText(status.getText());
if (statusElement != null) {
statusElement.setAttribute("categid", status.getText());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ private MCRObject buildMCRObject(Element publicationXML) {
setPreconfiguredClasses(publicationXML);

MCRObject obj = new MCRObject(new Document(publicationXML));
obj.getService().setState(STATUS);

MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
wrapper.setServiceFlag("status", STATUS);
wrapper.setServiceFlag("importID", importIdProvider.getImportId());
MCRObjectID oid = MCRMetadataManager.getMCRObjectIDGenerator().getNextFreeId(PROJECT_ID, "mods");
obj.setId(oid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,25 @@
</xed:template>

<xed:template id="status">
<xed:bind xpath="../../../../service/servflags[@class='MCRMetaLangText']/servflag[@type='status']">
<xed:bind xpath="../../../../service/servstates[@class='MCRMetaClassification']/servstate[@classid='state']/@categid">
<xed:choose>
<xed:when test="xed:call-java('org.mycore.ubo.AccessControl','currentUserIsAdmin')">
<xed:bind xpath="." default="confirmed" />
<div class="form-inline form-group">
<label for="{xed:generate-id()}" class="mycore-form-label">
<xed:output value="concat(i18n:translate('ubo.status'), ': ')" />
<xed:output value="concat(i18n:translate('ubo.status'), ': ')"/>
</label>
<select id="{xed:generate-id()}" class="mycore-form-input custom-select">
<xed:include uri="xslStyle:items2options:resource:status.xml" />
<xed:include uri="xslStyle:mycoreclass-options:classification:metadata:-1:children:state"/>
</select>
<a tabindex="0" class="btn btn-secondary info-button" role="button" data-toggle="popover" data-placement="right" data-content="{i18n:ubo.help.status}">
<i class="fas fa-info"></i>
<a tabindex="0" class="btn btn-secondary info-button" role="button" data-toggle="popover"
data-placement="right" data-content="{i18n:ubo.help.status}">
<i class="fas fa-info"/>
</a>
</div>
</xed:when>
<xed:otherwise>
<xed:bind xpath="." default="submitted" />
<xed:bind xpath="." default="submitted"/>
</xed:otherwise>
</xed:choose>
</xed:bind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<option value="">
<xed:output i18n="search.select"/>
</option>
<xed:include uri="xslStyle:items2options:resource:status.xml"/>
<xed:include uri="xslStyle:mycoreclass-options:classification:metadata:-1:children:state"/>
</select>
</div>
</xed:bind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@
"stored": false
}
},
{
"add-copy-field": {
"source": "state",
"dest": "status"
}
},
{
"add-field": {
"name": "subject",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
</def.modsContainer>
</metadata>
<service>
<servflags class="MCRMetaLangText">
<servflag type="status" inherited="0" form="plain">imported</servflag>
</servflags>
<servstates class="MCRMetaClassification">
<servstate classid="state" categid="imported"/>
</servstates>
</service>
</mycoreobject>
</xsl:template>
Expand Down
Loading
Loading