use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(node.getId());
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
position = contractPositionService.publish(event).getContent();
UUID positionId = position.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method processPositions.
private Set<UUID> processPositions(IdmRoleTreeNodeDto automaticRole) {
Set<UUID> processedRoles = new HashSet<>();
//
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setWorkPosition(automaticRole.getTreeNode());
filter.setRecursionType(automaticRole.getRecursionType());
filter.setValidNowOrInFuture(Boolean.TRUE);
Pageable pageable = PageRequest.of(0, getPageSize(), new Sort(Direction.ASC, BaseEntity.PROPERTY_ID));
boolean canContinue = true;
//
do {
Page<IdmContractPositionDto> positions = contractPositionService.find(filter, pageable);
//
for (Iterator<IdmContractPositionDto> i = positions.iterator(); i.hasNext() && canContinue; ) {
IdmContractPositionDto position = i.next();
UUID contractId = position.getId();
//
if (!requireNewTransaction()) {
processedRoles.addAll(processPosition(position, automaticRole));
} else {
TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//
try {
template.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
processedRoles.addAll(processPosition(position, automaticRole));
}
});
} catch (UnexpectedRollbackException ex) {
// Just log for sure ... exception solved in new transaction, but this lower transaction is marked as roll-back.
LOG.debug("Statefull process [{}] processed contract [{}] failed", getClass().getSimpleName(), contractId, ex);
}
}
//
if (!this.updateState()) {
LOG.debug("Task [{}] was canceled.", getLongRunningTaskId());
// return null => not continue with role removal
return null;
}
}
canContinue &= positions.hasNext();
pageable = positions.nextPageable();
//
} while (canContinue);
//
return processedRoles;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testProjectionDontSaveOtherContractsAndPositions.
@Test
@Transactional
public void testProjectionDontSaveOtherContractsAndPositions() {
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection = projectionService.save(formProjection);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(formProjection.getId());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// 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);
//
// 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));
IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// other contract
Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
// other position
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdmContractPositionControllerRestTest method testFilterByContract.
@Test
public void testFilterByContract() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
IdmIdentityContractDto otherContract = getHelper().createContract(identity);
//
IdmContractPositionDto dtoOne = createDto(new IdmContractPositionDto(primeContract.getId(), null));
// other
createDto(new IdmContractPositionDto(otherContract.getId(), null));
//
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setIdentityContractId(primeContract.getId());
//
List<IdmContractPositionDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(dtoOne.getId(), results.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class IdmContractPositionControllerRestTest method testFilterByWorkPosition.
@Test
public void testFilterByWorkPosition() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
//
IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode();
IdmContractPositionDto dtoOne = createDto(new IdmContractPositionDto(primeContract.getId(), treeNodeOne.getId()));
// other
createDto(new IdmContractPositionDto(primeContract.getId(), getHelper().createTreeNode().getId()));
//
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setWorkPosition(treeNodeOne.getId());
//
List<IdmContractPositionDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(dtoOne.getId(), results.get(0).getId());
}
Aggregations