use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.
the class ProjectSynchronizationService method syncSingleEndSequenceFile.
/**
* Synchronize a given {@link SingleEndSequenceFile} to the local
* installation
*
* @param file
* the {@link SingleEndSequenceFile} to sync
* @param sample
* the {@link Sample} to add the file to
*/
public void syncSingleEndSequenceFile(SingleEndSequenceFile file, Sample sample) {
RemoteStatus fileStatus = file.getRemoteStatus();
fileStatus.setSyncStatus(SyncStatus.UPDATING);
try {
file = singleEndRemoteService.mirrorSequencingObject(file);
file.getSequenceFile().setId(null);
file.getSequenceFile().getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
objectService.createSequencingObjectInSample(file, sample);
fileStatus.setSyncStatus(SyncStatus.SYNCHRONIZED);
objectService.updateRemoteStatus(file.getId(), fileStatus);
} catch (Exception e) {
logger.error("Error transferring file: " + file.getRemoteStatus().getURL(), e);
throw new ProjectSynchronizationException("Could not synchronize file " + file.getRemoteStatus().getURL(), e);
}
}
use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.
the class RemoteRepositoryImpl method setRemoteStatus.
/**
* Set the {@link RemoteStatus} of a read remote entity
*
* @param entity The entity to set the remote status on
* @param api The API to connect to
* @param <T> The type of entity you're setting status of
* @return the enhanced entity
*/
protected <T extends IridaResourceSupport> T setRemoteStatus(T entity, RemoteAPI api) {
String selfHref = entity.getSelfHref();
// Get the logged in user and set them in the remote status object
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
RemoteStatus remoteStatus = new RemoteStatus(selfHref, api);
if (principal instanceof User) {
remoteStatus.setReadBy((User) principal);
}
remoteStatus.setRemoteHashCode(entity.hashCode());
entity.setRemoteStatus(remoteStatus);
return entity;
}
use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.
the class ProjectOwnerPermissionTest method testRemoteProjectWrongAuth.
@Test
public void testRemoteProjectWrongAuth() {
project.setRemoteStatus(new RemoteStatus("http://somewhere", null));
Authentication authentication = new PreAuthenticatedAuthenticationToken(user, user.getSystemRole());
boolean customPermissionAllowed = permission.customPermissionAllowed(authentication, project);
assertFalse("user should not be able to read project", customPermissionAllowed);
}
use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.
the class ProjectSynchronizationServiceTest method testSyncFilesError.
@Test(expected = ProjectSynchronizationException.class)
public void testSyncFilesError() {
Sample sample = new Sample();
SequenceFilePair pair = new SequenceFilePair();
RemoteStatus pairStatus = new RemoteStatus("http://pair", api);
pair.setRemoteStatus(pairStatus);
pair.setId(1L);
when(pairRemoteService.mirrorSequencingObject(pair)).thenReturn(pair);
when(objectService.createSequencingObjectInSample(pair, sample)).thenThrow(new NullPointerException("Bad file"));
syncService.syncSequenceFilePair(pair, sample);
}
use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus 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