use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractPositionAutomaticRoleProcessor method process.
@Override
public EventResult<IdmContractPositionDto> process(EntityEvent<IdmContractPositionDto> event) {
// flag can be processed afterwards
if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
IdmContractPositionDto contractPosition = event.getContent();
LOG.debug("Automatic roles are skipped for position [{}], state [AUTOMATIC_ROLE_SKIPPED] for position will be created only.", contractPosition.getId());
//
entityStateManager.createState(contractPosition, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
//
return new DefaultEventResult<>(event, this);
}
//
IdmContractPositionDto contractPosition = event.getContent();
IdmIdentityContractDto contract = DtoUtils.getEmbedded(contractPosition, IdmContractPosition_.identityContract);
//
UUID newPosition = contractPosition.getWorkPosition();
//
// check automatic roles - if position or contract was enabled
// work positions has some difference or validity changes
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByContractPosition(contractPosition.getId());
// and automatic roles given by contracts position
if (!assignedRoles.isEmpty()) {
assignedRoles = assignedRoles.stream().filter(autoRole -> {
// just for sure, other contract position supports automatic role by tree structure only for now
AbstractIdmAutomaticRoleDto automaticRoleDto = DtoUtils.getEmbedded(autoRole, IdmIdentityRole_.automaticRole, (AbstractIdmAutomaticRoleDto) null);
if (automaticRoleDto instanceof IdmRoleTreeNodeDto) {
return true;
}
return false;
}).collect(Collectors.toList());
}
//
Set<UUID> previousAutomaticRoles = assignedRoles.stream().filter(identityRole -> {
return identityRole.getAutomaticRole() != null;
}).map(identityRole -> {
return identityRole.getAutomaticRole();
}).collect(Collectors.toSet());
Set<IdmRoleTreeNodeDto> addedAutomaticRoles = new HashSet<>();
if (newPosition != null) {
addedAutomaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(newPosition);
}
// prevent to remove newly added or still exists roles
Set<UUID> removedAutomaticRoles = new HashSet<>(previousAutomaticRoles);
removedAutomaticRoles.removeAll(addedAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toList()));
addedAutomaticRoles.removeIf(a -> {
return previousAutomaticRoles.contains(a.getId());
});
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(removedAutomaticRoles.size() + addedAutomaticRoles.size());
//
for (UUID removedAutomaticRole : removedAutomaticRoles) {
Iterator<IdmIdentityRoleDto> iter = assignedRoles.iterator();
while (iter.hasNext()) {
IdmIdentityRoleDto identityRole = iter.next();
if (Objects.equals(identityRole.getAutomaticRole(), removedAutomaticRole)) {
// check, if role will be added by new automatic roles and prevent removing
IdmRoleTreeNodeDto addedAutomaticRole = getByRole(identityRole.getRole(), addedAutomaticRoles);
if (addedAutomaticRole == null) {
// remove assigned role
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
//
concepts.add(conceptRoleRequest);
//
iter.remove();
} else {
// change relation only
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setAutomaticRole(addedAutomaticRole.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setContractPosition(contractPosition.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
//
concepts.add(conceptRoleRequest);
//
// new automatic role is not needed
addedAutomaticRoles.remove(addedAutomaticRole);
}
}
}
}
// add identity roles
for (AbstractIdmAutomaticRoleDto autoRole : addedAutomaticRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setContractPosition(contractPosition.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(autoRole.getRole());
conceptRoleRequest.setAutomaticRole(autoRole.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
//
concepts.add(conceptRoleRequest);
}
//
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = (IdmRoleRequestDto) event.getProperties().get(IdentityContractUpdateByAutomaticRoleProcessor.EVENT_PROPERTY_REQUEST);
if (roleRequest != null) {
// add concept into single request
// single request will be executed by parent event
roleRequest.getConceptRoles().addAll(concepts);
} else {
// execute new request
roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(contract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
}
event.getProperties().put(IdentityContractUpdateByAutomaticRoleProcessor.EVENT_PROPERTY_REQUEST, roleRequest);
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdentityContractUpdateByAutomaticRoleProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
IdmIdentityContractDto previous = event.getOriginalSource();
UUID previousPosition = previous == null ? null : previous.getWorkPosition();
UUID newPosition = contract.getWorkPosition();
boolean validityChangedToValid = previous == null ? false : contract.isValidNowOrInFuture() && previous.isValidNowOrInFuture() != contract.isValidNowOrInFuture();
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
// flag can be processed afterwards
if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
LOG.debug("Automatic roles are skipped for contract [{}], state [{}] " + "for position will be created only.", contract.getId(), CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
//
Map<String, Serializable> properties = new HashMap<>();
// original contract as property
properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, event.getOriginalSource());
entityStateManager.createState(contract, OperationState.BLOCKED, contract.isValidNowOrInFuture() ? CoreResultCode.AUTOMATIC_ROLE_SKIPPED : CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
//
return new DefaultEventResult<>(event, this);
}
if (!contract.isValidNowOrInFuture()) {
// but we need to add skipped flag above, even when invalid contract is updated
return new DefaultEventResult<>(event, this);
}
//
if (previous == null || !Objects.equals(newPosition, previousPosition) || validityChangedToValid) {
// work positions has some difference or validity changes
List<IdmIdentityRoleDto> assignedRoles = getAssignedAutomaticRoles(contract.getId());
// remove all automatic roles by attribute and by other contract position
if (!assignedRoles.isEmpty()) {
assignedRoles = assignedRoles.stream().filter(autoRole -> {
// remove automatic roles by attribute - solved by different process
AbstractIdmAutomaticRoleDto automaticRoleDto = DtoUtils.getEmbedded(autoRole, IdmIdentityRole_.automaticRole, (AbstractIdmAutomaticRoleDto) null);
if (automaticRoleDto instanceof IdmRoleTreeNodeDto) {
return true;
}
return false;
}).filter(identityRole -> {
// remove automatic roles by attribute - solved by different process
return identityRole.getContractPosition() == null;
}).collect(Collectors.toList());
}
//
Set<UUID> previousAutomaticRoles = assignedRoles.stream().filter(identityRole -> {
return identityRole.getAutomaticRole() != null;
}).map(identityRole -> {
return identityRole.getAutomaticRole();
}).collect(Collectors.toSet());
Set<IdmRoleTreeNodeDto> addedAutomaticRoles = new HashSet<>();
if (newPosition != null && contract.isValidNowOrInFuture()) {
addedAutomaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(newPosition);
}
// prevent to remove newly added or still exists roles
Set<UUID> removedAutomaticRoles = new HashSet<>(previousAutomaticRoles);
removedAutomaticRoles.removeAll(addedAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toList()));
addedAutomaticRoles.removeIf(a -> {
return previousAutomaticRoles.contains(a.getId());
});
//
for (UUID removedAutomaticRole : removedAutomaticRoles) {
Iterator<IdmIdentityRoleDto> iter = assignedRoles.iterator();
while (iter.hasNext()) {
IdmIdentityRoleDto identityRole = iter.next();
if (Objects.equals(identityRole.getAutomaticRole(), removedAutomaticRole)) {
// check, if role will be added by new automatic roles and prevent removing
IdmRoleTreeNodeDto addedAutomaticRole = getByRole(identityRole.getRole(), addedAutomaticRoles);
if (addedAutomaticRole == null) {
// remove assigned role
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
iter.remove();
} else {
// change relation only
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setAutomaticRole(addedAutomaticRole.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
//
// new automatic role is not needed
addedAutomaticRoles.remove(addedAutomaticRole);
}
}
}
}
// change date - for unchanged assigned roles only
if (previous != null && EntityUtils.validableChanged(previous, contract)) {
roleRequest.getConceptRoles().addAll(changeValidable(contract, assignedRoles));
}
// add identity roles
for (AbstractIdmAutomaticRoleDto autoRole : addedAutomaticRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(autoRole.getRole());
conceptRoleRequest.setAutomaticRole(autoRole.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
}
// contract is enabled => process all contract positions
if (validityChangedToValid) {
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setIdentityContractId(contract.getId());
//
for (IdmContractPositionDto position : contractPositionService.find(filter, null).getContent()) {
CoreEvent<IdmContractPositionDto> positionEvent = new CoreEvent<>(CoreEventType.NOTIFY, position);
// we don't need the second asynchronicity
positionEvent.setPriority(PriorityType.IMMEDIATE);
positionEvent.getProperties().put(EVENT_PROPERTY_REQUEST, roleRequest);
// recount automatic roles for given position
EventContext<IdmContractPositionDto> context = contractPositionService.publish(positionEvent, event);
// get modified prepared request
if (context.getLastResult() != null) {
roleRequest = (IdmRoleRequestDto) context.getLastResult().getEvent().getProperties().get(EVENT_PROPERTY_REQUEST);
}
}
}
} else if (previous != null && EntityUtils.validableChanged(previous, contract)) {
// process validable change only
roleRequest.getConceptRoles().addAll(changeValidable(contract, getAssignedAutomaticRoles(contract.getId())));
}
// start request at end asynchronously
roleRequest.setApplicant(contract.getIdentity());
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
roleRequestService.startConcepts(requestEvent, event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdmContractPositionControllerRestTest method prepareDto.
@Override
protected IdmContractPositionDto prepareDto() {
IdmContractPositionDto dto = new IdmContractPositionDto();
dto.setIdentityContract(getHelper().getPrimeContract(getHelper().createIdentity().getId()).getId());
dto.setWorkPosition(getHelper().createTreeNode().getId());
dto.setPosition(getHelper().createName());
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractPositionProvisioningProcessor method process.
@Override
public EventResult<IdmContractPositionDto> process(EntityEvent<IdmContractPositionDto> event) {
IdmContractPositionDto contractPositionDto = event.getContent();
Assert.notNull(contractPositionDto, "Contract position cannot be null!");
Assert.notNull(contractPositionDto.getIdentityContract(), "Id of contract cannot be null!");
UUID identityId = null;
IdmIdentityContractDto contractDto = DtoUtils.getEmbedded(contractPositionDto, IdmContractPosition_.identityContract.getName(), IdmIdentityContractDto.class, (IdmIdentityContractDto) null);
if (contractDto == null) {
contractDto = identityContractService.get(contractPositionDto.getIdentityContract());
}
identityId = contractDto.getIdentity();
Assert.notNull(identityId, "Identity ID cannot be null!");
doProvisioning(identityId, event);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetFullProjectionGreenLine.
@Test
@Transactional
public void testSaveAndGetFullProjectionGreenLine() {
// role request implementer is needed
loginAsAdmin();
Assert.assertFalse(eventConfiguration.isAsynchronous());
//
try {
// prepare eav definition
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName());
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName());
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
attributeOne = formDefinitionOne.getMappedAttributeByCode(attributeOne.getCode());
attributeTwo = formDefinitionOne.getMappedAttributeByCode(attributeTwo.getCode());
IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(getHelper().createName());
attributeThree.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeThree));
attributeThree = formDefinitionTwo.getMappedAttributeByCode(attributeThree.getCode());
IdmFormAttributeDto attributeContract = new IdmFormAttributeDto(getHelper().createName());
attributeContract.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(attributeContract));
attributeContract = formDefinitionContract.getMappedAttributeByCode(attributeContract.getCode());
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
valueOne.setValue(getHelper().createName());
IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
valueTwo.setValue(getHelper().createName());
instanceOne.setValues(Lists.newArrayList(valueOne, valueTwo));
IdmFormInstanceDto instanceTwo = new IdmFormInstanceDto();
instanceTwo.setFormDefinition(formDefinitionTwo);
IdmFormValueDto valueThree = new IdmFormValueDto(attributeThree);
valueThree.setValue(getHelper().createName());
instanceTwo.setValues(Lists.newArrayList(valueThree));
identity.setEavs(Lists.newArrayList(instanceOne, instanceTwo));
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
projection.setContract(primeContract);
IdmFormInstanceDto instanceContract = new IdmFormInstanceDto();
instanceContract.setFormDefinition(formDefinitionContract);
IdmFormValueDto valueContract = new IdmFormValueDto(attributeContract);
valueContract.setValue(getHelper().createName());
instanceContract.setValues(Lists.newArrayList(valueContract));
primeContract.setEavs(Lists.newArrayList(instanceContract));
//
// set other contract
IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
otherContractOne.setPosition(getHelper().createName());
// preset uuid
IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
otherContractTwo.setPosition(getHelper().createName());
projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
//
// set other contract position
IdmContractPositionDto positionOne = new IdmContractPositionDto();
positionOne.setWorkPosition(getHelper().createTreeNode().getId());
positionOne.setPosition(getHelper().createName());
IdmContractPositionDto positionTwo = new IdmContractPositionDto();
positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
positionTwo.setPosition(getHelper().createName());
positionTwo.setIdentityContract(otherContractTwo.getId());
projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
//
// set assigned roles
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmIdentityRoleDto identityRoleOne = new IdmIdentityRoleDto();
identityRoleOne.setRole(roleOne.getId());
identityRoleOne.setValidFrom(LocalDate.now().plus(2l, ChronoUnit.DAYS));
IdmIdentityRoleDto identityRoleTwo = new IdmIdentityRoleDto();
identityRoleTwo.setRole(roleTwo.getId());
identityRoleTwo.setIdentityContract(otherContractTwo.getId());
projection.setIdentityRoles(Lists.newArrayList(identityRoleOne, identityRoleTwo));
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
projection = manager.publish(identityProjectionEvent).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
// eavs
Assert.assertEquals(valueOne.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
Assert.assertEquals(valueTwo.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
Assert.assertEquals(valueThree.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
// prime contract
IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
// eavs
Assert.assertEquals(valueContract.getValue(), createdProjection.getContract().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionContract.getId())).findFirst().get().toSinglePersistentValue(attributeContract.getCode()));
// other contract
Assert.assertEquals(2, createdProjection.getOtherContracts().size());
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
}));
Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
// other position
Assert.assertEquals(2, createdProjection.getOtherPositions().size());
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
// assigned roles
// check directly by service
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(createdProjection.getIdentity().getId());
List<IdmRoleRequestDto> roleRequests = roleRequestService.find(roleRequestFilter, null).getContent();
Assert.assertFalse(roleRequests.isEmpty());
Assert.assertTrue(roleRequests.stream().allMatch(r -> r.getState() == RoleRequestState.EXECUTED));
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(createdProjection.getIdentity().getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
// check by projection
Assert.assertEquals(2, createdProjection.getIdentityRoles().size());
Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
}));
Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
//
// simple update
String newUsername = getHelper().createName();
createdProjection.getIdentity().setUsername(newUsername);
//
IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
// IdmIdentityProjectionDto updatedProjection = manager.get(projection);
//
Assert.assertNotNull(updatedProjection);
Assert.assertNotNull(updatedProjection.getId());
Assert.assertEquals(createdProjection.getId(), updatedProjection.getIdentity().getId());
Assert.assertEquals(newUsername, updatedProjection.getIdentity().getUsername());
// eavs
Assert.assertEquals(valueOne.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
Assert.assertEquals(valueTwo.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
Assert.assertEquals(valueThree.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
// prime contract
IdmIdentityContractDto updatedPrimeContract = updatedProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), updatedPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), updatedPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), updatedPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), updatedPrimeContract.getValidTill());
Assert.assertEquals(updatedProjection.getIdentity().getId(), updatedPrimeContract.getIdentity());
Assert.assertFalse(updatedPrimeContract.getControlledBySlices());
// other contract
Assert.assertEquals(2, updatedProjection.getOtherContracts().size());
Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
}));
Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
c.getId().equals(otherContractTwo.getId());
}));
Assert.assertTrue(updatedProjection.getOtherContracts().stream().allMatch(c -> {
return !c.getControlledBySlices();
}));
// other position
Assert.assertEquals(2, updatedProjection.getOtherPositions().size());
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(updatedPrimeContract.getId());
}));
Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
}));
// assigned roles
Assert.assertEquals(2, updatedProjection.getIdentityRoles().size());
Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(updatedPrimeContract.getId());
}));
Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
}));
} finally {
logout();
}
}
Aggregations