예제 #1
0
        public WorkflowConfig(Int64 contextId, String name, String description, Int64 owner, WorkflowAccessType accessType)
            : this()
        {
            this.context_id  = contextId;
            this.name        = name;
            this.description = description;
            this.owner       = owner;
            this.access_type = accessType;
            this.enabled     = true;
            this.deleted     = false;
            this.deprecated  = false;
            this.original_id = 0;
            this.version     = 1;
            this.create_date = DateTime.Now;

            if (this.access_type == WorkflowAccessType.Unlock)
            {
                this.access = new WorkflowAccessUnlock();
            }
        }
예제 #2
0
        public void ParseFromJsonObject(Dictionary <String, Object> data)
        {
            this.context_id  = Int64.Parse(data["context_id"].ToString());
            this.workflow_id = Int64.Parse(data["workflow_id"].ToString());
            this.name        = (String)data["name"];
            this.description = (String)data["description"];
            this.owner       = Int64.Parse(data["owner_id"].ToString());
            this.enabled     = Boolean.Parse(data["enabled"].ToString());
            this.deleted     = Boolean.Parse(data["deleted"].ToString());
            this.deprecated  = Boolean.Parse(data["deprecated"].ToString());
            this.original_id = Int64.Parse(data["original_id"].ToString());
            this.version     = Int64.Parse(data["version"].ToString());
            this.create_date = new DateTime(1970, 1, 1).AddSeconds(Int64.Parse(data["create_date"].ToString()));

            switch (data["type"].ToString().ToLower())
            {
            case "rolegrant":
                this.access_type = WorkflowAccessType.RoleGrant;
                break;

            case "delegation":
                this.access_type = WorkflowAccessType.Delegation;
                break;

            case "unlock":
                this.access_type = WorkflowAccessType.Unlock;
                break;

            default:
                throw new Exception(String.Format("Access type {0} not implemented yet", data["type"]));
                break;
            }


            //if (!(lst[i] is Dictionary<String, Object>))
            //if (!(parameters["mapping"] is ArrayList))


            if (!(data["access"] is Dictionary <String, Object>))
            {
                throw new Exception("Access is not valid");
            }

            Dictionary <String, Object> access = (Dictionary <String, Object>)data["access"];

            switch (this.access_type)
            {
            case WorkflowAccessType.RoleGrant:
                WorkflowAccessRoleGrant roleGrant = new WorkflowAccessRoleGrant();

                if (!(access["role_id"] is ArrayList))
                {
                    throw new Exception("Access is not valid");
                }

                List <Object> lst = new List <Object>();
                lst.AddRange(((ArrayList)access["role_id"]).ToArray());

                foreach (Object r in lst)
                {
                    roleGrant.Add(Int64.Parse(r.ToString()));
                }

                if ((roleGrant.Roles == null) || (roleGrant.Roles.Count == 0))
                {
                    throw new Exception("Role list is empty");
                }

                this.access = roleGrant;
                break;

            case WorkflowAccessType.Delegation:
                WorkflowAccessDelegation entityDelegation = new WorkflowAccessDelegation();

                try
                {
                    entityDelegation.Entity = Int64.Parse(access["entity_id"].ToString());
                }
                catch
                {
                    throw new Exception("Access is not valid");
                }

                if (entityDelegation.Entity == 0)
                {
                    throw new Exception("Entity id is empty");
                }

                this.access = entityDelegation;
                break;

            case WorkflowAccessType.Unlock:
                this.access = new WorkflowAccessUnlock();
                break;
            }


            if (!(data["activities"] is ArrayList))
            {
                throw new Exception("Activity list is not valid");
            }

            List <Object> act = new List <Object>();

            act.AddRange(((ArrayList)data["activities"]).ToArray());

            for (Int32 i = 0; i < act.Count; i++)
            {
                if (!(act[i] is Dictionary <String, Object>))
                {
                    throw new Exception("Activity " + i + " is not valid");
                }

                Dictionary <String, Object> a = (Dictionary <String, Object>)act[i];

                WorkflowActivity activity = new WorkflowActivity(
                    a["name"].ToString(),
                    Int64.Parse(a["auto_approval"].ToString()),
                    Int64.Parse(a["auto_deny"].ToString()),
                    Int32.Parse(a["escalation_days"].ToString()),
                    Int32.Parse(a["expiration_days"].ToString())
                    );

                activity.ActivityId = Int64.Parse(a["activity_id"].ToString());

                if (a.ContainsKey("manual_approval") && (a["manual_approval"] is Dictionary <string, object>))
                {
                    activity.SetApprover(
                        Int64.Parse(((Dictionary <string, object>)a["manual_approval"])["entity_approver"].ToString()),
                        Int64.Parse(((Dictionary <string, object>)a["manual_approval"])["role_approver"].ToString())
                        );
                }

                if ((activity.AutoDeny == 0) && (activity.AutoDeny == 0) && (activity.ManualApproval == null || (activity.ManualApproval.EntityApprover == 0 && activity.ManualApproval.RoleApprover == 0)))
                {
                    throw new Exception("All activity approvers is empty in activity " + activity.Name);
                }

                this.activities.Add(activity);
            }

            if (this.activities.Count == 0)
            {
                throw new Exception("Activity list is empty");
            }
        }
예제 #3
0
 public WorkflowConfig()
 {
     this.activities  = new List <WorkflowActivity>();
     this.access_type = WorkflowAccessType.None;
 }
예제 #4
0
        public void GetDatabaseData(IAMDatabase database, Int64 workflowId, Object transaction)
        {
            this.workflow_id = workflowId;

            DataTable dtWorkflow = database.ExecuteDataTable("select * from st_workflow where id = " + this.workflow_id, CommandType.Text, null, transaction);

            if ((dtWorkflow == null) || (dtWorkflow.Rows.Count == 0))
            {
                throw new Exception("Workflow not found");
            }

            this.context_id  = (Int64)dtWorkflow.Rows[0]["context_id"];
            this.name        = (String)dtWorkflow.Rows[0]["name"];
            this.description = (String)dtWorkflow.Rows[0]["description"];
            this.owner       = (Int64)dtWorkflow.Rows[0]["owner_id"];
            this.enabled     = (Boolean)dtWorkflow.Rows[0]["enabled"];
            this.deleted     = (Boolean)dtWorkflow.Rows[0]["deleted"];
            this.deprecated  = (Boolean)dtWorkflow.Rows[0]["deprecated"];
            this.original_id = (Int64)dtWorkflow.Rows[0]["original_id"];
            this.version     = (Int64)dtWorkflow.Rows[0]["version"];
            this.create_date = (DateTime)dtWorkflow.Rows[0]["create_date"];

            switch (dtWorkflow.Rows[0]["type"].ToString().ToLower())
            {
            case "rolegrant":
                this.access_type = WorkflowAccessType.RoleGrant;
                break;

            case "delegation":
                this.access_type = WorkflowAccessType.Delegation;
                break;

            case "unlock":
                this.access_type = WorkflowAccessType.Unlock;
                break;

            default:
                throw new Exception(String.Format("Access type {0} not implemented yet", dtWorkflow.Rows[0]["type"]));
                break;
            }

            switch (this.access_type)
            {
            case WorkflowAccessType.RoleGrant:
                WorkflowAccessRoleGrant roleGrant = new WorkflowAccessRoleGrant();

                DataTable dtRG = database.ExecuteDataTable("select * from st_workflow_access_role where workflow_id = " + this.workflow_id, CommandType.Text, null, transaction);
                if (dtRG != null)
                {
                    foreach (DataRow dr in dtRG.Rows)
                    {
                        roleGrant.Add((Int64)dr["role_id"]);
                    }
                }

                if ((roleGrant.Roles == null) || (roleGrant.Roles.Count == 0))
                {
                    throw new Exception("Role list is empty");
                }

                this.access = roleGrant;
                break;

            case WorkflowAccessType.Delegation:
                WorkflowAccessDelegation entityDelegation = new WorkflowAccessDelegation();


                DataTable dtED = database.ExecuteDataTable("select * from st_workflow_access_role where workflow_id = " + this.workflow_id, CommandType.Text, null, transaction);
                if (dtED != null)
                {
                    foreach (DataRow dr in dtED.Rows)
                    {
                        entityDelegation.Entity = (Int64)dr["entity_id"];
                    }
                }

                if (entityDelegation.Entity == 0)
                {
                    throw new Exception("Entity id is empty");
                }

                this.access = entityDelegation;
                break;

            case WorkflowAccessType.Unlock:
                this.access = new WorkflowAccessUnlock();
                break;
            }

            DataTable dtActivity = database.ExecuteDataTable("select * from st_workflow_activity where workflow_id = " + this.workflow_id + " order by execution_order", CommandType.Text, null, transaction);

            if (dtActivity != null)
            {
                foreach (DataRow dr in dtActivity.Rows)
                {
                    WorkflowActivity activity = new WorkflowActivity(
                        dr["name"].ToString(),
                        (dr["auto_approval"] == DBNull.Value ? 0 : (Int64)dr["auto_approval"]),
                        (dr["auto_deny"] == DBNull.Value ? 0 : (Int64)dr["auto_deny"]),
                        (Int32)dr["escalation_days"],
                        (Int32)dr["expiration_days"]
                        );

                    activity.ActivityId    = (Int64)dr["id"];
                    activity.ExeutionOrder = (Int32)dr["execution_order"];

                    DataTable dtManual = database.ExecuteDataTable("select * from st_workflow_activity_manual_approval where workflow_activity_id = " + activity.ActivityId, CommandType.Text, null, transaction);
                    if (dtManual != null)
                    {
                        foreach (DataRow dr2 in dtManual.Rows)
                        {
                            activity.SetApprover(
                                (dr2["entity_approver"] == DBNull.Value ? 0 : (Int64)dr2["entity_approver"]),
                                (dr2["role_approver"] == DBNull.Value ? 0 : (Int64)dr2["role_approver"])
                                );
                        }
                    }

                    if ((activity.AutoDeny == 0) && (activity.AutoDeny == 0) && (activity.ManualApproval == null || (activity.ManualApproval.EntityApprover == 0 && activity.ManualApproval.RoleApprover == 0)))
                    {
                        throw new Exception("All activity approvers is empty in activity " + activity.Name);
                    }

                    this.activities.Add(activity);
                }
            }

            if (this.activities.Count == 0)
            {
                throw new Exception("Activity list is empty");
            }
        }