示例#1
0
        public void Setup()
        {
            IEnumerable <OutputMapping1GetListValues> returnValue = new OutputMapping1GetListValues[1]
            {
                new OutputMapping1GetListValues()
                {
                    Description = "This is a real long description."
                }
            };

            mockRemedyService = new Mock <IRemedyService>();
            mockRemedyService.Setup(remedyService =>
                                    remedyService.GetRemedyChangedWorkItems(It.IsAny <DateTime>())
                                    ).Returns(returnValue);

            mockIssueMessageSender = new Mock <IIssueMessageSender>();

            mockLogger = new Mock <Serilog.ILogger>();

            RemedyCheckerOptions options = new RemedyCheckerOptions()
            {
                ServiceUserName = "******",
                ServicePassword = "******",
                TemplateName    = "",
                ApiUrl          = "localhost/api",
                TempDirectory   = "./Poll Files"
            };

            mockOptions = new Mock <IOptions <RemedyCheckerOptions> >();
            mockOptions.Setup(opt => opt.Value).Returns(options);

            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile <RemedyIssueMappingProfile>();
            });
            mapper = Mapper.Instance;
        }
        /// <summary>
        /// Tries to process Remedy's output mapping so it fits into an IssueCreatedEventArgs object.
        /// TODO: we need to convert the Assignee 3+3 to an email so Octava can use it
        /// </summary>
        /// <param name="workItem">The generated workItem object. This is generated from a SOAP interface.</param>
        /// <returns>An async task that resolves with the IssueCreatedEventArgs.</returns>
        protected virtual async Task <IssueCreatedEventArgs> TryProcessIssue(OutputMapping1GetListValues workItem)
        {
            string assignee3and3  = workItem.Assignee_Login_ID;
            string submitter3and3 = workItem.Corporate_ID;
            string assigneeGroup  = workItem.Owner_Group;

            PersonData assignee  = null;
            PersonData submitter = null;

            if (assignee3and3 == null)
            {
                _logger.Information("Assignee is empty");
            }
            else
            {
                _logger.Information("Looking up assignee with 3+3 {User3and3}", assignee3and3);
                try { assignee = await _peopleService.GetPersonAsync(assignee3and3); }
                catch (Exception err) {
                    assignee = null;
                    _logger.Warning(err, "Unable to get email for Remedy incident Assignee {User3and3}: {ErrorMessage}, using assignee group", assignee3and3, err.Message);
                }
            }


            if (submitter3and3 == null)
            {
                _logger.Information("Submitter is empty");
            }
            else
            {
                _logger.Information("Looking up submitter with 3+3 {User3and3}", submitter3and3);
                try { submitter = await _peopleService.GetPersonAsync(submitter3and3); }
                catch (Exception err) {
                    submitter = null;
                    _logger.Warning(err, "Unable to get email for Remedy incident Submitter {User3and3}: {ErrorMessage}", submitter3and3, err.Message);
                }
            }

            IssueUrgency?newIssueUrgency = GetIssueUrgencyForRemedyStatus(workItem.Urgency);

            if (newIssueUrgency == null)
            {
                _logger.Information("Abondining updated work item because an appropriate IssueStatus could not be determined from the Remedy Status {WorkItemStatus}", workItem.Status);
                return(null);
            }

            try
            {
                // convert Remedy object to IssueCreatedEventArgs
                var args = _mapper.Map <OutputMapping1GetListValues, IssueCreatedEventArgs>(workItem);
                args.AssigneeGroup = assigneeGroup;
                args.Urgency       = newIssueUrgency.ToString();
                if (assignee != null)
                {
                    args.AssigneeEmail = assignee.Email;
                }

                if (submitter != null)
                {
                    args.RequestorEmail       = submitter.Email;
                    args.RequestorGivenName   = submitter.GivenName;
                    args.RequestorSurnName    = submitter.Surname;
                    args.RequestorTelephone   = submitter.Telephone;
                    args.RequestorDisplayName = submitter.DisplayName;
                }
                await _issueMessageSender.SendIssueCreatedAsync(args);

                return(args);
            }
            catch (Exception e)
            {
                Guid correlationId = Guid.NewGuid();
                _logger.Error(e, $"Unable to process work item changed (correlationId {correlationId}): {e.Message}");
                _logger.Debug($"Work item change that caused processing error (correlationId {correlationId}): { workItem }");
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Tries to process Remedy's output mapping so it fits into an IssueCreatedEventArgs object.
        /// TODO: we need to convert the Assignee 3+3 to an email so Octava can use it
        /// </summary>
        /// <param name="workItem">The generated workItem object. This is generated from a SOAP interface.</param>
        /// <returns>An async task that resolves with the IssueCreatedEventArgs.</returns>
        ///


        protected virtual async Task <IssueCreatedEventArgs> TryProcessWorkItemChanged(OutputMapping1GetListValues workItem)
        {
            string assignee3and3  = workItem.ASLOGID;
            string submitter3and3 = workItem.Requestor_ID;
            string assigneeGroup  = workItem.Support_Group_Name;

            PersonData assignee  = null;
            PersonData submitter = null;

            if (assignee3and3 == null)
            {
                _logger.Information("Assignee is empty");
            }
            else
            {
                _logger.Information("Looking up assignee with 3+3 {User3and3}", assignee3and3);
                try { assignee = await _peopleService.GetPersonAsync(assignee3and3); }
                catch (Exception err)
                {
                    assignee = null;
                    _logger.Warning(err, "Unable to get email for Remedy incident Assignee {User3and3}: {ErrorMessage}, using assignee group", assignee3and3, err.Message);
                }
            }


            if (submitter3and3 == null)
            {
                _logger.Information("Submitter is empty");
            }
            else
            {
                _logger.Information("Looking up submitter with 3+3 {User3and3}", submitter3and3);
                try { submitter = await _peopleService.GetPersonAsync(submitter3and3); }
                catch (Exception err)
                {
                    submitter = null;
                    _logger.Warning(err, "Unable to get email for Remedy incident Submitter {User3and3}: {ErrorMessage}", submitter3and3, err.Message);
                }
            }

            try
            {
                // convert Remedy object to IssueCreatedEventArgs
                var args = _mapper.Map <OutputMapping1GetListValues, IssueCreatedEventArgs>(workItem);
                args.AssigneeGroup = assigneeGroup;
                args.Urgency       = workItem.Priority.ToString();
                if (assignee != null)
                {
                    args.AssigneeEmail = assignee.Email;
                }

                if (submitter != null)
                {
                    args.RequestorEmail       = submitter.Email;
                    args.RequestorGivenName   = submitter.GivenName;
                    args.RequestorSurnName    = submitter.Surname;
                    args.RequestorTelephone   = submitter.Telephone;
                    args.RequestorDisplayName = submitter.DisplayName;
                }
                await _issueMessageSender.SendIssueCreatedAsync(args);

                return(args);
            }
            catch (Exception e)
            {
                Guid correlationId = Guid.NewGuid();
                _logger.Error(e, $"Unable to process work item changed (correlationId {correlationId}): {e.Message}");
                _logger.Debug($"Work item change that caused processing error (correlationId {correlationId}): { workItem }");
                throw;
            }
        }
        protected virtual async Task <WorkOrderUpdatedEventArgs> TryProcessWorkItemChanged(
            OutputMapping1GetListValues workItem)
        {
            // we need to convert the Assignee 3+3 to an email so Octava can use it
            // from manual inspection in looks like this field is the "assignee 3+3":
            string assignee3and3 = workItem.ASLOGID;

            PersonData assignee = null;

            if (string.IsNullOrWhiteSpace(assignee3and3))
            {
                _logger.Information("Assignee is empty");
            }
            else
            {
                _logger.Information("Looking up assignee with 3+3 {User3and3}", assignee3and3);
                try { assignee = await _peopleService.GetPersonAsync(assignee3and3); }
                catch (Exception err) { _logger.Warning(err, "Unable to get email for Remedy Work Order Assignee {User3and3}: {ErrorMessage}", assignee3and3, err.Message); }
            }

            InitiativeStatus?newInitiativeStatus = GetInitiativeStatusForRemedyStatus(workItem.Status);

            if (newInitiativeStatus == null)
            {
                _logger.Information("Abondining updated work item because an appropriate InitiativeStatus could not be determined from the Remedy Status {WorkItemStatus}", workItem.Status);
                return(null);
            }

            DateTime?etaUtc = null;

            try
            {
                etaUtc = await _initiativeStatusEtaService.GetStatusEtaFromNowUtcAsync(newInitiativeStatus.Value);
            }
            catch (Exception err) { _logger.Warning(err, "Unable to get an updated ETA for initiative status {InitiativeStatus}: {ErrorMessage}", newInitiativeStatus.Value, err.Message); }

            try
            {
                // Note the ToUniversalTime on the Last_Modified_Date:
                // this works because this service runs in the same time zone as Remedy.
                var args = new WorkOrderUpdatedEventArgs()
                {
                    WorkOrderId         = workItem.InstanceId,
                    UpdatedDateUtc      = workItem.Last_Modified_Date.ToUniversalTime(),
                    RemedyStatus        = workItem.Status.ToString(),
                    UpdatedStatus       = newInitiativeStatus.Value.ToString(),
                    AssigneeEmail       = assignee?.Email,
                    AssigneeDisplayName = assignee?.DisplayName,
                    EtaUtc = etaUtc
                };
                await _initiativeMessageSender.SendWorkOrderUpdatedAsync(args);

                return(args);
            }
            catch (Exception e)
            {
                Guid correlationId = Guid.NewGuid();
                _logger.Error(e, $"Unable to process work item changed (correlationId {correlationId}): {e.Message}");
                _logger.Debug($"Work item change that caused processing error (correlationId {correlationId}): { workItem }");
                throw;
            }
        }