Search in sources :

Example 11 with RemoteStatus

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);
    }
}
Also used : ProjectSynchronizationException(ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) ProjectSynchronizationException(ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException)

Example 12 with RemoteStatus

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;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)

Example 13 with RemoteStatus

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);
}
Also used : Authentication(org.springframework.security.core.Authentication) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 14 with RemoteStatus

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);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 15 with RemoteStatus

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);
            }
        }
    }
}
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

RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)15 Test (org.junit.Test)8 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)7 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)3 HashMap (java.util.HashMap)3 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)2 ProjectSynchronizationException (ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException)2 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 Date (java.util.Date)2 Link (org.springframework.hateoas.Link)2 Authentication (org.springframework.security.core.Authentication)2 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1 ProjectSyncFrequency (ca.corefacility.bioinformatics.irida.model.project.ProjectSyncFrequency)1 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 ProjectSynchronizationAuthenticationToken (ca.corefacility.bioinformatics.irida.security.ProjectSynchronizationAuthenticationToken)1