Exemplo n.º 1
0
        /// <summary>
        /// Get the background check type that the request is for.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="requestTypeAttribute">The request type attribute.</param>
        /// <param name="packageName"></param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>True/False value of whether the request was successfully sent or not.</returns>
        private bool GetPackageName(RockContext rockContext, Model.Workflow workflow, AttributeCache requestTypeAttribute, out string packageName, List <string> errorMessages)
        {
            packageName = null;
            if (requestTypeAttribute == null)
            {
                errorMessages.Add("The 'Checkr' background check provider requires a background check type.");
                return(false);
            }

            DefinedValueCache pkgTypeDefinedValue = DefinedValueCache.Get(workflow.GetAttributeValue(requestTypeAttribute.Key).AsGuid());

            if (pkgTypeDefinedValue == null)
            {
                errorMessages.Add("The 'Checkr' background check provider couldn't load background check type.");
                return(false);
            }

            if (pkgTypeDefinedValue.Attributes == null)
            {
                // shouldn't happen since pkgTypeDefinedValue is a ModelCache<,> type
                return(false);
            }

            packageName = pkgTypeDefinedValue.GetAttributeValue("PMMPackageName");
            return(true);
        }
Exemplo n.º 2
0
        //private void inintTable()
        //{
        //    IList<Model.Tables> tables = this.tablemanage.Select();
        //    this.comboBoxEditTable.Properties.Items.Clear();
        //    foreach (Model.Tables _table in tables)
        //    {
        //        if (!workflowmanage.getTable(_table.TablesID))
        //        {
        //            this.comboBoxEditTable.Properties.Items.Add(_table.Tablename);
        //        }
        //    }
        //}

        public EditForm(Model.Workflow workflow)
            : this()
        {
            this.wf     = workflow;
            this.action = "update";
            loadprocess();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the person that the request is for.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="personAttribute">The person attribute.</param>
        /// <param name="person">Return the person.</param>
        /// <param name="personAliasId">Return the person alias ID.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>True/False value of whether the request was successfully sent or not.</returns>
        private bool GetPerson(RockContext rockContext, Model.Workflow workflow, AttributeCache personAttribute, out Person person, out int?personAliasId, List <string> errorMessages)
        {
            person        = null;
            personAliasId = null;
            if (personAttribute != null)
            {
                Guid?personAliasGuid = workflow.GetAttributeValue(personAttribute.Key).AsGuidOrNull();
                if (personAliasGuid.HasValue)
                {
                    person = new PersonAliasService(rockContext).Queryable()
                             .Where(p => p.Guid.Equals(personAliasGuid.Value))
                             .Select(p => p.Person)
                             .FirstOrDefault();
                    person.LoadAttributes(rockContext);
                }
            }

            if (person == null)
            {
                errorMessages.Add("The 'Checkr' background check provider requires the workflow to have a 'Person' attribute that contains the person who the background check is for.");
                return(false);
            }

            personAliasId = person.PrimaryAliasId;
            if (!personAliasId.HasValue)
            {
                errorMessages.Add("The 'Checkr' background check provider requires the workflow to have a 'Person' attribute that contains the person who the background check is for.");
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public WorkflowActor(WorkflowDefinition workflowDefinition, ISagaStepBehaviorFactory sagaStepBehaviorFactory, IJsonSchemaDefinitionFactory jsonSchemaDefinitionFactory)
        {
            //TODO check that sagaStepBehaviorFactory contains behaviors defined in workflowdefinition
            Workflow = new Model.Workflow(workflowDefinition, sagaStepBehaviorFactory, jsonSchemaDefinitionFactory);
            _sagaStepBehaviorFactory = sagaStepBehaviorFactory;

            Command <ISagaCRUDMessage>(message =>
            {
                Context.IncrementMessagesReceived();
                PersistWorkflowData(message);
                SagaCRUDMessageHandler(message);
            });

            Command <LookupSagaMessage>(message =>
            {
                Context.IncrementMessagesReceived();
                LookupSagaMessageHandler(message);
            });

            Command <ListAllSagasMessage>(message =>
            {
                Context.IncrementMessagesReceived();
                ListAllSagasMessageHandler(message);
            });

            #region Ignored Messages

            #endregion
        }
Exemplo n.º 5
0
        public EditForm(Model.Workflow workflow, string action)
            : this()
        {
            this.wf = workflow;

            this.action = action;
            //loadprocess();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Sets the workflow RequestStatus attribute.
 /// </summary>
 /// <param name="workflow">The workflow.</param>
 /// <param name="rockContext">The rock context.</param>
 /// <param name="requestStatus">The request status.</param>
 private void UpdateWorkflowRequestStatus(Model.Workflow workflow, RockContext rockContext, string requestStatus)
 {
     if (SaveAttributeValue(workflow, "RequestStatus", requestStatus,
                            FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext, null))
     {
         rockContext.SaveChanges();
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Delete Workflow by primary key.
        /// </summary>
        public void Delete(Model.Workflow workflow)
        {
            //
            // todo:add other logic here
            //

            accessor.Delete(workflow.WorkflowId);
        }
Exemplo n.º 8
0
        protected override void AddNew()
        {
            /// this.duty = new Book.Model.Duty();

            this.action        = "insert";
            this.wf            = new Book.Model.Workflow();
            this.wf.WorkflowId = Guid.NewGuid().ToString();
            this.wf.OnofOff    = true;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Update a Workflow.
 /// </summary>
 public void Update(Model.Workflow workflow)
 {
     //
     // todo: add other logic here.
     //
     Validate(workflow);
     workflow.UpdateTime = DateTime.Now;
     accessor.Update(workflow);
 }
Exemplo n.º 10
0
        /// <summary>
        /// 根据tablecode查寻 wflow
        /// </summary>
        /// <param name="tablecode"></param>
        /// <returns></returns>
        public Model.Workflow GetWorkflowbytablecode(string tablecode)
        {
            Model.Workflow wf     = null;
            Model.Tables   tables = GetTablesbycode(tablecode);
            if (tables != null)
            {
                wf = workflowm.getWfbytable(tables.TablesID);
            }

            return(wf);
        }
Exemplo n.º 11
0
 private void Validate(Model.Workflow Workflow)
 {
     if (string.IsNullOrEmpty(Workflow.workflowname))
     {
         throw new Helper.RequireValueException(Model.Workflow.PRO_workflowname);
     }
     //if (string.IsNullOrEmpty(Workflow.TablesID))
     //{
     //    throw new Helper.InvalidValueException(Model.Workflow.PROPERTY_TABLESID);
     //}
 }
Exemplo n.º 12
0
        /// <summary>
        /// Insert a Workflow.
        /// </summary>
        public void Insert(Model.Workflow workflow)
        {
            //
            // todo:add other logic here
            //

            Validate(workflow);
            workflow.WorkflowId = Guid.NewGuid().ToString();
            workflow.InsertTime = DateTime.Now;
            accessor.Insert(workflow);
            addprocess(workflow.WorkflowId);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the completion message to use based on the block settings.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="responseText">The response text from the last action.</param>
        /// <returns></returns>
        private WorkflowFormMessage GetCompletionMessage(Model.Workflow workflow, string responseText)
        {
            int completionAction = GetAttributeValue(AttributeKeys.CompletionAction).AsInteger();
            var xaml             = GetAttributeValue(AttributeKeys.CompletionXaml);
            var redirectToPage   = GetAttributeValue(AttributeKeys.RedirectToPage).AsGuidOrNull();

            if (completionAction == 2 && redirectToPage.HasValue)
            {
                return(new WorkflowFormMessage
                {
                    Type = WorkflowFormMessageType.Redirect,
                    Content = redirectToPage.ToString()
                });
            }
            else if (completionAction == 1 && !string.IsNullOrWhiteSpace(xaml))
            {
                var mergeFields = RequestContext.GetCommonMergeFields();

                mergeFields.Add("Workflow", workflow);

                return(new WorkflowFormMessage
                {
                    Type = WorkflowFormMessageType.Xaml,
                    Content = xaml.ResolveMergeFields(mergeFields, null, GetAttributeValue(AttributeKeys.EnabledLavaCommands))
                });
            }
            else
            {
                if (string.IsNullOrWhiteSpace(responseText))
                {
                    var message     = workflow.WorkflowTypeCache.NoActionMessage;
                    var mergeFields = RequestContext.GetCommonMergeFields();

                    mergeFields.Add("Workflow", workflow);

                    responseText = message.ResolveMergeFields(mergeFields, null, GetAttributeValue(AttributeKeys.EnabledLavaCommands));
                }

                return(new WorkflowFormMessage
                {
                    Type = WorkflowFormMessageType.Information,
                    Content = responseText
                });
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Processes the workflow and then get next action.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        private WorkflowAction ProcessAndGetNextAction(Model.Workflow workflow, Person currentPerson, RockContext rockContext, out WorkflowFormMessage message)
        {
            message = null;

            var processStatus = new WorkflowService(rockContext).Process(workflow, null, out var errorMessages);

            if (!processStatus)
            {
                message = new WorkflowFormMessage
                {
                    Type    = WorkflowFormMessageType.Error,
                    Title   = "Workflow Error",
                    Content = string.Join("\n", errorMessages)
                };

                return(null);
            }

            return(GetNextAction(workflow, currentPerson));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the next action with a Form attached.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <returns></returns>
        private WorkflowAction GetNextAction(Model.Workflow workflow, Person currentPerson)
        {
            int  personId = currentPerson?.Id ?? 0;
            bool canEdit  = BlockCache.IsAuthorized(Authorization.EDIT, currentPerson);

            //
            // Find all the activities that this person can see.
            //
            var activities = workflow.Activities
                             .Where(a =>
                                    a.IsActive &&
                                    (
                                        canEdit ||
                                        (!a.AssignedGroupId.HasValue && !a.AssignedPersonAliasId.HasValue) ||
                                        (a.AssignedPersonAlias != null && a.AssignedPersonAlias.PersonId == personId) ||
                                        (a.AssignedGroup != null && a.AssignedGroup.Members.Any(m => m.PersonId == personId))
                                    )
                                    )
                             .OrderBy(a => a.ActivityTypeCache.Order)
                             .ToList();

            //
            // Find the first action that the user is authorized to work with that has a Form
            // attached to it.
            //
            foreach (var activity in activities)
            {
                if (canEdit || activity.ActivityTypeCache.IsAuthorized(Authorization.VIEW, currentPerson))
                {
                    foreach (var action in activity.ActiveActions)
                    {
                        if (action.ActionTypeCache.WorkflowForm != null && action.IsCriteriaValid)
                        {
                            return(action);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the initial workflow attributes.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="fields">The fields.</param>
        private void SetInitialWorkflowAttributes(Model.Workflow workflow, List <MobileField> fields)
        {
            //
            // Set initial values from the page parameters.
            //
            foreach (var pageParameter in RequestContext.PageParameters)
            {
                workflow.SetAttributeValue(pageParameter.Key, pageParameter.Value);
            }

            //
            // Set/Update initial values from what the shell sent us.
            //
            if (fields != null)
            {
                foreach (var field in fields)
                {
                    workflow.SetAttributeValue(field.Key, field.Value);
                }
            }
        }
Exemplo n.º 17
0
        public WorkflowRunDeferred(Model.Workflow wf, WfTrigger trigger = null)
        {
            WorkflowBeingRun = wf;

            if (trigger != null)
            {
                TriggerForRun = trigger;
            }

            TaskId = Guid.NewGuid().ToString("N");

            CreatedDate            = DateTime.UtcNow;
            WorkflowRunStatus_Enum = WorkflowRunState_Enumeration.WorkflowRunQueued;
            RunStepCounter         = 0;

            var ctx = RequestContext.GetContext();

            if (ctx != null)
            {
                TriggerDepth     = WorkflowRunContext.Current.TriggerDepth;
                TriggeringUserId = ctx.Identity.Id;
                TriggeringUser   = GetTriggeringUser();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Sends a background request to Checkr.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="personAttribute">The person attribute.</param>
        /// <param name="ssnAttribute">The SSN attribute.</param>
        /// <param name="requestTypeAttribute">The request type attribute.</param>
        /// <param name="billingCodeAttribute">The billing code attribute.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>
        /// True/False value of whether the request was successfully sent or not.
        /// </returns>
        public override bool SendRequest(RockContext rockContext, Model.Workflow workflow,
                                         AttributeCache personAttribute, AttributeCache ssnAttribute, AttributeCache requestTypeAttribute,
                                         AttributeCache billingCodeAttribute, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            try
            {
                // Check to make sure workflow is not null
                if (workflow == null)
                {
                    errorMessages.Add("The 'Checkr' background check provider requires a valid workflow.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                Person person;
                int?   personAliasId;
                if (!GetPerson(rockContext, workflow, personAttribute, out person, out personAliasId, errorMessages))
                {
                    errorMessages.Add("Unable to get Person.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                string packageName;
                if (!GetPackageName(rockContext, workflow, requestTypeAttribute, out packageName, errorMessages))
                {
                    errorMessages.Add("Unable to get Package.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                string candidateId;
                if (!CreateCandidate(person, out candidateId, errorMessages))
                {
                    errorMessages.Add("Unable to create candidate.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                if (!CreateInvitation(candidateId, packageName, errorMessages))
                {
                    errorMessages.Add("Unable to create invitation.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                using (var newRockContext = new RockContext())
                {
                    var backgroundCheckService = new BackgroundCheckService(newRockContext);
                    var backgroundCheck        = backgroundCheckService.Queryable()
                                                 .Where(c =>
                                                        c.WorkflowId.HasValue &&
                                                        c.WorkflowId.Value == workflow.Id)
                                                 .FirstOrDefault();

                    if (backgroundCheck == null)
                    {
                        backgroundCheck            = new Rock.Model.BackgroundCheck();
                        backgroundCheck.WorkflowId = workflow.Id;
                        backgroundCheckService.Add(backgroundCheck);
                    }

                    backgroundCheck.PersonAliasId = personAliasId.Value;
                    backgroundCheck.ForeignId     = 2;
                    backgroundCheck.PackageName   = packageName;
                    backgroundCheck.RequestDate   = RockDateTime.Now;
                    backgroundCheck.RequestId     = candidateId;
                    newRockContext.SaveChanges();

                    UpdateWorkflowRequestStatus(workflow, newRockContext, "SUCCESS");
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
                errorMessages.Add(ex.Message);
                UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                return(true);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Sends a background request to Checkr.  This method is called by the BackgroundCheckRequest action's Execute
        /// method for the Checkr component.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="personAttribute">The person attribute.</param>
        /// <param name="ssnAttribute">The SSN attribute.</param>
        /// <param name="requestTypeAttribute">The request type attribute.</param>
        /// <param name="billingCodeAttribute">The billing code attribute.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>
        /// True/False value of whether the request was successfully sent or not.
        /// </returns>
        public override bool SendRequest(RockContext rockContext, Model.Workflow workflow,
                                         AttributeCache personAttribute, AttributeCache ssnAttribute, AttributeCache requestTypeAttribute,
                                         AttributeCache billingCodeAttribute, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            try
            {
                // Check to make sure workflow is not null
                if (workflow == null)
                {
                    errorMessages.Add("The 'Checkr' background check provider requires a valid workflow.");
                    UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                    return(true);
                }

                // Lock the workflow until we're finished saving so the webhook can't start working on it.
                var lockObject = _lockObjects.GetOrAdd(workflow.Id, new object());
                lock ( lockObject )
                {
                    // Checkr can respond very fast, possibly before the workflow finishes.
                    // Save the workflow now to ensure previously completed activities/actions
                    // are not run again via the checkr webhook. This is not done at the Action
                    // or Activity level for speed reasons.
                    if (workflow.IsPersisted == true)
                    {
                        rockContext.SaveChanges();
                    }

                    Person person;
                    int?   personAliasId;
                    if (!GetPerson(rockContext, workflow, personAttribute, out person, out personAliasId, errorMessages))
                    {
                        errorMessages.Add("Unable to get Person.");
                        UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                        return(true);
                    }

                    string packageName;
                    if (!GetPackageName(rockContext, workflow, requestTypeAttribute, out packageName, errorMessages))
                    {
                        errorMessages.Add("Unable to get Package.");
                        UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                        return(true);
                    }

                    string candidateId;
                    if (!CreateCandidate(person, out candidateId, errorMessages))
                    {
                        errorMessages.Add("Unable to create candidate.");
                        UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                        return(true);
                    }

                    if (!CreateInvitation(candidateId, packageName, errorMessages))
                    {
                        errorMessages.Add("Unable to create invitation.");
                        UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                        return(true);
                    }

                    using (var newRockContext = new RockContext())
                    {
                        var backgroundCheckService = new BackgroundCheckService(newRockContext);
                        var backgroundCheck        = backgroundCheckService.Queryable()
                                                     .Where(c =>
                                                            c.WorkflowId.HasValue &&
                                                            c.WorkflowId.Value == workflow.Id)
                                                     .FirstOrDefault();

                        if (backgroundCheck == null)
                        {
                            backgroundCheck            = new BackgroundCheck();
                            backgroundCheck.WorkflowId = workflow.Id;
                            backgroundCheckService.Add(backgroundCheck);
                        }

                        backgroundCheck.PersonAliasId = personAliasId.Value;
                        backgroundCheck.ForeignId     = 2;
                        backgroundCheck.PackageName   = packageName;
                        backgroundCheck.RequestDate   = RockDateTime.Now;
                        backgroundCheck.RequestId     = candidateId;
                        newRockContext.SaveChanges();
                    }

                    UpdateWorkflowRequestStatus(workflow, rockContext, "SUCCESS");

                    if (workflow.IsPersisted)
                    {
                        // Make sure the AttributeValues are saved to the database immediately because the Checkr WebHook
                        // (which might otherwise get called before they are saved by the workflow processing) needs to
                        // have the correct attribute values.
                        workflow.SaveAttributeValues(rockContext);
                    }

                    _lockObjects.TryRemove(workflow.Id, out _);   // we no longer need that lock for this workflow
                }

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
                errorMessages.Add(ex.Message);
                UpdateWorkflowRequestStatus(workflow, rockContext, "FAIL");
                return(true);
            }
        }
        /// <summary>
        /// Sends a background request to Protect My Ministry
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="personAttribute">The person attribute.</param>
        /// <param name="ssnAttribute">The SSN attribute.</param>
        /// <param name="requestTypeAttribute">The request type attribute.</param>
        /// <param name="billingCodeAttribute">The billing code attribute.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>
        /// True/False value of whether the request was successfully sent or not
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <remarks>
        /// Note: If the associated workflow type does not have attributes with the following keys, they
        /// will automatically be added to the workflow type configuration in order to store the results
        /// of the PMM background check request
        ///     ReportStatus:           The status returned by PMM
        ///     ReportLink:             The location of the background report on PMM server
        ///     ReportRecommendation:   PMM's recomendataion
        ///     Report (BinaryFile):    The downloaded background report
        /// </remarks>
        public override bool SendRequest(RockContext rockContext, Model.Workflow workflow,
                                         AttributeCache personAttribute, AttributeCache ssnAttribute, AttributeCache requestTypeAttribute,
                                         AttributeCache billingCodeAttribute, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            try
            {
                // Check to make sure workflow is not null
                if (workflow == null)
                {
                    errorMessages.Add("The 'ProtectMyMinistry' requires a valid workflow.");
                    return(false);
                }

                // Get the person that the request is for
                Person person = null;
                if (personAttribute != null)
                {
                    Guid?personAliasGuid = workflow.GetAttributeValue(personAttribute.Key).AsGuidOrNull();
                    if (personAliasGuid.HasValue)
                    {
                        person = new PersonAliasService(rockContext).Queryable()
                                 .Where(p => p.Guid.Equals(personAliasGuid.Value))
                                 .Select(p => p.Person)
                                 .FirstOrDefault();
                    }
                }

                if (person == null)
                {
                    errorMessages.Add("The 'ProtectMyMinistry' background check requires the workflow to have a 'Person' attribute that contains the person who the background check is for.");
                    return(false);
                }

                string password = Encryption.DecryptString(GetAttributeValue("Password"));

                XElement rootElement = new XElement("OrderXML",
                                                    new XElement("Method", "SEND ORDER"),
                                                    new XElement("Authentication",
                                                                 new XElement("Username", GetAttributeValue("UserName")),
                                                                 new XElement("Password", password)
                                                                 )
                                                    );

                if (GetAttributeValue("TestMode").AsBoolean())
                {
                    rootElement.Add(new XElement("TestMode", "YES"));
                }

                rootElement.Add(new XElement("ReturnResultURL", GetAttributeValue("ReturnURL")));

                XElement orderElement = new XElement("Order");
                rootElement.Add(orderElement);

                if (billingCodeAttribute != null)
                {
                    Guid?campusGuid = workflow.GetAttributeValue(billingCodeAttribute.Key).AsGuidOrNull();
                    if (campusGuid.HasValue)
                    {
                        var campus = CampusCache.Read(campusGuid.Value);
                        if (campus != null)
                        {
                            orderElement.Add(new XElement("BillingReferenceCode", campus.Name));
                        }
                    }
                }

                XElement subjectElement = new XElement("Subject",
                                                       new XElement("FirstName", person.FirstName),
                                                       new XElement("MiddleName", person.MiddleName),
                                                       new XElement("LastName", person.LastName)
                                                       );
                orderElement.Add(subjectElement);

                if (person.BirthDate.HasValue)
                {
                    subjectElement.Add(new XElement("DOB", person.BirthDate.Value.ToString("MM/dd/yyyy")));
                }

                if (ssnAttribute != null)
                {
                    string ssn = Encryption.DecryptString(workflow.GetAttributeValue(ssnAttribute.Key)).AsNumeric();
                    if (!string.IsNullOrWhiteSpace(ssn) && ssn.Length == 9)
                    {
                        subjectElement.Add(new XElement("SSN", ssn.Insert(5, "-").Insert(3, "-")));
                    }
                }

                if (person.Gender == Gender.Male)
                {
                    subjectElement.Add(new XElement("Gender", "Male"));
                }
                if (person.Gender == Gender.Female)
                {
                    subjectElement.Add(new XElement("Gender", "Female"));
                }

                var homelocation = person.GetHomeLocation();
                if (homelocation != null)
                {
                    subjectElement.Add(new XElement("CurrentAddress",
                                                    new XElement("StreetAddress", homelocation.Street1),
                                                    new XElement("City", homelocation.City),
                                                    new XElement("State", homelocation.State),
                                                    new XElement("Zipcode", homelocation.PostalCode)
                                                    ));
                }

                XElement aliasesElement = new XElement("Aliases");
                if (person.NickName != person.FirstName)
                {
                    aliasesElement.Add(new XElement("Alias", new XElement("FirstName", person.NickName)));
                }
                // foreach ( string lastName in [previous last names] )
                //{
                //    aliasesElement.Add( new XElement( "Alias", new XElement( "LastName", lastName ) ) );
                //}
                if (aliasesElement.HasElements)
                {
                    subjectElement.Add(aliasesElement);
                }

                string packageType = requestTypeAttribute != null?workflow.GetAttributeValue(requestTypeAttribute.Key) : string.Empty;

                if (string.IsNullOrWhiteSpace(packageType))
                {
                    packageType = "Basic";
                }
                orderElement.Add(new XElement("PackageServiceCode", packageType,
                                              new XAttribute("OrderId", workflow.Id.ToString())));
                orderElement.Add(new XElement("OrderDetail",
                                              new XAttribute("OrderId", workflow.Id.ToString()),
                                              new XAttribute("ServiceCode", "combo")));

                XDocument xdoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), rootElement);

                XDocument xResult = PostToWebService(xdoc, GetAttributeValue("RequestURL"));

                if (_HTTPStatusCode == HttpStatusCode.OK)
                {
                    if (xResult.Root.Descendants().Count() > 0)
                    {
                        SaveResults(xResult, workflow, rockContext);
                    }
                    return(true);
                }
                else
                {
                    errorMessages.Add("Invalid HttpStatusCode: " + _HTTPStatusCode.ToString());
                }

                return(false);
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
                errorMessages.Add(ex.Message);
                return(false);
            }
        }
Exemplo n.º 21
0
 public bool HasRowsBefore(Model.Workflow e)
 {
     return(accessor.HasRowsBefore(e));
 }
Exemplo n.º 22
0
 public bool HasRowsAfter(Model.Workflow e)
 {
     return(accessor.HasRowsAfter(e));
 }
Exemplo n.º 23
0
 public void CreateNewWorkflow()
 {
     CurrentWorkflow = new Model.Workflow();
 }
Exemplo n.º 24
0
 public Model.Workflow GetPrev(Model.Workflow e)
 {
     return(accessor.GetPrev(e));
 }
Exemplo n.º 25
0
 public Model.Workflow GetNext(Model.Workflow e)
 {
     return(accessor.GetNext(e));
 }
Exemplo n.º 26
0
        /// <summary>
        /// Sends a background request to Protect My Ministry
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflow">The Workflow initiating the request.</param>
        /// <param name="personAttribute">The person attribute.</param>
        /// <param name="ssnAttribute">The SSN attribute.</param>
        /// <param name="requestTypeAttribute">The request type attribute.</param>
        /// <param name="billingCodeAttribute">The billing code attribute.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>
        /// True/False value of whether the request was successfully sent or not
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <remarks>
        /// Note: If the associated workflow type does not have attributes with the following keys, they
        /// will automatically be added to the workflow type configuration in order to store the results
        /// of the PMM background check request
        ///     RequestStatus:          The request status returned by PMM request
        ///     RequestMessage:         Any error messages returned by PMM request
        ///     ReportStatus:           The report status returned by PMM
        ///     ReportLink:             The location of the background report on PMM server
        ///     ReportRecommendation:   PMM's recomendataion
        ///     Report (BinaryFile):    The downloaded background report
        /// </remarks>
        public override bool SendRequest(RockContext rockContext, Model.Workflow workflow,
                                         AttributeCache personAttribute, AttributeCache ssnAttribute, AttributeCache requestTypeAttribute,
                                         AttributeCache billingCodeAttribute, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            try
            {
                // Check to make sure workflow is not null
                if (workflow == null)
                {
                    errorMessages.Add("The 'Protect My Ministry' background check provider requires a valid workflow.");
                    return(false);
                }

                // Get the person that the request is for
                Person person = null;
                if (personAttribute != null)
                {
                    Guid?personAliasGuid = workflow.GetAttributeValue(personAttribute.Key).AsGuidOrNull();
                    if (personAliasGuid.HasValue)
                    {
                        person = new PersonAliasService(rockContext).Queryable()
                                 .Where(p => p.Guid.Equals(personAliasGuid.Value))
                                 .Select(p => p.Person)
                                 .FirstOrDefault();
                        person.LoadAttributes(rockContext);
                    }
                }

                if (person == null)
                {
                    errorMessages.Add("The 'Protect My Ministry' background check provider requires the workflow to have a 'Person' attribute that contains the person who the background check is for.");
                    return(false);
                }

                string password = Encryption.DecryptString(GetAttributeValue("Password"));

                XElement rootElement = new XElement("OrderXML",
                                                    new XElement("Method", "SEND ORDER"),
                                                    new XElement("Authentication",
                                                                 new XElement("Username", GetAttributeValue("UserName")),
                                                                 new XElement("Password", password)
                                                                 )
                                                    );

                if (GetAttributeValue("TestMode").AsBoolean())
                {
                    rootElement.Add(new XElement("TestMode", "YES"));
                }

                rootElement.Add(new XElement("ReturnResultURL", GetAttributeValue("ReturnURL")));

                XElement orderElement = new XElement("Order");
                rootElement.Add(orderElement);

                if (billingCodeAttribute != null)
                {
                    string billingCode = workflow.GetAttributeValue(billingCodeAttribute.Key);
                    Guid?  campusGuid  = billingCode.AsGuidOrNull();
                    if (campusGuid.HasValue)
                    {
                        var campus = CampusCache.Read(campusGuid.Value);
                        if (campus != null)
                        {
                            billingCode = campus.Name;
                        }
                    }
                    orderElement.Add(new XElement("BillingReferenceCode", billingCode));
                }

                XElement subjectElement = new XElement("Subject",
                                                       new XElement("FirstName", person.FirstName),
                                                       new XElement("MiddleName", person.MiddleName),
                                                       new XElement("LastName", person.LastName)
                                                       );
                orderElement.Add(subjectElement);

                if (person.SuffixValue != null)
                {
                    subjectElement.Add(new XElement("Generation", person.SuffixValue.Value));
                }
                if (person.BirthDate.HasValue)
                {
                    subjectElement.Add(new XElement("DOB", person.BirthDate.Value.ToString("MM/dd/yyyy")));
                }

                if (ssnAttribute != null)
                {
                    string ssn = Encryption.DecryptString(workflow.GetAttributeValue(ssnAttribute.Key)).AsNumeric();
                    if (!string.IsNullOrWhiteSpace(ssn) && ssn.Length == 9)
                    {
                        subjectElement.Add(new XElement("SSN", ssn.Insert(5, "-").Insert(3, "-")));
                    }
                }

                if (person.Gender == Gender.Male)
                {
                    subjectElement.Add(new XElement("Gender", "Male"));
                }
                if (person.Gender == Gender.Female)
                {
                    subjectElement.Add(new XElement("Gender", "Female"));
                }

                string dlNumber = person.GetAttributeValue("com.sparkdevnetwork.DLNumber");
                if (!string.IsNullOrWhiteSpace(dlNumber))
                {
                    subjectElement.Add(new XElement("DLNumber", dlNumber));
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    subjectElement.Add(new XElement("EmailAddress", person.Email));
                }

                var homelocation = person.GetHomeLocation();
                if (homelocation != null)
                {
                    subjectElement.Add(new XElement("CurrentAddress",
                                                    new XElement("StreetAddress", homelocation.Street1),
                                                    new XElement("City", homelocation.City),
                                                    new XElement("State", homelocation.State),
                                                    new XElement("Zipcode", homelocation.PostalCode)
                                                    ));
                }

                XElement aliasesElement = new XElement("Aliases");
                if (person.NickName != person.FirstName)
                {
                    aliasesElement.Add(new XElement("Alias", new XElement("FirstName", person.NickName)));
                }

                foreach (var previousName in person.GetPreviousNames())
                {
                    aliasesElement.Add(new XElement("Alias", new XElement("LastName", previousName.LastName)));
                }

                if (aliasesElement.HasElements)
                {
                    subjectElement.Add(aliasesElement);
                }

                DefinedValueCache pkgTypeDefinedValue = null;
                string            packageName         = "BASIC";
                string            county          = string.Empty;
                string            state           = string.Empty;
                string            mvrJurisdiction = string.Empty;
                string            mvrState        = string.Empty;

                if (requestTypeAttribute != null)
                {
                    pkgTypeDefinedValue = DefinedValueCache.Read(workflow.GetAttributeValue(requestTypeAttribute.Key).AsGuid());
                    if (pkgTypeDefinedValue != null)
                    {
                        if (pkgTypeDefinedValue.Attributes == null)
                        {
                            pkgTypeDefinedValue.LoadAttributes(rockContext);
                        }

                        packageName = pkgTypeDefinedValue.GetAttributeValue("PMMPackageName");
                        county      = pkgTypeDefinedValue.GetAttributeValue("DefaultCounty");
                        state       = pkgTypeDefinedValue.GetAttributeValue("DefaultState");
                        Guid?mvrJurisdictionGuid = pkgTypeDefinedValue.GetAttributeValue("MVRJurisdiction").AsGuidOrNull();
                        if (mvrJurisdictionGuid.HasValue)
                        {
                            var mvrJurisdictionDv = DefinedValueCache.Read(mvrJurisdictionGuid.Value);
                            if (mvrJurisdictionDv != null)
                            {
                                mvrJurisdiction = mvrJurisdictionDv.Value;
                                if (mvrJurisdiction.Length >= 2)
                                {
                                    mvrState = mvrJurisdiction.Left(2);
                                }
                            }
                        }

                        if (homelocation != null)
                        {
                            if (!string.IsNullOrWhiteSpace(homelocation.County) &&
                                pkgTypeDefinedValue.GetAttributeValue("SendHomeCounty").AsBoolean())
                            {
                                county = homelocation.County;
                            }

                            if (!string.IsNullOrWhiteSpace(homelocation.State))
                            {
                                if (pkgTypeDefinedValue.GetAttributeValue("SendHomeState").AsBoolean())
                                {
                                    state = homelocation.State;
                                }
                                if (pkgTypeDefinedValue.GetAttributeValue("SendHomeStateMVR").AsBoolean())
                                {
                                    mvrState = homelocation.State;
                                }
                            }
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(packageName))
                {
                    orderElement.Add(new XElement("PackageServiceCode", packageName,
                                                  new XAttribute("OrderId", workflow.Id.ToString())));

                    if (packageName.Trim().Equals("BASIC", StringComparison.OrdinalIgnoreCase) ||
                        packageName.Trim().Equals("PLUS", StringComparison.OrdinalIgnoreCase))
                    {
                        orderElement.Add(new XElement("OrderDetail",
                                                      new XAttribute("OrderId", workflow.Id.ToString()),
                                                      new XAttribute("ServiceCode", "combo")));
                    }
                }

                if (!string.IsNullOrWhiteSpace(county) ||
                    !string.IsNullOrWhiteSpace(state))
                {
                    orderElement.Add(new XElement("OrderDetail",
                                                  new XAttribute("OrderId", workflow.Id.ToString()),
                                                  new XAttribute("ServiceCode", string.IsNullOrWhiteSpace(county) ? "StateCriminal" : "CountyCrim"),
                                                  new XElement("County", county),
                                                  new XElement("State", state),
                                                  new XElement("YearsToSearch", 7),
                                                  new XElement("CourtDocsRequested", "NO"),
                                                  new XElement("RushRequested", "NO"),
                                                  new XElement("SpecialInstructions", ""))
                                     );
                }

                if (!string.IsNullOrWhiteSpace(mvrJurisdiction) && !string.IsNullOrWhiteSpace(mvrState))
                {
                    orderElement.Add(new XElement("OrderDetail",
                                                  new XAttribute("OrderId", workflow.Id.ToString()),
                                                  new XAttribute("ServiceCode", "MVR"),
                                                  new XElement("JurisdictionCode", mvrJurisdiction),
                                                  new XElement("State", mvrState))
                                     );
                }

                XDocument xdoc            = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), rootElement);
                var       requestDateTime = RockDateTime.Now;

                XDocument xResult          = PostToWebService(xdoc, GetAttributeValue("RequestURL"));
                var       responseDateTime = RockDateTime.Now;

                int?personAliasId = person.PrimaryAliasId;
                if (personAliasId.HasValue)
                {
                    // Create a background check file
                    using (var newRockContext = new RockContext())
                    {
                        var backgroundCheckService = new BackgroundCheckService(newRockContext);
                        var backgroundCheck        = backgroundCheckService.Queryable()
                                                     .Where(c =>
                                                            c.WorkflowId.HasValue &&
                                                            c.WorkflowId.Value == workflow.Id)
                                                     .FirstOrDefault();

                        if (backgroundCheck == null)
                        {
                            backgroundCheck = new Rock.Model.BackgroundCheck();
                            backgroundCheck.PersonAliasId = personAliasId.Value;
                            backgroundCheck.WorkflowId    = workflow.Id;
                            backgroundCheckService.Add(backgroundCheck);
                        }

                        backgroundCheck.RequestDate = RockDateTime.Now;

                        // Clear any SSN nodes before saving XML to record
                        foreach (var xSSNElement in xdoc.Descendants("SSN"))
                        {
                            xSSNElement.Value = "XXX-XX-XXXX";
                        }
                        foreach (var xSSNElement in xResult.Descendants("SSN"))
                        {
                            xSSNElement.Value = "XXX-XX-XXXX";
                        }

                        backgroundCheck.ResponseXml = string.Format(@"
Request XML ({0}): 
------------------------ 
{1}

Response XML ({2}): 
------------------------ 
{3}

", requestDateTime, xdoc.ToString(), responseDateTime, xResult.ToString());
                        newRockContext.SaveChanges();
                    }
                }

                using (var newRockContext = new RockContext())
                {
                    var handledErrorMessages = new List <string>();

                    bool createdNewAttribute = false;
                    if (_HTTPStatusCode == HttpStatusCode.OK)
                    {
                        var xOrderXML = xResult.Elements("OrderXML").FirstOrDefault();
                        if (xOrderXML != null)
                        {
                            var xStatus = xOrderXML.Elements("Status").FirstOrDefault();
                            if (xStatus != null)
                            {
                                if (SaveAttributeValue(workflow, "RequestStatus", xStatus.Value,
                                                       FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()), newRockContext, null))
                                {
                                    createdNewAttribute = true;
                                }
                            }

                            handledErrorMessages.AddRange(xOrderXML.Elements("Message").Select(x => x.Value).ToList());
                            var xErrors = xOrderXML.Elements("Errors").FirstOrDefault();
                            if (xErrors != null)
                            {
                                handledErrorMessages.AddRange(xOrderXML.Elements("Message").Select(x => x.Value).ToList());
                            }

                            if (xResult.Root.Descendants().Count() > 0)
                            {
                                SaveResults(xResult, workflow, rockContext, false);
                            }
                        }
                    }
                    else
                    {
                        handledErrorMessages.Add("Invalid HttpStatusCode: " + _HTTPStatusCode.ToString());
                    }

                    if (handledErrorMessages.Any())
                    {
                        if (SaveAttributeValue(workflow, "RequestMessage", handledErrorMessages.AsDelimited(Environment.NewLine),
                                               FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()), newRockContext, null))
                        {
                            createdNewAttribute = true;
                        }
                    }

                    newRockContext.SaveChanges();

                    if (createdNewAttribute)
                    {
                        AttributeCache.FlushEntityAttributes();
                    }

                    return(true);
                }
            }

            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
                errorMessages.Add(ex.Message);
                return(false);
            }
        }
Exemplo n.º 27
0
 public SagaActor(Model.Workflow workflow, KeyString sagaKey)
 {
     SagaKey   = sagaKey;
     _workflow = workflow;
 }