Search in sources :

Example 61 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto 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 62 with IdmContractSliceDto

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

the class DefaultContractSliceManager method updateValidTillOnPreviousSlice.

@Override
@Transactional
public void updateValidTillOnPreviousSlice(IdmContractSliceDto slice, List<IdmContractSliceDto> slices) {
    Assert.notNull(slice, "Contract slice cannot be null!");
    Assert.notNull(slices, "Contract slices are required.");
    if (slice.getValidFrom() == null) {
        return;
    }
    IdmContractSliceDto previousSlice = this.findPreviousSlice(slice, slices);
    if (previousSlice == null) {
        return;
    }
    // Previous slice will be valid till starts of validity next slice
    previousSlice.setValidTill(slice.getValidFrom().minusDays(1));
    contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, previousSlice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto 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 64 with IdmContractSliceDto

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

the class DefaultContractSliceManager method recalculateValidTill.

/**
 * Recalculate valid till on given slice and on previous slice
 *
 * @param slice
 * @param slices
 */
private void recalculateValidTill(IdmContractSliceDto slice, List<IdmContractSliceDto> slices) {
    this.getBean().updateValidTillOnPreviousSlice(slice, slices);
    IdmContractSliceDto nextSlice = this.getBean().findNextSlice(slice, slices);
    if (nextSlice != null) {
        LocalDate validTill = nextSlice.getValidFrom().minusDays(1);
        slice.setValidTill(validTill);
    } else {
        slice.setValidTill(null);
    }
    // Save with skip this processor
    saveWithoutRecalculate(slice);
}
Also used : LocalDate(java.time.LocalDate) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 65 with IdmContractSliceDto

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

the class ContractSliceSynchronizationExecutor method doDeleteEntity.

/**
 * Delete entity linked with given account
 *
 * @param account
 * @param entityType
 * @param log
 * @param logItem
 * @param actionLogs
 */
protected void doDeleteEntity(AccAccountDto account, SystemEntityType entityType, SysSyncLogDto log, SysSyncItemLogDto logItem, List<SysSyncActionLogDto> actionLogs) {
    IdmContractSliceDto dto = this.getDtoByAccount(null, account);
    if (dto == null) {
        addToItemLog(logItem, MessageFormat.format("Warning! - Entity for account [{0}] was not found!", account.getUid()));
        initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
    String entityIdentification = dto.getId().toString();
    if (dto instanceof Codeable) {
        entityIdentification = ((Codeable) dto).getCode();
    }
    logItem.setDisplayName(entityIdentification);
    // Delete entity
    // Set dirty state during recalculation, the process of recalculation will be
    // solved in ClearDirtyStateForContractSliceTaskExecutor
    // ClearDirtyStateForContractSliceTaskExecutor will be started with HR
    // processes.
    EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(ContractSliceEventType.DELETE, dto, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE));
    // We do not want execute HR processes for every contract. We need start
    // them for every identity only once.
    // For this we skip them now. HR processes must be start after whole
    // sync finished (by using dependent scheduled task)!
    event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
    // 
    // We don't want recalculate automatic role by attribute recalculation for every
    // contract.
    // Recalculation will be started only once.
    event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
    getService().publish(event);
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Aggregations

IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 Test (org.junit.Test)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)36 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)35 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)26 UUID (java.util.UUID)22 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)21 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)20 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)19 HashMap (java.util.HashMap)19 ImmutableMap (com.google.common.collect.ImmutableMap)17 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)17 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 ContractSliceManager (eu.bcvsolutions.idm.core.api.service.ContractSliceManager)17 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)16