use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerIntegrationTest method testFilterNotSupported.
@Test(expected = FilterNotSupportedException.class)
public void testFilterNotSupported() {
try {
configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, true);
DataFilter filter = new DataFilter(IdmConfigurationDto.class);
filter.set("wrong", "mock");
configurationService.find(filter, null);
} finally {
configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, FilterManager.DEFAULT_CHECK_SUPPORTED_FILTER_ENABLED);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerIntegrationTest method testFilterSupportedByFilterInstance.
@Test
public void testFilterSupportedByFilterInstance() {
try {
configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, true);
DataFilter filter = new DataFilter(IdmConfigurationDto.class) {
@SuppressWarnings("unused")
private String wrong;
};
filter.set("wrong", "mock");
Page<IdmConfigurationDto> configurations = configurationService.find(filter, null);
//
Assert.assertNotNull(configurations);
} finally {
configurationService.setBooleanValue(FilterManager.PROPERTY_CHECK_SUPPORTED_FILTER_ENABLED, FilterManager.DEFAULT_CHECK_SUPPORTED_FILTER_ENABLED);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testDuplicateExternalId.
@Test
public void testDuplicateExternalId() throws Exception {
if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
LOG.warn("Controller [{}] doesn't support DataFilter. Find by external id will not be tested.", getController().getClass());
return;
}
//
DTO dto = prepareDto();
if (!(dto instanceof ExternalIdentifiable)) {
// ignore test
return;
}
//
ExternalIdentifiable externalIdentifiableDto = (ExternalIdentifiable) dto;
String name = getHelper().createName();
externalIdentifiableDto.setExternalId(name);
//
DTO original = createDto(dto);
DTO duplicate = prepareDto();
((ExternalIdentifiable) duplicate).setExternalId(name);
//
if (!supportsPost()) {
try {
createDto(duplicate);
Assert.fail();
} catch (DuplicateExternalIdException ex) {
Assert.assertEquals(original.getId(), ex.getDuplicateId());
}
} else {
getMockMvc().perform(post(getBaseUrl()).with(authentication(getAdminAuthentication())).content(getMapper().writeValueAsString(duplicate)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isConflict());
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testDuplicateExternalCode.
@Test
public void testDuplicateExternalCode() throws Exception {
if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
LOG.warn("Controller [{}] doesn't support DataFilter. Find by external id will not be tested.", getController().getClass());
return;
}
//
DTO dto = prepareDto();
if (!(dto instanceof ExternalCodeable)) {
// ignore test
return;
}
//
ExternalCodeable externalIdentifiableDto = (ExternalCodeable) dto;
String name = getHelper().createName();
externalIdentifiableDto.setExternalCode(name);
//
createDto(dto);
//
getMockMvc().perform(post(getBaseUrl()).with(authentication(getAdminAuthentication())).content(getMapper().writeValueAsString(dto)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isConflict());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class IdmAuditController method loadEmbeddedEntity.
/**
* Fills referenced entity to dto - prevent to load entity for each row.
*
* @param dto
*/
private void loadEmbeddedEntity(Map<UUID, BaseDto> loadedDtos, IdmAuditDto dto) {
UUID entityId = dto.getEntityId();
if (entityId == null || StringUtils.isEmpty(dto.getType())) {
// just for sure - IdmAudit entity doesn't specify it as required (but it should be)
return;
}
// set context - add additional common props
DataFilter context = new DataFilter(null);
context.set(IdmFormValueFilter.PARAMETER_ADD_OWNER_DTO, Boolean.TRUE);
BaseDto revision = null;
if (loadedDtos.containsKey(entityId)) {
revision = loadedDtos.get(entityId);
} else {
try {
BaseEntity revisionEntity = getLookupService().lookupEntity(dto.getType(), entityId);
if (revisionEntity != null) {
revision = getLookupService().toDto(revisionEntity, null, context);
}
loadedDtos.put(entityId, revision);
} catch (IllegalArgumentException ex) {
LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getType(), ex);
} catch (Exception ex) {
LOG.debug("Type [{}] cannot be mapped to dto.", dto.getType(), ex);
}
}
// nullable
dto.getEmbedded().put(IdmAudit_.entityId.getName(), revision);
// try to load last revision for deleted entity - main table only ~ subowner will not be solved
if (revision == null) {
dto.setDeleted(true);
try {
Object lastPersistedVersion = auditService.findLastPersistedVersion(Class.forName(dto.getType()), entityId);
if (lastPersistedVersion != null) {
dto.getEmbedded().put(IdmAudit_.entityId.getName(), getLookupService().toDto((BaseEntity) lastPersistedVersion, null, context));
}
} catch (IllegalArgumentException | ClassNotFoundException ex) {
LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getType(), ex);
} catch (Exception ex) {
LOG.debug("Type [{}] cannot be mapped to dto.", dto.getType(), ex);
}
}
// For subowner, some entities doesn't support owner and subowner.
if (dto.getSubOwnerId() != null) {
try {
UUID subOwnerId = UUID.fromString(dto.getSubOwnerId());
if (!loadedDtos.containsKey(subOwnerId)) {
loadedDtos.put(subOwnerId, getLookupService().lookupDto(dto.getSubOwnerType(), subOwnerId));
}
dto.getEmbedded().put(IdmAudit_.subOwnerId.getName(), loadedDtos.get(subOwnerId));
} catch (IllegalArgumentException ex) {
LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getSubOwnerType(), ex);
} catch (Exception ex) {
LOG.debug("Type [{}] cannot be mapped to dto.", dto.getSubOwnerId(), ex);
}
}
// For owner, some entities doesn't support owner and subowner.
if (dto.getOwnerId() != null) {
try {
UUID ownerId = UUID.fromString(dto.getOwnerId());
if (!loadedDtos.containsKey(ownerId)) {
loadedDtos.put(ownerId, getLookupService().lookupDto(dto.getOwnerType(), ownerId));
}
dto.getEmbedded().put(IdmAudit_.ownerId.getName(), loadedDtos.get(ownerId));
} catch (IllegalArgumentException ex) {
LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getSubOwnerType(), ex);
} catch (Exception ex) {
LOG.debug("Entity [{}] cannot be mapped to dto.", dto.getOwnerId(), ex);
}
}
// Fill embedded contract for FE agenda (prevent to load contract for each row).
if ((dto instanceof IdmAuditEntityDto) && dto.getType().equals(IdmIdentityRole.class.getCanonicalName())) {
IdmAuditEntityDto auditEntity = (IdmAuditEntityDto) dto;
if (auditEntity.getEntity().containsKey(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT) && !auditEntity.getEmbedded().containsKey(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT)) {
UUID contractId = DtoUtils.toUuid(auditEntity.getEntity().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
if (contractId != null) {
if (!loadedDtos.containsKey(contractId)) {
loadedDtos.put(contractId, getLookupService().lookupDto(IdmIdentityContractDto.class, contractId));
}
auditEntity.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, loadedDtos.get(contractId));
}
}
}
}
Aggregations