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 <keerthi.bl@siemens.com>
  • Loading branch information
keerthi-bl committed Dec 13, 2024
1 parent da677a6 commit fe6dc84
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,17 @@ include::{snippets}/should_document_get_project_release_with_ecc_spreadsheet/cur
===== Example response
include::{snippets}/should_document_get_project_release_with_ecc_spreadsheet/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 @@ -50,6 +50,11 @@ public class SW360ReportController implements RepresentationModelProcessor<Repos
private static final String LICENSES_RESOURCE_BUNDLE = "licenseResourceBundle";
private static final String ZIP_CONTENT_TYPE = "application/zip";
private ByteBuffer defaultByteBufferVal = null;
private static final String EXPORT_CREATE_PROJ_CLEARING_REPORT = "exportCreateProjectClearingReport";

public static final String REPORTS_URL = "/reports";

private static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

@NonNull
private final RestControllerHelper restControllerHelper;
Expand Down Expand Up @@ -102,14 +107,17 @@ public void getProjectReport(
getLicensesReports(request, response, sw360User, module, excludeReleaseVersion);
break;
case LICENSE_INFO:
getLicensesInfoReports(request, response, sw360User, module, projectId, excludeReleaseVersion);
getLicensesInfoReports(request, response, sw360User, module, projectId, excludeReleaseVersion);
break;
case LICENSES_RESOURCE_BUNDLE:
getLicenseResourceBundleReports(projectId, request, response, sw360User, module, excludeReleaseVersion);
break;
case SW360Constants.PROJECT_RELEASE_SPREADSHEET_WITH_ECCINFO:
getProjectReleaseWithEccSpreadSheet(response, sw360User, module, projectId, request, excludeReleaseVersion);
break;
case EXPORT_CREATE_PROJ_CLEARING_REPORT:
exportProjectCreateClearingRequest(request, response, sw360User, module, projectId, excludeReleaseVersion);
break;
default:
break;
}
Expand Down Expand Up @@ -171,6 +179,15 @@ private void getLicensesInfoReports(HttpServletRequest request, HttpServletRespo
}
}

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

private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest request,
HttpServletResponse response, User user, String module,
String projectId, boolean excludeReleaseVersion, ByteBuffer buffer)
Expand All @@ -191,6 +208,7 @@ private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest
buff = buffer;
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 @@ -213,6 +231,8 @@ private void downloadExcelReport(boolean withLinkedReleases, HttpServletRequest
} else if (module.equals(LICENSES_RESOURCE_BUNDLE)) {
response.setContentType(ZIP_CONTENT_TYPE);
fileName = sw360ReportService.getSourceCodeBundleName(projectId, user);
} else if(module.equals(LICENSE_INFO) || module.equals(EXPORT_CREATE_PROJ_CLEARING_REPORT)) {
fileName = sw360ReportService.getGenericLicInfoFileName(request, user);
} else if ( module.equals(SW360Constants.PROJECTS) || module.equals(SW360Constants.PROJECT_RELEASE_SPREADSHEET_WITH_ECCINFO) ) {
fileName = sw360ReportService.getDocumentName(user, projectId, module);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public void before() throws TException, IOException {
given(this.projectServiceMock.getProjectForUserById(eq(project7.getId()), any())).willReturn(project7);
given(this.projectServiceMock.getProjectForUserById(eq(project8.getId()), any())).willReturn(project8);
given(this.sw360ReportServiceMock.downloadSourceCodeBundle(any(), any(), any())).willReturn(ByteBuffer.allocate(10000));
given(this.sw360ReportServiceMock.getLicenseInfoBuffer(any(), any(), any(), any(), any(), any(), anyBoolean())).willReturn(ByteBuffer.allocate(10000));
given(this.sw360ReportServiceMock.getSourceCodeBundleName(any(), any())).willReturn("SourceCodeBundle-ProjectName");
given(this.projectServiceMock.getLicenseInfoAttachmentUsage(eq(project8.getId()))).willReturn(licenseInfoUsages);
given(this.projectServiceMock.getObligationData(eq(project8.getLinkedObligationId()), any())).willReturn(obligationLists);
Expand Down Expand Up @@ -2502,6 +2503,27 @@ public void should_document_get_project_licenseclearing_spreadsheet() throws Exc
)));
}

@Test
public void should_document_get_export_project_create_clearing_request() throws Exception{
mockMvc.perform(get("/api/reports")
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
.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(
queryParameters(
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 fe6dc84

Please sign in to comment.