Search in sources :

Example 1 with BaseDto

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

the class DefaultWorkflowTaskInstanceService method internalSearch.

private PageImpl<WorkflowTaskInstanceDto> internalSearch(WorkflowFilterDto filter, Pageable pageable) {
    // if currently logged user can read all task continue
    if (!canReadAllTask()) {
        // if user can't read all task check filter
        if (filter.getCandidateOrAssigned() == null) {
            filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
        } else {
            IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
            if (!identity.getId().equals(securityService.getCurrentId())) {
                throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for access to all tasks!");
            }
        }
    // else is filled candidate and it is equals currently logged user
    }
    String processDefinitionId = filter.getProcessDefinitionId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    TaskQuery query = taskService.createTaskQuery();
    query.active();
    query.includeProcessVariables();
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    if (filter.getProcessInstanceId() != null) {
        query.processInstanceId(filter.getProcessInstanceId());
    }
    if (filter.getId() != null) {
        query.taskId(filter.getId().toString());
    }
    if (filter.getCreatedAfter() != null) {
        query.taskCreatedAfter(filter.getCreatedAfter().toDate());
    }
    if (filter.getCreatedBefore() != null) {
        query.taskCreatedBefore(filter.getCreatedBefore().toDate());
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.processVariableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    if (filter.getCandidateOrAssigned() != null) {
        BaseDto dto = lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
        Assert.notNull(dto);
        query.taskCandidateOrAssigned(String.valueOf(dto.getId()));
    }
    query.orderByTaskCreateTime();
    query.desc();
    long count = query.count();
    // it's possible that pageable is null
    List<Task> tasks = null;
    if (pageable == null) {
        tasks = query.list();
    } else {
        tasks = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowTaskInstanceDto> dtos = new ArrayList<>();
    if (tasks != null) {
        for (Task task : tasks) {
            dtos.add(toResource(task));
        }
    }
    return new PageImpl<WorkflowTaskInstanceDto>(dtos, pageable, count);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Task(org.activiti.engine.task.Task) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) TaskQuery(org.activiti.engine.task.TaskQuery) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with BaseDto

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

the class EntityToUuidConverter method convert.

@Override
public UUID convert(MappingContext<BaseEntity, UUID> context) {
    if (context != null && context.getSource() != null && context.getSource().getId() instanceof UUID) {
        MappingContext<?, ?> parentContext = context.getParent();
        if (parentContext != null && parentContext.getDestination() != null && AbstractDto.class.isAssignableFrom(parentContext.getDestinationType()) && parentContext.getSource() != null && BaseEntity.class.isAssignableFrom(parentContext.getSourceType())) {
            try {
                AbstractDto parentDto = (AbstractDto) parentContext.getDestination();
                BaseEntity entity = (BaseEntity) context.getSource();
                Map<String, BaseDto> embedded = parentDto.getEmbedded();
                PropertyMapping propertyMapping = (PropertyMapping) context.getMapping();
                // Find name of field by property mapping
                String field = propertyMapping.getLastDestinationProperty().getName();
                // Find field in DTO class
                Field fieldTyp = getFirstFieldInClassHierarchy(parentContext.getDestinationType(), field);
                if (fieldTyp.isAnnotationPresent(Embedded.class)) {
                    Embedded embeddedAnnotation = fieldTyp.getAnnotation(Embedded.class);
                    if (embeddedAnnotation.enabled()) {
                        // If has field Embedded (enabled) annotation, then
                        // we will create new
                        // instance of DTO
                        // 
                        AbstractDto dto = null;
                        // If dto class is abstract get dto from lookup
                        if (Modifier.isAbstract(embeddedAnnotation.dtoClass().getModifiers())) {
                            dto = (AbstractDto) getLookupService().lookupDto(entity.getClass(), entity.getId());
                        } else {
                            dto = embeddedAnnotation.dtoClass().newInstance();
                        }
                        dto.setTrimmed(true);
                        // Separate map entity to new embedded DTO
                        modeler.map(entity, dto);
                        embedded.put(field, dto);
                        // Add filled DTO to embedded map to parent DTO
                        parentDto.setEmbedded(embedded);
                    }
                }
            } catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
                throw new CoreException(e);
            }
        }
        return (UUID) context.getSource().getId();
    }
    return null;
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) PropertyMapping(org.modelmapper.spi.PropertyMapping) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) UUID(java.util.UUID)

Example 3 with BaseDto

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

the class UuidToUuidConverter method convert.

@Override
public UUID convert(MappingContext<UUID, UUID> context) {
    if (context != null && context.getSource() != null && context.getSource() instanceof UUID) {
        MappingContext<?, ?> parentContext = context.getParent();
        if (parentContext != null && parentContext.getDestination() != null && AbstractDto.class.isAssignableFrom(parentContext.getDestinationType()) && parentContext.getSource() != null && BaseEntity.class.isAssignableFrom(parentContext.getSourceType())) {
            try {
                AbstractDto parentDto = (AbstractDto) parentContext.getDestination();
                UUID entityId = (UUID) context.getSource();
                Map<String, BaseDto> embedded = parentDto.getEmbedded();
                PropertyMapping propertyMapping = (PropertyMapping) context.getMapping();
                // Find name of field by property mapping
                String field = propertyMapping.getLastDestinationProperty().getName();
                // Find field in DTO class
                Field fieldTyp = getFirstFieldInClassHierarchy(parentContext.getDestinationType(), field);
                if (fieldTyp.isAnnotationPresent(Embedded.class)) {
                    Embedded embeddedAnnotation = fieldTyp.getAnnotation(Embedded.class);
                    if (embeddedAnnotation.enabled()) {
                        // Load DTO service by dtoClass and get DTO by UUID
                        ReadDtoService<?, ?> lookup = getLookupService().getDtoService(embeddedAnnotation.dtoClass());
                        if (lookup != null) {
                            AbstractDto dto = (AbstractDto) lookup.get(entityId);
                            dto.setTrimmed(true);
                            embedded.put(field, dto);
                            // Add filled DTO to embedded map to parent DTO
                            parentDto.setEmbedded(embedded);
                        }
                    }
                }
            } catch (NoSuchFieldException | SecurityException e) {
                throw new CoreException(e);
            }
        }
    }
    return context == null ? null : (UUID) context.getSource();
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) PropertyMapping(org.modelmapper.spi.PropertyMapping) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) UUID(java.util.UUID)

Example 4 with BaseDto

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

the class DefaultIdmConceptRoleRequestService method toDto.

@Override
protected IdmConceptRoleRequestDto toDto(IdmConceptRoleRequest entity, IdmConceptRoleRequestDto dto) {
    dto = super.toDto(entity, dto);
    if (dto == null) {
        return null;
    }
    // Contract from identity role has higher priority then contract ID in concept role
    if (entity != null && entity.getIdentityRole() != null) {
        dto.setIdentityContract(entity.getIdentityRole().getIdentityContract().getId());
    }
    // we must set automatic role to role tree node
    if (entity != null && entity.getAutomaticRole() != null) {
        dto.setAutomaticRole(entity.getAutomaticRole().getId());
        IdmAutomaticRole automaticRole = entity.getAutomaticRole();
        Map<String, BaseDto> embedded = dto.getEmbedded();
        // 
        BaseDto baseDto = null;
        if (automaticRole instanceof IdmAutomaticRoleAttribute) {
            baseDto = lookupService.getDtoService(IdmAutomaticRoleAttributeDto.class).get(automaticRole.getId());
        } else {
            baseDto = lookupService.getDtoService(IdmRoleTreeNodeDto.class).get(automaticRole.getId());
        }
        // roleTreeNode must be placed there as string, in meta model isn't any attribute like this
        embedded.put("roleTreeNode", baseDto);
        dto.setEmbedded(embedded);
    }
    return dto;
}
Also used : IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute)

Example 5 with BaseDto

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

the class AbstractSynchronizationExecutor method findByCorrelationAttribute.

/**
 * Find entity by correlation attribute
 *
 * @param attribute
 * @param entityType
 * @param icAttributes
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
protected DTO findByCorrelationAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Assert.notNull(attribute);
    Assert.notNull(icAttributes);
    Object value = getValueByMappedAttribute(attribute, icAttributes, context);
    if (value == null) {
        return null;
    }
    if (attribute.isEntityAttribute()) {
        return findByAttribute(attribute.getIdmPropertyName(), value.toString());
    } else if (attribute.isExtendedAttribute()) {
        try {
            Serializable serializableValue = Serializable.class.cast(value);
            List<? extends BaseDto> entities = formService.findOwners(getEntityClass(), attribute.getIdmPropertyName(), serializableValue, null).getContent();
            if (CollectionUtils.isEmpty(entities)) {
                return null;
            }
            if (entities.size() > 1) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", attribute.getName(), "value", value));
            }
            if (entities.size() == 1) {
                return (DTO) entities.get(0);
            }
        } catch (ClassCastException e) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_BAD_VALUE, ImmutableMap.of("value", value), e);
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) List(java.util.List) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto)

Aggregations

BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)6 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)2 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)2 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)2 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)2 IdmAutomaticRole (eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole)2 IdmAutomaticRoleAttribute (eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 PropertyMapping (org.modelmapper.spi.PropertyMapping)2 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)1 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)1 Serializable (java.io.Serializable)1 List (java.util.List)1 Task (org.activiti.engine.task.Task)1 TaskQuery (org.activiti.engine.task.TaskQuery)1