use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeRuleSaveProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
//
dto = automactiRoleAttributeRuleService.saveInternal(dto);
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method changeAutomaticRoleRules.
@Override
public IdmAutomaticRoleAttributeDto changeAutomaticRoleRules(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... newRules) {
Assert.notNull(automaticRole);
Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setOperation(RequestOperationType.UPDATE);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(executeImmediately);
request.setAutomaticRole(automaticRole.getId());
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
final IdmAutomaticRoleRequestDto createdRequest = roleRequestService.save(request);
ArrayList<IdmAutomaticRoleAttributeRuleDto> rules = Lists.newArrayList(newRules);
if (rules != null) {
// Creates request for change or add rule
rules.forEach(rule -> {
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(createdRequest.getId());
ruleRequest.setOperation(rule.getId() != null ? RequestOperationType.UPDATE : RequestOperationType.ADD);
ruleRequest.setAttributeName(rule.getAttributeName());
ruleRequest.setComparison(rule.getComparison());
ruleRequest.setType(rule.getType());
ruleRequest.setFormAttribute(rule.getFormAttribute());
ruleRequest.setValue(rule.getValue());
ruleRequest.setRule(rule.getId());
ruleRequest = ruleRequestService.save(ruleRequest);
});
}
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> currentRules = ruleService.find(ruleFilter, null).getContent();
currentRules.stream().filter(currentRule -> {
return rules == null || !rules.contains(currentRule);
}).forEach(ruleToDelete -> {
// Creates request for remove rule
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(createdRequest.getId());
ruleRequest.setOperation(RequestOperationType.REMOVE);
ruleRequest.setAttributeName(ruleToDelete.getAttributeName());
ruleRequest.setComparison(ruleToDelete.getComparison());
ruleRequest.setType(ruleToDelete.getType());
ruleRequest.setFormAttribute(ruleToDelete.getFormAttribute());
ruleRequest.setValue(ruleToDelete.getValue());
ruleRequest.setRule(ruleToDelete.getId());
ruleRequest = ruleRequestService.save(ruleRequest);
});
IdmAutomaticRoleRequestDto executedRequest = roleRequestService.startRequestInternal(createdRequest.getId(), true);
if (RequestState.EXECUTED == executedRequest.getState()) {
UUID createdAutomaticRoleId = executedRequest.getAutomaticRole();
Assert.notNull(createdAutomaticRoleId);
return automaticRoleAttributeService.get(executedRequest.getAutomaticRole());
}
if (RequestState.IN_PROGRESS == executedRequest.getState()) {
throw new AcceptedException(executedRequest.getId().toString());
}
if (RequestState.EXCEPTION == executedRequest.getState()) {
throw new CoreException(executedRequest.getResult().getCause());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method realizeAttributeRules.
/**
* Execute change of the request for attribute automatic role
*
* @param request
* @param automaticRoleId
* @param ruleConcepts
*/
private void realizeAttributeRules(IdmAutomaticRoleRequestDto request, IdmAutomaticRoleAttributeDto automaticRole, List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts) {
// Create new rule
ruleConcepts.stream().filter(concept -> {
return RequestOperationType.ADD == concept.getOperation();
}).forEach(concept -> {
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAutomaticRoleAttribute(automaticRole.getId());
rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
// Save created identity role id
concept.setRule(rule.getId());
automaticRoleRuleRequestService.save(concept);
});
// Update rule
ruleConcepts.stream().filter(concept -> {
return RequestOperationType.UPDATE == concept.getOperation();
}).filter(concept -> {
return concept.getRule() != null;
}).forEach(concept -> {
IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
// Save created identity role id
concept.setRule(rule.getId());
automaticRoleRuleRequestService.save(concept);
});
// Delete rule
ruleConcepts.stream().filter(concept -> {
return RequestOperationType.REMOVE == concept.getOperation();
}).filter(concept -> {
return concept.getRule() != null;
}).forEach(concept -> {
IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
if (rule != null) {
concept.setRule(rule.getId());
automaticRoleRuleRequestService.save(concept);
// Finally delete of the rule
automaticRoleRuleService.delete(rule);
}
});
}
Aggregations