Search in sources :

Example 1 with IdmCodeListItemDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.

the class CodeListItemDeleteProcessor method process.

@Override
public EventResult<IdmCodeListItemDto> process(EntityEvent<IdmCodeListItemDto> event) {
    IdmCodeListItemDto item = event.getContent();
    // 
    service.deleteInternal(item);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto)

Example 2 with IdmCodeListItemDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.

the class DefaultCodeListManager method createItem.

@Override
@Transactional
public IdmCodeListItemDto createItem(Serializable codeListIdentifier, String code, String name, BasePermission... permission) {
    Assert.notNull(codeListIdentifier, "CodeList identifier is required.");
    Assert.notNull(code, "Item code is required.");
    Assert.notNull(name, "Item name is required.");
    // 
    IdmCodeListDto codeList = get(codeListIdentifier);
    Assert.notNull(codeList, "CodeList is required.");
    // 
    IdmCodeListItemDto item = new IdmCodeListItemDto();
    item.setCodeList(codeList.getId());
    item.setCode(code);
    item.setName(name);
    // 
    return saveItem(item, permission);
}
Also used : IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmCodeListItemDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.

the class CodeListItemByCodeEvaluatorIntegrationTest method testPermissions.

@Test
public void testPermissions() {
    // create codelist and items
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
    IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListItemDto itemTwo = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
    // other
    codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
    // 
    List<IdmCodeListItemDto> items = null;
    IdmRoleDto roleOne = getHelper().createRole();
    // 
    getHelper().createIdentityRole(identity, roleOne);
    // check - read without policy
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertTrue(items.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
    Assert.assertTrue(items.isEmpty());
    // 
    // create authorization policies - assign to role
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.AUTOCOMPLETE);
    ConfigurationMap properties = new ConfigurationMap();
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_ITEM_CODES, itemOne.getCode());
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // without read permission
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(items.isEmpty());
        // 
        // evaluate	access
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertEquals(1, items.size());
        Assert.assertEquals(itemOne.getId(), items.get(0).getId());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.AUTOCOMPLETE.name())));
    } finally {
        logout();
    }
    // all items by default
    properties = new ConfigurationMap();
    properties.put(CodeListItemByCodeEvaluator.PARAMETER_CODELIST, codeListOne.getId());
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeEvaluator.class, properties, IdmBasePermission.AUTOCOMPLETE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.AUTOCOMPLETE).getContent();
        Assert.assertEquals(2, items.size());
        Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemOne.getId())));
        Assert.assertTrue(items.stream().anyMatch(i -> i.getId().equals(itemTwo.getId())));
    } finally {
        logout();
    }
}
Also used : IdmCodeListItemService(eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) CodeListManager(eu.bcvsolutions.idm.core.eav.api.service.CodeListManager) IdmCodeListItem(eu.bcvsolutions.idm.core.eav.entity.IdmCodeListItem) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 4 with IdmCodeListItemDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.

the class CodeListItemByCodeListEvaluatorIntegrationTest method testPermissions.

@Test
public void testPermissions() {
    // create codelist and items
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmCodeListDto codeListOne = codeListManager.create(getHelper().createName());
    IdmCodeListItemDto itemOne = codeListManager.createItem(codeListOne.getId(), getHelper().createName(), getHelper().createName());
    IdmCodeListDto codeListTwo = codeListManager.create(getHelper().createName());
    // other
    codeListManager.createItem(codeListTwo.getId(), getHelper().createName(), getHelper().createName());
    // 
    List<IdmCodeListItemDto> items = null;
    IdmRoleDto roleOne = getHelper().createRole();
    // 
    getHelper().createIdentityRole(identity, roleOne);
    // check - read without policy
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(items.isEmpty());
    } finally {
        logout();
    }
    // 
    // without login
    items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
    Assert.assertTrue(items.isEmpty());
    // 
    // create authorization policies - assign to role
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.READ);
    getHelper().createAuthorizationPolicy(roleOne.getId(), CoreGroupPermission.CODELISTITEM, IdmCodeListItem.class, CodeListItemByCodeListEvaluator.class);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // without update permission
        items = codeListItemService.find(null, IdmBasePermission.UPDATE).getContent();
        Assert.assertTrue(items.isEmpty());
        // 
        // evaluate	access
        items = codeListItemService.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, items.size());
        Assert.assertEquals(itemOne.getId(), items.get(0).getId());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
    } finally {
        logout();
    }
    // 
    getHelper().createUuidPolicy(roleOne.getId(), codeListOne.getId(), IdmBasePermission.UPDATE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        Set<String> permissions = codeListItemService.getPermissions(itemOne);
        Assert.assertEquals(2, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
    } finally {
        logout();
    }
}
Also used : IdmCodeListItemService(eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) CodeListManager(eu.bcvsolutions.idm.core.eav.api.service.CodeListManager) IdmCodeListItem(eu.bcvsolutions.idm.core.eav.entity.IdmCodeListItem) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 5 with IdmCodeListItemDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto in project CzechIdMng by bcvsolutions.

the class DefaultCodeListManagerIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    IdmCodeListDto codeList = manager.create(getHelper().createName());
    IdmCodeListItemDto item = manager.createItem(codeList, getHelper().createName(), getHelper().createName());
    // 
    Assert.assertNotNull(manager.get(codeList));
    Assert.assertNotNull(manager.getItem(codeList, item.getCode()));
    Assert.assertNotNull(formService.getDefinition(codeList.getFormDefinition().getId()));
    // 
    manager.delete(codeList);
    // 
    Assert.assertNull(manager.get(codeList));
    Assert.assertNull(manager.getItem(codeList, item.getCode()));
    Assert.assertNull(formService.getDefinition(codeList.getFormDefinition().getId()));
}
Also used : IdmCodeListDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto) IdmCodeListItemDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmCodeListItemDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListItemDto)9 IdmCodeListDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmCodeListDto)6 Transactional (org.springframework.transaction.annotation.Transactional)5 Test (org.junit.Test)4 List (java.util.List)3 Assert (org.junit.Assert)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 CodeListManager (eu.bcvsolutions.idm.core.eav.api.service.CodeListManager)2 IdmCodeListItemService (eu.bcvsolutions.idm.core.eav.api.service.IdmCodeListItemService)2 IdmCodeListItem (eu.bcvsolutions.idm.core.eav.entity.IdmCodeListItem)2 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)2 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)2 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 Set (java.util.Set)2 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1