-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: UBO-300 Flip parts of name in PersonResult list UBO-299 Fixed ZDB import of publisher information Add MARC Genre Term mapping for research_data UBO-296 Made indexing of year independent of actual position of the mods:originInfo/mods:dateIssued element (#347) UBO-288 publication event handler needs refactoring (#346) UBO-297 Implement command to export selected publications via CLI
- Loading branch information
Showing
7 changed files
with
236 additions
and
142 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
ubo-common/src/main/java/org/mycore/ubo/export/MCRExportCommands.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,61 @@ | ||
package org.mycore.ubo.export; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.mycore.common.MCRException; | ||
import org.mycore.common.content.MCRContent; | ||
import org.mycore.common.content.transformer.MCRContentTransformer; | ||
import org.mycore.common.content.transformer.MCRContentTransformerFactory; | ||
import org.mycore.frontend.basket.MCRBasket; | ||
import org.mycore.frontend.basket.MCRBasketEntry; | ||
import org.mycore.frontend.basket.MCRBasketManager; | ||
import org.mycore.frontend.cli.MCRObjectCommands; | ||
import org.mycore.frontend.cli.annotation.MCRCommand; | ||
import org.mycore.frontend.cli.annotation.MCRCommandGroup; | ||
import org.mycore.frontend.export.MCRExportCollection; | ||
|
||
/** | ||
* @author Frank L\u00FCtzenkirchen | ||
*/ | ||
@MCRCommandGroup(name = "UBO export commands") | ||
public class MCRExportCommands { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
@MCRCommand( | ||
syntax = "ubo export selected using transformer {0} to file {1}", | ||
help = "Exports previously selected objects using the transformer with the ID {0} and writes the output to file {1}", | ||
order = 1) | ||
public static void export(String transformerID, String pathOfOutputFile) throws IOException { | ||
List<String> objectIDs = MCRObjectCommands.getSelectedObjectIDs(); | ||
LOGGER.info("Exporting {} objects using transformer {}...", objectIDs.size(), transformerID); | ||
|
||
MCRContent source = buildExportCollection(objectIDs); | ||
MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer(transformerID); | ||
MCRContent result = transformer.transform(source); | ||
|
||
LOGGER.info("Writing transformed output to file {}", pathOfOutputFile); | ||
result.sendTo(new File(pathOfOutputFile)); | ||
} | ||
|
||
private static MCRContent buildExportCollection(List<String> objectIDs) { | ||
MCRBasket basket = MCRBasketManager.getOrCreateBasketInSession("objects"); | ||
objectIDs.forEach(objectID -> { | ||
basket.add(new MCRBasketEntry(objectID, "mcrobject:" + objectID)); | ||
}); | ||
|
||
MCRExportCollection collection = new MCRExportCollection(); | ||
try { | ||
collection.add(basket); | ||
} catch (Exception ex) { | ||
throw new MCRException(ex); | ||
} | ||
|
||
basket.clear(); | ||
return collection.getContent(); | ||
} | ||
} |
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
Oops, something went wrong.