Skip to content
This repository was archived by the owner on Jul 25, 2018. It is now read-only.

Commit 25a45b5

Browse files
authored
Merge pull request #352 from sw360/fix/singleProjectSpreadsheetExport#325
Added Download Spreadsheet button to project's Clearing Status tab review-by:[email protected] tested-by:[email protected]
2 parents 4a3ee4b + 4efad78 commit 25a45b5

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/PortalConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public class PortalConstants {
275275

276276
// Excel export
277277
public static final String EXPORT_TO_EXCEL = "export_to_excel";
278+
public static final String EXPORT_CLEARING_TO_EXCEL = "export_clearing_to_excel";
278279
public static final String EXPORT_ID = "export_id";
279280

280281
// Import Projects

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/admin/VendorPortlet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Map;
3737

3838
import static com.google.common.base.Strings.isNullOrEmpty;
39+
import static org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET;
3940
import static org.eclipse.sw360.portal.common.PortalConstants.*;
4041

4142
/**
@@ -75,7 +76,7 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
7576
VendorService.Iface client = thriftClients.makeVendorClient();
7677
List<Vendor> vendors = client.getAllVendors();
7778

78-
PortletResponseUtil.sendFile(request, response, "Vendors.xlsx", exporter.makeExcelExport(vendors), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
79+
PortletResponseUtil.sendFile(request, response, "Vendors.xlsx", exporter.makeExcelExport(vendors), CONTENT_TYPE_OPENXML_SPREADSHEET);
7980
} catch (IOException | TException e) {
8081
log.error("An error occured while generating the Excel export", e);
8182
}

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/components/ComponentPortlet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static com.google.common.base.Strings.isNullOrEmpty;
5252
import static com.google.common.base.Strings.nullToEmpty;
5353
import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList;
54+
import static org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET;
5455
import static org.eclipse.sw360.datahandler.common.SW360Utils.printName;
5556
import static org.eclipse.sw360.portal.common.PortalConstants.*;
5657
import static org.eclipse.sw360.portal.common.PortletUtils.addToMatchedByHistogram;
@@ -232,7 +233,7 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
232233
List<Component> components = getFilteredComponentList(request);
233234
ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), extendedByReleases);
234235
PortletResponseUtil.sendFile(request, response, "Components.xlsx", exporter.makeExcelExport(components),
235-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
236+
CONTENT_TYPE_OPENXML_SPREADSHEET);
236237
} catch (IOException | SW360Exception e) {
237238
log.error("An error occurred while generating the Excel export", e);
238239
}

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/licenses/LicensesPortlet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static com.google.common.base.Strings.isNullOrEmpty;
3939
import static org.eclipse.sw360.datahandler.common.CommonUtils.TMP_TODO_ID_PREFIX;
4040
import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList;
41+
import static org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET;
4142
import static org.eclipse.sw360.portal.common.PortalConstants.*;
4243

4344
/**
@@ -83,7 +84,7 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
8384
LicenseService.Iface client = thriftClients.makeLicenseClient();
8485
List<License> licenses = client.getLicenseSummaryForExport();
8586

86-
PortletResponseUtil.sendFile(request, response, "Licenses.xlsx", exporter.makeExcelExport(licenses), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
87+
PortletResponseUtil.sendFile(request, response, "Licenses.xlsx", exporter.makeExcelExport(licenses), CONTENT_TYPE_OPENXML_SPREADSHEET);
8788
} catch (IOException | TException e) {
8889
log.error("An error occurred while generating the Excel export", e);
8990
}

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.sw360.datahandler.thrift.vendors.VendorService;
4444
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.*;
4545
import org.eclipse.sw360.exporter.ProjectExporter;
46+
import org.eclipse.sw360.exporter.ReleaseExporter;
4647
import org.eclipse.sw360.portal.common.*;
4748
import org.eclipse.sw360.portal.portlets.FossologyAwarePortlet;
4849
import org.eclipse.sw360.portal.users.LifeRayUserSession;
@@ -67,6 +68,7 @@
6768
import static com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject;
6869
import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList;
6970
import static org.eclipse.sw360.datahandler.common.CommonUtils.wrapThriftOptionalReplacement;
71+
import static org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET;
7072
import static org.eclipse.sw360.datahandler.common.SW360Utils.printName;
7173
import static org.eclipse.sw360.portal.common.PortalConstants.*;
7274
import static org.eclipse.sw360.portal.common.PortletUtils.addToMatchedByHistogram;
@@ -135,6 +137,8 @@ public void serveResource(ResourceRequest request, ResourceResponse response) th
135137
updateVulnerabilityRating(request, response);
136138
} else if (PortalConstants.EXPORT_TO_EXCEL.equals(action)) {
137139
exportExcel(request, response);
140+
} else if (PortalConstants.EXPORT_CLEARING_TO_EXCEL.equals(action)) {
141+
exportReleasesSpreadsheet(request, response);
138142
} else if (PortalConstants.DOWNLOAD_LICENSE_INFO.equals(action)) {
139143
downloadLicenseInfo(request, response);
140144
} else if (PortalConstants.DOWNLOAD_SOURCE_CODE_BUNDLE.equals(action)) {
@@ -256,12 +260,33 @@ private void exportExcel(ResourceRequest request, ResourceResponse response) {
256260
thriftClients.makeProjectClient(),
257261
user,
258262
extendedByReleases);
259-
PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
263+
PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), CONTENT_TYPE_OPENXML_SPREADSHEET);
260264
} catch (IOException | SW360Exception e) {
261265
log.error("An error occurred while generating the Excel export", e);
262266
}
263267
}
264268

269+
private void exportReleasesSpreadsheet(ResourceRequest request, ResourceResponse response) {
270+
final User user = UserCacheHolder.getUserFromRequest(request);
271+
try {
272+
String id = request.getParameter(PROJECT_ID);
273+
Project project = null;
274+
if (!isNullOrEmpty(id)) {
275+
project = thriftClients.makeProjectClient().getProjectById(id, user);
276+
}
277+
if (project != null) {
278+
Map<Release, String> releaseStringMap = getReleaseStringMap(id, user);
279+
List<Release> releases = releaseStringMap.keySet().stream().sorted(Comparator.comparing(SW360Utils::printFullname)).collect(Collectors.toList());
280+
ReleaseExporter exporter = new ReleaseExporter(thriftClients.makeComponentClient());
281+
PortletResponseUtil.sendFile(request, response,
282+
String.format("releases-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn()),
283+
exporter.makeExcelExport(releases), CONTENT_TYPE_OPENXML_SPREADSHEET);
284+
}
285+
} catch (IOException | TException e) {
286+
log.error("An error occurred while generating the Excel export", e);
287+
}
288+
}
289+
265290
private RequestStatus removeProject(PortletRequest request) {
266291
String projectId = request.getParameter(PortalConstants.PROJECT_ID);
267292
final User user = UserCacheHolder.getUserFromRequest(request);

frontend/sw360-portlet/src/main/webapp/html/projects/includes/projects/clearingStatus.jspf

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
</tr>
3131
</tfoot>
3232
</table>
33+
<core_rt:if test="${inProjectDetailsContext}">
34+
<div class="clear-float"></div>
35+
<span class="pull-right">
36+
<input type="button" class="addButton" id="exportReleasesSpreadsheetButton" value="Export Spreadsheet" class="addButton" onclick="exportReleasesSpreadsheet()"/>
37+
</span>
38+
</core_rt:if>
3339
</div>
3440
</core_rt:if>
3541

@@ -77,6 +83,13 @@
7783

7884
}
7985

86+
function exportReleasesSpreadsheet() {
87+
var portletURL = Liferay.PortletURL.createURL('<%= PortletURLFactoryUtil.create(request, portletDisplay.getId(), themeDisplay.getPlid(), PortletRequest.RESOURCE_PHASE) %>')
88+
.setParameter('<%=PortalConstants.ACTION%>', '<%=PortalConstants.EXPORT_CLEARING_TO_EXCEL%>');
89+
portletURL.setParameter('<%=PortalConstants.PROJECT_ID%>','${project.id}');
90+
window.location.href = portletURL.toString();
91+
}
92+
8093
//This can not be document ready function as liferay definitions need to be loaded first
8194
$(window).load(function () {
8295
createClearingTable();

libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class SW360Constants {
6666

6767
public static final Collection<AttachmentType> LICENSE_INFO_ATTACHMENT_TYPES = Arrays.asList(AttachmentType.COMPONENT_LICENSE_INFO_XML, AttachmentType.COMPONENT_LICENSE_INFO_COMBINED);
6868
public static final Collection<AttachmentType> SOURCE_CODE_ATTACHMENT_TYPES = Arrays.asList(AttachmentType.SOURCE, AttachmentType.SOURCE_SELF);
69+
public static final String CONTENT_TYPE_OPENXML_SPREADSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
6970

7071
public static Collection<AttachmentType> allowedAttachmentTypes(String documentType) {
7172
Set<AttachmentType> types = newHashSet(AttachmentType.values());

0 commit comments

Comments
 (0)