|
101 | 101 | import org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService;
|
102 | 102 | import org.eclipse.sw360.rest.resourceserver.vulnerability.VulnerabilityController;
|
103 | 103 | import org.jetbrains.annotations.NotNull;
|
| 104 | +import org.jose4j.json.internal.json_simple.JSONObject; |
104 | 105 | import org.springframework.beans.factory.annotation.Autowired;
|
105 | 106 | import org.springframework.boot.json.GsonJsonParser;
|
106 | 107 | import org.springframework.data.domain.Pageable;
|
|
119 | 120 | import org.springframework.security.access.prepost.PreAuthorize;
|
120 | 121 | import org.springframework.util.FileCopyUtils;
|
121 | 122 | import org.springframework.web.bind.annotation.PathVariable;
|
| 123 | +import org.springframework.web.bind.annotation.PostMapping; |
122 | 124 | import org.springframework.web.bind.annotation.RequestBody;
|
123 | 125 | import org.springframework.web.bind.annotation.RequestMapping;
|
124 | 126 | import org.springframework.web.bind.annotation.RequestMethod;
|
@@ -192,6 +194,8 @@ public class ProjectController implements RepresentationModelProcessor<Repositor
|
192 | 194 | private static final List<String> enumMainlineStateValues = Stream.of(MainlineState.values())
|
193 | 195 | .map(MainlineState::name)
|
194 | 196 | .collect(Collectors.toList());
|
| 197 | + private static final ImmutableMap<String, String> RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT = ImmutableMap.<String, String>builder() |
| 198 | + .put("message", "Unauthorized user or empty commit message passed.").build(); |
195 | 199 |
|
196 | 200 | @NonNull
|
197 | 201 | private final Sw360ProjectService projectService;
|
@@ -3480,4 +3484,73 @@ public ResponseEntity<?> createDuplicateProjectWithDependencyNetwork(
|
3480 | 3484 | return true;
|
3481 | 3485 | };
|
3482 | 3486 | }
|
| 3487 | + |
| 3488 | + @Operation( |
| 3489 | + summary = "Add licenses to linked releases of a project.", |
| 3490 | + description = "This API adds license information to linked releases of a project by processing the approved CLI attachments for each release. It categorizes releases based on the number of CLI attachments (single, multiple, or none) and updates their main and other licenses accordingly.", |
| 3491 | + tags = {"Project"}, |
| 3492 | + parameters = { |
| 3493 | + @Parameter( |
| 3494 | + name = "projectId", |
| 3495 | + description = "The ID of the project whose linked releases need license updates.", |
| 3496 | + required = true, |
| 3497 | + example = "12345", |
| 3498 | + schema = @Schema(type = "string") |
| 3499 | + ) |
| 3500 | + }, |
| 3501 | + responses = { |
| 3502 | + @ApiResponse( |
| 3503 | + responseCode = "200", |
| 3504 | + description = "License information successfully added to linked releases.", |
| 3505 | + content = @Content( |
| 3506 | + mediaType = "application/hal+json", |
| 3507 | + schema = @Schema(type = "object", implementation = JSONObject.class), |
| 3508 | + examples = @ExampleObject( |
| 3509 | + value = "{\n \"one\": [\"Release1\", \"Release2\"],\n \"mul\": [\"Release3\"]\n}" |
| 3510 | + ) |
| 3511 | + ) |
| 3512 | + ), |
| 3513 | + @ApiResponse( |
| 3514 | + responseCode = "500", |
| 3515 | + description = "Error occurred while processing license information for linked releases.", |
| 3516 | + content = @Content( |
| 3517 | + mediaType = "application/json", |
| 3518 | + examples = @ExampleObject( |
| 3519 | + value = "{\n \"error\": \"Error adding license info to linked releases.\"\n}" |
| 3520 | + ) |
| 3521 | + ) |
| 3522 | + ) |
| 3523 | + } |
| 3524 | + ) |
| 3525 | + @PostMapping(value = PROJECTS_URL + "/{id}/addLinkedRelesesLicenses") |
| 3526 | + public ResponseEntity<?> addLicenseToLinkedReleases( |
| 3527 | + @Parameter(description = "Project ID", example = "376576") |
| 3528 | + @PathVariable("id") String projectId, |
| 3529 | + @Parameter(description = "Comment message.") |
| 3530 | + @RequestParam(value = "comment", required = false) String comment |
| 3531 | + ) throws TTransportException, TException { |
| 3532 | + try { |
| 3533 | + User sw360User = restControllerHelper.getSw360UserFromAuthentication(); |
| 3534 | + sw360User.setCommentMadeDuringModerationRequest(comment); |
| 3535 | + Project project = projectService.getProjectForUserById(projectId, sw360User); |
| 3536 | + |
| 3537 | + if (!restControllerHelper.isWriteActionAllowed(project, sw360User) && comment == null) { |
| 3538 | + return new ResponseEntity<>(RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT, HttpStatus.BAD_REQUEST); |
| 3539 | + } |
| 3540 | + RequestStatus requestStatus = projectService.addLicenseToLinkedReleases(projectId, sw360User); |
| 3541 | + |
| 3542 | + switch (requestStatus) { |
| 3543 | + case SENT_TO_MODERATOR: |
| 3544 | + return new ResponseEntity<>(RESPONSE_BODY_FOR_MODERATION_REQUEST, HttpStatus.ACCEPTED); |
| 3545 | + case SUCCESS: |
| 3546 | + return ResponseEntity.ok().body(Map.of("message", "License information successfully added to linked releases.")); |
| 3547 | + default: |
| 3548 | + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error adding license info to linked releases."); |
| 3549 | + } |
| 3550 | + |
| 3551 | + } catch (Exception e) { |
| 3552 | + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) |
| 3553 | + .body("Error adding license info to linked releases: " + e.getMessage()); |
| 3554 | + } |
| 3555 | + } |
3483 | 3556 | }
|
0 commit comments