Skip to content

Commit

Permalink
Support v0.9 of BTE
Browse files Browse the repository at this point in the history
  • Loading branch information
kstamatis committed Oct 4, 2013
1 parent 3db23c0 commit c9041fc
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 223 deletions.
17 changes: 6 additions & 11 deletions dspace-api/pom.xml
Expand Up @@ -434,19 +434,14 @@
<version>1.0</version>
</dependency>
<dependency>
<groupId>gr.ekt</groupId>
<artifactId>biblio-transformation-engine</artifactId>
<version>0.82</version>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.jbibtex</groupId>
<artifactId>jbibtex</artifactId>
<version>1.0.0</version>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-io</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
Expand Down
Expand Up @@ -7,11 +7,11 @@
*/
package org.dspace.app.itemimport;

import gr.ekt.bte.core.DataLoader;

import java.util.HashMap;
import java.util.Map;

import gr.ekt.transformationengine.core.DataLoader;




Expand All @@ -22,6 +22,7 @@ public class DataLoaderService
{

Map<String, DataLoader> dataLoaders = new HashMap<String, DataLoader>();
Map<String, String> outputMap = new HashMap<String,String>();

/**
* Default constructor
Expand All @@ -48,5 +49,21 @@ public Map<String, DataLoader> getDataLoaders()
{
return dataLoaders;
}

}

/**
*
* @return the outputMapping
*/
public Map<String, String> getOutputMap() {
return outputMap;
}

/**
* Setter method for the outputMapping
* @param outputMapping
*/
public void setOutputMap(Map<String, String> outputMap) {
this.outputMap = outputMap;
}

}
102 changes: 55 additions & 47 deletions dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java
Expand Up @@ -7,13 +7,12 @@
*/
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 gr.ekt.bte.core.DataLoader;
import gr.ekt.bte.core.TransformationEngine;
import gr.ekt.bte.core.TransformationResult;
import gr.ekt.bte.core.TransformationSpec;
import gr.ekt.bte.dataloader.FileDataLoader;
import gr.ekt.bteio.generators.DSpaceOutputGenerator;

import java.io.*;
import java.sql.SQLException;
Expand Down Expand Up @@ -54,6 +53,7 @@
import org.dspace.eperson.Group;
import org.dspace.handle.HandleManager;
import org.dspace.search.DSIndexer;
import org.dspace.utils.DSpace;
import org.dspace.workflow.WorkflowManager;
import org.dspace.xmlworkflow.XmlWorkflowManager;
import org.w3c.dom.Document;
Expand All @@ -62,7 +62,6 @@
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
Expand Down Expand Up @@ -206,7 +205,7 @@ public static void main(String[] argv) throws Exception

if (line.hasOption('i'))
{
bteInputType = line.getOptionValue('i');;
bteInputType = line.getOptionValue('i');
}

if (line.hasOption('w'))
Expand Down Expand Up @@ -314,13 +313,7 @@ else if ("add".equals(command) || "replace".equals(command))
}
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);
}
//Source dir can be null, the user can specify the parameters for his loader in the Spring XML configuration file

if (mapfile == null)
{
Expand Down Expand Up @@ -638,36 +631,51 @@ private void addBTEItems(Context c, Collection[] mycollections,

DataLoaderService dls = new DSpace().getSingletonService(DataLoaderService.class);
DataLoader dataLoader = dls.getDataLoaders().get(inputType);
Map<String, String> outputMap = dls.getOutputMap();

if (dataLoader==null){
System.out.println("ERROR: The key used in -i parameter must match a valid DataLoader in the BTE Spring XML configuration file!");
return;
}

if (outputMap==null){
System.out.println("ERROR: The key used in -i parameter must match a valid outputMapping in the BTE Spring XML configuration file!");
return;
}

if (dataLoader instanceof FileDataLoader){
FileDataLoader fdl = (FileDataLoader) dataLoader;
if (!"".equals(sourceDir)){
System.out.println("INFO: Dataloader will load data from the file specified in the command prompt (and not from the Spring XML configuration file)");
fdl.setFilename(sourceDir);
}
}

if (dataLoader!=null){
System.out.println("INFO: Dataloader " + dataLoader.toString()+" will be used for the import!");

dataLoader.setFileName(sourceDir);
te.setDataLoader(dataLoader);
System.out.println("INFO: Dataloader " + dataLoader.toString()+" will be used for the import!");

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();
}
te.setDataLoader(dataLoader);

DSpaceOutputGenerator outputGenerator = new DSpaceOutputGenerator(outputMap);
outputGenerator.setOutputDirectory("./.bte_output_dspace");

te.setOutputGenerator(outputGenerator);

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;
try {
TransformationResult res = te.transform(new TransformationSpec());
List<String> output = res.getOutput();
outputGenerator.writeOutput(output);
} catch (Exception e) {
System.err.println("Exception");
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"));
}
}

Expand Down Expand Up @@ -1546,7 +1554,7 @@ private void registerBitstream(Context c, Item i, int assetstore,
// find the bundle
Bundle[] bundles = i.getBundles(newBundleName);
Bundle targetBundle = null;

if( bundles.length < 1 )
{
// not found, create a new one
Expand All @@ -1557,19 +1565,19 @@ private void registerBitstream(Context c, Item i, int assetstore,
// put bitstreams into first bundle
targetBundle = bundles[0];
}

// now add the bitstream
bs = targetBundle.registerBitstream(assetstore, bitstreamPath);

// set the name to just the filename
int iLastSlash = bitstreamPath.lastIndexOf('/');
bs.setName(bitstreamPath.substring(iLastSlash + 1));

// Identify the format
// FIXME - guessing format guesses license.txt incorrectly as a text file format!
BitstreamFormat bf = FormatIdentifier.guessFormat(c, bs);
bs.setFormat(bf);

bs.update();
}
}
Expand Down Expand Up @@ -1876,4 +1884,4 @@ private static boolean deleteDirectory(File path)
boolean pathDeleted = path.delete();
return (pathDeleted);
}
}
}

0 comments on commit c9041fc

Please sign in to comment.