Search in sources :

Example 1 with CONTENT_TYPE_OPENXML_SPREADSHEET

use of org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET in project sw360portal by sw360.

the class ProjectPortlet 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<Project> projects = getFilteredProjectList(request);
        ProjectExporter exporter = new ProjectExporter(thriftClients.makeComponentClient(), thriftClients.makeProjectClient(), user, projects, extendedByReleases);
        PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), 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) IOException(java.io.IOException) ProjectExporter(org.eclipse.sw360.exporter.ProjectExporter)

Example 2 with CONTENT_TYPE_OPENXML_SPREADSHEET

use of org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET 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 3 with CONTENT_TYPE_OPENXML_SPREADSHEET

use of org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET in project sw360portal by sw360.

the class ProjectPortlet method exportReleasesSpreadsheet.

private void exportReleasesSpreadsheet(ResourceRequest request, ResourceResponse response) {
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        String id = request.getParameter(PROJECT_ID);
        ProjectService.Iface client = thriftClients.makeProjectClient();
        Project project = null;
        if (!isNullOrEmpty(id)) {
            project = client.getProjectById(id, user);
        }
        if (project != null) {
            List<ReleaseClearingStatusData> releaseStringMap = client.getReleaseClearingStatuses(id, user);
            List<Release> releases = releaseStringMap.stream().map(ReleaseClearingStatusData::getRelease).sorted(Comparator.comparing(SW360Utils::printFullname)).collect(Collectors.toList());
            ReleaseExporter exporter = new ReleaseExporter(thriftClients.makeComponentClient(), releases, user, releaseStringMap);
            PortletResponseUtil.sendFile(request, response, String.format("releases-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn()), exporter.makeExcelExport(releases), CONTENT_TYPE_OPENXML_SPREADSHEET);
        }
    } catch (IOException | TException 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 : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ReleaseClearingStatusData(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData) IOException(java.io.IOException) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

IOException (java.io.IOException)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 TException (org.apache.thrift.TException)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1 ReleaseClearingStatusData (org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData)1 ComponentExporter (org.eclipse.sw360.exporter.ComponentExporter)1 ProjectExporter (org.eclipse.sw360.exporter.ProjectExporter)1 ReleaseExporter (org.eclipse.sw360.exporter.ReleaseExporter)1