use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method findTreeNode.
private IdmTreeNodeDto findTreeNode(Object value, SynchronizationContext context) {
if (value instanceof Serializable) {
// Find by UUID
context.getLogItem().addToLog(MessageFormat.format("Work position - try find directly by transformed value [{0}]!", value));
IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, (Serializable) value);
if (node != null) {
IdmTreeTypeDto treeTypeDto = DtoUtils.getEmbedded(node, IdmTreeNode_.treeType, IdmTreeTypeDto.class);
context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] (in tree type [{2}]) was found directly by transformed value [{0}]!", value, node.getCode(), treeTypeDto.getCode()));
return node;
}
context.getLogItem().addToLog(MessageFormat.format("Work position - was not not found directly from transformed value [{0}]!", value));
if (value instanceof String) {
// Find by code in default tree type
SysSyncContractConfigDto config = this.getConfig(context);
if (config.getDefaultTreeType() == null) {
context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - we cannot finding node by code [{0}], because default tree node is not set (in sync configuration)!", value));
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
return null;
}
IdmTreeNodeFilter treeNodeFilter = new IdmTreeNodeFilter();
IdmTreeTypeDto defaultTreeType = DtoUtils.getEmbedded(config, SysSyncContractConfig_.defaultTreeType, IdmTreeTypeDto.class);
treeNodeFilter.setTreeTypeId(config.getDefaultTreeType());
treeNodeFilter.setCode((String) value);
context.getLogItem().addToLog(MessageFormat.format("Work position - try find in default tree type [{1}] with code [{0}]!", value, defaultTreeType.getCode()));
List<IdmTreeNodeDto> nodes = treeNodeService.find(treeNodeFilter, null).getContent();
if (nodes.isEmpty()) {
context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - none node found for code [{0}]!", value));
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
return null;
} else if (nodes.size() > 1) {
context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - more then one [{0}] node found for code [{1}]!", value, nodes.size()));
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
return null;
} else {
context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] was found for code [{0}]!", value, nodes.get(0).getId()));
return nodes.get(0);
}
}
} else {
context.getLogItem().addToLog(MessageFormat.format("Warning! - Work position cannot be found, because transformed value [{0}] is not Serializable!", value));
this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method organizationPosition.
/**
* Get given identity's prime position in organization.
*
* @param backendId
* @return Positions from root to closest parent
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/work-position", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity prime position in organization.", nickname = "getIdentityPosition", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> organizationPosition(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
IdmIdentityDto identity = getDto(backendId);
if (identity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
//
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
if (primeContract == null) {
return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
WorkPositionDto position = new WorkPositionDto(identity, primeContract);
if (primeContract.getWorkPosition() != null) {
IdmTreeNodeDto contractPosition = treeNodeService.get(primeContract.getWorkPosition());
position.getPath().addAll(treeNodeService.findAllParents(contractPosition.getId(), new Sort(Direction.ASC, "forestIndex.lft")));
position.getPath().add(contractPosition);
}
return new ResponseEntity<WorkPositionDto>(position, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeController method getDefaultTreeNode.
/**
* Returns default tree node or {@code null}, if no default tree node is defined
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/search/default", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.TREENODE_AUTOCOMPLETE + "')" + " or hasAuthority('" + CoreGroupPermission.TREENODE_READ + "')")
@ApiOperation(value = "Get default tree node detail", nickname = "getDefaultTreeNode", response = IdmTreeNodeDto.class, tags = { IdmTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREENODE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREENODE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREENODE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREENODE_READ, description = "") }) })
public ResponseEntity<?> getDefaultTreeNode() {
IdmTreeNodeDto defaultTreeNode = treeNodeService.getDefaultTreeNode();
if (defaultTreeNode == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", "default tree type"));
}
Set<String> permissions = getService().getPermissions(defaultTreeNode.getId());
if (!PermissionUtils.hasAnyPermission(permissions, IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ)) {
throw new ForbiddenEntityException(defaultTreeNode.getId(), IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
}
return new ResponseEntity<>(toResource(defaultTreeNode), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeController method getFormValues.
/**
* Returns filled form values
*
* @param backendId
* @return
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.GET)
@ApiOperation(value = "Tree node form definition - read values", nickname = "getTreeNodeFormValues", tags = { IdmTreeNodeController.TAG })
public Resource<?> getFormValues(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode) {
IdmTreeNodeDto dto = getDto(backendId);
if (dto == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
//
IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(IdmTreeNode.class, definitionCode);
//
return formDefinitionController.getFormValues(dto, formDefinition);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method doUpdateEntity.
/**
* Fill data from IC attributes to entity (EAV and confidential storage too)
*
* @param account
* @param entityType
* @param uid
* @param icAttributes
* @param mappedAttributes
* @param log
* @param logItem
* @param actionLogs
*/
@Override
protected void doUpdateEntity(SynchronizationContext context) {
String uid = context.getUid();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
AccAccountDto account = context.getAccount();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
UUID entityId = getEntityByAccount(account.getId());
IdmTreeNodeDto treeNode = null;
if (entityId != null) {
treeNode = treeNodeService.get(entityId);
}
if (treeNode != null) {
// Update entity
treeNode = fillEntity(mappedAttributes, uid, icAttributes, treeNode, false, context);
treeNode = this.save(treeNode, true);
// Update extended attribute (entity must be persisted first)
updateExtendedAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
// Update confidential attribute (entity must be persisted first)
updateConfidentialAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
// TreeNode Updated
addToItemLog(logItem, MessageFormat.format("TreeNode with id {0} was updated", treeNode.getId()));
if (logItem != null) {
logItem.setDisplayName(treeNode.getName());
}
// Call provisioning for entity
this.callProvisioningForEntity(treeNode, context.getEntityType(), logItem);
return;
} else {
addToItemLog(logItem, "Tree - account relation (with ownership = true) was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
return;
}
}
Aggregations