[DS-2763] More serialization

This commit is contained in:
Mark H. Wood
2015-11-16 14:23:12 -05:00
committed by Mark H. Wood
parent 3b123a05e0
commit e7060bdc2d
3 changed files with 62 additions and 60 deletions

View File

@@ -9,12 +9,8 @@ package org.dspace.app.bulkedit;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dspace.authority.AuthorityValue; import org.dspace.authority.AuthorityValue;
import org.dspace.app.bulkedit.DSpaceCSVLine;
import org.dspace.app.bulkedit.MetadataImport;
import org.dspace.app.bulkedit.MetadataImportInvalidHeadingException;
import org.dspace.authority.factory.AuthorityServiceFactory; import org.dspace.authority.factory.AuthorityServiceFactory;
import org.dspace.authority.service.AuthorityValueService; import org.dspace.authority.service.AuthorityValueService;
import org.dspace.content.Collection;
import org.dspace.content.*; import org.dspace.content.*;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
@@ -73,10 +69,10 @@ public class DSpaceCSV implements Serializable
/** The authority separator in an escaped form for using in regexes */ /** The authority separator in an escaped form for using in regexes */
protected String escapedAuthoritySeparator; protected String escapedAuthoritySeparator;
protected final ItemService itemService = ContentServiceFactory.getInstance().getItemService(); protected transient final ItemService itemService = ContentServiceFactory.getInstance().getItemService();
protected final MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService(); protected transient final MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
protected final MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService(); protected transient final MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
protected final AuthorityValueService authorityValueService = AuthorityServiceFactory.getInstance().getAuthorityValueService(); protected transient final AuthorityValueService authorityValueService = AuthorityServiceFactory.getInstance().getAuthorityValueService();
/** Whether to export all metadata such as handles and provenance information */ /** Whether to export all metadata such as handles and provenance information */
@@ -262,16 +258,16 @@ public class DSpaceCSV implements Serializable
setAuthoritySeparator(); setAuthoritySeparator();
// Create the headings // Create the headings
headings = new ArrayList<String>(); headings = new ArrayList<>();
// Create the blank list of items // Create the blank list of items
lines = new ArrayList<DSpaceCSVLine>(); lines = new ArrayList<>();
// Initialise the counter // Initialise the counter
counter = 0; counter = 0;
// Set the metadata fields to ignore // Set the metadata fields to ignore
ignore = new HashMap<String, String>(); ignore = new HashMap<>();
String toIgnore = ConfigurationManager.getProperty("bulkedit", "ignore-on-export"); String toIgnore = ConfigurationManager.getProperty("bulkedit", "ignore-on-export");
if ((toIgnore == null) || ("".equals(toIgnore.trim()))) if ((toIgnore == null) || ("".equals(toIgnore.trim())))
{ {
@@ -495,7 +491,7 @@ public class DSpaceCSV implements Serializable
// Split up on field separator // Split up on field separator
String[] parts = line.split(escapedFieldSeparator); String[] parts = line.split(escapedFieldSeparator);
ArrayList<String> bits = new ArrayList<String>(); ArrayList<String> bits = new ArrayList<>();
bits.addAll(Arrays.asList(parts)); bits.addAll(Arrays.asList(parts));
// Merge parts with embedded separators // Merge parts with embedded separators
@@ -624,7 +620,7 @@ public class DSpaceCSV implements Serializable
// Create the headings line // Create the headings line
String[] csvLines = new String[counter + 1]; String[] csvLines = new String[counter + 1];
csvLines[0] = "id" + fieldSeparator + "collection"; csvLines[0] = "id" + fieldSeparator + "collection";
List<String> headingsCopy = new ArrayList<String>(headings); List<String> headingsCopy = new ArrayList<>(headings);
Collections.sort(headingsCopy); Collections.sort(headingsCopy);
for (String value : headingsCopy) for (String value : headingsCopy)
{ {
@@ -701,10 +697,11 @@ public class DSpaceCSV implements Serializable
* *
* @return The formatted String as a csv * @return The formatted String as a csv
*/ */
@Override
public final String toString() public final String toString()
{ {
// Return the csv as one long string // Return the csv as one long string
StringBuffer csvLines = new StringBuffer(); StringBuilder csvLines = new StringBuilder();
String[] lines = this.getCSVLinesAsStringArray(); String[] lines = this.getCSVLinesAsStringArray();
for (String line : lines) for (String line : lines)
{ {

View File

@@ -22,15 +22,16 @@ import java.util.*;
public class DSpaceCSVLine implements Serializable public class DSpaceCSVLine implements Serializable
{ {
/** The item id of the item represented by this line. -1 is for a new item */ /** The item id of the item represented by this line. -1 is for a new item */
private UUID id; private final UUID id;
/** The elements in this line in a hashtable, keyed by the metadata type */ /** The elements in this line in a hashtable, keyed by the metadata type */
private Map<String, ArrayList> items; private final Map<String, ArrayList> items;
protected final AuthorityValueService authorityValueService = AuthorityServiceFactory.getInstance().getAuthorityValueService(); protected transient final AuthorityValueService authorityValueService
= AuthorityServiceFactory.getInstance().getAuthorityValueService();
/** ensuring that the order-sensible columns of the csv are processed in the correct order */ /** ensuring that the order-sensible columns of the csv are processed in the correct order */
private final Comparator<? super String> headerComparator = new Comparator<String>() { private transient final Comparator<? super String> headerComparator = new Comparator<String>() {
@Override @Override
public int compare(String md1, String md2) { public int compare(String md1, String md2) {
// The metadata coming from an external source should be processed after the others // The metadata coming from an external source should be processed after the others
@@ -60,7 +61,7 @@ public class DSpaceCSVLine implements Serializable
{ {
// Store the ID + separator, and initialise the hashtable // Store the ID + separator, and initialise the hashtable
this.id = itemId; this.id = itemId;
items = new TreeMap<String, ArrayList>(headerComparator); items = new TreeMap<>(headerComparator);
// this.items = new HashMap<String, ArrayList>(); // this.items = new HashMap<String, ArrayList>();
} }
@@ -71,7 +72,7 @@ public class DSpaceCSVLine implements Serializable
{ {
// Set the ID to be null, and initialise the hashtable // Set the ID to be null, and initialise the hashtable
this.id = null; this.id = null;
this.items = new TreeMap<String, ArrayList>(headerComparator); this.items = new TreeMap<>(headerComparator);
} }
/** /**
@@ -149,6 +150,7 @@ public class DSpaceCSVLine implements Serializable
* Write this line out as a CSV formatted string, in the order given by the headings provided * Write this line out as a CSV formatted string, in the order given by the headings provided
* *
* @param headings The headings which define the order the elements must be presented in * @param headings The headings which define the order the elements must be presented in
* @param fieldSeparator
* @return The CSV formatted String * @return The CSV formatted String
*/ */
protected String toCSV(List<String> headings, String fieldSeparator) protected String toCSV(List<String> headings, String fieldSeparator)
@@ -177,6 +179,7 @@ public class DSpaceCSVLine implements Serializable
* Internal method to create a CSV formatted String joining a given set of elements * Internal method to create a CSV formatted String joining a given set of elements
* *
* @param values The values to create the string from * @param values The values to create the string from
* @param valueSeparator
* @return The line as a CSV formatted String * @return The line as a CSV formatted String
*/ */
protected String valueToCSV(List<String> values, String valueSeparator) protected String valueToCSV(List<String> values, String valueSeparator)

View File

@@ -7,6 +7,7 @@
*/ */
package org.dspace.browse; package org.dspace.browse;
import java.io.Serializable;
import java.util.*; import java.util.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -40,7 +41,8 @@ public class SolrBrowseDAO implements BrowseDAO
this.context = context; this.context = context;
} }
static private class FacetValueComparator implements Comparator static private class FacetValueComparator
implements Comparator, Serializable
{ {
@Override @Override
public int compare(Object o1, Object o2) public int compare(Object o1, Object o2)
@@ -64,10 +66,10 @@ public class SolrBrowseDAO implements BrowseDAO
} }
/** Log4j log */ /** Log4j log */
private static Logger log = Logger.getLogger(SolrBrowseDAO.class); private static final Logger log = Logger.getLogger(SolrBrowseDAO.class);
/** The DSpace context */ /** The DSpace context */
private Context context; private final Context context;
// SQL query related attributes for this class // SQL query related attributes for this class
@@ -254,7 +256,7 @@ public class SolrBrowseDAO implements BrowseDAO
int count = doCountQuery(); int count = doCountQuery();
int start = offset > 0 ? offset : 0; int start = offset > 0 ? offset : 0;
int max = limit > 0 ? limit : count; //if negative, return everything int max = limit > 0 ? limit : count; //if negative, return everything
List<String[]> result = new ArrayList<String[]>(); List<String[]> result = new ArrayList<>();
if (ascending) if (ascending)
{ {
for (int i = start; i < (start + max) && i < count; i++) for (int i = start; i < (start + max) && i < count; i++)