Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#1902 from siemens/fix/myprojects
Browse files Browse the repository at this point in the history
feat(rest): New end point for downloading project reports.

Reviewed by: [email protected]
Tested by: [email protected]
  • Loading branch information
ag4ums authored and keerthi-bl committed Jun 27, 2023
2 parents 823f6fd + 032c765 commit ddf974b
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService;
import org.eclipse.sw360.exporter.ComponentExporter;
import org.eclipse.sw360.exporter.ProjectExporter;
import org.eclipse.sw360.mail.MailConstants;
import org.eclipse.sw360.mail.MailUtil;
import org.apache.logging.log4j.Logger;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.thrift.TException;
Expand All @@ -69,6 +72,7 @@
import org.spdx.library.InvalidSPDXAnalysisException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
Expand Down Expand Up @@ -2832,4 +2836,44 @@ public Map<String, String> getReleasesName(String releases) {
}
return releaseNames;
}

public String getComponentReportInEmail(User user,boolean extendedByReleases) throws TException {
try {
List<Component> componentlist = getRecentComponentsSummary(-1, user);
ComponentExporter exporter = getComponentExporterObject(componentlist,user, extendedByReleases);
return exporter.makeExcelExportForProject(componentlist, user);
}catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}

private ComponentExporter getComponentExporterObject(List<Component> componentList ,User user,
boolean extendedByRelease) throws SW360Exception {
ThriftClients thriftClients = new ThriftClients();
return new ComponentExporter(thriftClients.makeComponentClient(), componentList, user,extendedByRelease);
}

public ByteBuffer downloadExcel(User user,boolean extendedByReleases,String token) throws SW360Exception {
try {
ThriftClients thriftClients = new ThriftClients();
ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), user,
extendedByReleases);
InputStream stream = exporter.downloadExcelSheet(token);
return ByteBuffer.wrap(IOUtils.toByteArray(stream));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public ByteBuffer getComponentReportDataStream(User user, boolean extendedByReleases) throws TException{
try {
List<Component> componentlist = getRecentComponentsSummary(-1, user);
ComponentExporter exporter = getComponentExporterObject(componentlist, user, extendedByReleases);
InputStream stream = exporter.makeExcelExport(componentlist);
return ByteBuffer.wrap(IOUtils.toByteArray(stream));
}catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
import static org.eclipse.sw360.datahandler.common.SW360Utils.printName;
import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException;
import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission;
import org.apache.commons.io.IOUtils;
import org.eclipse.sw360.exporter.ProjectExporter;
import java.nio.ByteBuffer;

/**
* Class for accessing the CouchDB database
Expand All @@ -85,6 +88,7 @@
*/
public class ProjectDatabaseHandler extends AttachmentAwareDatabaseHandler {

private static final String PROJECTS = "projects";
private static final Logger log = LogManager.getLogger(ProjectDatabaseHandler.class);
private static final int DELETION_SANITY_CHECK_THRESHOLD = 5;
private static final String DUMMY_NEW_PROJECT_ID = "newproject";
Expand Down Expand Up @@ -1907,4 +1911,44 @@ public ProjectData searchByTag(String tag, User user) {
public ProjectData searchByType(String type, User user) {
return repository.searchByType(type, user);
}

public ByteBuffer getReportDataStream(User user, boolean extendedByReleases) throws TException {
try {
List<Project> documents = getAccessibleProjectsSummary(user);
ProjectExporter exporter = getProjectExporterObject(documents, user, extendedByReleases);
InputStream stream = exporter.makeExcelExport(documents);
return ByteBuffer.wrap(IOUtils.toByteArray(stream));
}catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}

private ProjectExporter getProjectExporterObject(List<Project> documents, User user, boolean extendedByReleases) throws SW360Exception {
ThriftClients thriftClients = new ThriftClients();
return new ProjectExporter(thriftClients.makeComponentClient(),
thriftClients.makeProjectClient(), user, documents, extendedByReleases);
}

public String getReportInEmail(User user,
boolean extendedByReleases) throws TException {
try {
List<Project> documents = getAccessibleProjectsSummary(user);
ProjectExporter exporter = getProjectExporterObject(documents, user, extendedByReleases);
return exporter.makeExcelExportForProject(documents, user);
}catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}

public ByteBuffer downloadExcel(User user, boolean extendedByReleases, String token) throws SW360Exception {
ThriftClients thriftClients = new ThriftClients();
ProjectExporter exporter = new ProjectExporter(thriftClients.makeComponentClient(),
thriftClients.makeProjectClient(), user, extendedByReleases);
try {
InputStream stream = exporter.downloadExcelSheet(token);
return ByteBuffer.wrap(IOUtils.toByteArray(stream));
} catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package org.eclipse.sw360.datahandler.db;

import org.apache.thrift.TException;
import org.eclipse.sw360.components.summary.ProjectSummary;
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
Expand All @@ -19,8 +20,10 @@
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
import org.eclipse.sw360.datahandler.permissions.ProjectPermissions;
import org.eclipse.sw360.datahandler.thrift.PaginationData;
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectData;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectService;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.cloudant.client.api.CloudantClient;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -717,4 +718,19 @@ public Map<PaginationData, List<Component>> getRecentComponentsSummaryWithPagina
public void sendExportSpreadsheetSuccessMail(String url, String recepient) throws TException {
handler.sendExportSpreadsheetSuccessMail(url, recepient);
}

@Override
public ByteBuffer downloadExcel(User user, boolean extendedByReleases, String token) throws TException {
return handler.downloadExcel(user,extendedByReleases,token);
}

@Override
public ByteBuffer getComponentReportDataStream(User user, boolean extendedByReleases) throws TException {
return handler.getComponentReportDataStream(user,extendedByReleases);
}

@Override
public String getComponentReportInEmail(User user, boolean extendedByReleases) throws TException {
return handler.getComponentReportInEmail(user,extendedByReleases);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.function.Supplier;

import static org.eclipse.sw360.datahandler.common.SW360Assert.*;
import java.nio.ByteBuffer;

/**
* Implementation of the Thrift service
Expand Down Expand Up @@ -462,4 +463,22 @@ public int getMyAccessibleProjectCounts(User user) throws TException {
public void sendExportSpreadsheetSuccessMail(String url, String recepient) throws TException {
handler.sendExportSpreadsheetSuccessMail(url, recepient);
}

@Override
public ByteBuffer downloadExcel(User user, boolean extendedByReleases, String token)
throws TException {
return handler.downloadExcel(user, extendedByReleases,token);
}

@Override
public ByteBuffer getReportDataStream(User user, boolean extendedByReleases)
throws TException {
return handler.getReportDataStream(user, extendedByReleases);
}

@Override
public String getReportInEmail(User user, boolean extendedByReleases)
throws TException {
return handler.getReportInEmail(user, extendedByReleases);
}
}
12 changes: 12 additions & 0 deletions libraries/datahandler/src/main/thrift/components.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,16 @@ service ComponentService {
* Send email to the user once spreadsheet export completed
*/
void sendExportSpreadsheetSuccessMail(1: string url, 2: string userEmail);
/*
* download api
*/
binary downloadExcel(1:User user,2:bool extendedByReleases,3:string token) throws (1: SW360Exception exp);
/*
* get report data stream
*/
binary getComponentReportDataStream(1: User user, 2: bool extendedByReleases) throws (1: SW360Exception exp);
/*
* get component report in mail
*/
string getComponentReportInEmail(1: User user, 2: bool extendedByReleases) throws (1: SW360Exception exp);
}
12 changes: 12 additions & 0 deletions libraries/datahandler/src/main/thrift/projects.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,16 @@ service ProjectService {
* Send email to the user once spreadsheet export completed
*/
void sendExportSpreadsheetSuccessMail(1: string url, 2: string userEmail);
/*
* make excel export
*/
binary getReportDataStream(1: User user,2: bool extendedByReleases) throws (1: SW360Exception exp);
/*
* excel export - return the filepath
*/
string getReportInEmail(1: User user, 2: bool extendedByReleases) throws (1: SW360Exception exp);
/*
* download excel
*/
binary downloadExcel(1:User user,2:bool extendedByReleases,3:string token) throws (1: SW360Exception exc);
}
32 changes: 32 additions & 0 deletions rest/resource-server/src/docs/asciidoc/components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ include::{snippets}/should_document_get_mycomponents_components/http-response.ad
===== Links
include::{snippets}/should_document_get_mycomponents_components/links.adoc[]

<<<<<<< HEAD
[[resources-component-get-component-vulnerabilities]]
==== Listing component vulnerabilities

Expand Down Expand Up @@ -491,3 +492,34 @@ include::{snippets}/should_document_import_sbom_for_component/curl-request.adoc[

===== Example response
include::{snippets}/should_document_import_sbom_for_component/http-response.adoc[]

[[resources-components-download-report]]
==== Downloading component report

A `GET` request help to download the components report.

===== Request parameter
include::{snippets}/should_document_get_component_report/request-parameters.adoc[]

===== Example request
include::{snippets}/should_document_get_component_report/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_component_report/http-response.adoc[]

[[resources-components-download-report-mail_req]]
==== Downloading component report with mail request

A `GET` request help to download the components report with mail request.

===== Request parameter
include::{snippets}/should_document_get_component_report_with_mail_req/request-parameters.adoc[]

===== Response structure
include::{snippets}/should_document_get_component_report_with_mail_req/response-fields.adoc[]

===== Example request
include::{snippets}/should_document_get_component_report_with_mail_req/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_component_report_with_mail_req/http-response.adoc[]
33 changes: 32 additions & 1 deletion rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,35 @@ include::{snippets}/should_document_create_summary_administration/response-field
include::{snippets}/should_document_create_summary_administration/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_create_summary_administration/http-response.adoc[]
include::{snippets}/should_document_create_summary_administration/http-response.adoc[]

[[resources-projects-download-report]]
==== Downloading project report

A `GET` request help to download the projects report with mail request false.

===== Request parameter
include::{snippets}/should_document_get_project_report_without_mail_req/request-parameters.adoc[]

===== Example request
include::{snippets}/should_document_get_project_report_without_mail_req/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_project_report_without_mail_req/http-response.adoc[]

[[resources-projects-download-report-mail-request]]
==== Downloading project report with mail request

A `GET` request help to download the projects report with mail request true.

===== Request parameter
include::{snippets}/should_document_get_project_report/request-parameters.adoc[]

===== Response structure
include::{snippets}/should_document_get_project_report/response-fields.adoc[]

===== Example request
include::{snippets}/should_document_get_project_report/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_project_report/http-response.adoc[]
Loading

0 comments on commit ddf974b

Please sign in to comment.