Search in sources :

Example 16 with SW360Exception

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

the class LicenseDatabaseHandler method getLicenseForOrganisationWithOwnModerationRequests.

public License getLicenseForOrganisationWithOwnModerationRequests(String id, String organisation, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    License license = getLicenseForOrganisation(id, organisation);
    DocumentState documentState;
    if (moderationRequestsForDocumentId.isEmpty()) {
        documentState = CommonUtils.getOriginalDocumentState();
    } else {
        final String email = user.getEmail();
        Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
        if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
            ModerationRequest moderationRequest = moderationRequestOptional.get();
            license = moderator.updateLicenseFromModerationRequest(license, moderationRequest.getLicenseAdditions(), moderationRequest.getLicenseDeletions(), organisation);
            for (Todo todo : license.getTodos()) {
                // remove other organisations from whitelist of todo
                todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
            }
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    license.setPermissions(makePermission(license, user).getPermissionMap());
    license.setDocumentState(documentState);
    return license;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 17 with SW360Exception

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

the class CombinedCLIParser method getLicenseInfos.

@Override
public <T> List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context) throws TException {
    AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment);
    InputStream attachmentStream = null;
    List<LicenseInfoParsingResult> parsingResults = new ArrayList<>();
    Map<String, Release> releasesByExternalId = prepareReleasesByExternalId(getCorrelationKey());
    try {
        attachmentStream = attachmentConnector.getAttachmentStream(attachmentContent, user, context);
        Document doc = getDocument(attachmentStream);
        Map<String, Set<String>> copyrightSetsByExternalId = getCopyrightSetsByExternalIdsMap(doc);
        Map<String, Set<LicenseNameWithText>> licenseNamesWithTextsByExternalId = getLicenseNamesWithTextsByExternalIdsMap(doc);
        Set<String> allExternalIds = Sets.union(copyrightSetsByExternalId.keySet(), licenseNamesWithTextsByExternalId.keySet());
        allExternalIds.forEach(extId -> {
            LicenseInfoParsingResult parsingResult = getLicenseInfoParsingResultForExternalId(attachmentContent, releasesByExternalId, copyrightSetsByExternalId, licenseNamesWithTextsByExternalId, extId);
            parsingResults.add(parsingResult);
        });
    } catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException | SW360Exception e) {
        log.error(e);
        parsingResults.add(new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage("Error while parsing combined CLI file: " + e.toString()));
    } finally {
        closeQuietly(attachmentStream, log);
    }
    return parsingResults;
}
Also used : InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) Document(org.w3c.dom.Document) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Release(org.eclipse.sw360.datahandler.thrift.components.Release) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 18 with SW360Exception

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

the class FossologySshConnector method runInFossologyViaSsh.

public int runInFossologyViaSsh(String command, InputStream stdin, OutputStream stdout) {
    ChannelExec channel = null;
    Session session = null;
    int exitCode = -1;
    try {
        session = jSchSessionProvider.getSession(connectionTimeout);
        channel = (ChannelExec) session.openChannel("exec");
        channel.setOutputStream(stdout);
        channel.setInputStream(stdin);
        channel.setCommand(command);
        channel.connect(connectionTimeout);
        waitCompletion(channel, executionTimeout);
        channel.disconnect();
        exitCode = channel.getExitStatus();
    } catch (JSchException | SW360Exception | NullPointerException | ClassCastException e) {
        log.error("error executing remote command on Fossology Server " + jSchSessionProvider.getServerString(), e);
    } finally {
        if (channel != null && channel.isConnected()) {
            channel.disconnect();
        }
        jSchSessionProvider.closeSession(session);
    }
    return exitCode;
}
Also used : JSchException(com.jcraft.jsch.JSchException) ChannelExec(com.jcraft.jsch.ChannelExec) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Session(com.jcraft.jsch.Session)

Example 19 with SW360Exception

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

the class FossologyFileHandler method fillAttachment.

protected FilledAttachment fillAttachment(Attachment attachment) throws SW360Exception {
    String attachmentContentId = attachment.getAttachmentContentId();
    try {
        AttachmentContent attachmentContent = attachmentConnector.getAttachmentContent(attachmentContentId);
        assertNotNull(attachmentContent);
        return new FilledAttachment().setAttachment(attachment).setAttachmentContent(attachmentContent);
    } catch (SW360Exception e) {
        log.error("cannot retrieve attachment " + attachmentContentId, e);
        throw e;
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 20 with SW360Exception

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

the class ProjectHelper method makeRowsWithReleases.

private SubTable makeRowsWithReleases(Project project) throws SW360Exception {
    List<Release> releases = getReleases(project);
    SubTable table = new SubTable();
    if (releases.size() > 0) {
        for (Release release : releases) {
            List<String> currentRow = makeRowForProject(project);
            currentRow.addAll(releaseHelper.makeRows(release).elements.get(0));
            table.addRow(currentRow);
        }
    } else {
        List<String> projectRowWithEmptyReleaseFields = makeRowForProject(project);
        for (int i = 0; i < releaseHelper.getColumns(); i++) {
            projectRowWithEmptyReleaseFields.add("");
        }
        table.addRow(projectRowWithEmptyReleaseFields);
    }
    return table;
}
Also used : SW360Utils.fieldValueAsString(org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)23 IOException (java.io.IOException)10 InputStream (java.io.InputStream)9 TException (org.apache.thrift.TException)9 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)8 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 Test (org.junit.Test)4 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)3 SW360Utils.fieldValueAsString (org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 PipedInputStream (java.io.PipedInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ConcatClosingInputStream (org.eclipse.sw360.datahandler.common.ConcatClosingInputStream)2 WrappedSW360Exception (org.eclipse.sw360.datahandler.common.WrappedException.WrappedSW360Exception)2