Skip to content

Commit

Permalink
feat(rest) : Export Project Create Clearing Request
Browse files Browse the repository at this point in the history
Signed-off-by: Keerthi B L <[email protected]>
  • Loading branch information
keerthi-bl committed Jun 21, 2024
1 parent 6479bf0 commit 3d356fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
13 changes: 13 additions & 0 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -943,3 +943,16 @@ include::{snippets}/should_document_create_clearing_request/curl-request.adoc[]
===== Example response
include::{snippets}/should_document_create_clearing_request/http-response.adoc[]

[[resources-project-get-download-project-clearing-report]]
==== Export Create Project Clearing Report

A `GET` request is used to export Create Project Clearing Report.

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

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

===== Example response
include::{snippets}/should_document_get_export_project_create_clearing_request/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class SW360ReportController implements RepresentationModelProcessor<Repos
private static final String PROJECTS = "projects";
private static final String LICENSES = "licenses";
private static final String LICENSE_INFO = "licenseInfo";
private static final String EXPORT_CREATE_PROJ_CLEARING_REPORT = "exportCreateProjectClearingReport";

public static final String REPORTS_URL = "/reports";

Expand Down Expand Up @@ -107,6 +108,9 @@ public void getProjectReport(
case LICENSE_INFO:
getLicensesInfoReports(request, response, sw360User, module, projectId);
break;
case EXPORT_CREATE_PROJ_CLEARING_REPORT:
exportProjectCreateClearingRequest(request, response, sw360User, module, projectId);
break;
default:
break;
}
Expand Down Expand Up @@ -166,6 +170,14 @@ private void getLicensesInfoReports(HttpServletRequest request, HttpServletRespo
}
}

private void exportProjectCreateClearingRequest(HttpServletRequest request, HttpServletResponse response, User sw360User, String module, String projectId) throws TException {
try {
downloadExcelReport(false, request, response, sw360User, module, projectId);
}catch (Exception e) {
throw new TException(e.getMessage());
}
}

private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest request , HttpServletResponse response, User user, String module, String projectId)
throws TException {
try {
Expand All @@ -181,6 +193,7 @@ private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest
buffer = sw360ReportService.getLicenseBuffer();
break;
case LICENSE_INFO:
case EXPORT_CREATE_PROJ_CLEARING_REPORT:
final String generatorClassName = request.getParameter("generatorClassName");
final String variant = request.getParameter("variant");
final String template = request.getParameter("template");
Expand All @@ -199,7 +212,7 @@ private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest
fileName = String.format("licenses-%s.xlsx", SW360Utils.getCreatedOn());
} else if(module.equals(PROJECTS)) {
fileName = sw360ReportService.getDocumentName(user, projectId);
} else if(module.equals(LICENSE_INFO)) {
} else if(module.equals(LICENSE_INFO) || module.equals(EXPORT_CREATE_PROJ_CLEARING_REPORT)) {
fileName = sw360ReportService.getGenericLicInfoFileName(request, user);
}else {
fileName = sw360ReportService.getDocumentName(user, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,28 @@ public void should_document_get_project_licenseclearing_spreadsheet() throws Exc
));
}

@Test
public void should_document_get_export_project_create_clearing_request() throws Exception{
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(get("/api/reports")
.header("Authorization", "Bearer " + accessToken)
.param("module", "exportCreateProjectClearingReport")
.param("projectId", project.getId())
.param("generatorClassName", "DocxGenerator")
.param("variant", "REPORT")
.param("externalIds", "portal-id,main-project-id")
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
requestParameters(
parameterWithName("projectId").description("Id for the project."),
parameterWithName("generatorClassName").description("Projects download format. Possible values are `<DocxGenerator>`"),
parameterWithName("variant").description("The possible values for variants are `<REPORT>`"),
parameterWithName("externalIds").description("The external Ids of the project"),
parameterWithName("module").description("module possible values are `<exportCreateProjectClearingReport>`")
)));
}

@Test
public void should_document_import_cyclonedx() throws Exception {
MockMultipartFile file = new MockMultipartFile("file","file=@/sampleBOM.xml".getBytes());
Expand Down

0 comments on commit 3d356fc

Please sign in to comment.