use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method overwriteAttributesByUnresolvedRequests.
/**
* Overwrite attributes form VS account with attributes from unresloved requests
*
* @param account
*
* @param account
* @param vsAttributes
* @return
*/
private List<IcAttribute> overwriteAttributesByUnresolvedRequests(VsAccountDto account, String uid, List<IcAttribute> vsAttributes) {
Map<String, IcAttribute> attributesMap = new HashMap<>();
List<VsRequestDto> unresolvedRequests = requestService.findDuplicities(uid, this.systemId);
vsAttributes.forEach(attribute -> {
attributesMap.put(attribute.getName(), attribute);
});
if (unresolvedRequests != null) {
unresolvedRequests = Lists.reverse(unresolvedRequests);
boolean deleteAccount = false;
boolean createAccount = false;
for (VsRequestDto request : unresolvedRequests) {
if (VsOperationType.DELETE == request.getOperationType()) {
deleteAccount = true;
createAccount = false;
continue;
}
if (VsOperationType.CREATE == request.getOperationType()) {
deleteAccount = false;
createAccount = true;
}
// VsRequestDto fullRequest =
// requestService.get(request.getId());
VsRequestDto fullRequest = request;
if (fullRequest.getConnectorObject() != null && fullRequest.getConnectorObject().getAttributes() != null) {
fullRequest.getConnectorObject().getAttributes().forEach(attribute -> {
attributesMap.put(attribute.getName(), attribute);
});
}
}
// return null
if (deleteAccount) {
return null;
}
// return null
if (account == null && !createAccount) {
return null;
}
}
return new ArrayList<>(attributesMap.values());
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method createRequest.
/**
* Create new instance of request DTO. Method does not persist him.
*
* @param objectClass
* @param attributes
* @param uidString
* @param operationType
* @return
*/
private VsRequestDto createRequest(IcObjectClass objectClass, List<IcAttribute> attributes, String uidString, VsOperationType operationType) {
VsRequestDto request = new VsRequestDto();
request.setUid(uidString);
request.setState(VsRequestState.CONCEPT);
request.setSystem(this.systemId);
request.setConfiguration(this.configuration);
request.setConnectorKey(connectorKey);
request.setConnectorObject(new IcConnectorObjectImpl(uidString, objectClass, attributes));
request.setExecuteImmediately(!this.virtualConfiguration.isRequiredConfirmation());
request.setOperationType(operationType);
// Set UUID of IdmRoleRequest (can be null, doesn't have to exist)
request.setRoleRequestId(objectClass.getRoleRequestId());
// request.setImplementers(this.loadImplementers(this.virtualConfiguration.getImplementers()));
return request;
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method update.
@Override
public IcUidAttribute update(IcUidAttribute uid, IcObjectClass objectClass, List<IcAttribute> attributes) {
Assert.notNull(objectClass, "Object class cannot be null!");
Assert.notNull(attributes, "Attributes cannot be null!");
Assert.notNull(uid, "UID cannot be null!");
if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
throw new IcException("Only ACCOUNT object class is supported now!");
}
String uidValue = uid.getUidValue();
if (uidValue == null) {
throw new IcException("UID value cannot be null!");
}
VsRequestDto request = createRequest(objectClass, attributes, (String) uidValue, VsOperationType.UPDATE);
return requestService.execute(request);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class VsRequestRealizeBulkAction method processEntities.
@Override
protected OperationResult processEntities(Collection<UUID> entitiesId) {
// TODO: Potentially memory problem.
// Load all vs-requests. We need to order requests by
// date of creation, because create requests have to be first.
ArrayList<VsRequestDto> requests = Lists.newArrayList();
entitiesId.forEach(uuid -> {
VsRequestDto vsRequestDto = requestService.get(uuid);
if (vsRequestDto != null) {
requests.add(vsRequestDto);
}
});
// Sort by created.
List<UUID> sortedIds = requests.stream().sorted(Comparator.comparing(VsRequestDto::getCreated)).map(VsRequestDto::getId).collect(Collectors.toList());
return super.processEntities(sortedIds);
}
use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method realizeUpdateAndDeleteRequestsTest.
@Test
public void realizeUpdateAndDeleteRequestsTest() {
String changed = "changed";
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), 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);
IdmIdentityDto userOne = identityService.getByUsername(USER_ONE_NAME);
userOne.setFirstName(changed);
userOne.setLastName(changed);
identityService.save(userOne);
// Delete identity
identityService.delete(userOne);
// Test read rights (none requests can be returned for UserOne)
IdmIdentityDto userTwo = helper.createIdentity("vsUserTwo");
super.logout();
loginService.login(new LoginDto(userTwo.getUsername(), new GuardedString("password")));
requests = requestService.find(requestFilter, null, IdmBasePermission.READ).getContent();
Assert.assertEquals("We found request without correct rights!", 0, requests.size());
// Test read rights (3 requests must be returned for UserImplementer)
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
requests = requestService.find(requestFilter, null, IdmBasePermission.READ).getContent();
Assert.assertEquals(3, requests.size());
VsRequestDto changeRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.UPDATE == req.getOperationType()).findFirst().orElse(null);
Assert.assertNotNull("Request with change not found!", changeRequest);
VsRequestDto deleteRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.DELETE == req.getOperationType()).findFirst().orElse(null);
Assert.assertNotNull("Request with delete not found!", deleteRequest);
VsRequestDto createRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.CREATE == req.getOperationType()).findFirst().orElse(null);
Assert.assertNotNull("Request with create not found!", createRequest);
// Realize create request
request = requestService.realize(createRequest);
// Realize update request
request = requestService.realize(changeRequest);
// Realize delete request
request = requestService.realize(deleteRequest);
// Find only archived
requestFilter.setOnlyArchived(Boolean.TRUE);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(3, requests.size());
boolean foundNotRealized = requests.stream().filter(req -> VsRequestState.REALIZED != req.getState()).findFirst().isPresent();
Assert.assertTrue("Found not realized requests!", !foundNotRealized);
}
Aggregations