|
78 | 78 | import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant;
|
79 | 79 | import org.eclipse.sw360.datahandler.thrift.licenses.License;
|
80 | 80 | import org.eclipse.sw360.datahandler.thrift.projects.*;
|
| 81 | +import org.eclipse.sw360.datahandler.thrift.packages.Package; |
| 82 | +import org.eclipse.sw360.datahandler.thrift.projects.ObligationList; |
| 83 | +import org.eclipse.sw360.datahandler.thrift.projects.ObligationStatusInfo; |
| 84 | +import org.eclipse.sw360.datahandler.thrift.projects.Project; |
| 85 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState; |
| 86 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectLink; |
| 87 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship; |
| 88 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship; |
| 89 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectDTO; |
| 90 | +import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest; |
81 | 91 | import org.eclipse.sw360.datahandler.thrift.users.User;
|
82 | 92 | import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
|
83 | 93 | import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
|
@@ -484,6 +494,49 @@ public ResponseEntity<EntityModel<Project>> getProject(
|
484 | 494 | return new ResponseEntity<>(userHalResource, HttpStatus.OK);
|
485 | 495 | }
|
486 | 496 |
|
| 497 | + @Operation( |
| 498 | + description = "Get a package with project id.", |
| 499 | + tags = {"Projects"} |
| 500 | + ) |
| 501 | + @RequestMapping(value = PROJECTS_URL + "/{id}/packages", method = RequestMethod.GET) |
| 502 | + public ResponseEntity<List<HalResource<Project>>> getPackagesByProjectId( |
| 503 | + @Parameter(description = "Project ID", example = "376576") |
| 504 | + @PathVariable("id") String id) throws TException { |
| 505 | + |
| 506 | + User sw360User = restControllerHelper.getSw360UserFromAuthentication(); |
| 507 | + Project sw360Project = projectService.getProjectForUserById(id, sw360User); |
| 508 | + List<HalResource<Package>> halPackages = new ArrayList<>(); |
| 509 | + if (sw360Project.getPackageIdsSize() > 0) { |
| 510 | + for (String packageId : sw360Project.getPackageIds()) { |
| 511 | + Package sw360Package = packageService.getPackageForUserById(packageId); |
| 512 | + HalResource<Package> halPackage = createHalPackage(sw360Package, sw360User); |
| 513 | + halPackages.add(halPackage); |
| 514 | + } |
| 515 | + } |
| 516 | + return new ResponseEntity(halPackages, HttpStatus.OK); |
| 517 | + } |
| 518 | + |
| 519 | + private HalResource<Package> createHalPackage(Package sw360Package, User sw360User) throws TException { |
| 520 | + HalResource<Package> halPackage = new HalResource<>(sw360Package); |
| 521 | + User packageCreator = restControllerHelper.getUserByEmail(sw360Package.getCreatedBy()); |
| 522 | + String linkedRelease = sw360Package.getReleaseId(); |
| 523 | + |
| 524 | + restControllerHelper.addEmbeddedUser(halPackage, packageCreator, "createdBy"); |
| 525 | + if (CommonUtils.isNotNullEmptyOrWhitespace(linkedRelease)) { |
| 526 | + Release release = releaseService.getReleaseForUserById(linkedRelease, sw360User); |
| 527 | + |
| 528 | + if (release != null) { |
| 529 | + restControllerHelper.addEmbeddedSingleRelease(halPackage, release); |
| 530 | + } else { |
| 531 | + log.warn("Release not found for ID: {}", linkedRelease); |
| 532 | + } |
| 533 | + } |
| 534 | + if (sw360Package.getModifiedBy() != null) { |
| 535 | + restControllerHelper.addEmbeddedModifiedBy(halPackage, sw360User, "modifiedBy"); |
| 536 | + } |
| 537 | + return halPackage; |
| 538 | + } |
| 539 | + |
487 | 540 | @Operation(
|
488 | 541 | description = "Get linked projects of a single project.",
|
489 | 542 | tags = {"Projects"}
|
|
0 commit comments