use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteBulkActionIntegrationTest method testForceDelete.
@Test
public void testForceDelete() {
logout();
loginAsAdmin();
// create sub tree nodes, automatic roles, contract, contract positions
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmTreeNodeDto subTreeNode = getHelper().createTreeNode((String) null, treeNode);
IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode((String) null, subTreeNode);
IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
//
// 3 manual, 2 automatic
Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
//
// remove tree node
Map<String, Object> properties = new HashMap<>();
properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeNode.class, TreeNodeDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(treeNode.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertNull(treeNodeService.get(treeNode));
Assert.assertNull(treeNodeService.get(subTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
Assert.assertNull(identityContractService.get(contract).getWorkPosition());
Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
Assert.assertNull(roleTreeNodeService.get(automaticRole));
//
Assert.assertNotNull(treeNodeService.get(otherTreeNode));
Assert.assertNotNull(getHelper().getPrimeContract(identity));
Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class RoleTreeNodeSaveProcessor method process.
@Override
public EventResult<IdmRoleTreeNodeDto> process(EntityEvent<IdmRoleTreeNodeDto> event) {
IdmRoleTreeNodeDto dto = event.getContent();
//
dto = service.saveInternal(dto);
event.setContent(dto);
// assign role by this added automatic role to all existing identity contracts with long running task
try {
ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
automaticRoleTask.setAutomaticRoles(Lists.newArrayList(dto.getId()));
executeTask(event, automaticRoleTask);
} catch (AcceptedException ex) {
DefaultEventResult<IdmRoleTreeNodeDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(true);
//
return result;
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method getItemsToProcess.
@Override
public Page<IdmRoleTreeNodeDto> getItemsToProcess(Pageable pageable) {
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
//
// we need to process all automatic roles => assigned role removal is on the end
List<IdmRoleTreeNodeDto> items = new ArrayList<>(automaticRoles.size());
//
// prevent to exceed IN limit sql clause
int pageSize = 500;
Page<UUID> idPage = new PageImpl<UUID>(automaticRoles, PageRequest.of(0, pageSize), automaticRoles.size());
for (int page = 0; page < idPage.getTotalPages(); page++) {
int end = (page + 1) * pageSize;
if (end > automaticRoles.size()) {
end = automaticRoles.size();
}
filter.setIds(automaticRoles.subList(page * pageSize, end));
items.addAll(roleTreeNodeService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(String.format("%s.%s", IdmRoleTreeNode_.role.getName(), IdmRole_.code.getName())))).getContent());
}
//
return new PageImpl<>(items, PageRequest.of(0, automaticRoles.size()), automaticRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class RemoveAutomaticRoleTaskExecutor method end.
@Override
protected Boolean end(Boolean result, Exception ex) {
if (!BooleanUtils.isTrue(result) || ex != null) {
return super.end(result, ex);
}
//
IdmRoleDto role = DtoUtils.getEmbedded(getAutomaticRole(), IdmRoleTreeNode_.role);
long assignedRoles = identityRoleService.findByAutomaticRole(getAutomaticRoleId(), PageRequest.of(0, 1)).getTotalElements();
if (assignedRoles != 0) {
// some assigned role was created in the meantime
UUID automaticRoleId = getAutomaticRoleId();
LOG.debug("Remove role [{}] by automatic role [{}] is not complete, some roles [{}] remains assigned to identities.", role.getCode(), automaticRoleId, assignedRoles);
ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_REMOVE_HAS_ASSIGNED_ROLES, ImmutableMap.of("automaticRoleId", automaticRoleId.toString(), "assignedRoles", String.valueOf(assignedRoles)));
saveResult(resultModel, OperationState.EXCEPTION, null);
} else {
//
LOG.debug("Remove role [{}] by automatic role [{}]", role.getCode(), getAutomaticRole().getId());
try {
//
// Find all concepts and remove relation on automatic role
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setAutomaticRole(getAutomaticRoleId());
//
List<IdmConceptRoleRequestDto> concepts = conceptRequestService.find(conceptRequestFilter, null).getContent();
for (IdmConceptRoleRequestDto concept : concepts) {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("Automatic role [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", getAutomaticRoleId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested automatic role [{1}] was deleted (not from this role request)!", concept.getId(), getAutomaticRoleId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setAutomaticRole(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
}
// by default is this allowed
if (this.isDeleteEntity()) {
// delete entity
if (getAutomaticRole() instanceof IdmRoleTreeNodeDto) {
roleTreeNodeService.deleteInternalById(getAutomaticRole().getId());
} else {
// remove all rules
automaticRoleAttributeRuleService.deleteAllByAttribute(getAutomaticRole().getId());
automaticRoleAttributeService.deleteInternalById(getAutomaticRole().getId());
}
}
//
LOG.debug("End: Remove role [{}] by automatic role [{}].", role.getCode(), getAutomaticRole().getId());
//
} catch (Exception O_o) {
LOG.debug("Remove role [{}] by automatic role [{}] failed", role.getCode(), getAutomaticRole().getId(), O_o);
//
IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
saveResult(resultModel, OperationState.EXCEPTION, O_o);
}
}
//
return super.end(result, ex);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testChangePositionWithAutomaticRolesAssigned.
@Test
@Transactional
public void testChangePositionWithAutomaticRolesAssigned() {
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
IdmContractPositionDto position = getHelper().createContractPosition(contract);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(treeNode.getId());
position = service.save(position);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
//
position.setWorkPosition(null);
position = service.save(position);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
Aggregations