Added code to handle edge case

If one of the 'collections' files contains a handle or an id that cannot
be resolved to a collection, the specific item is skipped but the
procedure continues with subsequent items.
This commit is contained in:
Panagiotis Koutsourakis
2014-07-16 11:05:21 +03:00
committed by Kostas Stamatis
parent 5c8cbf2c05
commit 4b92fdd91b

View File

@@ -780,13 +780,19 @@ public class ItemImport
{
if (mycollections == null) {
String path = sourceDir + File.separatorChar + dircontents[i];
Collection [] cols = processCollectionFile(c, path, "collections");
if (cols == null) {
System.out.println("No collections specified for item " + dircontents[i] + ". Skipping.");
try {
Collection[] cols = processCollectionFile(c, path, "collections");
if (cols == null) {
System.out.println("No collections specified for item " + dircontents[i] + ". Skipping.");
continue;
}
mycollections = cols;
}
catch (IllegalArgumentException e)
{
System.out.println(e.getMessage() + " Skipping." );
continue;
}
mycollections = cols;
}
addItem(c, mycollections, sourceDir, dircontents[i], mapOut, template);
@@ -1221,7 +1227,8 @@ public class ItemImport
* @return
*/
private Collection[] processCollectionFile(Context c, String path, String filename) throws IOException, SQLException {
private Collection[] processCollectionFile(Context c, String path, String filename) throws IOException, SQLException
{
File file = new File(path + File.separatorChar + filename);
ArrayList<Collection> collections = new ArrayList<Collection>();
Collection[] result = null;
@@ -1251,7 +1258,7 @@ public class ItemImport
}
if (obj == null) {
throw new IllegalArgumentException("Cannot resolve " + line + " to a collection");
throw new IllegalArgumentException("Cannot resolve " + line + " to a collection.");
}
collections.add((Collection)obj);