Skip to content

Commit 886ad47

Browse files
nikkuma7GMishx
authored andcommitted
fix(Rest): Updated the REST endpoint to schedule the upload of release component attachments.
Signed-off-by: Nikesh kumar <kumar.nikesh@siemens.com>
1 parent 2d0664f commit 886ad47

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

rest/resource-server/src/docs/asciidoc/schedule.adoc

+11
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,14 @@ include::{snippets}/should_document_cancel_monitoring_cancel_svm_list/curl-reque
189189

190190
===== Example response
191191
include::{snippets}/should_document_cancel_monitoring_cancel_svm_list/http-response.adoc[]
192+
193+
[[schedule-source-upload]]
194+
==== Schedule Source Upload Service
195+
196+
A `POST` request will schedule the source upload process for release components.
197+
198+
===== Example Request
199+
include::{snippets}/schedule_source_upload/curl-request.adoc[]
200+
201+
===== Example Response
202+
include::{snippets}/schedule_source_upload/http-response.adoc[]

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/schedule/ScheduleAdminController.java

+19
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,23 @@ public ResponseEntity<?> cancelsrcUpload()throws TException {
360360
HttpStatus status = HttpStatus.ACCEPTED;
361361
return new ResponseEntity<>(requestStatus, status);
362362
}
363+
364+
@Operation(
365+
summary = "Schedule the source upload for release components.",
366+
description = "Schedules the source upload process for release components.",
367+
tags = {"Admin"}
368+
)
369+
@ApiResponses(value = {
370+
@ApiResponse(responseCode = "202", description = "Status in the response body.",
371+
content = @Content(mediaType = "application/json",
372+
schema = @Schema(implementation = String.class,
373+
example = "SUCCESS")))
374+
})
375+
@PostMapping(SCHEDULE_URL + "/scheduleSourceUploadForReleaseComponents")
376+
public ResponseEntity<?> scheduleSourceUploadForReleaseComponents()throws TException {
377+
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
378+
RequestStatus requestStatus = scheduleService.triggerSourceUploadForReleaseComponents(sw360User);
379+
HttpStatus status = HttpStatus.ACCEPTED;
380+
return new ResponseEntity<>(requestStatus, status);
381+
}
363382
}

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/schedule/Sw360ScheduleService.java

+15
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,19 @@ public RequestStatus unscheduleSrcUpload(User sw360User) throws TException {
262262
throw e;
263263
}
264264
}
265+
266+
public RequestStatus triggerSourceUploadForReleaseComponents(User sw360User) throws TException {
267+
try {
268+
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
269+
RequestStatus requestStatus = new ThriftClients().makeComponentClient()
270+
.uploadSourceCodeAttachmentToReleases();
271+
return requestStatus;
272+
} else {
273+
throw new AccessDeniedException("User is not admin");
274+
}
275+
} catch (TException e) {
276+
log.error("Error occurred while scheduling service: " + e);
277+
throw e;
278+
}
279+
}
265280
}

rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ScheduleSpecTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,12 @@ public void should_document_delete_old_attachment_from_local() throws Exception
201201
.andExpect(status().isAccepted());
202202
}
203203

204+
@Test
205+
public void schedule_source_upload() throws Exception {
206+
mockMvc.perform(post("/api/schedule/scheduleSourceUploadForReleaseComponents")
207+
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
208+
.accept(MediaTypes.HAL_JSON))
209+
.andExpect(status().isAccepted());
210+
}
211+
204212
}

0 commit comments

Comments
 (0)