use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeService method deleteInternal.
/**
* Publish {@link TreeNodeEvent} only.
*
* @see {@link TreeNodeDeleteProcessor}
*/
@Override
@Transactional
public void deleteInternal(IdmTreeNodeDto treeNode) {
Assert.notNull(treeNode);
Assert.notNull(treeNode.getTreeType());
LOG.debug("Deleting tree node [{}] - [{}]", treeNode.getTreeType(), treeNode.getCode());
//
// if index rebuild is in progress, then throw exception
checkTreeType(treeNode.getTreeType());
//
Page<IdmTreeNode> nodes = repository.findChildren(null, treeNode.getId(), new PageRequest(0, 1));
if (nodes.getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeNode", treeNode.getName()));
}
if (this.identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
}
//
forestContentService.deleteIndex(treeNode.getId());
super.deleteInternal(treeNode);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.
the class TreeNodeAndTypeRestTest method getIdmTreeNode.
private IdmTreeNode getIdmTreeNode(IdmTreeType type, IdmTreeNode parent, String code, String name) {
IdmTreeNode node2 = new IdmTreeNode();
node2.setCode(code);
node2.setName(name);
node2.setTreeType(type);
node2.setParent(parent);
return node2;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeController method findRevision.
@ResponseBody
@RequestMapping(value = "{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Tree node audit - read revision detail", nickname = "getTreeNodeRevision", tags = { IdmTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
IdmTreeNodeDto treeNode = getDto(backendId);
if (treeNode == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("treeNode", backendId));
}
IdmTreeNode revision;
try {
revision = this.auditService.findRevision(IdmTreeNode.class, treeNode.getId(), revId);
} catch (RevisionDoesNotExistException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
}
// TODO: dto
return new ResponseEntity<>(revision, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceUnitTest method testPrimeContractWithWorkingPosition.
@Test
public void testPrimeContractWithWorkingPosition() {
List<IdmIdentityContract> contracts = new ArrayList<>();
IdmIdentityContract contractWithPosition = new IdmIdentityContract(UUID.randomUUID());
contractWithPosition.setMain(false);
IdmTreeNode workPosition = new IdmTreeNode();
workPosition.setId(UUID.randomUUID());
workPosition.setTreeType(new IdmTreeType(UUID.randomUUID()));
contractWithPosition.setWorkPosition(workPosition);
//
IdmIdentityContract otherContract = new IdmIdentityContract(UUID.randomUUID());
otherContract.setMain(false);
contracts.add(contractWithPosition);
contracts.add(otherContract);
//
when(applicationContext.getBean(LookupService.class)).thenReturn(lookupService);
when(lookupService.toDto(any(), any(), any())).then(new LookupAnswer());
when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
when(treeConfiguration.getDefaultType()).thenReturn(null);
when(contractSliceService.count(any(IdmContractSliceFilter.class))).thenReturn(0L);
//
Assert.assertEquals(contractWithPosition.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.
the class RebuildTreeNodeIndexTaskExecutor method processChildren.
private boolean processChildren(List<IdmTreeNode> nodes) {
boolean canContinue = true;
for (IdmTreeNode node : nodes) {
if (node.getForestIndex() == null) {
forestIndexService.index(node.getForestTreeType(), node.getId(), node.getParentId());
}
counter++;
canContinue = updateState();
if (!canContinue) {
break;
}
// proces nodes childred
canContinue = processChildren(treeNodeRepository.findDirectChildren(node, null).getContent());
if (!canContinue) {
break;
}
}
;
return canContinue;
}
Aggregations