}
}
File tempCsv = new File(tempDirectory.getPath() + File.separatorChar + "temp." + i + ".csv");
tempCsvFiles.add(tempCsv);
CSVWriter csvp = new CSVWriter(new FileWriter(tempCsv));
//csvp.setAlwaysQuote(false);
//Write the header !
csvp.writeNext((String[]) ArrayUtils.add(header, "bundleName"));
Map<Integer, String> bitBundleCache = new HashMap<Integer, String>();
//Loop over each line (skip the headers though)!
for (int j = 1; j < csvParsed.length; j++){
String[] csvLine = csvParsed[j];
//Write the default line !
int bitstreamId = Integer.parseInt(csvLine[idIndex]);
//Attempt to retrieve our bundle name from the cache !
String bundleName = bitBundleCache.get(bitstreamId);
if(bundleName == null){
//Nothing found retrieve the bitstream
Bitstream bitstream = Bitstream.find(context, bitstreamId);
//Attempt to retrieve our bitstream !
if (bitstream != null){
Bundle[] bundles = bitstream.getBundles();
if(bundles != null && 0 < bundles.length){
Bundle bundle = bundles[0];
bundleName = bundle.getName();
context.removeCached(bundle, bundle.getID());
}else{
//No bundle found, we are either a collection or a community logo, check for it !
DSpaceObject parentObject = bitstream.getParentObject();
if(parentObject instanceof Collection){
bundleName = "LOGO-COLLECTION";
}else
if(parentObject instanceof Community){
bundleName = "LOGO-COMMUNITY";
}
if(parentObject != null){
context.removeCached(parentObject, parentObject.getID());
}
}
//Cache the bundle name
bitBundleCache.put(bitstream.getID(), bundleName);
//Remove the bitstream from cache
context.removeCached(bitstream, bitstreamId);
}
//Check if we don't have a bundlename
//If we don't have one & we do not need to delete the deleted bitstreams ensure that a BITSTREAM_DELETED bundle name is given !
if(bundleName == null && !removeDeletedBitstreams){
bundleName = "BITSTREAM_DELETED";
}
}
csvp.writeNext((String[]) ArrayUtils.add(csvLine, bundleName));
}
//Loop over our parsed csv
csvp.flush();
csvp.close();
}
//Add all the separate csv files
for (File tempCsv : tempCsvFiles) {
ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest("/update/csv");