Skip to content

Commit

Permalink
Merge pull request #290 from eclipse/maierthomas/#223/filename-spread…
Browse files Browse the repository at this point in the history
…sheet

chore(projects): Change the file name of export spreadsheet

review-by:alex.borodin@evosoft.com
tested-by:thomas.maier@evosoft.com
  • Loading branch information
maierthomas authored Jun 15, 2018
2 parents a700290 + 59cf17a commit c3359b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.google.common.collect.Sets;
import com.liferay.portal.kernel.portlet.PortletResponseUtil;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.Release;
Expand Down Expand Up @@ -72,8 +73,8 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
try {
VendorService.Iface client = thriftClients.makeVendorClient();
List<Vendor> vendors = client.getAllVendors();

PortletResponseUtil.sendFile(request, response, "Vendors.xlsx", exporter.makeExcelExport(vendors), CONTENT_TYPE_OPENXML_SPREADSHEET);
String filename = String.format("vendors-%s.xlsx", SW360Utils.getCreatedOn());
PortletResponseUtil.sendFile(request, response, filename, exporter.makeExcelExport(vendors), 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
List<Component> components = getFilteredComponentList(request);
ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), components, user,
extendedByReleases);
PortletResponseUtil.sendFile(request, response, "Components.xlsx", exporter.makeExcelExport(components),
String filename = String.format("components-%s.xlsx", SW360Utils.getCreatedOn());
PortletResponseUtil.sendFile(request, response, filename, exporter.makeExcelExport(components),
CONTENT_TYPE_OPENXML_SPREADSHEET);
} catch (IOException | SW360Exception e) {
log.error("An error occurred while generating the Excel export", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,22 @@ private void serveRemoveProject(ResourceRequest request, ResourceResponse respon

private void exportExcel(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);
final String projectId = request.getParameter(Project._Fields.ID.toString());
String filename = String.format("projects-%s.xlsx", SW360Utils.getCreatedOn());
try {
boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
List<Project> projects = getFilteredProjectList(request);
if (!isNullOrEmpty(projectId)) {
Project project = projects.stream().filter(p -> p.getId().equals(projectId)).findFirst().get();
filename = String.format("project-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn());
}
ProjectExporter exporter = new ProjectExporter(
thriftClients.makeComponentClient(),
thriftClients.makeProjectClient(),
user,
projects,
extendedByReleases);
PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), CONTENT_TYPE_OPENXML_SPREADSHEET);
PortletResponseUtil.sendFile(request, response, filename, 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,
Expand Down

0 comments on commit c3359b4

Please sign in to comment.