Search in sources :

Example 1 with Iface

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface in project sw360 by eclipse.

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) {
    Iface componentClient = thriftClients.makeComponentClient();
    String releaseId = request.getParameter(RELEASE_ID);
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    try {
        Release release = componentClient.getReleaseById(releaseId, UserCacheHolder.getUserFromRequest(request));
        Set<ExternalToolProcess> fossologyProcesses = SW360Utils.getNotOutdatedExternalToolProcessesForTool(release, ExternalTool.FOSSOLOGY);
        fillJsonObjectFromFossologyProcess(jsonObject, fossologyProcesses);
        Set<Attachment> sourceAttachments = componentClient.getSourceAttachments(releaseId);
        jsonObject.put("sourceAttachments", sourceAttachments.size());
        if (sourceAttachments.size() == 1) {
            jsonObject.put("sourceAttachmentName", sourceAttachments.iterator().next().getFilename());
        }
    } catch (TException e) {
        jsonObject.put("error", "Could not determine FOSSology state for this release!");
    }
    try {
        writeJSON(request, response, jsonObject);
    } catch (IOException e) {
        log.error("Problem rendering RequestStatus", e);
    }
}
Also used : TException(org.apache.thrift.TException) Iface(org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) IOException(java.io.IOException)

Example 2 with Iface

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface in project sw360 by eclipse.

the class FossologyHandlerLocalhostIntegrationTest method prepareValidPreconditions.

// FIXME:
// test preconditions in normal test (only mocks needed, no integration):
// - more than one fossology process
// - more than one source attachment
// - new source attachment, different from existing fossology process
private void prepareValidPreconditions(User user) throws FileNotFoundException, TException {
    Attachment sourceAttachment = new Attachment("84", "commons-lang3-3.5-sources.jar");
    sourceAttachment.setAttachmentContentId("84c");
    AttachmentContent sourceAttachmentContent = new AttachmentContent("commons-lang3-3.5-sources.jar");
    InputStream attachmentInputStream = new FileInputStream("src/test/resources/commons-lang3-3.5-sources.jar");
    when(attachmentConnector.getAttachmentContent("84c")).thenReturn(sourceAttachmentContent);
    when(attachmentConnector.getAttachmentStream(Mockito.eq(sourceAttachmentContent), any(), any())).thenReturn(attachmentInputStream);
    Iface componentClient = mock(Iface.class);
    when(componentClient.getReleaseById(sharedRelease.getId(), user)).thenReturn(sharedRelease);
    when(componentClient.getSourceAttachments(sharedRelease.getId())).thenReturn(Stream.of(sourceAttachment).collect(Collectors.toSet()));
    when(thriftClients.makeComponentClient()).thenReturn(componentClient);
}
Also used : Iface(org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Example 3 with Iface

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface in project sw360 by eclipse.

the class FossologyHandler method triggerReportGenerationFossology.

@Override
public RequestStatus triggerReportGenerationFossology(String releaseId, User user) throws TException {
    Iface componentClient = thriftClients.makeComponentClient();
    Release release = componentClient.getReleaseById(releaseId, user);
    Set<ExternalToolProcess> fossologyProcesses = SW360Utils.getNotOutdatedExternalToolProcessesForTool(release, ExternalTool.FOSSOLOGY);
    if (isIllegalStateFossologyProcesses(releaseId, fossologyProcesses)) {
        return RequestStatus.FAILURE;
    }
    if (fossologyProcesses.size() == 0) {
        log.info("No FOSSology process found for release with id {}.", releaseId);
        return RequestStatus.FAILURE;
    } else if (fossologyProcesses.size() == 1) {
        ExternalToolProcess extToolProcess = fossologyProcesses.iterator().next();
        if (extToolProcess.getProcessSteps().size() > 2) {
            extToolProcess.getProcessSteps().get(extToolProcess.getProcessSteps().size() - 1).setStepStatus(ExternalToolProcessStatus.NEW);
        } else {
            log.info("Either the source of release with id {} is not yet uploaded or not yet scanned", releaseId);
            return RequestStatus.FAILURE;
        }
        handleReportStep(componentClient, release, user, extToolProcess);
        updateFossologyProcessInRelease(extToolProcess, release, user, componentClient);
        return RequestStatus.SUCCESS;
    }
    return RequestStatus.SUCCESS;
}
Also used : Iface(org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface)

Example 4 with Iface

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface in project sw360 by eclipse.

the class FossologyHandler method markFossologyProcessOutdated.

@Override
public RequestStatus markFossologyProcessOutdated(String releaseId, User user) throws TException {
    ExternalToolProcess fossologyProcess;
    Iface componentClient = thriftClients.makeComponentClient();
    Release release;
    try {
        release = componentClient.getReleaseById(releaseId, user);
        Set<ExternalToolProcess> fossologyProcesses = SW360Utils.getNotOutdatedExternalToolProcessesForTool(release, ExternalTool.FOSSOLOGY);
        if (isIllegalStateFossologyProcesses(releaseId, fossologyProcesses)) {
            return RequestStatus.FAILURE;
        }
        if (fossologyProcesses.size() == 0) {
            log.info("No FOSSology process found for release with id {}, so nothing to set to OUTDATED.", releaseId);
            return RequestStatus.SUCCESS;
        } else {
            // after illegal state check, we know exactly 1 fossology process
            fossologyProcess = fossologyProcesses.iterator().next();
            fossologyProcess.setProcessStatus(ExternalToolProcessStatus.OUTDATED);
            release.setClearingState(calculateCurrentClearingState(release, fossologyProcess));
            componentClient.updateReleaseFossology(release, user);
            return RequestStatus.SUCCESS;
        }
    } catch (TException e) {
        log.error("Could not set FOSSology process to status OUTDATED for release id " + releaseId + " because of exceptions in components backend: ", e);
        return RequestStatus.FAILURE;
    }
}
Also used : TException(org.apache.thrift.TException) Iface(org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface)

Example 5 with Iface

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface in project sw360 by eclipse.

the class FossologyHandler method process.

@Override
public ExternalToolProcess process(String releaseId, User user) throws TException {
    ExternalToolProcess fossologyProcess;
    Iface componentClient = thriftClients.makeComponentClient();
    Release release = componentClient.getReleaseById(releaseId, user);
    Set<ExternalToolProcess> fossologyProcesses = SW360Utils.getNotOutdatedExternalToolProcessesForTool(release, ExternalTool.FOSSOLOGY);
    if (isIllegalStateFossologyProcesses(releaseId, fossologyProcesses)) {
        return null;
    }
    Set<Attachment> sourceAttachments = componentClient.getSourceAttachments(release.getId());
    if (isIllegalStateSourceAttachments(releaseId, sourceAttachments)) {
        return null;
    }
    Attachment sourceAttachment = sourceAttachments.iterator().next();
    if (isIllegalStateProcessAndAttachments(fossologyProcesses, sourceAttachment)) {
        return null;
    }
    if (fossologyProcesses.size() == 0) {
        fossologyProcess = createFossologyProcess(release, user, sourceAttachment.getAttachmentContentId(), sourceAttachment.getSha1());
    } else {
        // after illegal state check, we know exactly 1 fossology process
        fossologyProcess = fossologyProcesses.iterator().next();
    }
    FossologyUtils.ensureOrderOfProcessSteps(fossologyProcess);
    ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1);
    if (FossologyUtils.FOSSOLOGY_STEP_NAME_UPLOAD.equals(furthestStep.getStepName())) {
        handleUploadStep(componentClient, release, user, fossologyProcess, sourceAttachment);
    } else if (FossologyUtils.FOSSOLOGY_STEP_NAME_SCAN.equals(furthestStep.getStepName())) {
        handleScanStep(componentClient, release, user, fossologyProcess);
    } else if (FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT.equals(furthestStep.getStepName())) {
        handleReportStep(componentClient, release, user, fossologyProcess);
    }
    updateFossologyProcessInRelease(fossologyProcess, release, user, componentClient);
    return fossologyProcess;
}
Also used : Iface(org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface)

Aggregations

Iface (org.eclipse.sw360.datahandler.thrift.components.ComponentService.Iface)6 TException (org.apache.thrift.TException)3 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)2 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 IOException (java.io.IOException)2 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)1 FossologyService (org.eclipse.sw360.datahandler.thrift.fossology.FossologyService)1 LicenseInfoRequestStatus (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoRequestStatus)1