Search in sources :

Example 6 with DeferredResultWrapper

use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.

the class DefaultLongPollingManagerTest method testExecuteDeferredResultOnCreateRoleRequest.

@Test
public void testExecuteDeferredResultOnCreateRoleRequest() throws InterruptedException {
    DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
    IdmIdentityDto identityOne = this.getHelper().createIdentity();
    DeferredResult<OperationResultDto> result = new DeferredResult<OperationResultDto>(10000l, new OperationResultDto(OperationState.NOT_EXECUTED));
    DeferredResultWrapper wrapper = new DeferredResultWrapper(identityOne.getId(), identityOne.getClass(), result);
    wrapper.onCheckResultCallback(new CheckLongPollingResult() {

        @Override
        public void checkDeferredResult(DeferredResult<OperationResultDto> result, LongPollingSubscriber subscriber) {
            checkDeferredRequest(result, subscriber);
        }
    });
    Queue<DeferredResultWrapper> suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(0, suspendedRequests.size());
    longPollingManager.addSuspendedResult(wrapper);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(1, suspendedRequests.size());
    longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(1, suspendedRequests.size());
    // Create role-request -> must be detected
    this.getHelper().createRoleRequest(identityOne, this.getHelper().createRole());
    // Check must be called twice, because first detect the change and second remove
    // ended deferred result (from some reason is not invoked method
    // result.onCompleted)
    longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
    longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(0, suspendedRequests.size());
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
}
Also used : LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) DeferredResult(org.springframework.web.context.request.async.DeferredResult) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 7 with DeferredResultWrapper

use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.

the class DefaultLongPollingManagerTest method testRegisteredSubscribers.

@Test
public void testRegisteredSubscribers() {
    DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
    IdmIdentityDto identityOne = this.getHelper().createIdentity();
    DeferredResult<OperationResultDto> result = new DeferredResult<OperationResultDto>(10000l, new OperationResultDto(OperationState.NOT_EXECUTED));
    DeferredResultWrapper wrapper = new DeferredResultWrapper(identityOne.getId(), identityOne.getClass(), result);
    wrapper.onCheckResultCallback(new CheckLongPollingResult() {

        @Override
        public void checkDeferredResult(DeferredResult<OperationResultDto> result, LongPollingSubscriber subscriber) {
            checkDeferredRequest(result, subscriber);
        }
    });
    longPollingManager.addSuspendedResult(wrapper);
    Map<UUID, LongPollingSubscriber> registredSubscirbers = defaultPollingManager.getRegistredSubscribers();
    assertEquals(1, registredSubscirbers.size());
    assertTrue(registredSubscirbers.containsKey(identityOne.getId()));
    longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
    // None subscriber will be cleared ... threshold time stamp is too small
    longPollingManager.clearUnUseSubscribers(ZonedDateTime.now().minusMinutes(1));
    registredSubscirbers = defaultPollingManager.getRegistredSubscribers();
    assertEquals(1, registredSubscirbers.size());
    longPollingManager.clearUnUseSubscribers(ZonedDateTime.now().plusMinutes(1));
    registredSubscirbers = defaultPollingManager.getRegistredSubscribers();
    assertEquals(0, registredSubscirbers.size());
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
}
Also used : LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) DeferredResult(org.springframework.web.context.request.async.DeferredResult) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 8 with DeferredResultWrapper

use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.

the class IdmMonitoringResultController method checkLastMonitoringResults.

/**
 * Long polling for check unresolved identity role-requests
 *
 * @param backendId - applicant ID
 *
 * @return DeferredResult<OperationResultDto>, where:
 *
 * - EXECUTED = All requests for this identity are resolved,
 * - RUNNING = Requests are not resolved, but some request was changed (since previous check).
 * - NOT_EXECUTED = Deferred-result expired
 */
@ResponseBody
@RequestMapping(value = "{backendId}/check-last-monitoring-results", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + MonitoringGroupPermission.MONITORINGRESULT_READ + "')")
@ApiOperation(value = "Check changes of last monitoring results (Long-polling request).", nickname = "checkLastMonitoringResults", tags = { IdmMonitoringResultController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = ""), @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public DeferredResult<OperationResultDto> checkLastMonitoringResults() {
    DeferredResultWrapper result = new DeferredResultWrapper(LONG_POOLING_IDENTIFIER, IdmMonitoringResultDto.class, new DeferredResult<OperationResultDto>(10000l, new OperationResultDto(OperationState.NOT_EXECUTED)));
    result.onCheckResultCallback(new CheckLongPollingResult() {

        @Override
        public void checkDeferredResult(DeferredResult<OperationResultDto> result, LongPollingSubscriber subscriber) {
            checkDeferredRequest(result, subscriber);
        }
    });
    // If isn't long polling enabled, then Blocked response will be sent.
    if (!longPollingManager.isLongPollingEnabled()) {
        result.getResult().setResult(new OperationResultDto(OperationState.BLOCKED));
        // 
        return result.getResult();
    }
    longPollingManager.addSuspendedResult(result);
    return result.getResult();
}
Also used : LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)8 CheckLongPollingResult (eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult)8 DeferredResultWrapper (eu.bcvsolutions.idm.core.rest.DeferredResultWrapper)8 LongPollingSubscriber (eu.bcvsolutions.idm.core.rest.LongPollingSubscriber)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 Test (org.junit.Test)5 DeferredResult (org.springframework.web.context.request.async.DeferredResult)5 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)4 ApiOperation (io.swagger.annotations.ApiOperation)3 UUID (java.util.UUID)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)1 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1