use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithoutCheck.
@Test
public void testRemoveLastRuleWithoutCheck() {
String eavCode = "testingEav";
Long testEavIdentityValue = System.currentTimeMillis();
UUID testEavContractValue = UUID.randomUUID();
IdmIdentityDto identity = testHelper.createIdentity();
IdmRoleDto role = testHelper.createRole();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
// create two eav attributes (for identity and contract)
IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.LONG);
testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.LONG);
IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.UUID);
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
automaticRoleAttributeRuleService.delete(rule1);
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
automaticRoleAttributeRuleService.delete(rule2);
// in this case we not able remove the last automatic role from identity
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithCheck.
@Test
public void testRemoveLastRuleWithCheck() {
String eavCode = "testingEav";
Long testEavContractValue = System.currentTimeMillis();
UUID testEavIdentityValue = UUID.randomUUID();
IdmIdentityDto identity = testHelper.createIdentity();
IdmRoleDto role = testHelper.createRole();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
// create two eav attributes (for identity and contract)
IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.UUID);
testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.UUID);
IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.LONG);
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
automaticRoleAttributeRuleService.delete(rule1);
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
// in process will be start LRT with async remove all identity roles
automaticRoleAttributeRuleService.delete(rule2);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testUpdateAutomaticRole.
@Test
public void testUpdateAutomaticRole() {
// automatic role on sub role
IdmRoleDto parentRole = createRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto subRole = createRole();
getHelper().createRoleComposition(parentRole, subRole);
// create attributes, automatic roles etc.
IdmAutomaticRoleAttributeDto automaticRoleAttribute = createAutomaticRole(subRole, identity.getUsername());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
//
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(parentRole.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, true);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), targetEnvironment);
//
IdmAutomaticRoleAttributeDto duplicateAutomaticRoleAttribute = findAutomaticRolesByAttribute(duplicate).get(0);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAutomaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
//
IdmIdentityDto otherIdentity = getHelper().createIdentity((GuardedString) null);
IdmAutomaticRoleAttributeRuleDto rule = automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRoleAttribute.getId()).get(0);
rule.setValue(otherIdentity.getUsername());
automaticRoleAttributeRuleService.save(rule);
automaticRoleAttributeService.recalculate(automaticRoleAttribute.getId());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
duplicate = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), targetEnvironment);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
assignedRoles = identityRoleService.findAllByIdentity(otherIdentity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method createAutoRoleByAttribute.
/**
* Defines automatic roles assigned based on contract attribute
*/
private void createAutoRoleByAttribute() {
IdmAutomaticRoleAttributeRuleDto attrRule = new IdmAutomaticRoleAttributeRuleDto();
IdmFormAttributeDto formAttr = null;
IdmAutomaticRoleAttributeDto roleAtt = null;
IdmFormAttributeFilter formAttrFilt = new IdmFormAttributeFilter();
formAttrFilt.setCode(eavAutoRoleAttrName);
formAttr = formAttrService.find(formAttrFilt, null).getContent().get(0);
// common part
attrRule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
attrRule.setType(AutomaticRoleAttributeRuleType.CONTRACT_EAV);
attrRule.setAttributeName(formAttr.getName());
attrRule.setFormAttribute(formAttr.getId());
// Consultant autorole
roleAtt = new IdmAutomaticRoleAttributeDto();
roleAtt.setRole(roleService.getByCode(consultantBusinessRole).getId());
roleAtt.setName("Consultant autorole");
roleAtt = autoRoleAttrService.save(roleAtt);
attrRule.setValue(consultantPositionName);
attrRule.setAutomaticRoleAttribute(roleAtt.getId());
attrRule = autoRoleAttrRuleService.save(attrRule);
// concept needs to be set to false after rule's been saved
roleAtt.setConcept(false);
roleAtt = autoRoleAttrService.save(roleAtt);
// Director autorole
roleAtt = new IdmAutomaticRoleAttributeDto();
roleAtt.setRole(roleService.getByCode(adGroupDirectorRole).getId());
roleAtt.setName("Director autorole");
roleAtt = autoRoleAttrService.save(roleAtt);
attrRule.setId(null);
attrRule.setValue(directorPositionName);
attrRule.setAutomaticRoleAttribute(roleAtt.getId());
attrRule = autoRoleAttrRuleService.save(attrRule);
// concept needs to be set to false after rule's been saved
roleAtt.setConcept(false);
roleAtt = autoRoleAttrService.save(roleAtt);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DuplicateRoleAutomaticByAttributeProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto cloned = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
//
IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
filter.setRoleId(cloned.getId());
Set<UUID> usedAutomaticRoles = new HashSet<>();
List<IdmAutomaticRoleAttributeDto> currentAutomaticRoles = automaticRoleAttributeService.find(filter, null).getContent();
//
filter.setRoleId(originalSource.getId());
automaticRoleAttributeService.find(filter, null).forEach(automaticRole -> {
UUID exists = exists(currentAutomaticRoles, automaticRole);
if (exists != null) {
usedAutomaticRoles.add(exists);
} else {
// create new with all rules
IdmAutomaticRoleAttributeDto clonedAutomaticRole = new IdmAutomaticRoleAttributeDto();
clonedAutomaticRole.setName(automaticRole.getName());
clonedAutomaticRole.setRole(cloned.getId());
clonedAutomaticRole.setConcept(true);
//
clonedAutomaticRole = automaticRoleAttributeService.save(clonedAutomaticRole);
//
for (IdmAutomaticRoleAttributeRuleDto rule : automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRole.getId())) {
IdmAutomaticRoleAttributeRuleDto clonedRule = new IdmAutomaticRoleAttributeRuleDto();
clonedRule.setAutomaticRoleAttribute(clonedAutomaticRole.getId());
clonedRule.setAttributeName(rule.getAttributeName());
clonedRule.setFormAttribute(rule.getFormAttribute());
clonedRule.setType(rule.getType());
clonedRule.setValue(rule.getValue());
clonedRule.setComparison(rule.getComparison());
//
automaticRoleAttributeRuleService.save(clonedRule);
}
AutomaticRoleAttributeEvent automaticRoleEvent = new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.UPDATE, clonedAutomaticRole);
// execute sync
automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
// FIXME: event parent ...
automaticRoleAttributeService.recalculate(automaticRoleEvent);
}
});
//
// remove not used originals
currentAutomaticRoles.stream().filter(automaticRole -> {
return !usedAutomaticRoles.contains(automaticRole.getId());
}).forEach(automaticRole -> {
// dirty flag automatic role only - will be processed after parent action ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setSuperOwnerId(cloned.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(automaticRole, stateDeleted);
});
return new DefaultEventResult<>(event, this);
}
Aggregations