Search in sources :

Example 1 with RemoteStatus

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

the class ProjectSettingsController method updateProjectSyncSettings.

/**
 * Update the project sync settings
 *
 * @param projectId
 *            the project id to update
 * @param frequency
 *            the sync frequency to set
 * @param forceSync
 *            Set the project's sync status to MARKED
 * @param changeUser
 *            update the user on a remote project to the current logged in
 *            user
 * @param principal
 *            The current logged in user
 * @param locale
 *            user's locale
 *
 * @return result message if successful
 */
@RequestMapping(value = "/sync", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateProjectSyncSettings(@PathVariable Long projectId, @RequestParam(required = false) ProjectSyncFrequency frequency, @RequestParam(required = false, defaultValue = "false") boolean forceSync, @RequestParam(required = false, defaultValue = "false") boolean changeUser, Principal principal, Locale locale) {
    Project read = projectService.read(projectId);
    RemoteStatus remoteStatus = read.getRemoteStatus();
    Map<String, Object> updates = new HashMap<>();
    String message = null;
    String error = null;
    if (frequency != null) {
        updates.put("syncFrequency", frequency);
        message = messageSource.getMessage("project.settings.notifications.sync", new Object[] {}, locale);
    }
    if (forceSync) {
        remoteStatus.setSyncStatus(SyncStatus.MARKED);
        updates.put("remoteStatus", remoteStatus);
        message = messageSource.getMessage("project.settings.notifications.sync", new Object[] {}, locale);
    }
    if (changeUser) {
        // ensure the user can read the project
        try {
            projectRemoteService.read(remoteStatus.getURL());
            User user = userService.getUserByUsername(principal.getName());
            remoteStatus.setReadBy(user);
            updates.put("remoteStatus", remoteStatus);
            message = messageSource.getMessage("project.settings.notifications.sync.userchange", new Object[] {}, locale);
        } catch (Exception ex) {
            error = messageSource.getMessage("project.settings.notifications.sync.userchange.error", new Object[] {}, locale);
        }
    }
    projectService.updateProjectSettings(read, updates);
    Map<String, String> response;
    if (error == null) {
        response = ImmutableMap.of("result", message);
    } else {
        response = ImmutableMap.of("error", error);
    }
    return response;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) HashMap(java.util.HashMap) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RemoteStatus

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

the class SampleRemoteServiceImplTest method testGetSamplesForProject.

@Test
public void testGetSamplesForProject() {
    String samplesHref = "http://somewhere/projects/5/samples";
    Project project = new Project();
    project.add(new Link(samplesHref, SampleRemoteServiceImpl.PROJECT_SAMPLES_REL));
    RemoteAPI api = new RemoteAPI();
    project.setRemoteStatus(new RemoteStatus("http://nowhere", api));
    Sample remoteSample = new Sample();
    remoteSample.setRemoteStatus(new RemoteStatus("http://nowhere", api));
    List<Sample> samples = Lists.newArrayList(remoteSample);
    when(sampleRemoteRepository.list(samplesHref, api)).thenReturn(samples);
    List<Sample> samplesForProject = sampleRemoteService.getSamplesForProject(project);
    verify(sampleRemoteRepository).list(samplesHref, api);
    assertEquals(samples, samplesForProject);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 3 with RemoteStatus

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

the class SingleEndSequenceFileRemoteServiceImplTest method testGetSequenceFilesForSample.

@Test
public void testGetSequenceFilesForSample() {
    String seqFilesHref = "http://somewhere/projects/1/samples/2/sequencefiles";
    RemoteAPI api = new RemoteAPI();
    Sample sample = new Sample();
    sample.add(new Link(seqFilesHref, SingleEndSequenceFileRemoteServiceImpl.SAMPLE_SEQENCE_FILE_UNPAIRED_REL));
    sample.setRemoteStatus(new RemoteStatus("http://nowhere", api));
    List<SingleEndSequenceFile> filesList = Lists.newArrayList(new SingleEndSequenceFile(new SequenceFile()));
    when(apiRepo.getRemoteAPIForUrl(seqFilesHref)).thenReturn(api);
    when(repository.list(seqFilesHref, api)).thenReturn(filesList);
    List<SingleEndSequenceFile> sequenceFilesForSample = service.getUnpairedFilesForSample(sample);
    assertEquals(filesList, sequenceFilesForSample);
    verify(repository).list(seqFilesHref, api);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Link(org.springframework.hateoas.Link) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 4 with RemoteStatus

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

the class ProjectOwnerPermissionTest method testRemoteProject.

@Test
public void testRemoteProject() {
    project.setRemoteStatus(new RemoteStatus("http://somewhere", null));
    Authentication authentication = new ProjectSynchronizationAuthenticationToken(user);
    boolean customPermissionAllowed = permission.customPermissionAllowed(authentication, project);
    assertTrue("user should be able to read project", customPermissionAllowed);
}
Also used : ProjectSynchronizationAuthenticationToken(ca.corefacility.bioinformatics.irida.security.ProjectSynchronizationAuthenticationToken) Authentication(org.springframework.security.core.Authentication) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 5 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus 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)

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