Search in sources :

Example 41 with RequestStatus

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

the class FossologyHandlerTest method testSendToFossology.

@Test
public void testSendToFossology() throws Exception {
    final String releaseId = "a";
    final String clearingTeam = "b";
    final RequestStatus requestStatus = RequestStatus.FAILURE;
    doReturn(requestStatus).when(fossologyFileHandler).sendToFossology(releaseId, user, clearingTeam);
    assertThat(fossologyHandler.sendToFossology(releaseId, user, clearingTeam), sameInstance(requestStatus));
    verify(fossologyFileHandler).sendToFossology(releaseId, user, clearingTeam);
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Example 42 with RequestStatus

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

the class CveSearchHandler method update.

@Override
public RequestStatus update() throws TException {
    log.info("Starting CveSearch update...");
    VulnerabilityUpdateStatus vulnerabilityUpdateStatus = fullUpdate();
    log.info("CveSearch update finished with status:" + vulnerabilityUpdateStatus.getRequestStatus());
    log.info("The following vulnerability/ies could not be imported:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED) + "\n" + "The following vulnerability/ies were updated:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED) + "\n" + "The following vulnerability/ies were added:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW));
    return vulnerabilityUpdateStatus.getRequestStatus();
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)

Example 43 with RequestStatus

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

the class FossologyFileHandler method sendToFossology.

public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException {
    Release release;
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    release = getReleaseAndUnlockIt(releaseId, user, componentClient);
    Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient);
    if (sourceAttachments.size() != 1) {
        log.error("release " + releaseId + " does not have a single source attachment");
        // TODO return a summary and better fitting status
        return RequestStatus.FAILURE;
    }
    final Attachment attachment = getFirst(sourceAttachments);
    final FilledAttachment filledAttachment = fillAttachment(attachment);
    if (!release.isSetFossologyId()) {
        /* send the attachment as a new upload */
        AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
        return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
    } else {
        if (!checkSourceAttachment(release, filledAttachment)) {
            // TODO summary
            return RequestStatus.FAILURE;
        } else {
            /* duplicate the old upload making it visible for clearingTeam */
            return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
        }
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 44 with RequestStatus

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

the class VulnerabilityConnector method addOrUpdate.

public UpdateType addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation) {
    RequestStatus vulRequestStatus = RequestStatus.SUCCESS;
    UpdateType updateType;
    Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
    if (dbVulnerability != null) {
        if (isMoreRecent(vulnerability, dbVulnerability)) {
            updateType = UpdateType.UPDATED;
            dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
            vulRequestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
        } else {
            updateType = UpdateType.OLD;
        }
    } else {
        updateType = UpdateType.NEW;
        vulRequestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
        dbVulnerability = vulnerability;
    }
    if (RequestStatus.FAILURE.equals(vulRequestStatus)) {
        return UpdateType.FAILED;
    }
    partiallyFilledRelation.setVulnerabilityId(dbVulnerability.getId());
    RequestStatus requestStatus = addOrUpdate(partiallyFilledRelation);
    if (RequestStatus.FAILURE.equals(requestStatus)) {
        return UpdateType.FAILED;
    }
    return updateType;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 45 with RequestStatus

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

the class ProjectDatabaseHandlerTest method testSanityCheckSucceeds.

@Test
public void testSanityCheckSucceeds() throws Exception {
    Project project = handler.getProjectById("P1", user1);
    project.setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
    RequestStatus status = handler.updateProject(project, user1);
    assertThat(status, is(RequestStatus.SUCCESS));
    Project project2 = handler.getProjectById("P2", user1);
    project2.setReleaseIdToUsage(Collections.emptyMap());
    RequestStatus status2 = handler.updateProject(project2, user1);
    assertThat(status2, is(RequestStatus.SUCCESS));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) 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