Skip to content

Commit

Permalink
feat(rest): endpoint to get list of obligations depending upon obliga…
Browse files Browse the repository at this point in the history
…tion level.

Signed-off-by: Rudra Chopra <prabhuchopra@gmail.com>
  • Loading branch information
rudra-superrr committed Sep 12, 2024
1 parent 8cceaae commit 1085858
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 15 deletions.
17 changes: 17 additions & 0 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,23 @@ include::{snippets}/should_document_get_license_obligations/curl-request.adoc[]
===== Example response
include::{snippets}/should_document_get_license_obligations/http-response.adoc[]

[[resources-project-get-project-page-obligations-information]]
==== List project page obligations

A `GET` request will list obligations of a project depending upon the type of obigation level.

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

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

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

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

[[resources-projects-create]]
==== Creating a project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ private Map<String, Object> createPaginationMetadata(Pageable pageable, Map<Stri
);
Map<String, Object> responseBody = new HashMap<>();
responseBody.put("page", pagination);
responseBody.put("licenseObligations", paginatedMap);
responseBody.put("obligations", paginatedMap);
return responseBody;
}

Expand Down Expand Up @@ -2488,6 +2488,61 @@ public ResponseEntity<HalResource> getLicenseObligations(Pageable pageable,
return new ResponseEntity<>(halObligation, HttpStatus.OK);
}

@Operation(
description = "Get obligation data of project tab.",
tags = {"Project"}
)
@RequestMapping(value = PROJECTS_URL + "/{id}/obligation", method = RequestMethod.GET)
public ResponseEntity<HalResource> getObligations(Pageable pageable,
@Parameter(description = "Project ID.") @PathVariable("id") String id,
@Parameter(description = "Obligation Level")
@RequestParam(value = "obligationLevel", required = true) String OblLevel)
throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication();
final Project sw360Project = projectService.getProjectForUserById(id, sw360User);
final Map<String, String> releaseIdToAcceptedCLI = Maps.newHashMap();
List<Release> releases = new ArrayList<>();;
ObligationList obligation = new ObligationList();
Map<String, ObligationStatusInfo> obligationStatusMap = Maps.newHashMap();
Map<String, ObligationStatusInfo> oblData = Maps.newHashMap();
Map<String, ObligationStatusInfo> filterData = Maps.newHashMap();

List<String> releaseIds = new ArrayList<>(sw360Project.getReleaseIdToUsage().keySet());
for (final String releaseId : releaseIds) {
Release sw360Release = releaseService.getReleaseForUserById(releaseId, sw360User);
if (sw360Release.getAttachmentsSize() > 0) {
releases.add(sw360Release);
}
}
if (CommonUtils.isNotNullEmptyOrWhitespace(sw360Project.getLinkedObligationId())) {
obligation = projectService.getObligationData(sw360Project.getLinkedObligationId(), sw360User);
obligationStatusMap = CommonUtils.nullToEmptyMap(obligation.getLinkedObligationStatus());
oblData = projectService.setObligationsFromAdminSection(sw360User, obligationStatusMap, sw360Project, OblLevel);
} else {
oblData = projectService.setObligationsFromAdminSection(sw360User, new HashMap(), sw360Project, OblLevel);
}

if (OblLevel.equalsIgnoreCase("License")) {
for (Map.Entry<String, ObligationStatusInfo> entry : obligationStatusMap.entrySet()) {
String key = entry.getKey();
if (!key.equals("compObl") && !key.equals("projectObl") && !key.equals("orgObl")) {
filterData.put(key, entry.getValue());
}
}
releaseIdToAcceptedCLI.putAll(SW360Utils.getReleaseIdtoAcceptedCLIMappings(filterData));
oblData = projectService.setLicenseInfoWithObligations(filterData, releaseIdToAcceptedCLI, releases, sw360User);
for (Map.Entry<String, ObligationStatusInfo> entry : oblData.entrySet()) {
ObligationStatusInfo statusInfo = entry.getValue();
Set<Release> limitedSet = releaseService.getReleasesForUserByIds(statusInfo.getReleaseIdToAcceptedCLI().keySet());
statusInfo.setReleases(limitedSet);
}
}

Map<String, Object> responseBody = createPaginationMetadata(pageable, oblData);
HalResource<Map<String, Object>> halObligation = new HalResource<>(responseBody);
return new ResponseEntity<>(halObligation, HttpStatus.OK);
}

@PreAuthorize("hasAuthority('WRITE')")
@Operation(
summary = "Add licenseObligations from license DB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
import org.eclipse.sw360.datahandler.thrift.licenses.Obligation;
import org.eclipse.sw360.datahandler.thrift.licenses.ObligationLevel;
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest;
import org.eclipse.sw360.datahandler.thrift.PaginationData;
import org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship;
Expand Down Expand Up @@ -437,6 +439,28 @@ public ObligationList getObligationData(String linkedObligationId, User user) th
return sw360ProjectClient.getLinkedObligations(linkedObligationId, user);
}

public Map<String, ObligationStatusInfo> setObligationsFromAdminSection(User user, Map<String, ObligationStatusInfo> obligationStatusMap,
Project project, String OblLevel) throws TException {
List<Obligation> obligations = SW360Utils.getObligations();
Map<String, ObligationStatusInfo> updatedObligationStatusMap = Maps.newHashMap();
ThriftClients thriftClients = new ThriftClients();
ComponentService.Iface componentClient = thriftClients.makeComponentClient();

if (OblLevel.equalsIgnoreCase("Project")) {
updatedObligationStatusMap = SW360Utils.getProjectComponentOrganisationLicenseObligationToDisplay(
obligationStatusMap, obligations, ObligationLevel.PROJECT_OBLIGATION, true);
return updatedObligationStatusMap;
} else if (OblLevel.equalsIgnoreCase("Organization")) {
updatedObligationStatusMap = SW360Utils.getProjectComponentOrganisationLicenseObligationToDisplay(
obligationStatusMap, obligations, ObligationLevel.ORGANISATION_OBLIGATION, true);
return updatedObligationStatusMap;
} else if (OblLevel.equalsIgnoreCase("Component")) {
updatedObligationStatusMap = SW360Utils.getProjectComponentOrganisationLicenseObligationToDisplay(
obligationStatusMap, obligations, ObligationLevel.COMPONENT_OBLIGATION, true);
return updatedObligationStatusMap;
} return updatedObligationStatusMap;
}

public Map<String, ObligationStatusInfo> setLicenseInfoWithObligations(Map<String, ObligationStatusInfo> obligationStatusMap, Map<String, String> releaseIdToAcceptedCLI,
List<Release> releases, User user) {

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public void before() throws TException, IOException {
osi.setStatus(ObligationStatus.OPEN);
osi.setObligationType(obligation.getObligationType());
Map<String, ObligationStatusInfo> obligationStatusMap = Map.of(obligation.getTitle(), osi);
Map<String, ObligationStatusInfo> obligationStatusMapFromAdminSection = new HashMap<>();

ObligationList obligationLists = new ObligationList();
obligationLists.setProjectId(project8.getId());
Expand Down Expand Up @@ -563,6 +564,7 @@ public void before() throws TException, IOException {
given(this.projectServiceMock.getProjectForUserById(eq(project8.getId()), any())).willReturn(project8);
given(this.projectServiceMock.getLicenseInfoAttachmentUsage(eq(project8.getId()))).willReturn(licenseInfoUsages);
given(this.projectServiceMock.getObligationData(eq(project8.getLinkedObligationId()), any())).willReturn(obligationLists);
given(this.projectServiceMock.setObligationsFromAdminSection(any(), any(), any(), any())).willReturn(obligationStatusMapFromAdminSection);
given(this.projectServiceMock.setLicenseInfoWithObligations(eq(obligationStatusMap), eq(releaseIdToAcceptedCLI), any(), any())).willReturn(obligationStatusMap);
given(this.projectServiceMock.getLicensesFromAttachmentUsage(eq(licenseInfoUsages), any())).willReturn(licensesFromAttachmentUsage);
given(this.projectServiceMock.getLicenseObligationData(eq(licensesFromAttachmentUsage), any())).willReturn(obligationStatusMap);
Expand Down Expand Up @@ -876,12 +878,12 @@ public void should_document_get_obligations_from_license_db() throws Exception {
parameterWithName("page_entries").description("Amount of projects per page")
),
responseFields(
subsectionWithPath("licenseObligations.obligation_title").description("Title of license obligation"),
subsectionWithPath("licenseObligations.obligation_title.text").description("Text of license obligation"),
subsectionWithPath("licenseObligations.obligation_title.licenseIds[]").description("List of licenseIds"),
subsectionWithPath("licenseObligations.obligation_title.id").description("Id of the obligation"),
subsectionWithPath("licenseObligations.obligation_title.releaseIdToAcceptedCLI").description("Releases having accepted attachments"),
subsectionWithPath("licenseObligations.obligation_title.obligationType").description("Type of the obligation"),
subsectionWithPath("obligations.obligation_title").description("Title of license obligation"),
subsectionWithPath("obligations.obligation_title.text").description("Text of license obligation"),
subsectionWithPath("obligations.obligation_title.licenseIds[]").description("List of licenseIds"),
subsectionWithPath("obligations.obligation_title.id").description("Id of the obligation"),
subsectionWithPath("obligations.obligation_title.releaseIdToAcceptedCLI").description("Releases having accepted attachments"),
subsectionWithPath("obligations.obligation_title.obligationType").description("Type of the obligation"),
fieldWithPath("page").description("Additional paging information"),
fieldWithPath("page.size").description("Number of obligations per page"),
fieldWithPath("page.totalElements").description("Total number of all license obligations"),
Expand Down Expand Up @@ -1126,14 +1128,46 @@ public void should_document_get_license_obligations() throws Exception {
parameterWithName("page_entries").description("Amount of projects per page")
),
responseFields(
subsectionWithPath("licenseObligations.obligation_title").description("Title of license obligation"),
subsectionWithPath("licenseObligations.obligation_title.text").description("Text of license obligation"),
subsectionWithPath("licenseObligations.obligation_title.releaseIdToAcceptedCLI").description("Release Ids having accepted attachments"),
subsectionWithPath("licenseObligations.obligation_title.licenseIds[]").description("List of licenseIds"),
subsectionWithPath("licenseObligations.obligation_title.comment").description("Comment on the obligation"),
subsectionWithPath("licenseObligations.obligation_title.status").description("Status of the obligation"),
subsectionWithPath("licenseObligations.obligation_title.id").description("Id of the obligation"),
subsectionWithPath("licenseObligations.obligation_title.obligationType").description("Type of the obligation"),
subsectionWithPath("obligations.obligation_title").description("Title of license obligation"),
subsectionWithPath("obligations.obligation_title.text").description("Text of license obligation"),
subsectionWithPath("obligations.obligation_title.releaseIdToAcceptedCLI").description("Release Ids having accepted attachments"),
subsectionWithPath("obligations.obligation_title.licenseIds[]").description("List of licenseIds"),
subsectionWithPath("obligations.obligation_title.comment").description("Comment on the obligation"),
subsectionWithPath("obligations.obligation_title.status").description("Status of the obligation"),
subsectionWithPath("obligations.obligation_title.id").description("Id of the obligation"),
subsectionWithPath("obligations.obligation_title.obligationType").description("Type of the obligation"),
fieldWithPath("page").description("Additional paging information"),
fieldWithPath("page.size").description("Number of obligations per page"),
fieldWithPath("page.totalElements").description("Total number of all license obligations"),
fieldWithPath("page.totalPages").description("Total number of pages"),
fieldWithPath("page.number").description("Number of the current page")
)));
}

@Test
public void should_document_get_project_page_obligations() throws Exception {
mockMvc.perform(get("/api/projects/" + project8.getId() + "/obligation")
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
.param("obligationLevel", "License")
.param("page", "0")
.param("page_entries", "5")
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
requestParameters(
parameterWithName("obligationLevel").description("Possible values are: [LICENSE, PROJECT, COMPONENT or ORGANIZATION]"),
parameterWithName("page").description("Page of projects"),
parameterWithName("page_entries").description("Amount of projects per page")
),
responseFields(
subsectionWithPath("obligations.obligation_title").description("Title of license obligation"),
subsectionWithPath("obligations.obligation_title.text").description("Text of license obligation"),
subsectionWithPath("obligations.obligation_title.releaseIdToAcceptedCLI").description("Release Ids having accepted attachments"),
subsectionWithPath("obligations.obligation_title.licenseIds[]").description("List of licenseIds"),
subsectionWithPath("obligations.obligation_title.comment").description("Comment on the obligation"),
subsectionWithPath("obligations.obligation_title.status").description("Status of the obligation"),
subsectionWithPath("obligations.obligation_title.id").description("Id of the obligation"),
subsectionWithPath("obligations.obligation_title.obligationType").description("Type of the obligation"),
fieldWithPath("page").description("Additional paging information"),
fieldWithPath("page.size").description("Number of obligations per page"),
fieldWithPath("page.totalElements").description("Total number of all license obligations"),
Expand Down

0 comments on commit 1085858

Please sign in to comment.