use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentityFilterTest method testPropertyValueFilter.
@Test
public void testPropertyValueFilter() {
IdmIdentityDto person = getIdmIdentity("ThisIsTestName012", "ThisIsTestName012", "ThisIsTestName012@gemail.eu", "100000012", false);
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setProperty(IdmIdentity_.username.getName());
filter.setValue(person.getUsername());
Page<IdmIdentityDto> result = identityService.find(filter, null);
assertEquals("Wrong Set Property and Value - username", 1, result.getTotalElements());
assertEquals("Wrong Property an Value - username user ID", person.getId(), result.getContent().get(0).getId());
filter.setProperty(IdmIdentity_.firstName.getName());
filter.setValue(person.getFirstName());
result = identityService.find(filter, null);
assertEquals("Wrong Set Property and Value - firstname", 1, result.getTotalElements());
assertEquals("Wrong Property an Value - firstname user ID", person.getId(), result.getContent().get(0).getId());
filter.setProperty(IdmIdentity_.lastName.getName());
filter.setValue(person.getLastName());
result = identityService.find(filter, null);
assertEquals("Wrong Set Property and Value - lastname", 1, result.getTotalElements());
assertEquals("Wrong Property an Value - lastname user ID", person.getId(), result.getContent().get(0).getId());
filter.setProperty(IdmIdentity_.email.getName());
filter.setValue(person.getEmail());
result = identityService.find(filter, null);
assertEquals("Wrong Set Property and Value - email", 1, result.getTotalElements());
assertEquals("Wrong Property an Value - email user ID", person.getId(), result.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeRuleDeleteProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
//
List<IdmAutomaticRoleAttributeRuleDto> allRules = automactiRoleAttributeRuleService.findAllRulesForAutomaticRole(dto.getAutomaticRoleAttribute());
// by default is skip value null => false
if (!this.getBooleanProperty(SKIP_CHECK_LAST_RULE, event.getProperties())) {
// it's last rule, remove all identity role
if (allRules.size() == 1 && dto.getId().equals(allRules.get(0).getId())) {
// before we start delete identity role, we check how many identities has the auto role
// if doesn't exist identities that has the role, skip remove
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
long totalElements = identityService.find(identityFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
UUID automaticRoleAttributeId = dto.getAutomaticRoleAttribute();
removeAllRoles(automaticRoleAttributeId);
//
// we also set concept to false
IdmAutomaticRoleAttributeDto roleAttributeDto = automaticRoleAttributeRuleService.get(automaticRoleAttributeId);
roleAttributeDto.setConcept(false);
roleAttributeDto = automaticRoleAttributeRuleService.save(roleAttributeDto);
}
}
}
UUID automaticRuleId = dto.getId();
// Find all automatic role requests and remove relation on rule
if (automaticRuleId != null) {
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRequestFilter.setRuleId(automaticRuleId);
ruleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setRule(null);
ruleRequestService.save(request);
});
}
//
automactiRoleAttributeRuleService.deleteInternal(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentitySynchronizationExecutor method findByAttribute.
@Override
protected IdmIdentityDto findByAttribute(String idmAttributeName, String value) {
CorrelationFilter filter = getEntityFilter();
filter.setProperty(idmAttributeName);
filter.setValue(value);
List<IdmIdentityDto> entities = identityService.find((IdmIdentityFilter) filter, null).getContent();
if (CollectionUtils.isEmpty(entities)) {
return null;
}
if (entities.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
}
if (entities.size() == 1) {
return entities.get(0);
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class ExecuteScriptTaskExecutorTest method testExeciteScriptWithResult.
@Test
public void testExeciteScriptWithResult() {
// remove previous long running task
List<IdmLongRunningTaskDto> tasks = longRunningTaskService.find(null).getContent();
for (IdmLongRunningTaskDto task : tasks) {
longRunningTaskService.delete(task);
}
IdmScriptDto scriptDto = new IdmScriptDto();
scriptDto.setCode(TEST_SCRIPT_CODE + "_3");
scriptDto.setName(TEST_SCRIPT_CODE + "_3");
scriptDto.setCategory(IdmScriptCategory.SYSTEM);
StringBuilder builder = new StringBuilder();
builder.append("import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;\n");
builder.append("task.setCounter(0l);\n");
builder.append("task.setCount(5l);\n");
builder.append("for (int index = 0; index < 5; index++) {\n");
builder.append(" IdmIdentityDto dto = new IdmIdentityDto();\n");
builder.append(" dto.setUsername('test-execute-' + index);\n");
builder.append(" dto.setLastName('test-execute-' + index);\n");
builder.append(" dto.setFirstName('' + index);\n");
builder.append(" identityService.save(dto);\n");
builder.append(" task.increaseCounter();\n");
builder.append(" task.updateState();\n");
builder.append("}\n");
scriptDto.setScript(builder.toString());
scriptDto = scriptService.save(scriptDto);
prepareAuthForTestScript(scriptDto);
IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.SERVICE);
authDto.setClassName("eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService");
authDto.setScript(scriptDto.getId());
authDto.setService("identityService");
scriptAuthorityService.save(authDto);
authDto = new IdmScriptAuthorityDto();
authDto.setType(ScriptAuthorityType.CLASS_NAME);
authDto.setClassName("eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto");
authDto.setScript(scriptDto.getId());
scriptAuthorityService.save(authDto);
Map<String, Object> parameters = new HashMap<>();
parameters.put("scriptCode", TEST_SCRIPT_CODE + "_3");
taskExecutor.init(parameters);
LongRunningFutureTask<Boolean> futureTask = manager.execute(taskExecutor);
try {
assertEquals(Boolean.TRUE, futureTask.getFutureTask().get());
} catch (InterruptedException | ExecutionException e) {
fail(e.getMessage());
}
IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(taskExecutor.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
assertEquals(5, longRunningTask.getCount().longValue());
assertEquals(5, longRunningTask.getCounter().longValue());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setText("test-execute-");
List<IdmIdentityDto> identities = identityService.find(identityFilter, new PageRequest(0, 20, new Sort(Direction.ASC, IdmIdentity_.firstName.getName()))).getContent();
assertEquals(5, identities.size());
for (int index = 0; index < 5; index++) {
assertEquals(String.valueOf(index), identities.get(index).getFirstName());
}
}
Aggregations