Skip to content

Commit

Permalink
fix(Rest): Updated the REST endpoint to schedule the upload of releas…
Browse files Browse the repository at this point in the history
…e component attachments.

Signed-off-by: Nikesh kumar <[email protected]>
  • Loading branch information
nikkuma7 authored and GMishx committed Jan 27, 2025
1 parent 2d0664f commit 886ad47
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rest/resource-server/src/docs/asciidoc/schedule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,14 @@ include::{snippets}/should_document_cancel_monitoring_cancel_svm_list/curl-reque

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

[[schedule-source-upload]]
==== Schedule Source Upload Service

A `POST` request will schedule the source upload process for release components.

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

===== Example Response
include::{snippets}/schedule_source_upload/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,23 @@ public ResponseEntity<?> cancelsrcUpload()throws TException {
HttpStatus status = HttpStatus.ACCEPTED;
return new ResponseEntity<>(requestStatus, status);
}

@Operation(
summary = "Schedule the source upload for release components.",
description = "Schedules the source upload process for release components.",
tags = {"Admin"}
)
@ApiResponses(value = {
@ApiResponse(responseCode = "202", description = "Status in the response body.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = String.class,
example = "SUCCESS")))
})
@PostMapping(SCHEDULE_URL + "/scheduleSourceUploadForReleaseComponents")
public ResponseEntity<?> scheduleSourceUploadForReleaseComponents()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestStatus requestStatus = scheduleService.triggerSourceUploadForReleaseComponents(sw360User);
HttpStatus status = HttpStatus.ACCEPTED;
return new ResponseEntity<>(requestStatus, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,19 @@ public RequestStatus unscheduleSrcUpload(User sw360User) throws TException {
throw e;
}
}

public RequestStatus triggerSourceUploadForReleaseComponents(User sw360User) throws TException {
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestStatus requestStatus = new ThriftClients().makeComponentClient()
.uploadSourceCodeAttachmentToReleases();
return requestStatus;
} else {
throw new AccessDeniedException("User is not admin");
}
} catch (TException e) {
log.error("Error occurred while scheduling service: " + e);
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,12 @@ public void should_document_delete_old_attachment_from_local() throws Exception
.andExpect(status().isAccepted());
}

@Test
public void schedule_source_upload() throws Exception {
mockMvc.perform(post("/api/schedule/scheduleSourceUploadForReleaseComponents")
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isAccepted());
}

}

0 comments on commit 886ad47

Please sign in to comment.