use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ReadSamplePermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, 1L));
verify(sampleRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class UsersControllerTest method testGetUserSpecificPage.
@SuppressWarnings("rawtypes")
@Test
public void testGetUserSpecificPage() {
Principal principal = () -> USER_NAME;
Long userId = 1L;
String roleString = "User";
ExtendedModelMap model = new ExtendedModelMap();
User user = new User(userId, USER_NAME, null, null, null, null, null);
user.setSystemRole(Role.ROLE_USER);
@SuppressWarnings("unchecked") List<Join<Project, User>> joins = Lists.newArrayList(new ProjectUserJoin(new Project("good project"), user, ProjectRole.PROJECT_USER));
when(userService.read(userId)).thenReturn(user);
when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
when(messageSource.getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class))).thenReturn(roleString);
when(projectService.getProjectsForUser(user)).thenReturn(joins);
String userSpecificPage = controller.getUserSpecificPage(userId, true, model, principal);
assertEquals(USERS_DETAILS_PAGE, userSpecificPage);
assertEquals(user, model.get("user"));
assertEquals(roleString, model.get("systemRole"));
assertEquals(true, model.get("canEditUser"));
assertEquals(joins.size(), ((List) model.get("projects")).size());
verify(userService).read(userId);
verify(userService).getUserByUsername(USER_NAME);
verify(messageSource).getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class));
verify(projectService).getProjectsForUser(user);
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ProjectSynchronizationService method syncProject.
/**
* Synchronize a given {@link Project} to the local installation.
*
* @param project
* the {@link Project} to synchronize. This should have been read
* from a remote api.
*/
private void syncProject(Project project) {
project.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
projectService.update(project);
String projectURL = project.getRemoteStatus().getURL();
Project readProject = projectRemoteService.read(projectURL);
// ensure we use the same IDs
readProject = updateIds(project, readProject);
// if project was updated remotely, update it here
if (checkForChanges(project.getRemoteStatus(), readProject)) {
logger.debug("found changes for project " + readProject.getSelfHref());
// need to keep the status and frequency of the local project
RemoteStatus originalStatus = project.getRemoteStatus();
readProject.getRemoteStatus().setSyncStatus(originalStatus.getSyncStatus());
readProject.setSyncFrequency(project.getSyncFrequency());
project = projectService.update(readProject);
}
List<Join<Project, Sample>> localSamples = sampleService.getSamplesForProject(project);
// get all the samples by their url
Map<String, Sample> samplesByUrl = new HashMap<>();
localSamples.forEach(j -> {
Sample sample = j.getObject();
// If a user has added a sample for some reason, ignore it
if (sample.getRemoteStatus() != null) {
String url = sample.getRemoteStatus().getURL();
samplesByUrl.put(url, sample);
} else {
logger.warn("Sample " + sample.getId() + " is not a remote sample. It will not be synchronized.");
}
});
List<Sample> readSamplesForProject = sampleRemoteService.getSamplesForProject(readProject);
for (Sample s : readSamplesForProject) {
s.setId(null);
s = syncSampleMetadata(s);
syncSample(s, project, samplesByUrl);
}
project.setRemoteStatus(readProject.getRemoteStatus());
project.getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
projectService.update(project);
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class AssemblyFileProcessor method shouldAssemble.
/**
* Check whether any {@link Project} associated with the
* {@link SequencingObject} is set to assemble
*
* @param object
* {@link SequencingObject} to check ot assemble
* @return true if it should assemble, false otherwise
*/
private boolean shouldAssemble(SequencingObject object) {
boolean assemble = false;
SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
/*
* This is something that should only ever happen in tests, but added
* check with a warning
*/
if (sampleForSequencingObject != null) {
List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
assemble = projectForSample.stream().anyMatch(j -> j.getSubject().getAssembleUploads());
} else {
logger.warn("Cannot find sample for sequencing object. Not assembling");
}
return assemble;
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class SistrTypingFileProcessor method shouldTypeWithSISTR.
/**
* Check whether any {@link Project} associated with the
* {@link SequencingObject} is set to type with SISTR.
*
* @param object {@link SequencingObject} to check to type with SISTR.
* @return true if it should type with SISTR, false otherwise
*/
private Project.AutomatedSISTRSetting shouldTypeWithSISTR(SequencingObject object) {
Project.AutomatedSISTRSetting type = Project.AutomatedSISTRSetting.OFF;
SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
/*
* This is something that should only ever happen in tests, but added
* check with a warning
*/
if (sampleForSequencingObject != null) {
List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
Set<Project.AutomatedSISTRSetting> sistrOptions = projectForSample.stream().map(j -> j.getSubject().getSistrTypingUploads()).collect(Collectors.toSet());
if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO_METADATA)) {
return Project.AutomatedSISTRSetting.AUTO_METADATA;
} else if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO))
return Project.AutomatedSISTRSetting.AUTO;
} else {
logger.warn("Cannot find sample for sequencing object. Not typing with SISTR");
}
return type;
}
Aggregations