use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method process.
@Override
@SuppressWarnings("unchecked")
public <E extends Serializable> EventContext<E> process(EntityEvent<E> event) {
Assert.notNull(event);
Serializable content = event.getContent();
//
LOG.info("Publishing event [{}]", event);
//
// continue suspended event
event.getContext().setSuspended(false);
// 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()));
}
}
//
publisher.publishEvent(event);
LOG.info("Event [{}] is completed", event);
//
return event.getContext();
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class AbstractReadDtoService method toDtos.
/**
* Converts list of entities to list of DTOs
*
* @param entities
* @param trimmed
* @return
*/
protected List<DTO> toDtos(List<E> entities, boolean trimmed) {
if (entities == null) {
return null;
}
List<DTO> dtos = new ArrayList<>();
entities.forEach(entity -> {
try {
DTO newDto = this.getDtoClass(entity).newInstance();
if (newDto instanceof AbstractDto) {
((AbstractDto) newDto).setTrimmed(trimmed);
}
dtos.add(this.toDto(entity, newDto));
} catch (InstantiationException | IllegalAccessException e) {
throw new CoreException(e);
}
});
return dtos;
}
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
* @param idmValue
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling) {
Object idmValue = 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(formValue.getValue());
});
idmValue = values;
} else {
// Single value extended attribute
IdmFormValueDto formValue = formValues.get(0);
if (formValue.isConfidential()) {
Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
// If is confidential value String and schema attribute is GuardedString type, 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 = formValue.getValue();
}
}
} 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 o_O) {
throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass()), o_O);
}
}
} 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);
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningExecutor method findOverloadingAttributes.
/**
* Return list of all overloading attributes for given identity, system and
* uid
*
* @param identityAccount
* @param idenityAccoutnList
* @param operationType
* @param entityType
* @return
*/
@Override
protected List<SysRoleSystemAttributeDto> findOverloadingAttributes(IdmIdentityDto entity, SysSystemDto system, List<? extends EntityAccountDto> idenityAccoutnList, SystemEntityType entityType) {
List<SysRoleSystemAttributeDto> roleSystemAttributesAll = new ArrayList<>();
idenityAccoutnList.stream().filter(ia -> {
AccAccountDto account = DtoUtils.getEmbedded((AccIdentityAccountDto) ia, AccIdentityAccount_.account, AccAccountDto.class);
return ((AccIdentityAccountDto) ia).getIdentityRole() != null && account.getSystem() != null && account.getSystem().equals(system.getId()) && ia.isOwnership();
}).forEach((identityAccountInner) -> {
AbstractDto identityAccount = (AbstractDto) identityAccountInner;
// All identity account with same system and with filled
// identityRole
AccAccountDto account = DtoUtils.getEmbedded(identityAccount, AccIdentityAccount_.account, AccAccountDto.class);
IdmIdentityRoleDto identityRole = DtoUtils.getEmbedded(identityAccount, AccIdentityAccount_.identityRole, IdmIdentityRoleDto.class);
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(identityRole.getRole());
roleSystemFilter.setSystemId(account.getSystem());
List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilter, null).getContent();
if (roleSystems.size() > 1) {
SysRoleSystemDto roleSystem = roleSystems.get(0);
IdmRoleDto roleDto = roleService.get(roleSystem.getRole());
SysSystemDto systemDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
throw new ProvisioningException(AccResultCode.PROVISIONING_DUPLICATE_ROLE_MAPPING, ImmutableMap.of("role", roleDto.getName(), "system", systemDto.getName(), "entityType", entityType));
}
if (!roleSystems.isEmpty()) {
SysRoleSystemDto roleSystem = roleSystems.get(0);
SysRoleSystemAttributeFilter roleSystemAttributeFilter = new SysRoleSystemAttributeFilter();
roleSystemAttributeFilter.setRoleSystemId(roleSystem.getId());
List<SysRoleSystemAttributeDto> roleAttributes = roleSystemAttributeService.find(roleSystemAttributeFilter, null).getContent();
if (!CollectionUtils.isEmpty(roleAttributes)) {
roleSystemAttributesAll.addAll(roleAttributes);
}
}
});
return roleSystemAttributesAll;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSyncConfigService method internalExport.
@Override
protected AbstractSysSyncConfigDto internalExport(UUID id) {
// For searching tree-type by code, have to be tree-type DTO embedded.
AbstractSysSyncConfigDto dto = this.get(id);
if (dto instanceof SysSyncContractConfigDto && ((SysSyncContractConfigDto) dto).getDefaultTreeType() != null) {
AbstractDto treeType = (AbstractDto) dto.getEmbedded().get(SysSyncContractConfig_.defaultTreeType.getName());
AbstractDto treeNode = (AbstractDto) dto.getEmbedded().get(SysSyncContractConfig_.defaultTreeNode.getName());
dto.getEmbedded().clear();
// Put tree-type to the node embedded (tree-type will be use for findByExample).
if (treeNode != null) {
treeNode.getEmbedded().put(SysSyncContractConfig_.defaultTreeType.getName(), treeType);
}
dto.getEmbedded().put(SysSyncContractConfig_.defaultTreeType.getName(), treeType);
dto.getEmbedded().put(SysSyncContractConfig_.defaultTreeNode.getName(), treeNode);
}
return dto;
}
Aggregations