@Transactional(propagation=Propagation.REQUIRED)
private List<ScanContext> createScanContexts() {
final List<ScanContext> scanContexts = new ArrayList<ScanContext>();
final long currentTimeMillis = System.currentTimeMillis();
final SystemDomain system = this.systemDao.getSystem(cfg.getUSN());
for (final ScanFolderDomain sfd : system.getScanFolder()) {
if (
!ScanFolderState.SCANNING.equals(sfd.getScanState()) &&
((sfd.getLastScan() == null) ||
((sfd.getLastScan().getTime() + (sfd.getScanInterval() * 60000)) < currentTimeMillis))) {
// should scan
final File dir = new File(sfd.getPath());
if (! dir.exists() || ! dir.isDirectory()) {
// this could happen with external storage ..
sfd.setScanState(ScanFolderState.NOT_FOUND);
didlDao.setOnline(sfd.getId(), false);
system.increaseUpdateId();
} else {
if (ScanFolderState.NOT_FOUND.equals(sfd.getScanState())) {
didlDao.setOnline(sfd.getId(), true);
system.increaseUpdateId();
}
sfd.setScanState(ScanFolderState.SCANNING);
scanContexts.add(new ScanContext(sfd.getId(), dir));
}