Search in sources :

Example 11 with SW360Exception

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

the class VendorDatabaseHandler method deleteVendor.

public RequestStatus deleteVendor(String id, User user) throws SW360Exception {
    Vendor vendor = repository.get(id);
    assertNotNull(vendor);
    if (makePermission(vendor, user).isActionAllowed(RequestedAction.DELETE)) {
        repository.remove(id);
        return RequestStatus.SUCCESS;
    } else {
        log.error("User is not allowed to delete!");
        return RequestStatus.FAILURE;
    }
}
Also used : ThriftValidate.prepareVendor(org.eclipse.sw360.datahandler.thrift.ThriftValidate.prepareVendor) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 12 with SW360Exception

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

the class FossologySshConnectorTest method testRunInFossologyViaSshReturnErrorOnTimeout.

@Test
public void testRunInFossologyViaSshReturnErrorOnTimeout() throws Exception {
    doThrow(new SW360Exception()).when(fossologySshConnector).waitCompletion(channel, executionTimeout);
    final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd");
    assertThat(exitCode, lessThan(0));
    verify(jSchSessionProvider).getSession(connectionTimeout);
    verify(jSchSessionProvider).getServerString();
    // isConnected is mocked: it is disconnected twice
    verify(channel, atLeastOnce()).disconnect();
    // isConnected is mocked: it is disconnected twice
    verify(jSchSessionProvider, atLeastOnce()).closeSession(session);
}
Also used : SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 13 with SW360Exception

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

the class AbstractCLIParser method hasThisXMLRootElement.

protected <T> boolean hasThisXMLRootElement(AttachmentContent content, String rootElementNamespace, String rootElementName, User user, T context) throws TException {
    XMLInputFactory xmlif = XMLInputFactory.newFactory();
    XMLStreamReader xmlStreamReader = null;
    InputStream attachmentStream = null;
    try {
        attachmentStream = attachmentConnector.getAttachmentStream(content, user, context);
        xmlStreamReader = xmlif.createXMLStreamReader(attachmentStream);
        // skip to first element
        while (xmlStreamReader.hasNext() && xmlStreamReader.next() != XMLStreamConstants.START_ELEMENT) ;
        xmlStreamReader.require(XMLStreamConstants.START_ELEMENT, rootElementNamespace, rootElementName);
        return true;
    } catch (XMLStreamException | SW360Exception e) {
        return false;
    } finally {
        if (null != xmlStreamReader) {
            try {
                xmlStreamReader.close();
            } catch (XMLStreamException e) {
            // ignore it
            }
        }
        closeQuietly(attachmentStream, log);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 14 with SW360Exception

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

the class CLIParser method getLicenseInfos.

@Override
public <T> List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context) throws TException {
    AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment);
    LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
    LicenseInfoParsingResult result = new LicenseInfoParsingResult().setLicenseInfo(licenseInfo);
    InputStream attachmentStream = null;
    try {
        attachmentStream = attachmentConnector.getAttachmentStream(attachmentContent, user, context);
        Document doc = getDocument(attachmentStream);
        Set<String> copyrights = getCopyrights(doc);
        licenseInfo.setCopyrights(copyrights);
        Set<LicenseNameWithText> licenseNamesWithTexts = getLicenseNameWithTexts(doc);
        licenseInfo.setLicenseNamesWithTexts(licenseNamesWithTexts);
        result.setStatus(LicenseInfoRequestStatus.SUCCESS);
    } catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException | SW360Exception e) {
        log.error(e);
        result.setStatus(LicenseInfoRequestStatus.FAILURE).setMessage("Error while parsing CLI file: " + e.toString());
    } finally {
        closeQuietly(attachmentStream, log);
    }
    return Collections.singletonList(result);
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) 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) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 15 with SW360Exception

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

the class LicenseDatabaseHandler method updateLicenseFromInputLicense.

private License updateLicenseFromInputLicense(License license, License inputLicense, String businessUnit, User user) {
    if (inputLicense.isSetTodos()) {
        for (Todo todo : inputLicense.getTodos()) {
            if (isTemporaryTodo(todo)) {
                todo.unsetId();
                try {
                    String todoDatabaseId = addTodo(todo, user);
                    license.addToTodoDatabaseIds(todoDatabaseId);
                } catch (SW360Exception e) {
                    log.error("Error adding todo to database.");
                }
            } else if (todo.isSetId()) {
                Todo dbTodo = todoRepository.get(todo.id);
                if (todo.whitelist.contains(businessUnit) && !dbTodo.whitelist.contains(businessUnit)) {
                    dbTodo.addToWhitelist(businessUnit);
                    todoRepository.update(dbTodo);
                }
                if (!todo.whitelist.contains(businessUnit) && dbTodo.whitelist.contains(businessUnit)) {
                    dbTodo.whitelist.remove(businessUnit);
                    todoRepository.update(dbTodo);
                }
            }
        }
    }
    license.setText(inputLicense.getText());
    license.setFullname(inputLicense.getFullname());
    // only a new license gets its id from the shortname. Id of an existing license isn't supposed to be changed anyway
    if (!license.isSetId())
        license.setId(inputLicense.getShortname());
    license.unsetShortname();
    license.setLicenseTypeDatabaseId(inputLicense.getLicenseTypeDatabaseId());
    license.unsetLicenseType();
    license.setGPLv2Compat(Optional.ofNullable(inputLicense.getGPLv2Compat()).orElse(Ternary.UNDEFINED));
    license.setGPLv3Compat(Optional.ofNullable(inputLicense.getGPLv3Compat()).orElse(Ternary.UNDEFINED));
    license.setExternalLicenseLink(inputLicense.getExternalLicenseLink());
    return license;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

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