use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class LicenseDatabaseHandler method updateWhitelist.
/**
* Update the whitelisted todos for an organisation
*/
public RequestStatus updateWhitelist(String licenseId, Set<String> whitelistTodos, User user) throws SW360Exception {
License license = licenseRepository.get(licenseId);
assertNotNull(license);
String organisation = user.getDepartment();
String businessUnit = SW360Utils.getBUFromOrganisation(organisation);
if (makePermission(license, user).isActionAllowed(RequestedAction.WRITE)) {
List<Todo> todos = todoRepository.get(license.todoDatabaseIds);
for (Todo todo : todos) {
String todoId = todo.getId();
Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
// Add to whitelist if necessary
if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
todo.addToWhitelist(businessUnit);
todoRepository.update(todo);
}
// Remove from whitelist if necessary
if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
currentWhitelist.remove(businessUnit);
todoRepository.update(todo);
}
}
return RequestStatus.SUCCESS;
} else {
// add updated whitelists to todos in moderation request, not yet in database
License licenseForModerationRequest = getLicenseForOrganisationWithOwnModerationRequests(licenseId, user.getDepartment(), user);
List<Todo> todos = licenseForModerationRequest.getTodos();
for (Todo todo : todos) {
String todoId = todo.getId();
Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
// Add to whitelist if necessary
if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
todo.addToWhitelist(businessUnit);
}
// Remove from whitelist if necessary
if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
currentWhitelist.remove(businessUnit);
}
}
// Only moderators can edit whitelists!
return moderator.updateLicense(licenseForModerationRequest, user);
}
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class FossologyHandlerTest method testCheckConnection.
@Test
public void testCheckConnection() throws Exception {
final RequestStatus requestStatus = RequestStatus.SUCCESS;
doReturn(2).when(fossologySshConnector).runInFossologyViaSsh(anyString());
assertThat(fossologyHandler.checkConnection(), is(requestStatus));
verify(fossologySshConnector).runInFossologyViaSsh(anyString());
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class FossologyHandlerTest method testDeployScripts.
@Test
public void testDeployScripts() throws Exception {
final RequestStatus requestStatus = RequestStatus.FAILURE;
doReturn(requestStatus).when(fossologyScriptsHandler).deployScripts();
assertThat(fossologyHandler.deployScripts(), sameInstance(requestStatus));
verify(fossologyScriptsHandler).deployScripts();
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class ProjectHandler method removeAttachmentFromProject.
@Override
public RequestStatus removeAttachmentFromProject(String projectId, User user, String attachmentContentId) throws TException {
Project projectByIdForEdit = getProjectByIdForEdit(projectId, user);
Set<Attachment> attachments = projectByIdForEdit.getAttachments();
Optional<Attachment> attachmentOptional = CommonUtils.getAttachmentOptional(attachmentContentId, attachments);
if (attachmentOptional.isPresent()) {
attachments.remove(attachmentOptional.get());
return updateProject(projectByIdForEdit, user);
} else {
return RequestStatus.SUCCESS;
}
}
use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.
the class ProjectHandlerTest method testUpdateProject2_1.
@Test
public void testUpdateProject2_1() throws Exception {
ProjectModerator moderator = Mockito.mock(ProjectModerator.class);
ProjectDatabaseHandler handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName));
Project project2 = handler.getProjectById("P2", user1);
project2.setName("Project2new");
Mockito.doReturn(RequestStatus.SENT_TO_MODERATOR).when(moderator).updateProject(project2, user1);
RequestStatus status = handler.updateProject(project2, user1);
// Now contributors can also change the project
assertEquals(RequestStatus.SUCCESS, status);
// assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
// assertEquals("Project2", handler.getProjectById("P2", user1).getName());
// Mockito.verify(moderator, times(1)).updateProject(project2, user1.getEmail());
// Mockito.verifyNoMoreInteractions(moderator);
}
Aggregations