-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest): Create new endpoint for schedule CVE and schedule attachm…
…ent deletion. Signed-off-by: Nikesh kumar <kumar.nikesh@simens.com>
- Loading branch information
Nikesh kumar
committed
Jan 4, 2024
1 parent
47d14b1
commit 51f957f
Showing
6 changed files
with
420 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright Siemens AG, 2023. Part of the SW360 Portal Project. | ||
// | ||
// This program and the accompanying materials are made | ||
// available under the terms of the Eclipse Public License 2.0 | ||
// which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
// | ||
|
||
|
||
[[resources-schedule]] | ||
=== Schedule | ||
|
||
The Schedule resource is used to get and list the Schedule requests. | ||
|
||
[[schedule-cve]] | ||
==== schedule cve service | ||
|
||
A `POST` request will schedule the cve service. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_schedule_cve_service/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_schedule_cve_service/http-response.adoc[] | ||
|
||
[[unschedule-cve]] | ||
==== unschedule cve search | ||
|
||
A `DELETE` request will unschedule the cve search. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_unschedule_cve_search/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_unschedule_cve_search/http-response.adoc[] | ||
|
||
[[schedule-service]] | ||
==== schedule service for attachment deletion from local fs. | ||
|
||
A `POST` request will schedule attachment deletion. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_schedule_service_from_local/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_schedule_service_from_local/http-response.adoc[] | ||
|
||
[[cancel-schedule]] | ||
==== cancel schedule attachment from local fs | ||
|
||
A `DELETE` request will schedule attachment deletion. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_cancel_schedule_attachment/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_cancel_schedule_attachment/http-response.adoc[] | ||
|
||
[[delete-attachment]] | ||
==== delete old attachment from local fs | ||
|
||
A `DELETE` request will schedule attachment deletion. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_delete_old_attachment_from_local/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_delete_old_attachment_from_local/http-response.adoc[] | ||
|
||
[[cve-search]] | ||
==== schedule cve search | ||
|
||
A `POST` request will schedule the cve search. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_schedule_cve_search/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_schedule_cve_search/http-response.adoc[] |
105 changes: 105 additions & 0 deletions
105
...src/main/java/org/eclipse/sw360/rest/resourceserver/schedule/ScheduleAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright Siemens AG, 2023-2024. | ||
* Part of the SW360 Portal Project. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.sw360.rest.resourceserver.schedule; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
|
||
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.RequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; | ||
import org.eclipse.sw360.rest.resourceserver.license.LicenseController; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.rest.webmvc.BasePathAwareController; | ||
import org.springframework.data.rest.webmvc.RepositoryLinksResource; | ||
import org.springframework.hateoas.server.RepresentationModelProcessor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@BasePathAwareController | ||
@Slf4j | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
@RestController | ||
@SecurityRequirement(name = "tokenAuth") | ||
public class ScheduleAdminController implements RepresentationModelProcessor<RepositoryLinksResource> { | ||
public static final String SCHEDULE_URL = "/schedule"; | ||
|
||
@NonNull | ||
private final RestControllerHelper restControllerHelper; | ||
|
||
@NonNull | ||
private Sw360ScheduleService scheduleService; | ||
|
||
|
||
@Override | ||
public RepositoryLinksResource process(RepositoryLinksResource resource) { | ||
resource.add(linkTo(ScheduleAdminController.class).slash("api/schedule").withRel("schedule")); | ||
return resource; | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/cveService", method = RequestMethod.POST) | ||
public ResponseEntity<?> scheduleCve()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestSummary requestSummary = scheduleService.scheduleCveSearch(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestSummary, status); | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/unscheduleCve", method = RequestMethod.DELETE) | ||
public ResponseEntity<?> unscheduleCveSearch()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestStatus requestStatus = scheduleService.cancleCveSearch(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestStatus, status); | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/deleteAttachment", method = RequestMethod.POST) | ||
public ResponseEntity<?> scheduleDeleteAttachment()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestSummary requestSummary = scheduleService.deleteAttachmentService(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestSummary, status); | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/unscheduleDelete", method = RequestMethod.DELETE) | ||
public ResponseEntity<?> unscheduleDeleteAttachment()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestStatus requestStatus = scheduleService.cancleDeleteAttachment(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestStatus, status); | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/attachmentDelete", method = RequestMethod.DELETE) | ||
public ResponseEntity<?> attachmentDeleteLocalFS()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestStatus requestStatus = scheduleService.canclettachmentDeleteLocalFS(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestStatus, status); | ||
} | ||
|
||
@RequestMapping(value = SCHEDULE_URL + "/cveSearch", method = RequestMethod.POST) | ||
public ResponseEntity<?> CveAllSearch()throws TException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
RequestStatus requestStatus = scheduleService.triggerCveSearch(sw360User); | ||
HttpStatus status = HttpStatus.OK; | ||
return new ResponseEntity<>(requestStatus, status); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...er/src/main/java/org/eclipse/sw360/rest/resourceserver/schedule/Sw360ScheduleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright Siemens AG, 2023-2024. | ||
* Part of the SW360 Portal Project. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.sw360.rest.resourceserver.schedule; | ||
|
||
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.permissions.PermissionUtils; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.RequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.ThriftClients; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.datahandler.thrift.users.UserGroup; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.converter.HttpMessageNotReadableException; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class Sw360ScheduleService { | ||
|
||
public RequestSummary scheduleCveSearch(User sw360User) throws TException{ | ||
String serviceName = ThriftClients.CVESEARCH_SERVICE; | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(serviceName); | ||
return requestSummary; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
|
||
public RequestStatus cancleCveSearch(User sw360User) throws TException{ | ||
String serviceName = ThriftClients.CVESEARCH_SERVICE; | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleService(serviceName, sw360User); | ||
return requestStatus; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
|
||
public RequestSummary deleteAttachmentService(User sw360User) throws TException{ | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(ThriftClients.DELETE_ATTACHMENT_SERVICE); | ||
return requestSummary; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
|
||
public RequestStatus cancleDeleteAttachment(User sw360User) throws TException{ | ||
String serviceName = ThriftClients.DELETE_ATTACHMENT_SERVICE; | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleService(serviceName, sw360User); | ||
return requestStatus; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
|
||
public RequestStatus canclettachmentDeleteLocalFS(User sw360User) throws TException { | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestStatus requestStatus = new ThriftClients().makeAttachmentClient().deleteOldAttachmentFromFileSystem(); | ||
return requestStatus; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
|
||
public RequestStatus triggerCveSearch(User sw360User) throws TException { | ||
try { | ||
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) { | ||
RequestStatus requestStatus = new ThriftClients().makeCvesearchClient().update(); | ||
return requestStatus; | ||
} else { | ||
throw new HttpMessageNotReadableException("User is not admin"); | ||
} | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.