Search in sources :

Example 1 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManager method saveInternal.

@Override
@Transactional
public IdmIdentityProjectionDto saveInternal(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityProjectionDto dto = event.getContent();
    Assert.notNull(dto, "DTO is required.");
    // identity
    IdmIdentityDto identity = saveIdentity(event, permission);
    dto.setIdentity(identity);
    event.setContent(dto);
    // prime contract - will be saved all time
    dto.setContract(saveContract(event, permission));
    event.setContent(dto);
    // other contracts
    dto.setOtherContracts(saveOtherContracts(event, permission));
    event.setContent(dto);
    // other positions
    dto.setOtherPositions(saveOtherPositions(event, permission));
    event.setContent(dto);
    // assigned roles - new identity only
    saveIdentityRoles(event, permission);
    // 
    return event.getContent();
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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 3 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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)

Example 4 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto 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)

Example 5 with IdmIdentityProjectionDto

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

the class IdentityProjectionSaveProcessor method process.

@Override
public EventResult<IdmIdentityProjectionDto> process(EntityEvent<IdmIdentityProjectionDto> event) {
    IdmIdentityProjectionDto dto = manager.saveInternal(event, event.getPermission());
    event.setContent(dto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)

Aggregations

IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)32 Transactional (org.springframework.transaction.annotation.Transactional)24 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)23 Test (org.junit.Test)23 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)22 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)22 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)21 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)18 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)15 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)8 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)7 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)7