use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class IdmEntityEventController method toFilter.
@Override
protected IdmEntityEventFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmEntityEventFilter filter = new IdmEntityEventFilter(parameters, getParameterConverter());
// owner decorator
String ownerId = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
UUID ownerUuid = null;
String ownerType = filter.getOwnerType();
if (StringUtils.isNotEmpty(ownerType) && StringUtils.isNotEmpty(ownerId)) {
// try to find entity owner by Codeable identifier
AbstractDto owner = manager.findOwner(ownerType, ownerId);
if (owner != null) {
ownerUuid = owner.getId();
} else {
LOG.debug("Entity type [{}] with identifier [{}] does not found, raw ownerId will be used as uuid.", ownerType, ownerId);
// Better exception for FE.
try {
DtoUtils.toUuid(ownerId);
} catch (ClassCastException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", ownerId), ex);
}
}
}
if (ownerUuid == null) {
ownerUuid = getParameterConverter().toUuid(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
}
filter.setOwnerId(ownerUuid);
//
// super owner decorator
String superOwnerId = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_ID);
UUID superOwnerUuid = null;
String superOwnerType = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_TYPE);
if (StringUtils.isNotEmpty(superOwnerType) && StringUtils.isNotEmpty(superOwnerId)) {
// try to find entity owner by Codeable identifier
AbstractDto owner = manager.findOwner(superOwnerType, superOwnerId);
if (owner != null) {
superOwnerUuid = owner.getId();
} else {
LOG.debug("Entity type [{}] with identifier [{}] does not found, raw ownerId will be used as uuid.", superOwnerType, superOwnerId);
// Better exception for FE.
try {
DtoUtils.toUuid(ownerId);
} catch (ClassCastException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", ownerId), ex);
}
}
}
if (superOwnerUuid == null) {
superOwnerUuid = getParameterConverter().toUuid(parameters, IdmEntityEventFilter.PARAMETER_SUPER_OWNER_ID);
}
filter.setSuperOwnerId(superOwnerUuid);
//
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultLookupServiceIntegrationTest method testLookupEmbeddedReflectionFailed.
@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void testLookupEmbeddedReflectionFailed() {
AbstractDto mockDto = new AbstractDto() {
private static final long serialVersionUID = 1L;
@Embedded(dtoClass = IdmIdentityRoleDto.class)
private IdmIdentityRoleDto wrong;
public IdmIdentityRoleDto getWrong() {
throw new UnsupportedOperationException("mock");
}
public void setWrong(IdmIdentityRoleDto wrong) {
this.wrong = wrong;
}
};
//
lookupService.lookupEmbeddedDto(mockDto, "wrong");
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultLookupServiceIntegrationTest method testLookupEmbeddedNotSerializable.
@SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void testLookupEmbeddedNotSerializable() {
AbstractDto mockDto = new AbstractDto() {
private static final long serialVersionUID = 1L;
@Embedded(dtoClass = IdmIdentityRoleDto.class)
private GuardedString wrong = new GuardedString("mock");
public GuardedString getWrong() {
return wrong;
}
public void setWrong(GuardedString wrong) {
this.wrong = wrong;
}
};
//
lookupService.lookupEmbeddedDto(mockDto, "wrong");
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method getDtoByAccount.
@Override
@SuppressWarnings("unchecked")
public DTO getDtoByAccount(UUID entityId, AccAccountDto account) {
if (entityId == null && account != null) {
Assert.notNull(account.getId(), "Account ID cannot be null!");
EntityAccountFilter entityAccountFilter = createEntityAccountFilter();
entityAccountFilter.setAccountId(account.getId());
entityAccountFilter.setOwnership(Boolean.TRUE);
List<EntityAccountDto> entityAccounts = //
this.getEntityAccountService().find(entityAccountFilter, //
PageRequest.of(0, 1)).getContent();
if (!entityAccounts.isEmpty()) {
// We assume that all identity accounts
// (mark as
// ownership) have same identity!
EntityAccountDto entityAccountDto = entityAccounts.get(0);
if (entityAccountDto instanceof AbstractDto && entityAccountDto.getEntity() != null) {
UUID entityIdLocal = entityAccountDto.getEntity();
AbstractDto entityAccount = (AbstractDto) entityAccountDto;
// Try to find target entity in embedded by entityId.
BaseDto targetDto = //
entityAccount.getEmbedded().values().stream().filter(//
dto -> entityIdLocal.equals(dto.getId())).findFirst().orElse(null);
if (targetDto != null) {
return (DTO) targetDto;
} else {
entityId = entityIdLocal;
}
}
}
}
DTO entity = null;
if (entityId != null) {
entity = this.getService().get(entityId);
}
return entity;
}
Aggregations