Search in sources :

Example 1 with IdmAutomaticRoleAttributeRuleFilter

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 2 with IdmAutomaticRoleAttributeRuleFilter

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);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmAutomaticRoleAttributeRuleFilter

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmAutomaticRoleAttributeRuleFilter

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 5 with IdmAutomaticRoleAttributeRuleFilter

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Aggregations

IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)5 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)5 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 Test (org.junit.Test)4 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)2 Lists (com.google.common.collect.Lists)1 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)1 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)1 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)1 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)1 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)1 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)1 IdmAutomaticRoleAttributeRuleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 AutomaticRoleManager (eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager)1