use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class IdentityFindPositionsTest method testFindManagers.
@Test
public void testFindManagers() {
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 user = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user2 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user3 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto user4 = getHelper().createIdentity((GuardedString) null);
IdmTreeTypeDto treeTypeFirst = getHelper().createTreeType();
IdmTreeTypeDto treeTypeSecond = getHelper().createTreeType();
// create root for second type
getHelper().createTreeNode(treeTypeSecond, null);
// create root for first type
IdmTreeNodeDto nodeRoot = getHelper().createTreeNode(treeTypeFirst, null);
// create one for first type
IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeTypeFirst, nodeRoot);
// create two for first type
IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeTypeFirst, nodeOne);
createIdentityContract(user, null, nodeRoot);
createIdentityContract(user2, null, nodeOne);
createIdentityContract(user3, null, nodeOne);
createIdentityContract(user4, null, nodeTwo);
// createIdentityContract(user, manager3, null);
List<IdmIdentityDto> managersList = identityService.findAllManagers(user3.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
IdmIdentityDto manager = managersList.get(0);
assertEquals(user.getId(), manager.getId());
managersList = identityService.findAllManagers(user4.getId(), treeTypeFirst.getId(), Boolean.TRUE);
assertEquals(2, managersList.size());
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(1, managersList.size());
createIdentityContract(user, null, nodeTwo);
managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
assertEquals(2, managersList.size());
List<IdmIdentityDto> managersListSec = identityService.findAllManagers(user.getId(), treeTypeSecond.getId());
// user with superAdminRole
assertEquals(1, managersListSec.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method getBuilder.
@SuppressWarnings("unchecked")
private <E extends BaseEntity> FilterBuilder<E, DataFilter> getBuilder(FilterKey key) {
if (!builders.hasPluginFor(key)) {
return null;
}
//
// default plugin by ordered definition
FilterBuilder<E, DataFilter> builder = (FilterBuilder<E, DataFilter>) builders.getPluginFor(key);
if (builder.isDisabled()) {
return new DisabledFilterBuilder<E>(builder);
}
String implName = builder.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
if (StringUtils.isEmpty(implName)) {
// return default builder - configuration is empty
return builder;
}
//
try {
// returns bean by name from filter configuration
return (FilterBuilder<E, DataFilter>) context.getBean(implName);
} catch (Exception ex) {
throw new ResultCodeException(CoreResultCode.FILTER_IMPLEMENTATION_NOT_FOUND, ImmutableMap.of("implementation", implName, "propertyName", key.getName(), "configurationProperty", builder.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION)), ex);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class ConfigurationDeleteBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
List<IdmConfigurationDto> configs = createConfigurationItems(testCount);
DataFilter filter = new DataFilter(IdmConfigurationDto.class);
filter.setText(commonNameRoot);
List<IdmConfigurationDto> checkConfigs = configurationService.find(filter, null).getContent();
assertEquals(testCount, checkConfigs.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmConfiguration.class, ConfigurationDeleteBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, (long) testCount, null, null);
for (IdmConfigurationDto config : configs) {
IdmConfigurationDto dto = configurationService.get(config.getId());
assertNull(dto);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class UuidFilterBuilderIntegrationTest method testFindIdentityByUuid.
@Test
public void testFindIdentityByUuid() {
// prepare data
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = getHelper().createRole();
UuidFilter<IdmIdentity> identityFilter = new FindableUuidFilter<>(repository);
//
DataFilter dataFilter = new DataFilter(IdmIdentityDto.class);
dataFilter.setId(identityOne.getId());
List<IdmIdentity> identities = identityFilter.find(dataFilter, null).getContent();
//
assertEquals(1, identities.size());
assertEquals(identityOne.getId(), identities.get(0).getId());
//
dataFilter.setId(identityTwo.getId());
identities = identityFilter.find(dataFilter, null).getContent();
assertEquals(1, identities.size());
assertEquals(identityTwo.getId(), identities.get(0).getId());
//
dataFilter.setId(roleOne.getId());
assertEquals(0, identityFilter.find(dataFilter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.DataFilter in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testFindByCodeable.
/**
* Test search by external identifier, if DTO implements {@link ExternalIdentifiable}
*
* @throws Exception
*/
@Test
public void testFindByCodeable() {
if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
LOG.warn("Controller [{}] doesn't support DataFilter. Find by codeable will not be tested.", getController().getClass());
return;
}
//
DTO dto = prepareDto();
if (!(dto instanceof Codeable)) {
// ignore test
return;
}
Codeable codeable = (Codeable) dto;
if (StringUtils.isEmpty(codeable.getCode())) {
throw new CoreException("Code has to be set by #prepareDto method, its required by default");
}
//
DTO createdDto = createDto(dto);
// mock dto
createDto(prepareDto());
//
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set(DataFilter.PARAMETER_CODEABLE_IDENTIFIER, codeable.getCode());
//
List<DTO> results = find(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
//
if (supportsAutocomplete()) {
results = autocomplete(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
} else {
LOG.info("Controller [{}] doesn't support autocomplete method. Method will not be tested.", getController().getClass());
}
//
Assert.assertEquals(1, count(parameters));
}
Aggregations