Search in sources :

Example 11 with FossologyStatus

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

the class FossologyFileHandlerTest method testIsVisible.

@Test
public void testIsVisible() throws Exception {
    assertThat(FossologyFileHandler.isVisible(null), is(false));
    for (FossologyStatus fossologyStatus : FossologyStatus.values()) {
        final boolean expectedVisible;
        switch(fossologyStatus) {
            case CONNECTION_FAILED:
            case ERROR:
            case NON_EXISTENT:
            case NOT_SENT:
            case INACCESSIBLE:
                expectedVisible = false;
                break;
            case SENT:
            case SCANNING:
            case OPEN:
            case IN_PROGRESS:
            case CLOSED:
            case REJECTED:
            case REPORT_AVAILABLE:
            default:
                expectedVisible = true;
                break;
        }
        String errorMessage = "" + fossologyStatus + " should" + (expectedVisible ? "" : " not") + " be visible";
        assertThat(errorMessage, FossologyFileHandler.isVisible(fossologyStatus), is(expectedVisible));
    }
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Test(org.junit.Test)

Example 12 with FossologyStatus

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

the class FossologyFileHandler method getStatusInFossology.

public Release getStatusInFossology(String releaseId, User user, String clearingTeam) throws TException {
    final Release release;
    final ComponentService.Iface componentClient;
    try {
        componentClient = thriftClients.makeComponentClient();
        release = componentClient.getReleaseById(releaseId, user);
        assertNotNull(release);
    } catch (TException e) {
        log.error("cannot get release " + releaseId, e);
        throw e;
    }
    if (release.isSetFossologyId()) {
        int fossologyId = CommonUtils.toUnsignedInt(release.getFossologyId());
        boolean updateInDb = true;
        for (String allClearingTeam : getAllClearingTeams(release, clearingTeam)) {
            final FossologyStatus status = fossologyUploader.getStatusInFossology(fossologyId, allClearingTeam);
            setFossologyStatus(release, allClearingTeam, status);
            if (isError(status)) {
                updateInDb = false;
            }
        }
        Optional<FossologyStatus> maxStatus = nullToEmptyMap(release.getClearingTeamToFossologyStatus()).values().stream().max(FossologyStatus::compareTo);
        updateReleaseClearingState(release, maxStatus);
        if (updateInDb) {
            updateRelease(release, user, componentClient);
        }
    }
    // just unlockit
    getReleaseAndUnlockIt(releaseId, user, componentClient);
    return release;
}
Also used : TException(org.apache.thrift.TException) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 13 with FossologyStatus

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

the class FossologyFileHandler method sendToFossologyExistingUpload.

private RequestStatus sendToFossologyExistingUpload(Release release, User user, String clearingTeam, ComponentService.Iface componentClient) throws TException {
    int fossologyUploadId;
    fossologyUploadId = toUnsignedInt(release.getFossologyId());
    failIf(fossologyUploadId <= 0, "release %s has an inconsistent FossologyId", release.getId());
    FossologyStatus currentStatus = fossologyUploader.getStatusInFossology(fossologyUploadId, clearingTeam);
    if (isVisible(currentStatus)) {
        updateFossologyStatus(release, user, clearingTeam, currentStatus, componentClient);
        return RequestStatus.SUCCESS;
    } else {
        return duplicateUploadFor(release, user, clearingTeam, fossologyUploadId, componentClient);
    }
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)

Example 14 with FossologyStatus

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

the class FossologyFileHandler method getReleaseAndUnlockIt.

protected Release getReleaseAndUnlockIt(String releaseId, User user, ComponentService.Iface componentClient) throws TException {
    final Release release = componentClient.getReleaseById(releaseId, user);
    assertNotNull(release, "cannot get release %s", releaseId);
    final Collection<FossologyStatus> fossologyStatuses = nullToEmptyMap(release.getClearingTeamToFossologyStatus()).values();
    if (!fossologyStatuses.isEmpty() && all(fossologyStatuses, equalTo(FossologyStatus.REJECTED))) {
        release.unsetAttachmentInFossology();
        release.unsetFossologyId();
        release.unsetClearingTeamToFossologyStatus();
        updateRelease(release, user, componentClient);
    }
    return release;
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 15 with FossologyStatus

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

the class WhenComputeClearingState method team_$_sets_fossology_status_to.

public WhenComputeClearingState team_$_sets_fossology_status_to(@Quoted String clearingTeam, @TEnumToString FossologyStatus fossologyStatus) {
    Release release = getFirstRelease();
    Map<String, FossologyStatus> clearingTeamToFossologyStatus = release.getClearingTeamToFossologyStatus();
    clearingTeamToFossologyStatus.put(clearingTeam, fossologyStatus);
    the_clearing_state_is_computed_for(lastTestedClearingTeam);
    return self();
}
Also used : TEnumToString(org.eclipse.sw360.datahandler.TEnumToString) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)14 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 Test (org.junit.Test)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 OutputStream (java.io.OutputStream)2 Map (java.util.Map)2 TEnumToString (org.eclipse.sw360.datahandler.TEnumToString)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 TException (org.apache.thrift.TException)1 CommonUtils.nullToEmptyMap (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap)1