Search in sources :

Example 1 with TreeTypeException

use of eu.bcvsolutions.idm.core.exception.TreeTypeException in project CzechIdMng by bcvsolutions.

the class TreeTypeDeleteProcessor method process.

@Override
public EventResult<IdmTreeTypeDto> process(EntityEvent<IdmTreeTypeDto> event) {
    IdmTreeTypeDto treeType = event.getContent();
    Assert.notNull(treeType);
    // 
    Page<IdmTreeNode> nodes = nodeRepository.findChildren(treeType.getId(), null, new PageRequest(0, 1));
    if (nodes.getTotalElements() > 0) {
        throw new TreeTypeException(CoreResultCode.TREE_TYPE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeType", treeType.getName()));
    }
    if (identityContractRepository.countByWorkPosition_TreeType_Id(treeType.getId()) > 0) {
        throw new TreeTypeException(CoreResultCode.TREE_TYPE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeType", treeType.getName()));
    }
    // 
    service.deleteInternal(treeType);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) TreeTypeException(eu.bcvsolutions.idm.core.exception.TreeTypeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 2 with TreeTypeException

use of eu.bcvsolutions.idm.core.exception.TreeTypeException in project CzechIdMng by bcvsolutions.

the class TreeTypeDeleteProcessor method process.

@Override
public EventResult<IdmTreeTypeDto> process(EntityEvent<IdmTreeTypeDto> event) {
    IdmTreeTypeDto treeType = event.getContent();
    Asserts.notNull(treeType, "TreeType must be set!");
    SysSystemMappingFilter filter = new SysSystemMappingFilter();
    filter.setTreeTypeId(treeType.getId());
    List<SysSystemMappingDto> mappings = systemMappingService.find(filter, null).getContent();
    long count = mappings.size();
    if (count > 0) {
        SysSystemDto systemDto = systemService.get(schemaObjectClassService.get(mappings.get(0).getObjectClass()).getSystem());
        throw new TreeTypeException(AccResultCode.SYSTEM_MAPPING_TREE_TYPE_DELETE_FAILED, ImmutableMap.of("treeType", treeType.getName(), "system", systemDto.getCode()));
    }
    // Delete link to sync contract configuration
    if (treeType != null && treeType.getId() != null) {
        syncConfigRepository.clearDefaultTreeType(treeType.getId());
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) TreeTypeException(eu.bcvsolutions.idm.core.exception.TreeTypeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 TreeTypeException (eu.bcvsolutions.idm.core.exception.TreeTypeException)2 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)1 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)1 PageRequest (org.springframework.data.domain.PageRequest)1