Search in sources :

Example 6 with SW360Exception

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

the class ComponentPortlet method exportExcel.

private void exportExcel(ResourceRequest request, ResourceResponse response) {
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
        List<Component> components = getFilteredComponentList(request);
        ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), components, user, extendedByReleases);
        PortletResponseUtil.sendFile(request, response, "Components.xlsx", exporter.makeExcelExport(components), CONTENT_TYPE_OPENXML_SPREADSHEET);
    } catch (IOException | SW360Exception e) {
        log.error("An error occurred while generating the Excel export", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentExporter(org.eclipse.sw360.exporter.ComponentExporter) IOException(java.io.IOException)

Example 7 with SW360Exception

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

the class ModerationDatabaseHandler method createRequest.

public RequestStatus createRequest(Component component, User user, Boolean isDeleteRequest) {
    Component dbcomponent;
    try {
        dbcomponent = componentDatabaseHandler.getComponent(component.getId(), user);
    } catch (SW360Exception e) {
        log.error("Could not get original component from database. Could not generate moderation request.", e);
        return RequestStatus.FAILURE;
    }
    // Define moderators
    Set<String> moderators = new HashSet<>();
    CommonUtils.add(moderators, dbcomponent.getCreatedBy());
    try {
        String department = getDepartmentByUserEmail(component.getCreatedBy());
        CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.CLEARING_ADMIN, department));
    } catch (TException e) {
        log.error("Could not get user from database. Clearing admins not added as moderators, since department is missing.");
    }
    CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.ADMIN));
    ModerationRequest request = createStubRequest(user, isDeleteRequest, component.getId(), moderators);
    // Set meta-data
    request.setDocumentType(DocumentType.COMPONENT);
    request.setDocumentName(SW360Utils.printName(dbcomponent));
    // Fill the request
    ModerationRequestGenerator generator = new ComponentModerationRequestGenerator();
    request = generator.setAdditionsAndDeletions(request, component, dbcomponent);
    if (component.isSetComponentType()) {
        request.setComponentType(component.getComponentType());
    }
    addOrUpdate(request, user);
    return RequestStatus.SENT_TO_MODERATOR;
}
Also used : TException(org.apache.thrift.TException) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) Component(org.eclipse.sw360.datahandler.thrift.components.Component) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 8 with SW360Exception

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

the class ModerationDatabaseHandler method createRequest.

public RequestStatus createRequest(Release release, User user, Boolean isDeleteRequest, Function<Release, Set<String>> moderatorsProvider) {
    Release dbrelease;
    try {
        dbrelease = componentDatabaseHandler.getRelease(release.getId(), user);
    } catch (SW360Exception e) {
        log.error("Could not get original release from database. Could not generate moderation request.", e);
        return RequestStatus.FAILURE;
    }
    Set<String> moderators = moderatorsProvider.apply(dbrelease);
    ModerationRequest request = createStubRequest(user, isDeleteRequest, release.getId(), moderators);
    // Set meta-data
    request.setDocumentType(DocumentType.RELEASE);
    request.setDocumentName(SW360Utils.printName(dbrelease));
    // Fill the rest
    SW360Utils.setVendorId(release);
    SW360Utils.setVendorId(dbrelease);
    ModerationRequestGenerator generator = new ReleaseModerationRequestGenerator();
    request = generator.setAdditionsAndDeletions(request, release, dbrelease);
    try {
        Component parentComponent = componentDatabaseHandler.getComponent(release.getComponentId(), user);
        request.setComponentType(parentComponent.getComponentType());
    } catch (SW360Exception e) {
        log.error("Could not retrieve parent component type of release with ID=" + release.getId());
    }
    addOrUpdate(request, user);
    return RequestStatus.SENT_TO_MODERATOR;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 9 with SW360Exception

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

the class ModerationDatabaseHandler method createRequest.

public RequestStatus createRequest(License license, User user) {
    License dblicense;
    try {
        dblicense = licenseDatabaseHandler.getLicenseForOrganisation(license.getId(), user.getDepartment());
    } catch (SW360Exception e) {
        log.error("Could not get original license from database. Could not generate moderation request.", e);
        return RequestStatus.FAILURE;
    }
    // Define moderators
    Set<String> moderators = getLicenseModerators(user.getDepartment());
    ModerationRequest request = createStubRequest(user, false, license.getId(), moderators);
    // Set meta-data
    request.setDocumentType(DocumentType.LICENSE);
    request.setDocumentName(SW360Utils.printName(license));
    // Fill the request
    ModerationRequestGenerator generator = new LicenseModerationRequestGenerator();
    request = generator.setAdditionsAndDeletions(request, license, dblicense);
    addOrUpdate(request, user);
    return RequestStatus.SENT_TO_MODERATOR;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) License(org.eclipse.sw360.datahandler.thrift.licenses.License) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 10 with SW360Exception

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

the class RemoteAttachmentDownloader method retrieveRemoteAttachments.

public static int retrieveRemoteAttachments(Supplier<HttpClient> httpClient, String dbAttachments, Duration downloadTimeout) throws MalformedURLException {
    AttachmentConnector attachmentConnector = new AttachmentConnector(httpClient, dbAttachments, downloadTimeout);
    AttachmentRepository attachmentRepository = new AttachmentRepository(new DatabaseConnector(httpClient, dbAttachments));
    List<AttachmentContent> remoteAttachments = attachmentRepository.getOnlyRemoteAttachments();
    log.info(format("we have %d remote attachments to retrieve", remoteAttachments.size()));
    int count = 0;
    for (AttachmentContent attachmentContent : remoteAttachments) {
        if (!attachmentContent.isOnlyRemote()) {
            log.info(format("skipping attachment (%s), which should already be available", attachmentContent.getId()));
            continue;
        }
        String attachmentContentId = attachmentContent.getId();
        log.info(format("retrieving attachment (%s) {filename=%s}", attachmentContentId, attachmentContent.getFilename()));
        log.debug("url is " + attachmentContent.getRemoteUrl());
        InputStream content = null;
        try {
            content = attachmentConnector.unsafeGetAttachmentStream(attachmentContent);
            if (content == null) {
                log.error("null content retrieving attachment " + attachmentContentId);
                continue;
            }
            try {
                long length = length(content);
                log.info(format("retrieved attachment (%s), it was %d bytes long", attachmentContentId, length));
                count++;
            } catch (IOException e) {
                log.error("attachment was downloaded but somehow not available in database " + attachmentContentId, e);
            }
        } catch (SW360Exception e) {
            log.error("cannot retrieve attachment " + attachmentContentId, e);
        } finally {
            closeQuietly(content, log);
        }
    }
    return count;
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector) 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