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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations