Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command extendedimport #781

Merged
merged 1 commit into from
Aug 29, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cz.cuni.mff.ufal.dspace.app.itemimport;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

/**
* Created by okosarko on 24.1.17.
*/
public class ItemImport extends org.dspace.app.itemimport.ItemImport {


@Override
protected Item addItem(Context c, Collection[] mycollections, String path,
String itemname, PrintWriter mapOut, boolean template) throws Exception{
Item item = super.addItem(c, mycollections, path, itemname, mapOut, template);
Bitstream[] bits = item.getNonInternalBitstreams();
for(Bitstream bit : bits){
loadBitstreamMetadata(c, bit, path + File.separatorChar + itemname
+ File.separatorChar);
bit.update();
}
c.commit();
return item;
}

private void loadBitstreamMetadata(Context c, final Bitstream bit, String path) throws SAXException, AuthorizeException,
TransformerException, IOException, SQLException, ParserConfigurationException {
FilenameFilter bitstreamMetadataFileFilter = new FilenameFilter()
{
public boolean accept(File dir, String n)
{
return n.startsWith(bit.getName() + "_metadata_");
}
};
File folder = new File(path);
File[] files = folder.listFiles(bitstreamMetadataFileFilter);
for(File file : files){
loadDublinCore(c, bit, file.getAbsolutePath());
}

}
}
16 changes: 12 additions & 4 deletions dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public static void main(String[] argv) throws Exception

options.addOption("h", "help", false, "help");

options.addOption("x", "extending-class", true, "Class name to use in main. Leave empty if you don't know what it is.");

CommandLine line = parser.parse(options, argv);

String command = null; // add replace remove, etc
Expand Down Expand Up @@ -434,7 +436,13 @@ else if ("delete".equals(command))
System.exit(1);
}

ItemImport myloader = new ItemImport();
ItemImport myloader;
if(line.hasOption("x")){
String name = line.getOptionValue("x", "org.dspace.app.itemimport.ItemImport");
myloader = (ItemImport) Class.forName(name).newInstance();
}else{
myloader = new ItemImport();
}

// create a context
Context c = new Context();
Expand Down Expand Up @@ -883,7 +891,7 @@ private void deleteItems(Context c, String mapFile) throws Exception
* @param itemname handle - non-null means we have a pre-defined handle already
* @param mapOut - mapfile we're writing
*/
private Item addItem(Context c, Collection[] mycollections, String path,
protected Item addItem(Context c, Collection[] mycollections, String path,
String itemname, PrintWriter mapOut, boolean template) throws Exception
{
String mapOutputString = null;
Expand Down Expand Up @@ -1108,7 +1116,7 @@ private void loadMetadata(Context c, Item myitem, String path)
}
}

private void loadDublinCore(Context c, Item myitem, String filename)
protected void loadDublinCore(Context c, DSpaceObject myitem, String filename)
throws SQLException, IOException, ParserConfigurationException,
SAXException, TransformerException, AuthorizeException
{
Expand Down Expand Up @@ -1147,7 +1155,7 @@ private void loadDublinCore(Context c, Item myitem, String filename)
}
}

private void addDCValue(Context c, Item i, String schema, Node n) throws TransformerException, SQLException, AuthorizeException
private void addDCValue(Context c, DSpaceObject i, String schema, Node n) throws TransformerException, SQLException, AuthorizeException
{
String value = getStringValue(n); //n.getNodeValue();
// compensate for empty value getting read as "null", which won't display
Expand Down
8 changes: 8 additions & 0 deletions dspace/config/launcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
<class>org.dspace.app.itemimport.ItemImport</class>
</step>
</command>
<command>
<name>extendedimport</name>
<description>Import items with bitstream metadata into DSpace</description>
<step>
<class>cz.cuni.mff.ufal.dspace.app.itemimport.ItemImport</class>
<argument>-xcz.cuni.mff.ufal.dspace.app.itemimport.ItemImport</argument>
</step>
</command>
<command>
<name>index-authority</name>
<description>Indexes all metadata fields that use solr authority</description>
Expand Down