use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method saveStates.
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public <E extends Serializable> List<IdmEntityStateDto> saveStates(EntityEvent<E> event, List<IdmEntityStateDto> previousStates, EventResult<E> result) {
IdmEntityEventDto entityEvent = getEvent(event);
List<IdmEntityStateDto> results = new ArrayList<>();
if (entityEvent == null) {
return results;
}
// simple drop - we don't need to find and update results, we'll create new ones
if (previousStates != null && !previousStates.isEmpty()) {
previousStates.forEach(state -> {
entityStateService.delete(state);
});
}
//
if (result == null) {
IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
// default result without model
state.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
results.add(entityStateService.save(state));
return results;
}
if (result.getResults().isEmpty()) {
results.add(entityStateService.save(createState(entityEvent, result, new OperationResultDto.Builder(OperationState.EXECUTED).build())));
return results;
}
result.getResults().forEach(opeartionResult -> {
results.add(entityStateService.save(createState(entityEvent, result, opeartionResult.toDto())));
});
//
return results;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class EntityStateDeleteProcessor method process.
@Override
public EventResult<IdmEntityStateDto> process(EntityEvent<IdmEntityStateDto> event) {
IdmEntityStateDto entityState = event.getContent();
//
service.deleteInternal(entityState);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class ContractSliceDeleteProcessor method createDeleteDirtyState.
/**
* Create new dirty state for delete of contract slice
*
* @param slice
* @param parameters
* @return
*/
private IdmEntityStateDto createDeleteDirtyState(IdmContractSliceDto slice, Map<String, Serializable> parameters) {
Map<String, Object> transformedMarameters = new HashMap<String, Object>();
transformedMarameters.put("entityId", slice.getId());
// Mark state for delete the slice
transformedMarameters.put(ClearDirtyStateForContractSliceTaskExecutor.TO_DELETE, Boolean.TRUE);
transformedMarameters.putAll(parameters);
DefaultResultModel resultModel = new DefaultResultModel(CoreResultCode.DIRTY_STATE, transformedMarameters);
IdmEntityStateDto dirtyState = new IdmEntityStateDto();
dirtyState.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(resultModel).build());
return entityStateManager.saveState(slice, dirtyState);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method roleCleanup.
/**
**************** Cleanup methods *********************
*/
private void roleCleanup() {
Set<String> roleNames = Set.of(adGroupAllRole, adGroupPkiRole, adGroupDep1Role, adGroupDep2Role, adGroupCons1Role, adGroupCons2Role, adGroupDirectorRole, consultantBusinessRole, allBusinessRole, adUsersRole, system2ManualRole);
List<IdmRoleDto> roles = new ArrayList<IdmRoleDto>(roleNames.size());
for (String name : roleNames) {
IdmRoleDto dto = roleService.getByCode(name);
if (dto != null) {
roles.add(dto);
}
}
// sync role force deletion
Map<String, Serializable> properties = ImmutableMap.of(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
for (IdmRoleDto role : roles) {
EntityEvent<IdmRoleDto> event = new RoleEvent(RoleEventType.DELETE, role, properties);
roleService.publish(event);
}
// performing delete operation on all items marked in entity state as to delete
for (IdmRoleDto role : roles) {
List<IdmEntityStateDto> entityStates = entityStateManager.findStates(role, null).getContent();
OperationResultDto result = entityStates.get(0).getResult();
if (OperationState.RUNNING.equals(result.getState()) && CoreResultCode.DELETED.getCode().equals(result.getModel().getStatusEnum())) {
roleService.delete(role);
}
}
// check proper deletion
for (String name : roleNames) {
Assert.assertNull(roleService.getByCode(name));
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto 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);
}
Aggregations