Search in sources :

Example 21 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutor method processCandidate.

private void processCandidate(DTO candidate, boolean dryRun) {
    if (isInProcessedQueue(candidate)) {
        // item was processed earlier - just drop the count by one
        --count;
        return;
    }
    Optional<OperationResult> result;
    if (dryRun) {
        if (!supportsDryRun()) {
            throw new DryRunNotSupportedException(getName());
        }
        // dry run mode - operation is not executed with dry run code (no content)
        result = Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.DRY_RUN)).build());
    } else {
        result = this.processItem(candidate);
    }
    // 
    if (result.isPresent()) {
        OperationResult opResult = result.get();
        this.logItemProcessed(candidate, opResult);
        if (OperationState.isSuccessful(opResult.getState())) {
            ++counter;
            this.addToProcessedQueue(candidate, opResult);
        }
        LOG.debug("Statefull process [{}] intermediate result: [{}], count: [{}/{}]", getClass().getSimpleName(), opResult, count, counter);
    } else {
        ++counter;
        LOG.debug("Statefull process [{}] processed item [{}] without result.", getClass().getSimpleName(), candidate);
    }
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DryRunNotSupportedException(eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 22 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class ModelMapperConfig method modelMapper.

@SuppressWarnings("unchecked")
@Bean
public ModelMapper modelMapper() {
    ModelMapper modeler = new ModelMapper();
    // We want use STRICT matching strategy ... others can be ambiguous
    modeler.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    // Convert BaseEntity to UIID (get ID)
    Converter<? extends BaseEntity, UUID> entityToUiid = new EntityToUuidConverter(modeler, applicationContext);
    // Convert UIID to Entity
    Converter<UUID, ? extends BaseEntity> uiidToEntity = new UuidToEntityConverter(applicationContext);
    // This converter must be set for only one purpose... workaround fixed
    // error in ModelMapper.
    // When is in DTO field (applicant for example) with type UUID (with
    // conversion to IdmIdentity) and other UUID field (for example
    // modifierId), but with same value as first field, then mapper will be
    // set converted value from first field (applicant) to second field (IdmIdentity to UUID) ->
    // Class cast exception will be throw.
    // + Additionally this converter allows load DTO (by UUID) and put him to embedded map.
    Converter<UUID, UUID> uuidToUiid = new UuidToUuidConverter(applicationContext);
    modeler.createTypeMap(UUID.class, UUID.class).setConverter(uuidToUiid);
    // Converter for resolve problem with 0x00 character in Postgress.
    modeler.createTypeMap(String.class, String.class).setConverter(new StringToStringConverter());
    // Converter OperationResult for resolve problem with 0x00 character in Postgress.
    modeler.createTypeMap(OperationResult.class, OperationResult.class).setConverter(new OperationResultConverter(modeler));
    // Condition for property ... if is property list and dto is trimmed,
    // then will be not used (set null)
    // or if is property list and have parent dto, then will be to set null
    // (only two levels are allowed).
    Condition<Object, Object> trimmListCondition = new Condition<Object, Object>() {

        @Override
        public boolean applies(MappingContext<Object, Object> context) {
            if (List.class.isAssignableFrom(context.getDestinationType())) {
                MappingContext<?, ?> parentContext = context.getParent();
                MappingContext<?, ?> superContext = parentContext != null ? parentContext.getParent() : null;
                if (superContext != null) {
                    if (parentContext != null && parentContext.getDestination() instanceof AbstractDto) {
                        ((AbstractDto) parentContext.getDestination()).setTrimmed(true);
                    }
                    return false;
                }
                if (parentContext != null && parentContext.getDestination() instanceof AbstractDto && ((AbstractDto) parentContext.getDestination()).isTrimmed()) {
                    return false;
                }
            }
            return true;
        }
    };
    modeler.getConfiguration().setPropertyCondition(trimmListCondition);
    // entity to uiid converters will be set for all entities
    entityManager.getMetamodel().getEntities().forEach(entityType -> {
        if (entityType.getJavaType() == null) {
            return;
        }
        @SuppressWarnings("rawtypes") TypeMap typeMapEntityToUiid = modeler.createTypeMap(entityType.getJavaType(), UUID.class);
        typeMapEntityToUiid.setConverter(entityToUiid);
        @SuppressWarnings("rawtypes") TypeMap typeMapUiidToEntity = modeler.createTypeMap(UUID.class, entityType.getJavaType());
        typeMapUiidToEntity.setConverter(uiidToEntity);
    });
    // configure default type map for entities
    // this behavior must be placed in this class, not in toDto methods (getEmbedded use mapper for map entity to dto)
    // identity role and backward compatibility with automatic role
    TypeMap<IdmIdentityRole, IdmIdentityRoleDto> typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
    if (typeMapIdentityRole == null) {
        modeler.createTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole.addMappings(new PropertyMap<IdmIdentityRole, IdmIdentityRoleDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(this.source.getAutomaticRole() != null);
            }
        });
    }
    // concept role request and automatic role backward compatibility
    TypeMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto> typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
    if (typeMapRoleConcept == null) {
        modeler.createTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept.addMappings(new PropertyMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    return modeler;
}
Also used : IdmConceptRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) OperationResultConverter(eu.bcvsolutions.idm.core.config.domain.OperationResultConverter) EntityToUuidConverter(eu.bcvsolutions.idm.core.config.domain.EntityToUuidConverter) MappingContext(org.modelmapper.spi.MappingContext) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) UuidToUuidConverter(eu.bcvsolutions.idm.core.config.domain.UuidToUuidConverter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) UuidToEntityConverter(eu.bcvsolutions.idm.core.config.domain.UuidToEntityConverter) Condition(org.modelmapper.Condition) ModelMapper(org.modelmapper.ModelMapper) StringToStringConverter(eu.bcvsolutions.idm.core.config.domain.StringToStringConverter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) TypeMap(org.modelmapper.TypeMap) Bean(org.springframework.context.annotation.Bean)

Example 23 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class AbstractWorkflowEventProcessor method process.

@Override
public EventResult<DTO> process(EntityEvent<DTO> event) {
    Map<String, Object> variables = new HashMap<>();
    variables.put(WorkflowProcessInstanceService.VARIABLE_DTO, event.getContent());
    OperationResult result = process(variables);
    if (result == null) {
        return null;
    }
    // wf throws exception
    if (result.getException() != null) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, ImmutableMap.of("exception", result.getException()), result.getException());
    }
    return new DefaultEventResult.Builder<>(event, this).setResult(result).build();
}
Also used : HashMap(java.util.HashMap) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 24 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class IdentityContractEnableProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    if (!StringUtils.isEmpty(getWorkflowDefinitionKey())) {
        // wf is configured - execute wf instance
        return super.process(event);
    }
    // 
    IdmIdentityContractDto contract = event.getContent();
    OperationResult result = process(contract, (Boolean) event.getProperties().get(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION));
    return new DefaultEventResult.Builder<>(event, this).setResult(result).build();
}
Also used : OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 25 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class IdentityContractEnableProcessor method process.

/**
 * Check identity state after contract is enabled
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    if (contract.isValid() && contract.getState() != ContractState.EXCLUDED) {
        IdmIdentityDto identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        // we want to enable identity with contract other than default one
        if (newState == IdentityState.VALID && (identity.isDisabled() || identity.getState() == IdentityState.CREATED)) {
            LOG.info("Change identity [{}] state [{}]", identity.getUsername(), IdentityState.VALID);
            // 
            identity.setState(IdentityState.VALID);
            // is neccessary publish new event with skip recalculation automatic roles
            IdentityEvent event = new IdentityEvent(IdentityEventType.UPDATE, identity);
            event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
            identityService.publish(event);
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)14 Test (org.junit.Test)10 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)5 UUID (java.util.UUID)5 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)4 IdmAccountDto (eu.bcvsolutions.idm.core.api.dto.IdmAccountDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)4 ArrayList (java.util.ArrayList)4 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)3 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)3 IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3