Skip to content

Commit

Permalink
feat(rest): endpoint to get license info header text.
Browse files Browse the repository at this point in the history
Signed-off-by: Rudra Chopra <prabhuchopra@gmail.com>
  • Loading branch information
rudra-superrr committed Dec 10, 2024
1 parent 684e070 commit 3998bd8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
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 @@ -973,6 +973,20 @@ include::{snippets}/should_document_get_project_count/response-fields.adoc[]
===== Example response
include::{snippets}/should_document_get_project_count/http-response.adoc[]

[[resources-project-getprojectcount]]
==== Get license info header text

A `GET` request will get the default license info header text.

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

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

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

[[resources-project-get-summaryadministraion-project]]
==== Administration and Summary Info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,25 @@ public void getUserProjectCount(HttpServletResponse response) throws TException
}
}

@Operation(
description = "Get the default license info header text.",
tags = {"Projects"}
)
@RequestMapping(value = PROJECTS_URL + "/licenseInfoHeader", method = RequestMethod.GET)
public void getLicenseInfoheaderText(HttpServletResponse response) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
try {
response.setContentType("application/json; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String licenseHeaderText = projectService.getLicenseInfoHeaderText();
JsonObject resultJson = new JsonObject();
resultJson.addProperty("licenseInfoHeaderText", licenseHeaderText);
response.getWriter().write(resultJson.toString());
} catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}

@Operation(
description = "Get license clearing info for a project.",
tags = {"Projects"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,13 @@ public int getMyAccessibleProjectCounts(User sw360User) throws TException {
return sw360ProjectClient.getMyAccessibleProjectCounts(sw360User);
}

public String getLicenseInfoHeaderText() throws TException {
ThriftClients thriftClients = new ThriftClients();
final LicenseInfoService.Iface licenseClient = thriftClients.makeLicenseInfoClient();
String licenseInfoHeaderText = licenseClient.getDefaultLicenseInfoHeaderText(null);
return licenseInfoHeaderText;
}

/**
* Import SPDX SBOM using the method on the thrift client.
* @param user User uploading the SBOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ public void before() throws TException, IOException {
given(this.projectServiceMock.createClearingRequest(any(),any(),any(),eq(project.getId()))).willReturn(requestSummaryForCR);
given(this.projectServiceMock.loadPreferredClearingDateLimit()).willReturn(Integer.valueOf(7));

given(this.projectServiceMock.getLicenseInfoHeaderText()).willReturn("Default License Info Header Text");
given(this.projectServiceMock.importSPDX(any(),any())).willReturn(requestSummaryForSPDX);
given(this.projectServiceMock.importCycloneDX(any(),any(),any(),anyBoolean())).willReturn(requestSummaryForCycloneDX);
given(this.sw360ReportServiceMock.getDocumentName(any(), any())).willReturn(projectName);
Expand Down Expand Up @@ -2377,6 +2378,19 @@ public void should_document_get_project_count() throws Exception {
)));
}

@Test
public void should_document_get_license_info_header() throws Exception {
this.mockMvc.perform(get("/api/projects/licenseInfoHeader")
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
.accept(MediaTypes.HAL_JSON)
.contentType(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
responseFields(
fieldWithPath("licenseInfoHeaderText").description("default license info header text").optional()
)));
}

@Test
public void should_document_get_license_clearing_information() throws Exception {
this.mockMvc.perform(get("/api/projects/" + project.getId()+ "/licenseClearingCount")
Expand Down

0 comments on commit 3998bd8

Please sign in to comment.