Search in sources :

Example 21 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class ProjectSynchronizationServiceTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    syncService = new ProjectSynchronizationService(projectService, sampleService, objectService, metadataTemplateService, projectRemoteService, sampleRemoteService, singleEndRemoteService, pairRemoteService, tokenService);
    api = new RemoteAPI();
    expired = new Project();
    expired.setId(1L);
    RemoteStatus expStatus = new RemoteStatus("http://expired", api);
    expStatus.setId(1L);
    expStatus.setLastUpdate(new Date(1));
    expStatus.setSyncStatus(RemoteStatus.SyncStatus.SYNCHRONIZED);
    expired.setSyncFrequency(ProjectSyncFrequency.WEEKLY);
    expired.setRemoteStatus(expStatus);
    upToDate = new Project();
    upToDate.setId(2L);
    RemoteStatus upToDateStatus = new RemoteStatus("http://upToDate", api);
    upToDateStatus.setId(2L);
    upToDateStatus.setLastUpdate(new Date());
    upToDateStatus.setSyncStatus(RemoteStatus.SyncStatus.SYNCHRONIZED);
    upToDate.setSyncFrequency(ProjectSyncFrequency.WEEKLY);
    upToDate.setRemoteStatus(upToDateStatus);
    neverSync = new Project();
    neverSync.setId(3L);
    RemoteStatus neverSyncStatus = new RemoteStatus("http://never", api);
    neverSyncStatus.setId(3L);
    neverSyncStatus.setLastUpdate(new Date());
    neverSyncStatus.setSyncStatus(RemoteStatus.SyncStatus.SYNCHRONIZED);
    neverSync.setSyncFrequency(ProjectSyncFrequency.NEVER);
    neverSync.setRemoteStatus(neverSyncStatus);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectSynchronizationService(ca.corefacility.bioinformatics.irida.service.remote.ProjectSynchronizationService) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Date(java.util.Date) Before(org.junit.Before)

Example 22 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class ProjectSynchronizationService method findMarkedProjectsToSync.

/**
 * Find projects which should be synchronized and launch a synchornization
 * task.
 */
public synchronized void findMarkedProjectsToSync() {
    // mark any projects which should be synched first
    findProjectsToMark();
    List<Project> markedProjects = projectService.getProjectsWithRemoteSyncStatus(SyncStatus.MARKED);
    logger.trace("Checking for projects to sync");
    for (Project project : markedProjects) {
        /*
			 * Set the correct authorization for the user who's syncing the
			 * project
			 */
        User readBy = project.getRemoteStatus().getReadBy();
        setAuthentication(readBy);
        logger.debug("Syncing project at " + project.getRemoteStatus().getURL());
        try {
            RemoteAPI api = project.getRemoteStatus().getApi();
            tokenService.updateTokenFromRefreshToken(api);
            syncProject(project);
        } catch (IridaOAuthException e) {
            logger.trace("Can't sync project " + project.getRemoteStatus().getURL() + " due to oauth error:", e);
            project.getRemoteStatus().setSyncStatus(SyncStatus.UNAUTHORIZED);
            projectService.update(project);
        } catch (Exception e) {
            logger.debug("An error occurred while synchronizing project " + project.getRemoteStatus().getURL(), e);
            project.getRemoteStatus().setSyncStatus(SyncStatus.ERROR);
            projectService.update(project);
        } finally {
            // clear the context holder when you're done
            SecurityContextHolder.clearContext();
            logger.debug("Done project " + project.getRemoteStatus().getURL());
        }
    }
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) ProjectSynchronizationException(ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException)

Example 23 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class SequenceFilePairRemoteServiceImpl method getSequenceFilePairsForSample.

/**
 * {@inheritDoc}
 */
@Override
public List<SequenceFilePair> getSequenceFilePairsForSample(Sample sample) {
    Link link = sample.getLink(SAMPLE_SEQENCE_FILE_PAIRS_REL);
    String href = link.getHref();
    RemoteAPI remoteApiForURI = getRemoteApiForURI(href);
    return repository.list(href, remoteApiForURI);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Link(org.springframework.hateoas.Link)

Example 24 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class SequencingObjectRemoteServiceImpl method mirrorSequencingObject.

@Override
public Type mirrorSequencingObject(Type seqObject) {
    Set<SequenceFile> files = seqObject.getFiles();
    for (SequenceFile file : files) {
        String fileHref = file.getSelfHref();
        RemoteAPI api = getRemoteApiForURI(fileHref);
        Path downloadRemoteSequenceFile = sequenceFileRemoteRepository.downloadRemoteSequenceFile(fileHref, api);
        file.setFile(downloadRemoteSequenceFile);
    }
    return seqObject;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)

Example 25 with RemoteAPI

use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.

the class SingleEndSequenceFileRemoteServiceImpl method getUnpairedFilesForSample.

/**
 * {@inheritDoc}
 */
@Override
public List<SingleEndSequenceFile> getUnpairedFilesForSample(Sample sample) {
    Link link = sample.getLink(SAMPLE_SEQENCE_FILE_UNPAIRED_REL);
    String href = link.getHref();
    RemoteAPI remoteApiForURI = getRemoteApiForURI(href);
    return repository.list(href, remoteApiForURI);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Link(org.springframework.hateoas.Link)

Aggregations

RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)44 Test (org.junit.Test)30 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)6 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)6 URI (java.net.URI)5 Date (java.util.Date)5 Link (org.springframework.hateoas.Link)5 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)3 RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)3 Before (org.junit.Before)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 OAuthTokenRestTemplate (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)2