public async Task <SearchResult <TaskInstanceDetailsResult> > Handle(SearchHumanTaskInstanceDetailsQuery request, CancellationToken cancellationToken) { _logger.LogInformation("Search human task instance"); var nameIdentifier = _authorizationHelper.GetNameIdentifier(request.Claims); var roles = _authorizationHelper.GetRoles(request.Claims); var result = await _humanTaskInstanceQueryRepository.Search(new SearchHumanTaskInstanceParameter { UserIdentifier = nameIdentifier, GroupNames = roles, Count = request.Count, Order = request.Order, OrderBy = request.OrderBy, StartIndex = request.StartIndex, StatusLst = request.StatusLst, ActualOwner = request.ActualOwner }, cancellationToken); var content = new List <TaskInstanceDetailsResult>(); foreach (var record in result.Content) { var callbackTxt = new Func <ICollection <PresentationElementInstance>, Localization.Translation>((t) => { if (t == null || !t.Any()) { return(null); } try { return(_translationHelper.Translate(t)); } catch (BadOperationExceptions) { return(null); } }); var appRoles = await _authorizationHelper.GetRoles(record, request.Claims, cancellationToken); var name = callbackTxt(record.Names); var subject = callbackTxt(record.Subjects); content.Add(TaskInstanceDetailsResult.ToDto(record, name, subject, appRoles, _authorizationHelper.GetNameIdentifier(request.Claims))); } return(new SearchResult <TaskInstanceDetailsResult> { Count = result.Count, TotalLength = result.TotalLength, StartIndex = result.StartIndex, Content = content }); }
public async Task <bool> Handle(StartHumanTaskInstanceCommand request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var humanTaskInstance = await _humanTaskInstanceQueryRepository.Get(request.HumanTaskInstanceId, cancellationToken); if (humanTaskInstance == null) { _logger.LogError($"HumanTask '{request.HumanTaskInstanceId}' doesn't exist"); throw new UnknownHumanTaskInstanceException(string.Format(Global.UnknownHumanTaskInstance, request.HumanTaskInstanceId)); } var roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken); if (!roles.Contains(UserRoles.POTENTIALOWNER)) { _logger.LogError("User is not a potentiel owner"); throw new NotAuthorizedException(Global.UserNotAuthorized); } if (humanTaskInstance.Status != HumanTaskInstanceStatus.READY && humanTaskInstance.Status != HumanTaskInstanceStatus.RESERVED) { _logger.LogError("Claim operation can be performed only on READY / RESERVED human task instance"); throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Claim", "Ready/Reserved")); } var userPrincipal = request.Claims.GetUserNameIdentifier(); humanTaskInstance.Start(userPrincipal); await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken); await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken); if (humanTaskInstance.InstantiationPattern == InstantiationPatterns.AUTOMATIC && humanTaskInstance.SubTasks.Any()) { if (humanTaskInstance.Type == CompositionTypes.PARALLEL) { foreach (var subTask in humanTaskInstance.SubTasks) { await _mediator.Send(new InstantiateSubTaskCommand { Claims = request.Claims, HumanTaskInstanceId = humanTaskInstance.AggregateId, SubTaskName = subTask.HumanTaskName }, cancellationToken); } } } return(true); }
public async Task <SearchResult <NotificationDetailsResult> > Handle(SearchNotificationsQuery request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var userClaims = new UserClaims { UserIdentifier = _authorizationHelper.GetNameIdentifier(request.Claims), Roles = _authorizationHelper.GetRoles(request.Claims), LogicalGroups = (await _logicalPeopleGroupStore.GetLogicalGroups(request.Claims, cancellationToken)).Select(_ => _.Name).ToList() }; var result = await _notificationInstanceQueryRepository.Find(new FindNotificationInstanceParameter { Count = request.Count, Order = request.Order, OrderBy = request.OrderBy, StartIndex = request.StartIndex, User = userClaims }, cancellationToken); var content = new List <NotificationDetailsResult>(); foreach (var record in result.Content) { var callbackTxt = new Func <ICollection <PresentationElementInstance>, Localization.Translation>((t) => { if (t == null || !t.Any()) { return(null); } try { return(_translationHelper.Translate(t)); } catch (BadOperationExceptions) { return(null); } }); var name = callbackTxt(record.Names); var subject = callbackTxt(record.Subjects); content.Add(NotificationDetailsResult.ToDto(record, name, subject)); } return(new SearchResult <NotificationDetailsResult> { StartIndex = result.StartIndex, TotalLength = result.TotalLength, Count = result.Count, Content = content }); }
public async Task <bool> Handle(NominateHumanTaskInstanceCommand request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } if (request.GroupNames != null && request.GroupNames.Any() && request.UserIdentifiers != null && request.UserIdentifiers.Any()) { _logger.LogError("GroupNames and UserIdentifiers parameters cannot be specified at the same time"); throw new BadRequestException(Global.GroupNamesAndUserIdentifiersSpecified); } if ((request.GroupNames == null || !request.GroupNames.Any()) && (request.UserIdentifiers == null || !request.UserIdentifiers.Any())) { _logger.LogError("GroupNames or UserIdentifiers parameters must be specified"); throw new BadRequestException(string.Format(Global.MissingParameters, "GroupNames,UserIdentifiers")); } var humanTaskInstance = await _humanTaskInstanceQueryRepository.Get(request.HumanTaskInstanceId, cancellationToken); if (humanTaskInstance == null) { _logger.LogError($"HumanTask '{request.HumanTaskInstanceId}' doesn't exist"); throw new UnknownHumanTaskInstanceException(string.Format(Global.UnknownHumanTaskInstance, request.HumanTaskInstanceId)); } var roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken); if (!roles.Contains(UserRoles.BUSINESSADMINISTRATOR)) { _logger.LogError("User is not a business administrator"); throw new NotAuthorizedException(Global.UserNotAuthorized); } if (humanTaskInstance.Status != HumanTaskInstanceStatus.CREATED) { _logger.LogError("Nomination can be performed only on created human task instance"); throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Nominate", "Created")); } var userPrincipal = request.Claims.GetUserNameIdentifier(); humanTaskInstance.Nominate(userPrincipal, request.GroupNames, request.UserIdentifiers); await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken); await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken); return(true); }
public async Task <bool> Handle(ClaimHumanTaskInstanceCommand request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var humanTaskInstance = await _humanTaskInstanceQueryRepository.Get(request.HumanTaskInstanceId, cancellationToken); if (humanTaskInstance == null) { _logger.LogError($"HumanTask '{request.HumanTaskInstanceId}' doesn't exist"); throw new UnknownHumanTaskInstanceException(string.Format(Global.UnknownHumanTaskInstance, request.HumanTaskInstanceId)); } var roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken); if (!roles.Contains(UserRoles.POTENTIALOWNER)) { _logger.LogError("User is not a potentiel owner"); throw new NotAuthorizedException(Global.UserNotAuthorized); } if (humanTaskInstance.Status != HumanTaskInstanceStatus.READY) { _logger.LogError("Claim operation can be performed only on READY human task instance"); throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Claim", "Ready")); } var userPrincipal = request.Claims.GetUserNameIdentifier(); humanTaskInstance.Claim(userPrincipal); await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken); await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken); return(true); }
public async Task <TaskInstanceCreatedResult> Handle(CreateHumanTaskInstanceCommand request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var humanTaskDef = await _humanTaskDefQueryRepository.GetLatest(request.HumanTaskName, cancellationToken); if (humanTaskDef == null) { _logger.LogError($"Human task definition '{request.HumanTaskName}' doesn't exist"); throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.HumanTaskName)); } var operationParameters = request.OperationParameters == null ? new Dictionary <string, string>() : request.OperationParameters; var parameters = _parameterParser.ParseOperationParameters(humanTaskDef.InputParameters, operationParameters); var assignment = EnrichAssignment(humanTaskDef, request); var priority = EnrichPriority(humanTaskDef, request); var assignmentInstance = _parameterParser.ParsePeopleAssignments(assignment, parameters); if (!request.IgnorePermissions) { var roles = await _authorizationHelper.GetRoles(assignmentInstance, request.Claims, cancellationToken); if (!roles.Any(r => r == UserRoles.TASKINITIATOR)) { _logger.LogError("User is not a task initiator"); throw new NotAuthorizedException(Global.UserNotAuthorized); } } _logger.LogInformation($"Create human task '{request.HumanTaskName}'"); var userPrincipal = request.NameIdentifier; var id = Guid.NewGuid().ToString(); var deadLines = _deadlineParser.Evaluate(humanTaskDef.DeadLines, parameters); var presentationElements = _parameterParser.ParsePresentationElements(humanTaskDef.PresentationElements, humanTaskDef.PresentationParameters, operationParameters); var humanTaskInstance = HumanTaskInstanceAggregate.New( id, userPrincipal, request.HumanTaskName, humanTaskDef.ValidatorFullQualifiedName, parameters, assignmentInstance, priority, request.ActivationDeferralTime, request.ExpirationTime, deadLines, presentationElements, humanTaskDef.Type, humanTaskDef.InstantiationPattern, humanTaskDef.SubTasks.Select(_ => new HumanTaskInstanceSubTask { HumanTaskName = _.TaskName, ToParts = _.ToParts }).ToList(), humanTaskDef.OperationParameters, humanTaskDef.CompletionAction, humanTaskDef.Completions, humanTaskDef.Rendering, request.CallbackUrls == null ? new List <CallbackOperation>() : request.CallbackUrls.Select(_ => new CallbackOperation { Id = Guid.NewGuid().ToString(), Url = _ }).ToList()); await _humanTaskInstanceCommandRepository.Add(humanTaskInstance, cancellationToken); await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken); humanTaskDef.IncrementInstance(); await _humanTaskDefCommandRepository.Update(humanTaskDef, cancellationToken); return(new TaskInstanceCreatedResult { Id = humanTaskInstance.AggregateId, DefId = humanTaskDef.AggregateId }); }