use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class IdentityFilterTest method testManagersForFilter.
@Test
public void testManagersForFilter() {
FilterBuilder<IdmIdentity, DataFilter> filterBuilderSubordinates = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
FilterBuilder<IdmIdentity, DataFilter> filterBuilderManagers = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR);
FilterBuilder<IdmIdentityContract, DataFilter> filterBuilderContractByManager = filterManager.getBuilder(IdmIdentityContract.class, IdmIdentityContractFilter.PARAMETER_SUBORDINATES_FOR);
Assert.assertEquals(DefaultManagersFilter.FILTER_NAME, filterBuilderManagers.getId());
Assert.assertEquals(DefaultSubordinatesFilter.FILTER_NAME, filterBuilderSubordinates.getId());
Assert.assertEquals(DefaultContractByManagerFilter.FILTER_NAME, filterBuilderContractByManager.getId());
Assert.assertFalse(filterBuilderSubordinates.isDisabled());
Assert.assertFalse(filterBuilderManagers.isDisabled());
Assert.assertFalse(filterBuilderContractByManager.isDisabled());
//
IdmIdentityDto person = getIdmIdentity("ThisIsTestName009", "ThisIsTestName009", "ThisIsTestName009@gemail.eu", "000000009", false);
IdmIdentityDto manager = getIdmIdentity("ThisIsTestName010", "ThisIsTestName010", "ThisIsTestName010@gemail.eu", "000000010", false);
IdmTreeTypeDto type1 = getHelper().createTreeType();
IdmTreeNodeDto node2 = getHelper().createTreeNode(type1, null);
IdmTreeNodeDto node1 = getHelper().createTreeNode(type1, node2);
getHelper().createContract(manager, node2);
getHelper().createContract(person, node1);
//
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setIncludeGuarantees(false);
filter.setManagersFor(person.getId());
filter.setManagersByTreeType(type1.getId());
List<IdmIdentityDto> results = identityService.find(filter, null).getContent();
Assert.assertEquals(1, results.size());
Assert.assertEquals(manager.getId(), results.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class ModelMapperChecker method verify.
/**
* Check registered services and their conversions to dto provided by model mapper.
* Throws Exception, if check does not pass.
*
* @throws ConfigurationDisabledException if check is disabled by configuration.
* @throws ResultCodeException if service check failed (referential integrity is broken or other IdM exception occurs).
* @throws ModelMapperServiceInitException if mapper is wrongly inited.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void verify() {
if (!configurationService.getBooleanValue(PROPERTY_ENABLED, DEFAULT_ENABLED)) {
LOG.warn("Init: check registered IdM services is disabled.");
//
throw new ConfigurationDisabledException(ModelMapperChecker.PROPERTY_ENABLED);
}
long start = System.currentTimeMillis();
int modelMapperUsed = 0;
Map<String, ReadDtoService> services = context.getBeansOfType(ReadDtoService.class);
for (ReadDtoService service : services.values()) {
if ((service instanceof DefaultWorkflowHistoricTaskInstanceService) || (service instanceof DefaultWorkflowHistoricProcessInstanceService)) {
LOG.debug("Workflow history service [{}] will not be checked - find method with pagination is not fully supported and took long time.", service.getClass());
continue;
}
//
LOG.trace("Service [{}] will be checked.", service.getClass());
try {
BaseFilter filter = null;
if (service.getFilterClass() != null) {
// some services could not define filter
try {
if (service.getFilterClass().equals(DataFilter.class)) {
filter = new DataFilter(service.getDtoClass());
} else {
filter = (BaseFilter) mapper.convertValue(new HashMap(), service.getFilterClass());
}
} catch (Exception ex) {
LOG.debug("Service [{}] filter [{}] cannot be constructed. Find method will be checked without filter.", service.getClass(), service.getFilterClass());
}
}
if (!service.find(filter, PageRequest.of(0, 1)).getContent().isEmpty()) {
modelMapperUsed++;
}
} catch (UnsupportedOperationException ex) {
LOG.debug("Service [{}] does not support find method. Check will be skipped.", service.getClass());
} catch (MappingException ex) {
throw new ModelMapperServiceInitException(AutowireHelper.getTargetType(service), ex);
} catch (EntityNotFoundException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getMessage())), ex);
} catch (ResultCodeException ex) {
throw ex;
} catch (Exception ex) {
if (ex.getCause() instanceof EntityNotFoundException) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getCause().getMessage()), "service", service.getClass().getCanonicalName()), ex);
}
LOG.error("Service [{}] cannot be checked. Find method cannot be called.", service.getClass(), ex);
}
LOG.trace("Service [{}] was checked.", service.getClass());
}
LOG.info("Init: all registered IdM services [{}]. " + "Services usage were checked [{}] (agenda contains some records) [took: {}ms].", services.size(), modelMapperUsed, System.currentTimeMillis() - start);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class IdmConfigurationController method toFilter.
@Override
protected DataFilter toFilter(MultiValueMap<String, Object> parameters) {
DataFilter filter = new DataFilter(getDtoClass(), parameters, getParameterConverter());
filter.setAddSecredProxyString(true);
//
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerIntegrationTest method testDisableSubordinatesBuilder.
@Test
public void testDisableSubordinatesBuilder() {
IdmIdentityDto subordinate = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto manager = getHelper().createIdentity((GuardedString) null);
getHelper().createContractGuarantee(getHelper().getPrimeContract(subordinate.getId()).getId(), manager.getId());
//
FilterBuilder<IdmIdentity, DataFilter> filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
String enabledPropertyName = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_ENABLED);
String implProperty = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION);
String currentFilterBeanName = filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
//
Assert.assertNotNull(filter);
Assert.assertFalse(filter.isDisabled());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setSubordinatesFor(manager.getId());
identityFilter.setIncludeGuarantees(true);
List<IdmIdentityDto> subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertEquals(1, subordinates.size());
Assert.assertEquals(subordinate.getId(), subordinates.get(0).getId());
//
try {
configurationService.setBooleanValue(enabledPropertyName, false);
//
filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
Assert.assertNotNull(filter);
Assert.assertTrue(filter.isDisabled());
//
subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertTrue(subordinates.isEmpty());
//
// configure different filter - should be disabled to
configurationService.setValue(implProperty, GuaranteeSubordinatesFilter.BEAN_NAME);
filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
//
Assert.assertNotNull(filter);
Assert.assertTrue(filter.isDisabled());
Assert.assertEquals(GuaranteeSubordinatesFilter.BEAN_NAME, filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION));
//
subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertTrue(subordinates.isEmpty());
} finally {
configurationService.setBooleanValue(enabledPropertyName, true);
configurationService.setValue(implProperty, currentFilterBeanName);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerIntegrationTest method testFilterNotSupportedWithoutValues.
@Test
public void testFilterNotSupportedWithoutValues() {
DataFilter filter = new DataFilter(IdmConfigurationDto.class);
filter.put("wrong", new ArrayList<>());
//
Page<IdmConfigurationDto> configurations = configurationService.find(filter, PageRequest.of(0, 1));
//
Assert.assertNotNull(configurations);
}
Aggregations