Search in sources :

Example 41 with SW360Exception

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

the class FossologyScriptsHandler method deployScripts.

public RequestStatus deployScripts() throws SW360Exception {
    RequestStatus status = RequestStatus.SUCCESS;
    for (String scriptFileName : SCRIPT_FILE_NAMES) {
        final InputStream inputStream = FossologyScriptsHandler.class.getResourceAsStream(SCRIPTS_FOLDER + scriptFileName);
        if (inputStream == null) {
            log.error("cannot get content of script " + scriptFileName);
            status = RequestStatus.FAILURE;
            continue;
        }
        try {
            if (!fossologyUploader.copyToFossology(scriptFileName, inputStream, true)) {
                status = RequestStatus.FAILURE;
            }
        } finally {
            closeQuietly(inputStream, log);
        }
    }
    return status;
}
Also used : InputStream(java.io.InputStream) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 42 with SW360Exception

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

the class ModerationDatabaseHandler method createRequest.

public RequestStatus createRequest(Project project, User user, Boolean isDeleteRequest) {
    Project dbproject;
    try {
        dbproject = projectDatabaseHandler.getProjectById(project.getId(), user);
    } catch (SW360Exception e) {
        log.error("Could not get original project from database. Could not generate moderation request.", e);
        return RequestStatus.FAILURE;
    }
    // Define moderators
    Set<String> moderators = getProjectModerators(dbproject);
    ModerationRequest request = createStubRequest(user, isDeleteRequest, project.getId(), moderators);
    // Set meta-data
    request.setDocumentType(DocumentType.PROJECT);
    request.setDocumentName(SW360Utils.printName(dbproject));
    // Fill the request
    ModerationRequestGenerator generator = new ProjectModerationRequestGenerator();
    request = generator.setAdditionsAndDeletions(request, project, dbproject);
    addOrUpdate(request, user);
    return RequestStatus.SENT_TO_MODERATOR;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 43 with SW360Exception

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

the class ComponentImportUtilsTest method testImportOnEmptyDb.

@Test
public void testImportOnEmptyDb() throws Exception {
    FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName);
    assertThat(componentClient.getComponentSummary(user), is(empty()));
    assertThat(componentClient.getReleaseSummary(user), is(empty()));
    ComponentImportUtils.writeToDatabase(compCSVRecords, componentClient, vendorClient, attachmentClient, user);
    assertExpectedComponentsInDb();
    final String attachmentContentId = getCreatedAttachmentContentId();
    final AttachmentContent overwriter = new AttachmentContent().setId(OVERRIDING_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
    final AttachmentContent addition = new AttachmentContent().setId(ADDITIONAL_ID).setOnlyRemote(true).setRemoteUrl(REMOTE_URL).setType(TYPE_ATTACHMENT);
    attachmentRepository.add(overwriter);
    attachmentRepository.add(addition);
    assertThat(attachmentRepository.getAll(), Matchers.hasSize(3));
    FluentIterable<ComponentAttachmentCSVRecord> compAttachmentCSVRecords = getCompAttachmentCSVRecordsFromTestFile(attachmentsFilename);
    ComponentImportUtils.writeAttachmentsToDatabase(compAttachmentCSVRecords, user, componentClient, attachmentClient);
    try {
        attachmentClient.getAttachmentContent(attachmentContentId);
        fail("Expected exception not thrown");
    } catch (Exception e) {
        assertThat(e, is(instanceOf(SW360Exception.class)));
        assertThat(((SW360Exception) e).getWhy(), is("Cannot find " + attachmentContentId + " in database."));
    }
    assertThat(attachmentRepository.getAll(), Matchers.hasSize(2));
    final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(getCreatedAttachmentContentId());
    assertThat(attachmentContent, is(overwriter));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) TException(org.apache.thrift.TException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 44 with SW360Exception

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

the class ReleaseHelper method getReleases.

List<Release> getReleases(Set<String> ids) throws SW360Exception {
    if (preloadedLinkedReleases != null) {
        return getPreloadedReleases(ids);
    }
    List<Release> releasesByIdsForExport;
    try {
        releasesByIdsForExport = cClient.getReleasesByIdsForExport(nullToEmptySet(ids));
    } catch (TException e) {
        throw new SW360Exception("Error fetching release information");
    }
    // update preload cache so that it is available on next call to this method
    setPreloadedLinkedReleases(ThriftUtils.getIdMap(releasesByIdsForExport), false);
    return releasesByIdsForExport;
}
Also used : TException(org.apache.thrift.TException) WrappedException.wrapSW360Exception(org.eclipse.sw360.datahandler.common.WrappedException.wrapSW360Exception) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) WrappedSW360Exception(org.eclipse.sw360.datahandler.common.WrappedException.WrappedSW360Exception)

Example 45 with SW360Exception

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

the class AttachmentStreamConnector method downloadRemoteAttachmentAndUpdate.

private AttachmentContent downloadRemoteAttachmentAndUpdate(AttachmentContent attachmentContent) throws SW360Exception {
    final InputStream downloadStream;
    try {
        downloadStream = attachmentContentDownloader.download(attachmentContent, downloadTimeout);
    } catch (IOException e) {
        String msg = "Cannot download attachment " + attachmentContent.getId() + " from URL";
        log.error(msg, e);
        throw new SW360Exception(msg);
    }
    uploadAttachment(attachmentContent, downloadStream);
    attachmentContent = connector.get(AttachmentContent.class, attachmentContent.getId());
    attachmentContent.setOnlyRemote(false);
    connector.update(attachmentContent);
    return attachmentContent;
}
Also used : ConcatClosingInputStream(org.eclipse.sw360.datahandler.common.ConcatClosingInputStream) PipedInputStream(java.io.PipedInputStream) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

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