Search in sources :

Example 26 with AbstractDto

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

the class DefaultAuthorizationManager method getEnabledDistinctPolicies.

/**
 * Cache decorator - get or load current identity authorization policies.
 * Distinct policies are returned only
 *
 * @param identityId
 * @param entityType
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected List<IdmAuthorizationPolicyDto> getEnabledDistinctPolicies(UUID identityId, Class<? extends Identifiable> entityType) {
    if (identityId == null) {
        // TODO: support setting policies to not logged user - e.g. public endpoints.
        return Lists.newArrayList();
    }
    Assert.notNull(entityType, "Entity type is required.");
    // 
    // try to get cached policies
    Map<Class<? extends Identifiable>, List<UUID>> cachedPolicies;
    ValueWrapper value = cacheManager.getValue(AUTHORIZATION_POLICY_CACHE_NAME, identityId);
    if (value != null) {
        // cache value is never null - create copy
        cachedPolicies = new HashMap<>((Map) value.get());
    } else {
        cachedPolicies = new HashMap<>();
    }
    if (cachedPolicies.containsKey(entityType)) {
        // cache contains policy identifiers only -> get policy dto
        return cachedPolicies.get(entityType).stream().map(policyId -> getAuthorizationPolicy(policyId)).collect(Collectors.toList());
    }
    // distinct policies
    List<IdmAuthorizationPolicyDto> enabledDistinctPolicies = new ArrayList<>();
    // load policies
    service.getEnabledPolicies(identityId, entityType).stream().filter(// TODO: compatibility issues - agendas without authorization support
    p -> supportsEntityType(p, entityType)).forEach(policy -> {
        boolean contains = false;
        for (IdmAuthorizationPolicyDto registeredPolicy : enabledDistinctPolicies) {
            if (isDuplicate(policy, registeredPolicy)) {
                // policy with the same configuration is already registered
                contains = true;
                break;
            }
        }
        // register policy
        if (!contains) {
            enabledDistinctPolicies.add(policy);
        }
        // cache all policies (even duplicates to prevent select)
        cacheManager.cacheValue(AUTHORIZATION_POLICY_DEFINITION_CACHE_NAME, policy.getId(), policy);
    });
    // cache policies as uuid
    cachedPolicies.put(entityType, // dto => uuid
    enabledDistinctPolicies.stream().map(AbstractDto::getId).collect(Collectors.toList()));
    cacheManager.cacheValue(AUTHORIZATION_POLICY_CACHE_NAME, identityId, cachedPolicies);
    // 
    return enabledDistinctPolicies;
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ModuleService(eu.bcvsolutions.idm.core.api.service.ModuleService) AuthorizableService(eu.bcvsolutions.idm.core.security.api.service.AuthorizableService) Objects(com.google.common.base.Objects) Root(javax.persistence.criteria.Root) AuthorizationManager(eu.bcvsolutions.idm.core.security.api.service.AuthorizationManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) AuthorizationPolicy(eu.bcvsolutions.idm.core.security.api.domain.AuthorizationPolicy) Set(java.util.Set) UUID(java.util.UUID) AuthorizationEvaluator(eu.bcvsolutions.idm.core.security.api.service.AuthorizationEvaluator) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Serializable(java.io.Serializable) List(java.util.List) AuthorizationEvaluatorDto(eu.bcvsolutions.idm.core.security.api.dto.AuthorizationEvaluatorDto) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Assert(org.springframework.util.Assert) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) ArrayList(java.util.ArrayList) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with AbstractDto

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

the class DefaultSysSystemAttributeMappingService method getAttributeValue.

/**
 * Find value for this mapped attribute by property name. Returned value can be
 * list of objects. Returns transformed value.
 *
 * @param uid               - Account identifier
 * @param entity
 * @param attributeHandling
 * @return
 * @throws IntrospectionException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling, MappingContext mappingContext) {
    Object idmValue = null;
    // 
    if (attributeHandling.isPasswordAttribute()) {
        // there but in PrepareConnectorObjectProcessor
        return null;
    }
    // 
    SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeHandling);
    // 
    if (attributeHandling.isExtendedAttribute() && entity != null && formService.isFormable(entity.getClass())) {
        List<IdmFormValueDto> formValues = formService.getValues(entity, attributeHandling.getIdmPropertyName());
        if (formValues.isEmpty()) {
            idmValue = null;
        } else if (schemaAttributeDto.isMultivalued()) {
            // Multiple value extended attribute
            List<Object> values = new ArrayList<>();
            formValues.stream().forEachOrdered(formValue -> {
                values.add(this.resolveFormValue(formValue));
            });
            idmValue = values;
        } else {
            // Single value extended attribute
            IdmFormValueDto formValue = formValues.get(0);
            if (formValue.isConfidential()) {
                Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
                // then convert to GuardedString will be did.
                if (confidentialValue instanceof String && schemaAttributeDto.getClassType().equals(GuardedString.class.getName())) {
                    idmValue = new GuardedString((String) confidentialValue);
                } else {
                    idmValue = confidentialValue;
                }
            } else {
                idmValue = this.resolveFormValue(formValue);
            }
        }
    } else // Find value from entity
    if (attributeHandling.isEntityAttribute()) {
        if (attributeHandling.isConfidentialAttribute()) {
            // If is attribute isConfidential, then we will find value in
            // secured storage
            idmValue = confidentialStorage.getGuardedString(entity.getId(), entity.getClass(), attributeHandling.getIdmPropertyName());
        } else {
            try {
                // We will search value directly in entity by property name
                idmValue = EntityUtils.getEntityValue(entity, attributeHandling.getIdmPropertyName());
            } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException ex) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass(), "schemaAtribute", attributeHandling.getSchemaAttribute().toString()), ex);
            }
        }
    } else {
    // If Attribute value is not in entity nor in extended attribute, then idmValue
    // is null.
    // It means attribute is static ... we will call transformation to resource.
    }
    return this.transformValueToResource(uid, idmValue, attributeHandling, entity, mappingContext);
}
Also used : IdmScriptCategory(eu.bcvsolutions.idm.core.api.domain.IdmScriptCategory) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) SysSchemaAttribute(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOUtils(org.apache.commons.io.IOUtils) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SysSyncConfigRepository(eu.bcvsolutions.idm.acc.repository.SysSyncConfigRepository) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) SysSystemMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemMapping_) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) BooleanUtils(org.apache.commons.lang3.BooleanUtils) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Root(javax.persistence.criteria.Root) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) AbstractScriptEvaluator(eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) Subquery(javax.persistence.criteria.Subquery) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) SysSystemAttributeMappingRepository(eu.bcvsolutions.idm.acc.repository.SysSystemAttributeMappingRepository) FormPropertyManager(eu.bcvsolutions.idm.acc.service.api.FormPropertyManager) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SysSchemaAttribute_(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute_) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) SysSchemaObjectClass(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) SysRoleSystemAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysRoleSystemAttributeRepository) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Optional(java.util.Optional) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) OrderAwarePluginRegistry(org.springframework.plugin.core.OrderAwarePluginRegistry) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IcPasswordAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcPasswordAttributeImpl) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto) MessageFormat(java.text.MessageFormat) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) SysSystemMapping(eu.bcvsolutions.idm.acc.entity.SysSystemMapping) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) SysSyncRoleConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncRoleConfig_) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ArrayList(java.util.ArrayList) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 28 with AbstractDto

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

the class DefaultEntityEventManager method isDuplicate.

/**
 * Returns true, when events are duplicates
 * - event type, parent event type, properties and original source is compared => all properties, which can be used in processors.
 *
 * @param olderEvent
 * @param event
 * @return
 */
protected boolean isDuplicate(IdmEntityEventDto olderEvent, IdmEntityEventDto event) {
    Assert.notNull(olderEvent, "Older event is required.");
    Assert.notNull(event, "Event is required.");
    // 
    boolean result = Objects.equal(olderEvent.getEventType(), event.getEventType()) && Objects.equal(olderEvent.getParentEventType(), event.getParentEventType()) && Objects.equal(getProperties(olderEvent), getProperties(event));
    if (!result) {
        // we can end - events are different
        return false;
    }
    if (olderEvent.getOriginalSource() == null && event.getOriginalSource() == null) {
        return true;
    }
    // previous content to processing (e.g. contract processors).
    if (!Objects.equal(olderEvent.getOriginalSource(), event.getOriginalSource())) {
        return false;
    }
    if (!(olderEvent.getOriginalSource() instanceof AbstractDto)) {
        // Evaluated already by 'equal' method above.
        return false;
    }
    // If both original sources are DTOs, then we are comparing original sources (DTOs) as JSON without embedded.
    AbstractDto olderOriginalSource = (AbstractDto) olderEvent.getOriginalSource();
    AbstractDto originalSource = (AbstractDto) event.getOriginalSource();
    try {
        // Prevent to change event setting => defensive copy by mapper.
        AbstractDto olderOriginalSourceCopy = olderOriginalSource.getClass().getDeclaredConstructor().newInstance();
        modelMapper.map(olderOriginalSource, olderOriginalSourceCopy);
        AbstractDto originalSourceCopy = originalSource.getClass().getDeclaredConstructor().newInstance();
        modelMapper.map(originalSource, originalSourceCopy);
        // Embedded is ignored.
        olderOriginalSourceCopy.setEmbedded(null);
        originalSourceCopy.setEmbedded(null);
        // Audit fields are ignored.
        DtoUtils.clearAuditFields(olderOriginalSourceCopy);
        DtoUtils.clearAuditFields(originalSourceCopy);
        // 
        return mapper.writeValueAsString(olderOriginalSourceCopy).equals(mapper.writeValueAsString(originalSourceCopy));
    } catch (JsonProcessingException | ReflectiveOperationException ex) {
        LOG.warn("Comparing json for checking duplicate events failed - both events [{}]-[{}] will be executed!", olderEvent, event, ex);
        // 
        return false;
    }
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 29 with AbstractDto

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

the class DefaultEntityEventManager method process.

@Override
@Transactional
@SuppressWarnings("unchecked")
public <E extends Serializable> EventContext<E> process(EntityEvent<E> event, EntityEvent<?> parentEvent) {
    Assert.notNull(event, "Event is required for processing.");
    Serializable content = event.getContent();
    // 
    LOG.info("Publishing event [{}]", event);
    // 
    // continue suspended event
    event.getContext().setSuspended(false);
    // 
    if (parentEvent != null) {
        event.setParentId(parentEvent.getId());
        event.setRootId(parentEvent.getRootId() == null ? parentEvent.getId() : parentEvent.getRootId());
        if (parentEvent.getPriority() != null && (event.getPriority() == null || event.getPriority().getPriority() < parentEvent.getPriority().getPriority())) {
            // parent has higher priority ... execute with the same priority as parent
            event.setPriority(parentEvent.getPriority());
        }
        // parent event type can be preset manually
        if (StringUtils.isEmpty(event.getParentType())) {
            event.setParentType(parentEvent.getType().name());
        }
        // propagate properties from parent to child event.
        // properties need for internal event processing are ignored (see {@link EntityEvent} properties)
        propagateProperties(event, parentEvent);
    }
    // read previous (original) dto source - usable in "check modification" processors
    if (event.getOriginalSource() == null && (content instanceof AbstractDto)) {
        // original source could be set externally
        AbstractDto contentDto = (AbstractDto) content;
        // works only for dto modification
        if (contentDto.getId() != null && lookupService.getDtoLookup(contentDto.getClass()) != null) {
            event.setOriginalSource((E) lookupService.lookupDto(contentDto.getClass(), contentDto.getId()));
        }
    }
    // event is persisted automatically, when parent event is persisted
    try {
        if (content instanceof BaseDto && event.getId() == null && event.getParentId() != null && lookupService.getEntityClass(((BaseDto) content).getClass()) != null) {
            // entity event can be persisted into queue only
            BaseDto dto = (BaseDto) content;
            if (dto.getId() == null) {
                // prepare id for new content - event is persisted before entity is persisted.
                dto.setId(UUID.randomUUID());
            }
            // 
            IdmEntityEventDto preparedEvent = toDto(dto, (EntityEvent<AbstractDto>) event);
            // RUNNING => prevent to start by async task
            preparedEvent.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
            preparedEvent.setRootId(event.getRootId() == null ? event.getParentId() : event.getRootId());
            preparedEvent = entityEventService.save(preparedEvent);
            event.setId(preparedEvent.getId());
            // 
            // prepared event is be executed
            CoreEvent<IdmEntityEventDto> executeEvent = new CoreEvent<>(EntityEventType.EXECUTE, preparedEvent);
            publisher.publishEvent(executeEvent);
            // 
            // fill original event result
            E processedContent = (E) preparedEvent.getContent();
            if (processedContent != null) {
                event.setContent(processedContent);
            }
            event.getContext().addResult(new DefaultEventResult<E>(event, new EmptyEntityEventProcessor<E>()));
            // 
            return completeEvent(event);
        } else {
            publisher.publishEvent(event);
            // 
            return completeEvent(event);
        }
    } catch (Exception ex) {
        completeEvent(event);
        // 
        throw ex;
    }
}
Also used : Serializable(java.io.Serializable) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with AbstractDto

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

the class AbstractConnectorType method load.

@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
    if (!connectorType.isReopened()) {
        // Load default value for new system.
        connectorType.setMetadata(this.getMetadata());
        return connectorType;
    }
    // Load the system.
    SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemDto, "System must exists!");
    connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
    // Set remote server ID to the connector type.
    connectorType.setRemoteServer(systemDto.getRemoteServer());
    // Load the mapping.
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setSystemId(systemDto.getId());
    List<SysSystemMappingDto> mappingDtos = systemMappingService.find(mappingFilter, null).getContent().stream().sorted(Comparator.comparing(SysSystemMappingDto::getCreated)).collect(Collectors.toList());
    // Show alert if more mappings exists.
    if (mappingDtos.size() > 1) {
        connectorType.getMetadata().put(ALERT_MORE_MAPPINGS, Boolean.TRUE.toString());
    }
    SysSystemMappingDto mappingDto = mappingDtos.stream().findFirst().orElse(null);
    connectorType.getEmbedded().put(MAPPING_DTO_KEY, mappingDto);
    // Load the sync.
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(systemDto.getId());
    if (mappingDto != null) {
        syncFilter.setSystemMappingId(mappingDto.getId());
    }
    AbstractSysSyncConfigDto syncDto = syncConfigService.find(syncFilter, null).getContent().stream().min(Comparator.comparing(AbstractDto::getCreated)).orElse(null);
    connectorType.getEmbedded().put(SYNC_DTO_KEY, syncDto);
    return connectorType;
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)54 UUID (java.util.UUID)28 Test (org.junit.Test)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)15 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)13 HashMap (java.util.HashMap)12 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Assert (org.springframework.util.Assert)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 Map (java.util.Map)10 Service (org.springframework.stereotype.Service)10 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IntrospectionException (java.beans.IntrospectionException)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ImmutableMap (com.google.common.collect.ImmutableMap)8