/// <summary> /// Add a tag to this act /// </summary> public ITag AddTag(String tagKey, String tagValue) { var tag = new ActTag(tagKey, tagValue); this.Tags.Add(tag); return(tag); }
/// <summary> /// Issues the order response message which will mark the requested order as underway /// </summary> public void IssueOrderResponse(OrderResponseMessageType orderResponse) { // TODO: Validate the standard header Bundle orderTransaction = new Bundle(); // Loop foreach (var resp in orderResponse.orderResponse) { // Find the original order which this despatch advice is fulfilling Act orderRequestAct = this.m_gs1Util.GetOrder(resp.originalOrder, ActMoodKeys.Request); if (orderRequestAct == null) { throw new KeyNotFoundException("Could not find originalOrder"); } // Update the supplier if it exists Place sourceLocation = this.m_gs1Util.GetLocation(resp.seller); if (sourceLocation != null && !orderRequestAct.Participations.Any(o => o.ParticipationRoleKey == ActParticipationKey.Distributor)) { // Add participation orderRequestAct.Participations.Add(new ActParticipation() { ActKey = orderRequestAct.Key, PlayerEntityKey = sourceLocation.Key, ParticipationRoleKey = ActParticipationKey.Distributor }); } else if (resp.seller != null && sourceLocation == null) { throw new KeyNotFoundException($"Could not find seller id with {resp.seller?.additionalPartyIdentification?.FirstOrDefault()?.Value ?? resp.seller.gln}"); } var oidService = ApplicationContext.Current.GetService <IOidRegistrarService>(); var gln = oidService.GetOid("GLN"); var issuingAuthority = oidService.FindData($"{gln.Oid}.{resp.orderResponseIdentification.contentOwner.gln}"); if (issuingAuthority == null) { issuingAuthority = oidService.GetOid(this.m_configuration.DefaultContentOwnerAssigningAuthority); } if (issuingAuthority == null) { throw new KeyNotFoundException("Cannot find default issuing authority for advice identification. Please configure a valid OID"); } orderRequestAct.Identifiers.Add(new ActIdentifier(new AssigningAuthority(issuingAuthority.Mnemonic, issuingAuthority.Name, issuingAuthority.Oid), resp.orderResponseIdentification.entityIdentification)); // If the original order request is not comlete, then complete it var existingTag = orderRequestAct.Tags.FirstOrDefault(o => o.TagKey == "orderStatus"); if (existingTag == null) { existingTag = new ActTag("orderStatus", ""); orderRequestAct.Tags.Add(existingTag); } // Accepted or not if (resp.responseStatusCode?.Value == "ACCEPTED") { existingTag.Value = "accepted"; } else if (resp.responseStatusCode?.Value == "REJECTED") { existingTag.Value = "rejected"; } orderTransaction.Add(orderRequestAct); } // insert transaction try { ApplicationContext.Current.GetService <IBatchRepositoryService>().Insert(orderTransaction); } catch (Exception e) { this.m_tracer.TraceError("Error issuing despatch advice: {0}", e); throw new Exception($"Error issuing despatch advice: {e.Message}", e); } }