Search in sources :

Example 11 with LongPollingSubscriber

use of eu.bcvsolutions.idm.core.rest.LongPollingSubscriber 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

LongPollingSubscriber (eu.bcvsolutions.idm.core.rest.LongPollingSubscriber)11 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)10 CheckLongPollingResult (eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult)10 DeferredResultWrapper (eu.bcvsolutions.idm.core.rest.DeferredResultWrapper)10 DeferredResult (org.springframework.web.context.request.async.DeferredResult)7 UUID (java.util.UUID)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 Test (org.junit.Test)5 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)4 ApiOperation (io.swagger.annotations.ApiOperation)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)2 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)2 ModifiedFromFilter (eu.bcvsolutions.idm.core.api.dto.filter.ModifiedFromFilter)2 AbstractEntity_ (eu.bcvsolutions.idm.core.api.entity.AbstractEntity_)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)2 ReadDtoService (eu.bcvsolutions.idm.core.api.service.ReadDtoService)2 LongPollingManager (eu.bcvsolutions.idm.core.model.service.api.LongPollingManager)2