diff --git a/dspace-api/pom.xml b/dspace-api/pom.xml index 47af0037e1..3d449b3670 100644 --- a/dspace-api/pom.xml +++ b/dspace-api/pom.xml @@ -332,6 +332,21 @@ rome-modules 1.0 + + gr.ekt + biblio-transformation-engine + 0.81 + + + net.sf.opencsv + opencsv + 2.3 + + + org.jbibtex + jbibtex + 1.0.0 + diff --git a/dspace-api/src/main/java/org/dspace/app/itemimport/DataLoaderService.java b/dspace-api/src/main/java/org/dspace/app/itemimport/DataLoaderService.java new file mode 100644 index 0000000000..99cb0f9f95 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/app/itemimport/DataLoaderService.java @@ -0,0 +1,52 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.itemimport; + +import java.util.HashMap; +import java.util.Map; + +import gr.ekt.transformationengine.core.DataLoader; + + + + +/** + * This class acts as a Service in the procedure ot batch import using the Biblio-Transformation-Engine + */ +public class DataLoaderService +{ + + Map dataLoaders = new HashMap(); + + /** + * Default constructor + */ + public DataLoaderService() + { + super(); + } + + /** + * Setter method for dataLoaders parameter + * @param dataLoaders + */ + public void setDataLoaders(Map dataLoaders) + { + this.dataLoaders = dataLoaders; + } + + /** + * + * @return the map of DataLoaders + */ + public Map getDataLoaders() + { + return dataLoaders; + } + +} diff --git a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java index a255141171..dce235d949 100644 --- a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java +++ b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java @@ -7,6 +7,14 @@ */ package org.dspace.app.itemimport; +import gr.ekt.transformationengine.core.DataLoader; +import gr.ekt.transformationengine.core.TransformationEngine; +import gr.ekt.transformationengine.exceptions.UnimplementedAbstractMethod; +import gr.ekt.transformationengine.exceptions.UnknownClassifierException; +import gr.ekt.transformationengine.exceptions.UnknownInputFileType; +import gr.ekt.transformationengine.exceptions.UnsupportedComparatorMode; +import gr.ekt.transformationengine.exceptions.UnsupportedCriterion; + import java.io.*; import java.sql.SQLException; import java.util.*; @@ -54,6 +62,8 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import org.dspace.utils.DSpace; + /** * Import items into DSpace. The conventional use is upload files by copying * them. DSpace writes the item's bitstreams into its assetstore. Metadata is @@ -122,9 +132,11 @@ public class ItemImport Options options = new Options(); options.addOption("a", "add", false, "add items to DSpace"); + options.addOption("b", "add-bte", false, "add items to DSpace via Biblio-Transformation-Engine (BTE)"); options.addOption("r", "replace", false, "replace items in mapfile"); options.addOption("d", "delete", false, "delete items listed in mapfile"); + options.addOption("i", "inputtype", true, "input type in case of BTE import"); options.addOption("s", "source", true, "source of items (directory)"); options.addOption("z", "zip", true, "name of zip file"); options.addOption("c", "collection", true, @@ -148,6 +160,7 @@ public class ItemImport CommandLine line = parser.parse(options, argv); String command = null; // add replace remove, etc + String bteInputType = null; //ris, endnote, tsv, csv, bibtex String sourcedir = null; String mapfile = null; String eperson = null; // db ID or email @@ -185,6 +198,16 @@ public class ItemImport { command = "delete"; } + + if (line.hasOption('b')) + { + command = "add-bte"; + } + + if (line.hasOption('i')) + { + bteInputType = line.getOptionValue('i');; + } if (line.hasOption('w')) { @@ -289,6 +312,48 @@ public class ItemImport System.exit(1); } } + else if ("add-bte".equals(command)) + { + if (sourcedir == null) + { + System.out + .println("Error - a source file containing items must be set"); + System.out.println(" (run with -h flag for details)"); + System.exit(1); + } + + if (mapfile == null) + { + System.out + .println("Error - a map file to hold importing results must be specified"); + System.out.println(" (run with -h flag for details)"); + System.exit(1); + } + + if (eperson == null) + { + System.out + .println("Error - an eperson to do the importing must be specified"); + System.out.println(" (run with -h flag for details)"); + System.exit(1); + } + + if (collections == null) + { + System.out + .println("Error - at least one destination collection must be specified"); + System.out.println(" (run with -h flag for details)"); + System.exit(1); + } + + if (bteInputType == null) + { + System.out + .println("Error - an input type (tsv, csv, ris, endnote, bibtex or any other type you have specified in BTE Spring XML configuration file) must be specified"); + System.out.println(" (run with -h flag for details)"); + System.exit(1); + } + } else if ("delete".equals(command)) { if (eperson == null) @@ -505,6 +570,10 @@ public class ItemImport { myloader.deleteItems(c, mapfile); } + else if ("add-bte".equals(command)) + { + myloader.addBTEItems(c, mycollections, sourcedir, mapfile, template, bteInputType); + } // complete all transactions c.complete(); @@ -562,6 +631,47 @@ public class ItemImport System.exit(status); } + private void addBTEItems(Context c, Collection[] mycollections, + String sourceDir, String mapFile, boolean template, String inputType) throws Exception + { + TransformationEngine te = new DSpace().getSingletonService(TransformationEngine.class); + + DataLoaderService dls = new DSpace().getSingletonService(DataLoaderService.class); + DataLoader dataLoader = dls.getDataLoaders().get(inputType); + + if (dataLoader!=null){ + System.out.println("INFO: Dataloader " + dataLoader.toString()+" will be used for the import!"); + + dataLoader.setFileName(sourceDir); + te.setDataLoader(dataLoader); + + try { + te.transform(); + } catch (UnknownClassifierException e) { + e.printStackTrace(); + } catch (UnknownInputFileType e) { + e.printStackTrace(); + } catch (UnimplementedAbstractMethod e) { + e.printStackTrace(); + } catch (UnsupportedComparatorMode e) { + e.printStackTrace(); + } catch (UnsupportedCriterion e) { + e.printStackTrace(); + } + + ItemImport myloader = new ItemImport(); + myloader.addItems(c, mycollections, "./bte_output_dspace", mapFile, template); + + //remove files from output generator + deleteDirectory(new File("./bte_output_dspace")); + } + else { + System.out.println("Error: The key used in -i parameter must match a valid DataLoader in the BTE Spring XML configuration file!"); + return; + } + } + + private void addItems(Context c, Collection[] mycollections, String sourceDir, String mapFile, boolean template) throws Exception { @@ -746,7 +856,7 @@ public class ItemImport + File.separatorChar); // and the bitstreams from the contents file - // process contents file, add bitstreams and bundles, return any + // process contents file, add bistreams and bundles, return any // non-standard permissions List options = processContentsFile(c, myitem, path + File.separatorChar + itemname, "contents"); diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index daac5145f6..59968b92de 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1403,6 +1403,15 @@ webui.bitstream.order.field = bitstream_order google-metadata.config = ${dspace.dir}/config/crosswalks/google-metadata.properties google-metadata.enable = true + +#### DSpace services configuration #### +# +# Declare the Spirng xml resources for the SpringServiceManager +# (currently, only bibliotransformation-engine xml file) +# +service.manager.spring.configs=spring/bte/bte.xml + + #---------------------------------------------------------------# #--------------JSPUI SPECIFIC CONFIGURATIONS--------------------# #---------------------------------------------------------------# diff --git a/dspace/config/spring/bte/bte.xml b/dspace/config/spring/bte/bte.xml new file mode 100644 index 0000000000..dc714f83f5 --- /dev/null +++ b/dspace/config/spring/bte/bte.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + bibtex + + + + csv + + + + tsv + + + + endnote + + + + ris + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Title + + + + + + Type + + + + + + Author + + + + + + Journal + + + + + + Year + + + + + + ISSN + + + + + + + + + + + + + Title + + + + + + Type + + + + + + + + + + + + + dc + + + + + + ekt + + + + + + + + + + + + + + \ No newline at end of file