Search in sources :

Example 76 with RequestStatus

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);
    }
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 77 with RequestStatus

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());
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Example 78 with RequestStatus

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();
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Example 79 with RequestStatus

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;
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 80 with RequestStatus

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) ProjectDatabaseHandler(org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Aggregations

RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)52 TException (org.apache.thrift.TException)27 User (org.eclipse.sw360.datahandler.thrift.users.User)24 Test (org.junit.Test)16 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)13 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)10 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)5 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)4 AddDocumentRequestStatus (org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)4 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 PrintWriter (java.io.PrintWriter)2 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)2 Component (org.eclipse.sw360.datahandler.thrift.components.Component)2 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)2