Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(obligation): endpoint to list license obligations from license db. #2276

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -421,6 +421,20 @@ include::{snippets}/should_document_get_project_releases_ecc_information/http-re
===== Links
include::{snippets}/should_document_get_project_releases_ecc_information/links.adoc[]

[[resources-project-get-license-obligation-information]]
==== Listing obligations from licenseDB

A `GET` request will get all license obligations from licenseDB.

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

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

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

[[resources-project-get-license-clearing-information-information]]
==== Project's license clearing count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
import org.eclipse.sw360.datahandler.thrift.packages.Package;
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest;
import org.eclipse.sw360.datahandler.thrift.projects.ObligationStatusInfo;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectState;
Expand Down Expand Up @@ -106,6 +107,7 @@ public Sw360Module() {
setMixInAnnotation(ClearingRequest.class, Sw360Module.ClearingRequestMixin.class);
setMixInAnnotation(Comment.class, Sw360Module.CommentMixin.class);
setMixInAnnotation(ProjectReleaseRelationship.class, Sw360Module.ProjectReleaseRelationshipMixin.class);
setMixInAnnotation(ObligationStatusInfo.class, Sw360Module.ObligationStatusInfoMixin.class);
setMixInAnnotation(ReleaseVulnerabilityRelation.class, Sw360Module.ReleaseVulnerabilityRelationMixin.class);
setMixInAnnotation(VerificationStateInfo.class, Sw360Module.VerificationStateInfoMixin.class);
setMixInAnnotation(ProjectProjectRelationship.class, Sw360Module.ProjectProjectRelationshipMixin.class);
Expand Down Expand Up @@ -156,6 +158,7 @@ public Sw360Module() {
.replaceWithClass(ClearingRequest.class, ClearingRequestMixin.class)
.replaceWithClass(Comment.class, CommentMixin.class)
.replaceWithClass(ProjectReleaseRelationship.class, ProjectReleaseRelationshipMixin.class)
.replaceWithClass(ObligationStatusInfo.class, ObligationStatusInfoMixin.class)
.replaceWithClass(ReleaseVulnerabilityRelation.class, ReleaseVulnerabilityRelationMixin.class)
.replaceWithClass(VerificationStateInfo.class, VerificationStateInfoMixin.class)
.replaceWithClass(ProjectProjectRelationship.class, ProjectProjectRelationshipMixin.class)
Expand Down Expand Up @@ -1810,6 +1813,29 @@ public static abstract class CommentMixin extends Comment {
public static abstract class ProjectReleaseRelationshipMixin extends ProjectReleaseRelationship {
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({
"setComment",
"setText",
"setObligationType",
"setObligationLevel",
"setModifiedBy",
"setModifiedOn",
"setId",
"setStatus",
"setAction",
"setLicenseIds",
"setReleaseIdToAcceptedCLI",
"releaseIdToAcceptedCLISize",
"releasesSize",
"releasesIterator",
"setReleases",
"licenseIdsSize",
"licenseIdsIterator"
})
public static abstract class ObligationStatusInfoMixin extends ObligationStatusInfo {
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({
"setId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant;
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.datahandler.thrift.projects.ObligationStatusInfo;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectLink;
Expand Down Expand Up @@ -136,6 +137,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.InvalidPropertiesFormatException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -2061,6 +2063,57 @@ public void getlicenseClearingCount(HttpServletResponse response ,
}
}

@Operation(
description = "Get license obligations data from license database.",
tags = {"Project"}
)
@RequestMapping(value = PROJECTS_URL + "/{id}/licenseDbObligations", method = RequestMethod.GET)
public ResponseEntity<?> getLicObligations(@RequestParam(defaultValue = "0") int page,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Pageable instead of page and size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried with Pageable but finding some challenges, therefore switched to page and size for time being.

@RequestParam(defaultValue = "5") int size,
@Parameter(description = "Project ID.") @PathVariable("id") String id)
throws TException {

final User sw360User = restControllerHelper.getSw360UserFromAuthentication();
final Project sw360Project = projectService.getProjectForUserById(id, sw360User);
if (CommonUtils.isNullOrEmptyMap(sw360Project.getReleaseIdToUsage())) {
return new ResponseEntity<String>("No release linked to the project", HttpStatus.NO_CONTENT);
}
Map<String, AttachmentUsage> licenseInfoAttachmentUsage = projectService.getLicenseInfoAttachmentUsage(id);
if(licenseInfoAttachmentUsage.size() == 0) {
return new ResponseEntity<String>("No approved CLI or licenseInfo attachment usage present for the project", HttpStatus.NO_CONTENT);
}
Map<String, Set<Release>> licensesFromAttachmentUsage = projectService.getLicensesFromAttachmentUsage(
licenseInfoAttachmentUsage, sw360User);
Map<String, ObligationStatusInfo> licenseObligation = projectService.getLicenseObligationData(licensesFromAttachmentUsage, sw360User);

List<Map.Entry<String, ObligationStatusInfo>> entries = new ArrayList<>(licenseObligation.entrySet());
int startIndex = page * size;
int endIndex = Math.min(startIndex + size, entries.size());
entries = entries.subList(startIndex, endIndex);
Map<String, ObligationStatusInfo> paginatedMap = new LinkedHashMap<>();
for (Map.Entry<String, ObligationStatusInfo> entry : entries) {
paginatedMap.put(entry.getKey(), entry.getValue());
}

Map<String, Integer> paginationMetadata = createPaginationMetadata(page, size, licenseObligation.size());

Map<String, Object> responseBody = new LinkedHashMap<>();
responseBody.put("licenseDbObligations", paginatedMap);
responseBody.put("page", paginationMetadata);

return new ResponseEntity<>(responseBody, HttpStatus.OK);
}

private Map<String, Integer> createPaginationMetadata(int page, int size, int totalElements) {
int totalPages = (int) Math.ceil((double) totalElements / size);
return Map.of(
"size", size,
"totalElements", totalElements,
"totalPages", totalPages,
"number", page
);
}

@Operation(
description = "Get summary and administration page of project tab.",
tags = {"Projects"}
Expand Down
Loading
Loading