use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class RoleRequestCheckSystemStateProcessor method process.
@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
IdmRoleRequestDto request = event.getContent();
Assert.notNull(request, "Request is required.");
Assert.notNull(request.getId(), "Request identifier is required.");
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setRoleRequestId(request.getId());
// Some active requests for that request has state IN_PROGRESS -> we will wait for execution of all requests!
requestFilter.setState(VsRequestState.IN_PROGRESS);
List<VsRequestDto> inprogressRequests = requestService.find(requestFilter, null).getContent();
if (inprogressRequests.size() > 0) {
OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_IN_PROGRESS, ImmutableMap.of("systems", this.getSystems(inprogressRequests)))).build();
request.setSystemState(systemResult);
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
return result;
}
requestFilter.setState(null);
long countAllRequests = requestService.count(requestFilter);
requestFilter.setOnlyArchived(Boolean.TRUE);
long countArchives = requestService.count(requestFilter);
// Nothing was done
if (countAllRequests == 0) {
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
return result;
}
// Everything was done (in VS)
if (countAllRequests == countArchives && countArchives > 0) {
request.setSystemState(new OperationResultDto(OperationState.EXECUTED));
requestFilter.setOnlyArchived(Boolean.TRUE);
requestFilter.setState(VsRequestState.CANCELED);
// Check rejected requests - if exists some rejected request, we need to save this
// information to role-concepts using role with this system.
List<VsRequestDto> rejectedRequests = requestService.find(requestFilter, null).getContent();
if (!rejectedRequests.isEmpty()) {
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(request.getId());
rejectedRequests.forEach(vsRequest -> {
Assert.notNull(vsRequest.getSystem(), "System is required.");
UUID systemId = vsRequest.getSystem();
List<IdmConceptRoleRequestDto> rejectedConcepts = roleSystemService.getConceptsForSystem(concepts, systemId);
rejectedConcepts.forEach(concept -> {
OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.CANCELED).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_REJECTED, ImmutableMap.of("system", requestService.getSystem(vsRequest).getCode()))).build();
concept.setSystemState(systemResult);
// Save role concept
conceptRoleRequestService.save(concept);
});
});
}
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method delete.
@Override
public void delete(IcUidAttribute uid, IcObjectClass objectClass) {
Assert.notNull(objectClass, "Object class cannot be null!");
String uidValue = validateAndGetUid(uid);
if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
throw new IcException("Only ACCOUNT object class is supported now!");
}
// Create and execute request
VsRequestDto request = createRequest(objectClass, null, (String) uidValue, VsOperationType.DELETE);
requestService.execute(request);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method create.
@Override
public IcUidAttribute create(IcObjectClass objectClass, List<IcAttribute> attributes) {
Assert.notNull(objectClass, "Object class cannot be null!");
Assert.notNull(attributes, "Attributes cannot be null!");
if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
throw new IcException("Only ACCOUNT object class is supported now!");
}
IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
if (uidAttribute == null) {
throw new IcException("UID attribute was not found!");
}
Object uidValue = uidAttribute.getValue();
if (!(uidValue instanceof String)) {
throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", uidValue));
}
// Create and execute request
VsRequestDto request = createRequest(objectClass, attributes, (String) uidValue, VsOperationType.CREATE);
return requestService.execute(request);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class VsRequestCancelBulkActionTest method testCancelRequestWithoutReason.
@Test(expected = ResultCodeException.class)
public void testCancelRequestWithoutReason() {
IdmIdentityDto implementer = helper.createIdentity();
IdmIdentityDto identity = helper.createIdentity();
IdmRoleDto roleForVs = helper.createRole();
SysSystemDto system = this.createVirtualSystem(implementer, null);
helper.createRoleSystem(roleForVs, system);
helper.createIdentityRole(identity, roleForVs);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(identity.getUsername());
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto request = requests.get(0);
Assert.assertEquals(identity.getUsername(), request.getUid());
Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
VsAccountDto account = accountService.findByUidSystem(identity.getUsername(), system.getId());
Assert.assertNull("Account must be null, because request was not realized yet!", account);
// We try cancel the request
IdmBulkActionDto bulkAction = this.findBulkAction(VsRequest.class, VsRequestCancelBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(request.getId()));
// Reason is null -> request cannot be cancelled.
Map<String, Object> properties = new HashMap<>();
properties.put(VsRequestCancelBulkAction.REASON, null);
bulkAction.setProperties(properties);
bulkActionManager.processAction(bulkAction);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class CommonVsRequestControllerRestTest method prepareDto.
@Override
protected VsRequestDto prepareDto() {
VsRequestDto dto = new VsRequestDto();
SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
dto.setSystem(virtualSystem.getId());
dto.setUid(helper.createName());
dto.setConnectorKey("mock");
dto.setOperationType(VsOperationType.CREATE);
dto.setState(VsRequestState.CONCEPT);
//
return dto;
}
Aggregations