Search in sources :

Example 1 with ContractPositionEventType

use of eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method saveOtherPositions.

protected List<IdmContractPositionDto> saveOtherPositions(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
    List<IdmContractPositionDto> savedPositions = new ArrayList<>(dto.getOtherPositions().size());
    IdmIdentityContractDto contract = dto.getContract();
    // 
    // check other contract position 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_OTHER_POSITION)) {
            LOG.debug("Projection [{}] doesn't save other contract positions.", formProjection.getCode());
            return savedPositions;
        }
    }
    // 
    for (IdmContractPositionDto otherPosition : dto.getOtherPositions()) {
        if (otherPosition.getIdentityContract() == null) {
            if (contract == null) {
                throw new ForbiddenEntityException("contract", IdmBasePermission.READ);
            }
            otherPosition.setIdentityContract(contract.getId());
        }
        ContractPositionEventType positionEventType = ContractPositionEventType.CREATE;
        if (!contractPositionService.isNew(otherPosition)) {
            positionEventType = ContractPositionEventType.UPDATE;
        }
        ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, otherPosition);
        // 
        savedPositions.add(contractPositionService.publish(positionEvent, event, permission).getContent());
        if (previousProjection != null) {
            previousProjection.getOtherPositions().removeIf(p -> {
                return Objects.equals(p.getId(), otherPosition.getId());
            });
        }
    }
    // remove not sent positions, if previous exists
    if (previousProjection != null) {
        for (IdmContractPositionDto contractPosition : previousProjection.getOtherPositions()) {
            ContractPositionEventType positionEventType = ContractPositionEventType.DELETE;
            ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, contractPosition);
            // 
            contractPositionService.publish(positionEvent, event, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.DELETE);
        }
    }
    // 
    return savedPositions;
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ArrayList(java.util.ArrayList) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) 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) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

Aggregations

IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)1 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)1 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)1 ContractPositionEvent (eu.bcvsolutions.idm.core.model.event.ContractPositionEvent)1 ContractPositionEventType (eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType)1 ArrayList (java.util.ArrayList)1