Search in sources :

Example 1 with ProjectSyncFrequency

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);
            }
        }
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) ProjectSyncFrequency(ca.corefacility.bioinformatics.irida.model.project.ProjectSyncFrequency) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 ProjectSyncFrequency (ca.corefacility.bioinformatics.irida.model.project.ProjectSyncFrequency)1 RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)1 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1