Search in sources :

Example 51 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testDeleteReleaseNotModerator.

@Test
public void testDeleteReleaseNotModerator() throws Exception {
    when(releaseModerator.deleteRelease(any(Release.class), eq(user1))).thenReturn(RequestStatus.SENT_TO_MODERATOR);
    RequestStatus status = handler.deleteRelease("R1B", user1);
    assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
    List<Release> releaseSummary = handler.getReleaseSummary();
    assertEquals(5, releaseSummary.size());
    assertTrue("Component NOT deleted", releasesContain(releaseSummary, "R1B"));
    verify(releaseModerator).deleteRelease(any(Release.class), eq(user1));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 52 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.

the class ComponentDatabaseHandlerTest method testUpdateRelease.

@Test
public void testUpdateRelease() throws Exception {
    Release expected = releases.get(1);
    expected.setName("UPDATED");
    RequestStatus status = handler.updateRelease(expected, user2, ThriftUtils.IMMUTABLE_OF_RELEASE);
    Release actual = handler.getRelease("R1B", user1);
    assertEquals(RequestStatus.SUCCESS, status);
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getVersion(), actual.getVersion());
    assertEquals(expected.getComponentId(), actual.getComponentId());
    assertEquals(email2, actual.getCreatedBy());
    // Check releases
    assertEquals(1, actual.getSubscribersSize());
    assertTrue(actual.getSubscribers().contains(email1));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 53 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.

the class VulnerabilityConnector method addOrUpdateVulnerabilityAndSetId.

public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(Vulnerability vulnerability, Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
    Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
    if (dbVulnerability != null) {
        if (!isMoreRecent(vulnerability, dbVulnerability)) {
            statusToVulnerabilities.get(UpdateType.OLD).add(dbVulnerability);
            return statusToVulnerabilities;
        } else {
            dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
            RequestStatus requestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
            if (RequestStatus.SUCCESS.equals(requestStatus)) {
                statusToVulnerabilities.get(UpdateType.UPDATED).add(dbVulnerability);
                return statusToVulnerabilities;
            }
        }
    } else {
        RequestStatus requestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
        if (RequestStatus.SUCCESS.equals(requestStatus)) {
            statusToVulnerabilities.get(UpdateType.NEW).add(vulnerability);
            return statusToVulnerabilities;
        }
    }
    statusToVulnerabilities.get(UpdateType.FAILED).add(vulnerability);
    return statusToVulnerabilities;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 54 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.

the class VulnerabilityUtils method reduceVulnerabilityUpdateStatus.

public static VulnerabilityUpdateStatus reduceVulnerabilityUpdateStatus(VulnerabilityUpdateStatus... statuses) {
    VulnerabilityUpdateStatus resultStatus = getEmptyVulnerabilityUpdateStatus();
    RequestStatus requestStatus = Arrays.stream(statuses).map(VulnerabilityUpdateStatus::getRequestStatus).reduce(RequestStatus.SUCCESS, CommonUtils::reduceRequestStatus);
    resultStatus.setRequestStatus(requestStatus);
    for (UpdateType updateType : UpdateType.values()) {
        for (VulnerabilityUpdateStatus status : statuses) {
            if (status.isSetStatusToVulnerabilityIds()) {
                resultStatus.statusToVulnerabilityIds.get(updateType).addAll(nullToEmptyList(status.statusToVulnerabilityIds.get(updateType)));
            }
        }
    }
    return resultStatus;
}
Also used : CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 55 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus in project sw360portal by sw360.

the class ProjectDatabaseHandler method updateProject.

// /////////////////////////////
// UPDATE INDIVIDUAL OBJECTS //
// /////////////////////////////
public RequestStatus updateProject(Project project, User user) throws SW360Exception {
    // Prepare project for database
    prepareProject(project);
    Project actual = repository.get(project.getId());
    assertNotNull(project);
    if (!changePassesSanityCheck(project, actual)) {
        return RequestStatus.FAILED_SANITY_CHECK;
    } else if (makePermission(actual, user).isActionAllowed(RequestedAction.WRITE)) {
        copyImmutableFields(project, actual);
        project.setAttachments(getAllAttachmentsToKeep(actual.getAttachments(), project.getAttachments()));
        repository.update(project);
        // clean up attachments in database
        attachmentConnector.deleteAttachmentDifference(actual.getAttachments(), project.getAttachments());
        sendMailNotificationsForProjectUpdate(project, user.getEmail());
        return RequestStatus.SUCCESS;
    } else {
        return moderator.updateProject(project, user);
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

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