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