use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.
the class SystemDeleteProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto system = event.getContent();
Assert.notNull(system);
//
// If exists unresolved vs request, then is not possible to delete
// system
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setState(VsRequestState.IN_PROGRESS);
if (requestService.find(requestFilter, null).getTotalElements() > 0) {
throw new ResultCodeException(VsResultCode.VS_SYSTEM_DELETE_FAILED_HAS_REQUEST, ImmutableMap.of("system", system.getName()));
}
// Delete archived vs requests
requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setOnlyArchived(Boolean.TRUE);
requestService.find(requestFilter, null).forEach(entity -> {
requestService.delete(entity);
});
// Delete vs account
VsAccountFilter accountFilter = new VsAccountFilter();
accountFilter.setSystemId(system.getId());
accountService.find(accountFilter, null).forEach(entity -> {
accountService.delete(entity);
});
// Delete vs account form definition
if (system.getConnectorKey() != null) {
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId());
IdmFormDefinitionDto definition = this.formDefinitionService.findOneByTypeAndCode(VsAccount.class.getName(), virtualSystemKey);
if (definition != null) {
formDefinitionService.delete(definition);
}
}
// Delete vs implementers
VsSystemImplementerFilter implementerFilter = new VsSystemImplementerFilter();
implementerFilter.setSystemId(system.getId());
systemImplementerService.find(implementerFilter, null).forEach(entity -> {
systemImplementerService.delete(entity);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.
the class VsRequestController method toFilter.
@Override
protected VsRequestFilter toFilter(MultiValueMap<String, Object> parameters) {
VsRequestFilter filter = new VsRequestFilter();
filter.setText(getParameterConverter().toString(parameters, "text"));
filter.setState(getParameterConverter().toEnum(parameters, "state", VsRequestState.class));
filter.setSystemId(getParameterConverter().toUuid(parameters, "systemId"));
filter.setUid(getParameterConverter().toString(parameters, "uid"));
filter.setCreatedAfter(getParameterConverter().toDateTime(parameters, "createdAfter"));
filter.setCreatedBefore(getParameterConverter().toDateTime(parameters, "createdBefore"));
filter.setOnlyArchived(getParameterConverter().toBoolean(parameters, "onlyArchived"));
return filter;
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method internalExecute.
@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
request.setState(VsRequestState.REALIZED);
Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
// Find connector by request
VsVirtualConnector virtualConnector = getVirtualConnector(request);
IcUidAttribute result = null;
// Save the request
this.save(request);
switch(request.getOperationType()) {
case CREATE:
{
result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case UPDATE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case DELETE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
// All unresolved request created before this delete request will be
// canceled
VsRequestFilter filter = new VsRequestFilter();
filter.setCreatedBefore(request.getCreated());
filter.setUid(request.getUid());
filter.setSystemId(request.getSystem());
filter.setState(VsRequestState.IN_PROGRESS);
// Unresolved request created before this request
List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
beforeRequests.forEach(beforeRequest -> {
String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
this.cancel(beforeRequest, reason);
LOG.info(reason);
});
break;
}
default:
throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
}
return result;
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method findDuplicities.
/**
* Find duplicity requests. All request in state IN_PROGRESS for same UID and
* system. For all operation types.
*
* @param request
* @return
*/
@Override
public List<VsRequestDto> findDuplicities(String uid, UUID systemId) {
VsRequestFilter filter = new VsRequestFilter();
filter.setUid(uid);
filter.setSystemId(systemId);
filter.setState(VsRequestState.IN_PROGRESS);
Sort sort = new Sort(Direction.DESC, VsRequest_.created.getName());
return this.find(filter, new PageRequest(0, Integer.MAX_VALUE, sort)).getContent();
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method disableRequestTest.
@Test
public void disableRequestTest() {
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
IdmIdentityDto identity = helper.createIdentity(USER_ONE_NAME);
this.assignRoleSystem(system, identity, ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto request = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, request.getUid());
Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNull("Account must be null, because request was not realized yet!", account);
// We try realize the request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
request = requestService.realize(request);
Assert.assertEquals(VsRequestState.REALIZED, request.getState());
account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNotNull("Account cannot be null, because request was realized!", account);
Assert.assertEquals(Boolean.TRUE, account.isEnable());
super.logout();
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
// Disable the identity
identity.setState(IdentityState.DISABLED_MANUALLY);
identityService.save(identity);
// Find created requests
requests = requestService.find(requestFilter, null).getContent().stream().filter(r -> VsRequestState.IN_PROGRESS == r.getState()).collect(Collectors.toList());
Assert.assertEquals(1, requests.size());
request = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, request.getUid());
Assert.assertEquals(VsOperationType.UPDATE, request.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
// We try realize the request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
request = requestService.realize(request);
Assert.assertEquals(VsRequestState.REALIZED, request.getState());
account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
Assert.assertNotNull("Account cannot be null, because request was realized!", account);
Assert.assertEquals(Boolean.FALSE, account.isEnable());
}
Aggregations