/// <summary> /// Asynchronously routes an item for approvals /// </summary> /// <param name="routingItem">The information necessary to instantiate a new routing.</param> /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param> /// <param name="context">The optional execution context that applies to this operation.</param> /// <returns>An integer that contains the new process id.</returns> protected override async Task <int?> OnCreateRoutingAsync(RoutingItem routingItem, CancellationToken cancellationToken = default(CancellationToken), IDictionary <object, object> context = null) { // TODO: Fix this, errors in here need to be aggregated and passed back, right now it's a bit obtuse, but we need to validate the hanford ids PersonIdentification submitterIds = await _personIdentificationStore.GetByHanfordIdAsync(routingItem.SubmitUserHanfordId, cancellationToken, context); PersonIdentification originatorIds = await _personIdentificationStore.GetByHanfordIdAsync(routingItem.OriginatorHanfordId, cancellationToken, context); PersonIdentification beneficiaryIds = await _personIdentificationStore.GetByHanfordIdAsync(routingItem.BeneficiaryHanfordId, cancellationToken, context); try { Binding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); ChannelFactory <RoutingSoap> factory = new ChannelFactory <RoutingSoap>(binding, new EndpointAddress(_client.BaseAddress)); RoutingSoap serviceProxy = factory.CreateChannel(); InstantiateProcessRequest process = CreateInstProcessRequest(routingItem, submitterIds, originatorIds, beneficiaryIds); var result = await serviceProxy.InstantiateProcessAsync(process); if (result.InstantiateProcessResult.InstProcessId == 0) { throw new ArgumentException(result.InstantiateProcessResult.Status); } int?approvalResponse = result.InstantiateProcessResult.InstProcessId; return(approvalResponse); } catch (ArgumentException exception) { throw exception; } catch (Exception exception) { _logger.LogError("A web service error occurred while submitting the item for routing. Reason: {@Exception}", exception); _logger.LogDebug(JsonSerializer.Serialize(routingItem)); throw; } }
private static InstantiateProcessRequest CreateInstProcessRequest(RoutingItem routingItem, PersonIdentification submitterIds, PersonIdentification originatorIds, PersonIdentification beneficiaryIds) { NetworkIdentification1 instantiateUser = new NetworkIdentification1 { Domain = submitterIds.Domain, NetworkId = submitterIds.NetworkId }; InstantiateProcessRequest process = new InstantiateProcessRequest { InstantiateUser = instantiateUser }; RoutingPayload pay = new RoutingPayload { MetaData = new DocMetaData() }; pay.MetaData.ApplicationIRI = (int)routingItem.ApplicationItemId; pay.MetaData.DocumentTypeName = routingItem.DocumentTypeName; pay.MetaData.DocumentAtAGlance = routingItem.DocumentTitle; pay.MetaData.DocumentId = routingItem.DocumentId; pay.MetaData.DocumentOriginator = new NetworkIdentification { Domain = originatorIds.Domain, NetworkId = originatorIds.NetworkId }; pay.MetaData.DocumentBeneficiary = new NetworkIdentification { Domain = beneficiaryIds.Domain, NetworkId = beneficiaryIds.NetworkId }; // Example //<MetaData> //<ApprovalTechEmplId/> //<ApprovalUserEmplId/> //<AuthorEmplId/> //<ChangeSw/> //<OtherApproverList> //<OtherApproverList_items Type="USERIDLIST -or- ROLENAME -or- LISTVALUES"> //<ListItem Key="" Value=""/> //</OtherApproverList_items> //</OtherApproverList> //<QualityEngineerEmplId/> //<RadiologicalControlEmplId/> //<RespManagerEmplId/> //<SafetyAndHealth/> //<SMEApproverList> //<SMEApproverList_items Type="USERIDLIST -or- ROLENAME -or- LISTVALUES"> //<ListItem Key="" Value=""/> //</SMEApproverList_items> //</SMEApproverList> //<USQDSESNo/> //<USQTNumber/> //</MetaData> XElement metaData = new XElement("MetaData"); if (routingItem.IntFields != null && routingItem.IntFields.Count > 0) { foreach (var item in routingItem.IntFields) { XElement element = new XElement(item.Key) { Value = item.Value.ToString() }; metaData.Add(element); } } if (routingItem.StringFields != null && routingItem.StringFields.Count > 0) { foreach (var item in routingItem.StringFields) { XElement element = new XElement(item.Key) { Value = item.Value }; metaData.Add(element); } } if (routingItem.ListFields != null && routingItem.ListFields.Count > 0) { foreach (var item in routingItem.ListFields) { XElement listElement = new XElement(item.Key); var list = item.Value; XAttribute attribute = new XAttribute("Type", list.ListType); listElement.Add(attribute); XElement items = new XElement("LIST_ITEMS"); listElement.Add(item); foreach (var value in list.Values) { XElement element = new XElement("LIST_ITEM") { Value = value }; metaData.Add(element); } } } pay.MetaData.DocumentRoutingData = metaData; process.RoutingPayload = pay; pay.Document = new Document { FileExtension = routingItem.Document.FileExtension, MimeType = routingItem.Document.MimeType, AsciiContent = routingItem.Document.AsciiContent, XslStylesheet = routingItem.Document.XslStyleSheet, Content = routingItem.Document.Content }; return(process); }