Search in sources :

Example 1 with IdentityContractEventType

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method saveContract.

/**
 * Save the first ~ prime contract.
 *
 * @param event
 * @param permission
 * @return
 */
protected IdmIdentityContractDto saveContract(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityDto identity = dto.getIdentity();
    // 
    IdmIdentityContractDto contract = dto.getContract();
    if (contract == null) {
        // prime contract was not sent => not save, but is needed in other processing
        List<IdmIdentityContractDto> contracts = getContracts(dto, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.READ);
        if (contracts.isEmpty()) {
            return null;
        }
        // ~ prime contract
        return contracts.get(0);
    }
    // check contract has to be saved
    if (identity.getFormProjection() != null) {
        IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
        if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS) && !formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_PRIME_CONTRACT)) {
            LOG.debug("Projection [{}] doesn't save prime contract.", formProjection.getCode());
            return contract;
        }
    }
    contract.setIdentity(identity.getId());
    IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
    if (!contractService.isNew(contract)) {
        contractEventType = IdentityContractEventType.UPDATE;
    }
    EntityEvent<IdmIdentityContractDto> contractEvent = new IdentityContractEvent(contractEventType, contract);
    // 
    return contractService.publish(contractEvent, event, permission).getContent();
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)

Example 2 with IdentityContractEventType

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method deleteContract.

private void deleteContract(EntityEvent<IdmIdentityProjectionDto> event, IdmIdentityContractDto contract, BasePermission... permission) {
    IdentityContractEventType contractEventType = IdentityContractEventType.DELETE;
    IdentityContractEvent otherContractEvent = new IdentityContractEvent(contractEventType, contract);
    if (BooleanUtils.isTrue(contract.getControlledBySlices())) {
        LOG.debug("Contract [{}] is controlled by contract slices, will be ignored in projection.", contract.getId());
        return;
    }
    // 
    contractService.publish(otherContractEvent, event, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.DELETE);
}
Also used : IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType)

Example 3 with IdentityContractEventType

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method saveOtherContracts.

protected List<IdmIdentityContractDto> saveOtherContracts(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
    List<IdmIdentityContractDto> savedContracts = new ArrayList<>(dto.getOtherContracts().size());
    // 
    // check all contracts has to be saved
    IdmIdentityDto identity = dto.getIdentity();
    if (identity.getFormProjection() != null) {
        IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
        if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS)) {
            LOG.debug("Projection [{}] doesn't save other contracts.", formProjection.getCode());
            return savedContracts;
        }
    }
    // 
    for (IdmIdentityContractDto contract : dto.getOtherContracts()) {
        IdentityContractEventType contractEventType = IdentityContractEventType.CREATE;
        if (!contractService.isNew(contract)) {
            contractEventType = IdentityContractEventType.UPDATE;
        // TODO: validation - identity cannot be changed
        } else {
            contract.setIdentity(dto.getIdentity().getId());
        }
        IdentityContractEvent otherContractEvent = new IdentityContractEvent(contractEventType, contract);
        // 
        savedContracts.add(contractService.publish(otherContractEvent, event, permission).getContent());
        if (previousProjection != null) {
            previousProjection.getOtherContracts().removeIf(c -> {
                return Objects.equals(c.getId(), contract.getId());
            });
        }
    }
    // remove not sent contracts, if previous exists
    if (previousProjection != null) {
        boolean primeContractChanged = false;
        // 
        for (IdmIdentityContractDto contract : previousProjection.getOtherContracts()) {
            if (Objects.equals(dto.getContract(), contract)) {
                // new prime contract is saved all time
                primeContractChanged = true;
                continue;
            }
            // 
            deleteContract(event, contract, permission);
        }
        // delete previous prime contract, if order of contracts changed
        if (primeContractChanged && !savedContracts.contains(previousProjection.getContract())) {
            deleteContract(event, previousProjection.getContract(), permission);
        }
    }
    // 
    return savedContracts;
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ArrayList(java.util.ArrayList) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)

Aggregations

IdentityContractEvent (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)3 IdentityContractEventType (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)2 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)2 ArrayList (java.util.ArrayList)1