use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testChangeRule.
@Test
public void testChangeRule() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
Assert.assertNotNull(automaticRole.getId());
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
rule = rules.get(0);
rule.setValue(identityTwo.getUsername());
// Change automatic role via manager
automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true, rule);
// Find current rules
rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
// We updated rule ... must has same id and changed value
Assert.assertEquals(rule.getId(), rules.get(0).getId());
Assert.assertEquals(identityTwo.getUsername(), rules.get(0).getValue());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormAttributeService method deleteInternal.
@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
Assert.notNull(dto);
// attribute with filled values cannot be deleted
IdmFormValueFilter filter = new IdmFormValueFilter();
filter.setAttributeId(dto.getId());
formValueServices.getPlugins().forEach(formValueService -> {
if (formValueService.find(filter, new PageRequest(0, 1)).getTotalElements() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
}
});
// delete all values
// TODO: add some force delete parameter => rewrite service to event usage
/* formValueServices.getPlugins().forEach(formValueService -> {
formValueService.find(filter, null).getContent().forEach(formValue -> {
formValueService.delete((IdmFormValueDto) formValue);
});
});*/
//
// check rules for automatic role attributes
IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
automaticRoleRuleFilter.setFormAttributeId(dto.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic roles use this attribute
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
}
//
// Check rules requests for automatic role attributes. Deletes relation on this form attribute.
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
ruleRequests.forEach(rule -> {
rule.setFormAttribute(null);
automaticRoleAttributeRequestService.save(rule);
});
//
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleRuleCrud.
@Test
public void testAutomaticRoleRuleCrud() {
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(getTestName());
automaticRole = automaticRoleAttributeService.save(automaticRole);
//
IdmAutomaticRoleAttributeRuleDto rule1 = new IdmAutomaticRoleAttributeRuleDto();
rule1.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule1.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule1.setValue("test");
rule1.setAttributeName(IdmIdentity_.username.getName());
rule1.setAutomaticRoleAttribute(automaticRole.getId());
IdmAutomaticRoleAttributeRuleDto rule1Saved = automaticRoleAttributeRuleService.save(rule1);
//
assertNotNull(rule1Saved.getId());
assertEquals(rule1.getComparison(), rule1Saved.getComparison());
assertEquals(rule1.getValue(), rule1Saved.getValue());
assertEquals(rule1.getAttributeName(), rule1Saved.getAttributeName());
assertEquals(rule1.getAutomaticRoleAttribute(), rule1Saved.getAutomaticRoleAttribute());
//
IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule2.setType(AutomaticRoleAttributeRuleType.CONTRACT);
rule2.setAttributeName(IdmIdentityContract_.description.getName());
rule2.setValue("test2");
rule2.setAutomaticRoleAttribute(automaticRole.getId());
IdmAutomaticRoleAttributeRuleDto rule2Saved = automaticRoleAttributeRuleService.save(rule2);
//
assertNotNull(rule2Saved.getId());
assertEquals(rule2.getComparison(), rule2Saved.getComparison());
assertEquals(rule2.getValue(), rule2Saved.getValue());
assertEquals(rule2.getAttributeName(), rule2Saved.getAttributeName());
assertEquals(rule2.getAutomaticRoleAttribute(), rule2Saved.getAutomaticRoleAttribute());
//
// update is allowed
rule1Saved.setAttributeName(IdmIdentity_.description.getName());
IdmAutomaticRoleAttributeRuleDto updatedRule1 = automaticRoleAttributeRuleService.save(rule1Saved);
assertEquals(rule1Saved.getComparison(), updatedRule1.getComparison());
assertEquals(rule1Saved.getValue(), updatedRule1.getValue());
assertEquals(rule1Saved.getAttributeName(), updatedRule1.getAttributeName());
assertEquals(rule1Saved.getAutomaticRoleAttribute(), updatedRule1.getAutomaticRoleAttribute());
//
IdmAutomaticRoleAttributeRuleFilter filter = new IdmAutomaticRoleAttributeRuleFilter();
filter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> content = automaticRoleAttributeRuleService.find(filter, null).getContent();
assertEquals(2, content.size());
//
automaticRoleAttributeRuleService.delete(rule1Saved);
content = automaticRoleAttributeRuleService.find(filter, null).getContent();
assertEquals(1, content.size());
IdmAutomaticRoleAttributeRuleDto findAutomaticRole = automaticRoleAttributeRuleService.get(rule1Saved.getId());
assertNull(findAutomaticRole);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testRemoveRule.
@Test
public void testRemoveRule() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
Assert.assertNotNull(automaticRole.getId());
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
rule = rules.get(0);
rule.setValue(identityTwo.getUsername());
// Change automatic role via manager
automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true);
// Find current rules
rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(0, rules.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testAddRule.
@Test
public void testAddRule() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, true, rule);
Assert.assertNotNull(automaticRole.getId());
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
rule = rules.get(0);
// Create new rule
IdmAutomaticRoleAttributeRuleDto newRule = new IdmAutomaticRoleAttributeRuleDto();
newRule.setAttributeName(IdmIdentity_.username.getName());
newRule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
newRule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
newRule.setValue(identityTwo.getUsername());
// Change automatic role via manager
automaticRole = automaticRoleManager.changeAutomaticRoleRules(automaticRole, true, newRule);
// Find current rules
rules = ruleService.find(ruleFilter, null).getContent();
Assert.assertEquals(1, rules.size());
// We created new rule and deleted old
Assert.assertNotEquals(rule.getId(), rules.get(0).getId());
Assert.assertEquals(identityTwo.getUsername(), rules.get(0).getValue());
}
Aggregations