Skip to content

Commit

Permalink
feat(rest): Create new api's in schedule tab.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikesh kumar <kumar.nikesh@simens.com>
  • Loading branch information
Nikesh kumar committed Jan 12, 2024
1 parent 3e59dc7 commit c410901
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 6 deletions.
57 changes: 56 additions & 1 deletion rest/resource-server/src/docs/asciidoc/schedule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,59 @@ A `DELETE` request will cancel all the services.
include::{snippets}/should_document_cancel_all_schedule/curl-request.adoc[]

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

[[schedule-svmsync]]
==== Schedule svm sync for user.

A `POST` request will schedule svm sync for user.

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

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

[[unschedule-svmSync]]
==== Cancel schedule svm sync for user.

A `DELETE` request will cancel schedule svm sync for user.

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

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

[[reverse-svmmatch]]
==== Svm reverse match for user.

A `POST` request will reverse svm match.

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

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

[[unschedule-reversematch]]
==== Cancel reverse match for user.

A `DELETE` request will cancel the reverse match.

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

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

[[tracking-feedback]]
==== Tracking feedback for user.

A `POST` request will track the user feedback.

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

===== Example response
include::{snippets}/should_document_track_feedback/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -43,7 +44,6 @@ public class ScheduleAdminController implements RepresentationModelProcessor<Rep

@NonNull
private Sw360ScheduleService scheduleService;


@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
Expand All @@ -58,4 +58,44 @@ public ResponseEntity<?> unscheduleAllServices()throws TException {
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestStatus, status);
}

@RequestMapping(value = SCHEDULE_URL + "/scheduleSvmSync", method = RequestMethod.POST)
public ResponseEntity<?> scheduleSvmSync()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = scheduleService.svmSync(sw360User);
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestSummary, status);
}

@RequestMapping(value = SCHEDULE_URL + "/unscheduleSvmSync", method = RequestMethod.DELETE)
public ResponseEntity<?> unscheduleSvmSync()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestStatus requestStatus = scheduleService.cancelSvmSync(sw360User);
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestStatus, status);
}

@RequestMapping(value = SCHEDULE_URL + "/svmReverseMatch", method = RequestMethod.POST)
public ResponseEntity<?> svmReverseMatch()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = scheduleService.scheduleSvmReverseMatch(sw360User);
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestSummary, status);
}

@RequestMapping(value = SCHEDULE_URL + "/unscheduleSvmReverseMatch", method = RequestMethod.DELETE)
public ResponseEntity<?> unscheduleSvmReverseMatch()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestStatus requestStatus = scheduleService.cancelSvmReverseMatch(sw360User);
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestStatus, status);
}

@RequestMapping(value = SCHEDULE_URL + "/trackingFeedback", method = RequestMethod.POST)
public ResponseEntity<?> svmTrackingFeedback()throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = scheduleService.svmReleaseTrackingFeedback(sw360User);
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestSummary, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -42,4 +43,75 @@ public RequestStatus cancelAllServices(User sw360User) throws TException {
}
}

public RequestSummary svmSync(User sw360User) throws TException {
String serviceName = ThriftClients.SVMSYNC_SERVICE;
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(serviceName);
return requestSummary;
} else {
throw new RuntimeException("User is not admin");
}
} catch (TException e) {
throw new TException(e.getMessage());
}
}

public RequestStatus cancelSvmSync(User sw360User) throws TException {
String serviceName = ThriftClients.SVMSYNC_SERVICE;
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleService(serviceName, sw360User);
return requestStatus;
} else {
throw new RuntimeException("User is not admin");
}
} catch (TException e) {
throw new TException(e.getMessage());
}
}

public RequestSummary scheduleSvmReverseMatch(User sw360User) throws TException {
String serviceName = ThriftClients.SVMMATCH_SERVICE;
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(serviceName);
return requestSummary;
} else {
throw new RuntimeException("User is not admin");
}
} catch (TException e) {
throw new TException(e.getMessage());
}
}

public RequestStatus cancelSvmReverseMatch(User sw360User) throws TException {
String serviceName = ThriftClients.SVMMATCH_SERVICE;
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleService(serviceName, sw360User);
return requestStatus;
} else {
throw new RuntimeException("User is not admin");
}
} catch (TException e) {
throw new TException(e.getMessage());
}
}

public RequestSummary svmReleaseTrackingFeedback(User sw360User) throws TException {
String serviceName = ThriftClients.SVM_TRACKING_FEEDBACK_SERVICE;
try {
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(serviceName);;
return requestSummary;
} else {
throw new RuntimeException("User is not admin");
}
} catch (TException e) {
throw new TException(e.getMessage());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.IOException;

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.TestHelper;
import org.eclipse.sw360.rest.resourceserver.schedule.Sw360ScheduleService;
Expand All @@ -46,7 +47,9 @@ public class ScheduleSpecTest extends TestRestDocsSpecBase {

@MockBean
private Sw360ScheduleService scheduleServiceMock;


private RequestSummary requestSummary = new RequestSummary();

@Before
public void before() throws TException {

Expand All @@ -56,6 +59,10 @@ public void before() throws TException {
sw360User.setFullname("John Doe");
given(this.userServiceMock.getUserByEmailOrExternalId("admin@sw360.org")).willReturn(sw360User);
given(this.scheduleServiceMock.cancelAllServices(any())).willReturn(RequestStatus.SUCCESS);
given(this.scheduleServiceMock.cancelSvmSync(any())).willReturn(RequestStatus.SUCCESS);
given(this.scheduleServiceMock.cancelSvmReverseMatch(any())).willReturn(RequestStatus.SUCCESS);
given(this.scheduleServiceMock.scheduleSvmReverseMatch(any())).willReturn(requestSummary);
given(this.scheduleServiceMock.svmReleaseTrackingFeedback(any())).willReturn(requestSummary);

}

Expand All @@ -67,4 +74,49 @@ public void should_document_cancel_all_schedule() throws Exception {
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

@Test
public void should_document_schedule_svm_sync() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(post("/api/schedule/scheduleSvmSync")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

@Test
public void should_document_cancel_schedule_svm_sync() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(delete("/api/schedule/unscheduleSvmSync")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

@Test
public void should_document_reverse_svm_match() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(post("/api/schedule/svmReverseMatch")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

@Test
public void should_document_cancel_reverse_match() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(delete("/api/schedule/unscheduleSvmReverseMatch")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

@Test
public void should_document_track_feedback() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(post("/api/schedule/trackingFeedback")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}
}

0 comments on commit c410901

Please sign in to comment.