use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.
the class DuplicateRoleAutomaticByAttributeProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto cloned = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
//
IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
filter.setRoleId(cloned.getId());
Set<UUID> usedAutomaticRoles = new HashSet<>();
List<IdmAutomaticRoleAttributeDto> currentAutomaticRoles = automaticRoleAttributeService.find(filter, null).getContent();
//
filter.setRoleId(originalSource.getId());
automaticRoleAttributeService.find(filter, null).forEach(automaticRole -> {
UUID exists = exists(currentAutomaticRoles, automaticRole);
if (exists != null) {
usedAutomaticRoles.add(exists);
} else {
// create new with all rules
IdmAutomaticRoleAttributeDto clonedAutomaticRole = new IdmAutomaticRoleAttributeDto();
clonedAutomaticRole.setName(automaticRole.getName());
clonedAutomaticRole.setRole(cloned.getId());
clonedAutomaticRole.setConcept(true);
//
clonedAutomaticRole = automaticRoleAttributeService.save(clonedAutomaticRole);
//
for (IdmAutomaticRoleAttributeRuleDto rule : automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRole.getId())) {
IdmAutomaticRoleAttributeRuleDto clonedRule = new IdmAutomaticRoleAttributeRuleDto();
clonedRule.setAutomaticRoleAttribute(clonedAutomaticRole.getId());
clonedRule.setAttributeName(rule.getAttributeName());
clonedRule.setFormAttribute(rule.getFormAttribute());
clonedRule.setType(rule.getType());
clonedRule.setValue(rule.getValue());
clonedRule.setComparison(rule.getComparison());
//
automaticRoleAttributeRuleService.save(clonedRule);
}
AutomaticRoleAttributeEvent automaticRoleEvent = new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.UPDATE, clonedAutomaticRole);
// execute sync
automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
// FIXME: event parent ...
automaticRoleAttributeService.recalculate(automaticRoleEvent);
}
});
//
// remove not used originals
currentAutomaticRoles.stream().filter(automaticRole -> {
return !usedAutomaticRoles.contains(automaticRole.getId());
}).forEach(automaticRole -> {
// dirty flag automatic role only - will be processed after parent action ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setSuperOwnerId(cloned.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(automaticRole, stateDeleted);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method recalculate.
@Override
@Transactional
public IdmAutomaticRoleAttributeDto recalculate(UUID automaticRoleId) {
Assert.notNull(automaticRoleId, "Automatic role identifier is required.");
IdmAutomaticRoleAttributeDto automaticRole = get(automaticRoleId);
Assert.notNull(automaticRole, "Automatic role is required.");
//
EntityEvent<IdmAutomaticRoleAttributeDto> event = new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.UPDATE, automaticRole);
event.setPriority(PriorityType.NORMAL);
//
return recalculate(event);
}
use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method delete.
/**
* Publish {@link AutomaticRoleAttributeEvent} only.
*
* @see {@link AutomaticRoleAttributeDeleteProcessor}
*/
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public void delete(IdmAutomaticRoleAttributeDto dto, BasePermission... permission) {
Assert.notNull(dto, "DTO is required.");
checkAccess(this.getEntity(dto.getId()), permission);
//
LOG.debug("Deleting automatic role by attribute [{}]", dto.getRole());
//
EventContext<IdmAutomaticRoleAttributeDto> context = entityEventManager.process(new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.DELETE, dto));
//
if (context.isSuspended()) {
throw new AcceptedException();
}
}
Aggregations