use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method checkUnresolvedRequests.
/**
* 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-unresolved-request", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_READ + "')" + " and hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Check changes of unresloved requests for the identity (Long-polling request).", nickname = "checkUnresolvedRequests", tags = { IdmIdentityController.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> checkUnresolvedRequests(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
IdmIdentityDto dto = getDto(backendId);
if (dto == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
UUID identityId = dto.getId();
DeferredResultWrapper result = new //
DeferredResultWrapper(//
identityId, //
dto.getClass(), new //
DeferredResult<OperationResultDto>(30000l, //
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();
}
use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManagerTest method testExecuteDeferredResultOnDeleteRoleRequest.
@Test
public void testExecuteDeferredResultOnDeleteRoleRequest() {
DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
// Clear deferred result and subscribers
defaultPollingManager.getSuspendedRequests().clear();
defaultPollingManager.getRegistredSubscribers().clear();
IdmIdentityDto identityOne = this.getHelper().createIdentity();
IdmRoleRequestDto roleRequest = this.getHelper().createRoleRequest(identityOne, this.getHelper().createRole());
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());
// Delete of the role-request -> must be detected
roleRequestService.delete(roleRequest);
// 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();
}
use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManagerTest method testExecuteDeferredResultOnUpdateRoleRequest.
@Test
public void testExecuteDeferredResultOnUpdateRoleRequest() {
DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
// Clear deferred result and subscribers
defaultPollingManager.getSuspendedRequests().clear();
defaultPollingManager.getRegistredSubscribers().clear();
IdmIdentityDto identityOne = this.getHelper().createIdentity();
IdmRoleRequestDto roleRequest = this.getHelper().createRoleRequest(identityOne, this.getHelper().createRole());
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());
// Update of role-request -> must be detected
roleRequest.setState(RoleRequestState.IN_PROGRESS);
roleRequestService.save(roleRequest);
// 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)
getHelper().waitForResult(null, 1, 1);
longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
getHelper().waitForResult(null, 1, 1);
longPollingManager.checkDeferredRequests(IdmIdentityDto.class);
suspendedRequests = defaultPollingManager.getSuspendedRequests();
assertEquals(0, suspendedRequests.size());
// Clear deferred result and subscribers
defaultPollingManager.getSuspendedRequests().clear();
defaultPollingManager.getRegistredSubscribers().clear();
}
use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.
the class SysSystemController method checkRunningSyncs.
/**
* Long polling for check sync in progress for given system
*
* @param backendId - system ID
*
* @return DeferredResult<OperationResultDto>, where:
*
* - RUNNING = Some sync are not resolved, but some sync was changed (since previous check).
* - NOT_EXECUTED = Deferred-result expired
* - BLOCKED - Long polling is disabled
*/
@ResponseBody
@RequestMapping(value = "{backendId}/check-running-sync", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Check changes of unresloved sync for the system (Long-polling request).", nickname = "checkRunningSyncs", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public DeferredResult<OperationResultDto> checkRunningSyncs(@ApiParam(value = "System's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto dto = getDto(backendId);
if (dto == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
UUID systemId = dto.getId();
DeferredResultWrapper result = new //
DeferredResultWrapper(//
systemId, //
dto.getClass(), new //
DeferredResult<OperationResultDto>(30000l, //
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();
}
use of eu.bcvsolutions.idm.core.rest.DeferredResultWrapper in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceIntegrationTest method testExecuteDeferredResultOnCreateSyncItemLog.
@Test
public void testExecuteDeferredResultOnCreateSyncItemLog() {
DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
// Clear deferred result and subscribers
defaultPollingManager.getSuspendedRequests().clear();
defaultPollingManager.getRegistredSubscribers().clear();
// create test system and sync
SysSystemDto system = helper.createTestResourceSystem(true);
AbstractSysSyncConfigDto syncConfig = createSync(system);
DeferredResult<OperationResultDto> result = new DeferredResult<OperationResultDto>(1000000l, new OperationResultDto(OperationState.NOT_EXECUTED));
DeferredResultWrapper wrapper = new DeferredResultWrapper(system.getId(), system.getClass(), result);
wrapper.onCheckResultCallback(new CheckLongPollingResult() {
@Override
public void checkDeferredResult(DeferredResult<OperationResultDto> result, LongPollingSubscriber subscriber) {
systemController.checkDeferredRequest(result, subscriber);
}
});
Queue<DeferredResultWrapper> suspendedRequests = defaultPollingManager.getSuspendedRequests();
assertEquals(0, suspendedRequests.size());
longPollingManager.addSuspendedResult(wrapper);
suspendedRequests = defaultPollingManager.getSuspendedRequests();
assertEquals(1, suspendedRequests.size());
longPollingManager.checkDeferredRequests(SysSystemDto.class);
suspendedRequests = defaultPollingManager.getSuspendedRequests();
assertEquals(1, suspendedRequests.size());
helper.startSynchronization(syncConfig);
SysSyncConfigFilter logFilter = new SysSyncConfigFilter();
logFilter.setId(syncConfig.getId());
logFilter.setIncludeLastLog(Boolean.TRUE);
List<AbstractSysSyncConfigDto> configs = syncConfigService.find(logFilter, null).getContent();
Assert.assertEquals(1, configs.size());
SysSyncLogDto log = new SysSyncLogDto();
log.setSynchronizationConfig(syncConfig.getId());
log = syncLogService.save(log);
SysSyncActionLogDto mockAction = new SysSyncActionLogDto();
mockAction.setSyncAction(SynchronizationActionType.IGNORE);
mockAction.setSyncLog(log.getId());
mockAction.setOperationResult(OperationResultType.IGNORE);
mockAction = syncActionLogService.save(mockAction);
// Sync item log created -> must be detected
SysSyncItemLogDto mockItemLogDto = new SysSyncItemLogDto();
mockItemLogDto.setSyncActionLog(mockAction.getId());
mockItemLogDto.setIdentification(helper.createName());
mockItemLogDto = syncItemLogService.save(mockItemLogDto);
// 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(SysSystemDto.class);
longPollingManager.checkDeferredRequests(SysSystemDto.class);
suspendedRequests = defaultPollingManager.getSuspendedRequests();
assertEquals(0, suspendedRequests.size());
// Clear deferred result and subscribers
defaultPollingManager.getSuspendedRequests().clear();
defaultPollingManager.getRegistredSubscribers().clear();
}
Aggregations