final SystemDomain system = this.systemDao.getSystem(cfg.getUSN());
final Set<Object> itemsToPurge = new HashSet<Object>();
final Map<String, ScanContext> idScanContextMap = new HashMap<String, ScanContext>();
final Set<String> foundFileIds = new HashSet<String>();
final DidlChangeMap touchedDidlMap = new DidlChangeMap();
for (final ScanContext sc : scanContexts) {
idScanContextMap.put(sc.getScanFolderId(), sc);
}
// collect all Files, no Folders!
for (final ScanContext sc : scanContexts) {
logger.info("scanner [scan] "+sc.getScanFolder());
List<String> knownFileIds = this.fsDao.getAllFileIds(sc.getScanFolderId());
collectNewFiles(sc.getScanFolder(), sc.getFiles(), knownFileIds, foundFileIds);
logger.info("scanner [found files] " + sc.getFiles().size() + " " +sc.getScanFolder());
changedCount += sc.getFiles().size();
knownFileIds.removeAll(foundFileIds);
for (String removed : knownFileIds) {
sc.addDeletedMediaFile(removed);
changedCount += 1;
}
}
if (changedCount > 0) {
final List<String> allDidlIds= this.didlDao.getAllDidlIds();
for (String id : allDidlIds) {
touchedDidlMap.addDidl(id, null);
}
for (final ScanFolderDomain sfd : system.getScanFolder()) {
if (idScanContextMap.containsKey(sfd.getId())) {
final ScanContext sc = idScanContextMap.get(sfd.getId());
logger.info("scanner [filter] "+sc.getScanFolder());