Search in sources :

Example 41 with IdmContractSliceFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.

the class DefaultContractSliceManager method findValidSlice.

@Override
@Transactional
public IdmContractSliceDto findValidSlice(UUID contractId) {
    Assert.notNull(contractId, "Contract is mandatory!");
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setShouldBeUsingAsContract(Boolean.TRUE);
    sliceFilter.setParentContract(contractId);
    // First try found valid slice
    List<IdmContractSliceDto> validSlices = contractSliceService.find(sliceFilter, null).getContent();
    if (!validSlices.isEmpty()) {
        return validSlices.get(0);
    }
    // None valid slice exists, now we found all slices
    sliceFilter.setShouldBeUsingAsContract(null);
    List<IdmContractSliceDto> slices = contractSliceService.find(sliceFilter, null).getContent();
    // We does not have any slices for this contract
    if (slices.isEmpty()) {
        return null;
    }
    LocalDate now = LocalDate.now();
    // Try to find the nearest slice in future
    IdmContractSliceDto resultSlice = slices.stream().filter(slice -> now.isBefore(slice.getValidFrom())).min(Comparator.comparing(IdmContractSliceDto::getValidFrom)).orElse(null);
    if (resultSlice != null) {
        return resultSlice;
    }
    return null;
}
Also used : IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) LocalDate(java.time.LocalDate) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with IdmContractSliceFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.

the class DefaultContractSliceManager method setSliceAsCurrentlyUsing.

@Override
@Transactional
public IdmContractSliceDto setSliceAsCurrentlyUsing(IdmContractSliceDto slice, Map<String, Serializable> eventProperties) {
    // contract)
    if (slice.getParentContract() != null) {
        // Find other slices with this contract and marked "is using as contract"
        // (usually should be returned only one)
        IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
        sliceFilter.setParentContract(slice.getParentContract());
        sliceFilter.setUsingAsContract(Boolean.TRUE);
        List<IdmContractSliceDto> otherSlices = contractSliceService.find(sliceFilter, null).getContent();
        // To all this slices (exclude itself) set "using as contract" on false
        // 
        otherSlices.stream().filter(// 
        s -> !s.equals(slice)).forEach(s -> {
            // 
            s.setUsingAsContract(false);
            // We want only save data, not update contract by slice
            contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, s, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
        });
    }
    slice.setUsingAsContract(true);
    // attribute 'Is using as contract' to true.
    if (eventProperties == null) {
        return contractSliceService.save(slice);
    }
    return contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.copyOf(eventProperties))).getContent();
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) Map(java.util.Map) ContractSliceConfiguration(eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration) Pageable(org.springframework.data.domain.Pageable) Objects(com.google.common.base.Objects) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ImmutableMap(com.google.common.collect.ImmutableMap) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) LocalDate(java.time.LocalDate) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) HashMap(java.util.HashMap) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) Strings(com.google.common.base.Strings) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Service(org.springframework.stereotype.Service) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Logger(org.slf4j.Logger) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ChronoUnit(java.time.temporal.ChronoUnit) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) Comparator(java.util.Comparator) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with IdmContractSliceFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractService method applyContext.

@Override
protected IdmIdentityContractDto applyContext(IdmIdentityContractDto dto, IdmIdentityContractFilter context, BasePermission... permission) {
    dto = super.applyContext(dto, context, permission);
    if (dto == null || context == null) {
        return dto;
    }
    if (dto.getControlledBySlices() != null || !context.isAddControlledBySlices()) {
        // flag already initialized in toDto method
        return dto;
    }
    // 
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setParentContract(dto.getId());
    dto.setControlledBySlices(contractSliceService.count(sliceFilter) > 0);
    // 
    return dto;
}
Also used : IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)

Example 44 with IdmContractSliceFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.

the class IdmContractSliceController method toFilter.

@Override
protected IdmContractSliceFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmContractSliceFilter filter = new IdmContractSliceFilter(parameters, getParameterConverter());
    filter.setIdentity(getParameterConverter().toEntityUuid(parameters, "identity", IdmIdentityDto.class));
    filter.setValid(getParameterConverter().toBoolean(parameters, "valid"));
    filter.setExterne(getParameterConverter().toBoolean(parameters, "externe"));
    filter.setDisabled(getParameterConverter().toBoolean(parameters, "disabled"));
    filter.setMain(getParameterConverter().toBoolean(parameters, "main"));
    filter.setValidNowOrInFuture(getParameterConverter().toBoolean(parameters, "validNowOrInFuture"));
    filter.setExcludeContract(getParameterConverter().toUuid(parameters, "excludeContract"));
    filter.setParentContract(getParameterConverter().toUuid(parameters, "parentContract"));
    filter.setWithoutParent(getParameterConverter().toBoolean(parameters, "withoutParent"));
    filter.setContractCode(getParameterConverter().toString(parameters, "contractCode"));
    return filter;
}
Also used : IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 45 with IdmContractSliceFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.

the class TreeNodeDeleteProcessor method checkWithoutForceDelete.

/**
 * Check tree node can be deleted without force delete.
 *
 * @param treeNode deleted tree node
 * @throws ResultCodeException if not
 */
private void checkWithoutForceDelete(IdmTreeNodeDto treeNode) {
    UUID treeNodeId = treeNode.getId();
    // 
    if (service.findChildrenByParent(treeNodeId, PageRequest.of(0, 1)).getTotalElements() > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeNode", treeNode.getCode()));
    }
    // 
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setWorkPosition(treeNodeId);
    contractFilter.setRecursionType(RecursionType.NO);
    if (identityContractService.count(contractFilter) > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getCode()));
    }
    // 
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setTreeNode(treeNodeId);
    if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACT_SLICES, ImmutableMap.of("treeNode", treeNode.getCode()));
    }
    // 
    IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
    positionFilter.setWorkPosition(treeNodeId);
    if (contractPositionService.find(positionFilter, PageRequest.of(0, 1)).getTotalElements() > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACT_POSITIONS, ImmutableMap.of("treeNode", treeNode.getCode()));
    }
    // 
    // check related automatic roles
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setTreeNodeId(treeNodeId);
    if (roleTreeNodeService.find(filter, null).getTotalElements() > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_ROLE, ImmutableMap.of("treeNode", treeNode.getCode()));
    }
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) UUID(java.util.UUID) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)

Aggregations

IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)45 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 Test (org.junit.Test)29 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)24 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)23 UUID (java.util.UUID)20 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)16 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)16 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)16 HashMap (java.util.HashMap)14 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)13 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)13 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)13 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)13 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)13 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)13 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)13 LocalDate (java.time.LocalDate)13