use of ca.corefacility.bioinformatics.irida.model.project.ProjectSyncFrequency in project irida by phac-nml.
the class ProjectSynchronizationService method findProjectsToMark.
/**
* Method checking for remote projects that have passed their frequency
* time. It will mark them as {@link SyncStatus#MARKED}
*/
public void findProjectsToMark() {
List<Project> remoteProjects = projectService.getRemoteProjects();
for (Project p : remoteProjects) {
// check the frequency for each remote project
RemoteStatus remoteStatus = p.getRemoteStatus();
Date lastUpdate = remoteStatus.getLastUpdate();
ProjectSyncFrequency syncFrequency = p.getSyncFrequency();
// if the project is set to be synched
if (syncFrequency != null) {
if (syncFrequency != ProjectSyncFrequency.NEVER) {
/*
* find the next sync date and see if it's passed. if it has
* set as MARKED
*/
Date nextSync = DateUtils.addDays(lastUpdate, syncFrequency.getDays());
if (nextSync.before(new Date())) {
Map<String, Object> updates = new HashMap<>();
remoteStatus.setSyncStatus(SyncStatus.MARKED);
updates.put("remoteStatus", remoteStatus);
projectService.updateProjectSettings(p, updates);
}
} else if (remoteStatus.getSyncStatus() != RemoteStatus.SyncStatus.UNSYNCHRONIZED) {
/*
* if a sync frequency is NEVER and it's status isn't
* UNSYNCHRONIZED, it should be set as such
*/
remoteStatus.setSyncStatus(SyncStatus.UNSYNCHRONIZED);
Map<String, Object> updates = new HashMap<>();
updates.put("remoteStatus", remoteStatus);
projectService.updateProjectSettings(p, updates);
}
}
}
}
Aggregations