Skip to content

Commit

Permalink
feat(rest) : endpoint to add license obligations from license database.
Browse files Browse the repository at this point in the history
Signed-off-by: Rudra Chopra <[email protected]>
  • Loading branch information
rudra-superrr committed Jan 19, 2024
1 parent 76c869c commit 27ec465
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 2 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 @@ -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 @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.eclipse.sw360.datahandler.resourcelists.PaginationResult;
import org.eclipse.sw360.datahandler.resourcelists.ResourceClassNotFoundException;
import org.eclipse.sw360.datahandler.thrift.MainlineState;
import org.eclipse.sw360.datahandler.thrift.ObligationStatus;
import org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship;
import org.eclipse.sw360.datahandler.thrift.ReleaseRelationship;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
Expand All @@ -71,6 +73,8 @@
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.ObligationList;
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 @@ -1961,6 +1965,32 @@ 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(Pageable pageable,
@Parameter(description = "Project ID.") @PathVariable("id") String id, HttpServletRequest request)
throws TException, URISyntaxException, PaginationParameterException, ResourceClassNotFoundException {

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.CONFLICT);
}
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.CONFLICT);
}
Map<String, Set<Release>> licensesFromAttachmentUsage = projectService.getLicensesFromAttachmentUsage(
licenseInfoAttachmentUsage, sw360Project.getReleaseIdToUsage(), sw360User);
Map<String, ObligationStatusInfo> licenseObligation = projectService.getLicenseObligationData(licensesFromAttachmentUsage, sw360User);

HalResource<Map<String, ObligationStatusInfo>> halObligation = new HalResource<>(licenseObligation);
return new ResponseEntity<>(halObligation, HttpStatus.OK);
}

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

0 comments on commit 27ec465

Please sign in to comment.