private ReturnWithExceptions<Long, ModelObserver> indexFile(AIP aip, File file, List<String> ancestors,
boolean recursive) {
ReturnWithExceptions<Long, ModelObserver> ret = new ReturnWithExceptions<>(this);
Long sizeInBytes = 0L;
FileCollection.Info info = new FileCollection.Info(aip, ancestors);
SolrUtils.create2(index, (ModelObserver) this, IndexedFile.class, file, info).addTo(ret);
sizeInBytes = (Long) info.getAccumulators().get(RodaConstants.FILE_SIZE);
if (ret.isEmpty()) {
if (recursive && file.isDirectory()) {
try (CloseableIterable<OptionalWithCause<File>> allFiles = model.listFilesUnder(file, true)) {
for (OptionalWithCause<File> subfile : allFiles) {
if (subfile.isPresent()) {
sizeInBytes += indexFile(aip, subfile.get(), ancestors, false).addTo(ret).getReturnedObject();
} else {
LOGGER.error("Cannot index file", subfile.getCause());
ret.add(subfile.getCause());
}
}
} catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException
| IOException e) {
LOGGER.error("Cannot index file sub-resources: {}", file, e);
ret.add(e);
}
}
} else {
LOGGER.error("Cannot index file: {}", file);
}
ret.setReturnedObject(sizeInBytes);
return ret;
}