Esempio n. 1
0
        public void OnItemCheckChanged(object sender, GridItemCheckChangedEventArgs oArgs)
        {
            int IDbusrole = int.Parse(oArgs.Item["c_id"].ToString());

            returnGetBusRole detailsBusRole = engineBusRole.GetBusRole(IDbusrole);

            MAPbroleIdToName.Add(IDbusrole, detailsBusRole.Name);
            MAPbroleToSubproc.Add(IDbusrole, detailsBusRole.SubProcessID);

            if (oArgs.Checked)
            {
                QUEUEidsBusrolesToADD.Enqueue(IDbusrole);
            }
            else
            {
                QUEUEidsBusrolesToREMOVE.Enqueue(IDbusrole);
            }

            if (MAPsubprToEASet.ContainsKey(detailsBusRole.SubProcessID))
            {
                return;
            }

            // This role is in a subprocess we have not yet analyzed.
            // Must determine if in workspace or ACTIVE status.
            // If that subpr is in a workspace owned by someone else,
            //   the entire operation is aborted with no change being made.
            returnListEntAssignmentSetBySubProcess[] ret = engineEASet.ListEntAssignmentSetBySubProcess
                                                               (null, "\"Status\" = ?", new string[] { "WORKSPACE" }, "", detailsBusRole.SubProcessID);
            if (ret.Length > 1)
            {
                throw new Exception("More than one WORKSPACE open simultaneously for subprocess " +
                                    oArgs.Item["NamePr"].ToString());
            }
            if (ret.Length == 1)
            {
                // A workspace is open for this subprocess.
                // OK if userID matches this session's user
                if (ret[0].UserID == session.idUser)
                {
                    // It's a match, we can use this workspace.
                    HELPERS.infoEASet EAS = new HELPERS.infoEASet();
                    EAS.idEntAssSet          = ret[0].ID;
                    EAS.idEntAssSetCreator   = ret[0].UserID;
                    EAS.nameEntAssSetCreator = ret[0].UserLoginName;
                    EAS.nameSubprocess       = oArgs.Item["NamePr"].ToString();
                    EAS.strEntAssSetStatus   = "WORKSPACE";
                    MAPsubprToEASet.Add(detailsBusRole.SubProcessID, EAS);
                }
                else
                {
                    boolMustAbort = true;
                    messages     +=
                        "ERROR: Cannot make modifications regarding role " +
                        oArgs.Item["c_u_Name"] + ".  The workspace for " +
                        oArgs.Item["NamePr"] + " is owned by a 3rd party (" +
                        ret[0].UserLoginName + ").\n";
                }
            }
            else
            {
                // Make sure there is an ACTIVE EASet to build a workspace from.
                ret = engineEASet.ListEntAssignmentSetBySubProcess
                          (null, "\"Status\" = ?", new string[] { "ACTIVE" }, "", detailsBusRole.SubProcessID);
                if (ret.Length > 1)
                {
                    throw new Exception("More than one ACTIVE entitlement-assignment set for " +
                                        oArgs.Item["NamePr"].ToString());
                }
                if (ret.Length < 1)
                {
                    throw new Exception("Subprocess has NO active entitlement-assignment set yet: " +
                                        oArgs.Item["NamePr"].ToString());
                }
                if (ret.Length == 1)
                {
                    HELPERS.infoEASet EAS = new HELPERS.infoEASet();
                    EAS.idEntAssSet          = ret[0].ID;
                    EAS.idEntAssSetCreator   = ret[0].UserID;
                    EAS.nameEntAssSetCreator = ret[0].UserLoginName;
                    EAS.nameSubprocess       = oArgs.Item["NamePr"].ToString();
                    EAS.strEntAssSetStatus   = "ACTIVE";
                    MAPsubprToEASet.Add(detailsBusRole.SubProcessID, EAS);
                }
            }
        }
Esempio n. 2
0
        private void AutoRemoveEntitlementStatus
            (int idEntit, int idThisUser, HttpResponse theResponse)
        {
            // Get complete info about this entitlement
            IEntitlement         engine  = new IEntitlement(HELPERS.NewOdbcConn());
            returnGetEntitlement thisEnt = engine.GetEntitlement(idEntit);

            // Find every entAssignment that refers to this entitlement
            // and that is in an ACTIVE entset or a WORKSPACE entset.
            // Requires a JOIN
            string sqlFindEA =
                "SELECT EA.c_id, EAS.c_r_SubProcess as EASsubpr, EAS.c_id as EASid, EAS.c_u_Status as EASstatus, EAS.c_r_User as EASiduser, " +
                " USR.c_u_Name as EASnameuser, PR.c_u_Name + ' / ' + SUBPR.c_u_Name as SUBPRname, EA.c_r_Entitlement as EAentit, " +
                " BROLE.c_u_Name as BRname " +
                " FROM t_RBSR_AUFW_u_EntAssignment EA" +
                " LEFT OUTER JOIN t_RBSR_AUFW_u_EntAssignmentSet EAS ON EAS.c_id = EA.c_r_EntAssignmentSet " +
                " LEFT OUTER JOIN t_RBSR_AUFW_u_Subprocess SUBPR ON SUBPR.c_id = EAS.c_r_SubProcess " +
                " LEFT OUTER JOIN t_RBSR_AUFW_u_Process PR ON PR.c_id = SUBPR.c_r_Process " +
                " LEFT OUTER JOIN t_RBSR_AUFW_u_User USR ON USR.c_id = EAS.c_r_User " +
                " LEFT OUTER JOIN t_RBSR_AUFW_u_BusRole BROLE ON BROLE.c_id = EA.c_r_BusRole " +
                " WHERE EAS.c_u_Status IN ('WORKSPACE','ACTIVE') AND EA.c_r_Entitlement=" + idEntit;
            OdbcDataReader reader = HELPERS.RunSqlSelect(sqlFindEA);

            Dictionary <int, HELPERS.infoEASet> MAPsubprToEASet =
                new Dictionary <int, HELPERS.infoEASet>();



            Queue queueOfEA = new Queue();

            while (reader.Read())
            {
                HELPERS.infoEA baby = new HELPERS.infoEA();
                baby.idEntAss             = reader.GetInt32(0);
                baby.idSubpr              = reader.GetInt32(1);
                baby.idEntAssSet          = reader.GetInt32(2);
                baby.strEntAssSetStatus   = reader.GetString(3);
                baby.idEntAssSetCreator   = reader.GetInt32(4);
                baby.nameEntAssSetCreator = reader.GetString(5);
                baby.nameSubprocess       = reader.GetString(6);
                baby.idEntitlement        = reader.GetInt32(7);
                baby.nameBusRole          = reader.GetString(8);
                queueOfEA.Enqueue(baby);

                // An existing workspace OVERRULES an ACTIVE EASet.
                if (!MAPsubprToEASet.ContainsKey(baby.idSubpr))
                {
                    HELPERS.infoEASet infoeaset = new HELPERS.infoEASet();
                    infoeaset.idEntAssSet          = baby.idEntAssSet;
                    infoeaset.strEntAssSetStatus   = baby.strEntAssSetStatus;
                    infoeaset.idEntAssSetCreator   = baby.idEntAssSetCreator;
                    infoeaset.nameEntAssSetCreator = baby.nameEntAssSetCreator;
                    infoeaset.nameSubprocess       = baby.nameSubprocess;
                    MAPsubprToEASet.Add(baby.idSubpr, infoeaset);
                }
                else
                {
                    if (MAPsubprToEASet[baby.idSubpr].idEntAssSet == baby.idEntAssSet)
                    {
                        // This is another copy of the same registered EASet.
                        // Ignore!
                    }
                    else if (MAPsubprToEASet[baby.idSubpr].strEntAssSetStatus == "WORKSPACE")
                    {
                        // The registered EASet for this subprocess is already a workspace.
                        // This newcomer must be the ACTIVE easet and we are not interested.
                        if (baby.strEntAssSetStatus != "ACTIVE")
                        {
                            throw new Exception("DATABASE ERROR: Multiple workspaces are active for subprocess #" +
                                                baby.idSubpr + "(" + baby.nameSubprocess + ")");
                        }
                    }
                    else
                    {
                        if (baby.strEntAssSetStatus != "WORKSPACE")
                        {
                            throw new Exception("DATABASE ERROR: Multiple EASets are marked as 'ACTIVE' for subprocess #" +
                                                baby.idSubpr + "(" + baby.nameSubprocess + ")");
                        }
                        HELPERS.infoEASet infoeaset = new HELPERS.infoEASet();
                        infoeaset.idEntAssSet          = baby.idEntAssSet;
                        infoeaset.strEntAssSetStatus   = baby.strEntAssSetStatus;
                        infoeaset.idEntAssSetCreator   = baby.idEntAssSetCreator;
                        infoeaset.nameEntAssSetCreator = baby.nameEntAssSetCreator;
                        MAPsubprToEASet[baby.idSubpr]  = infoeaset;
                    }
                }
            }
            reader.Dispose();


            // We now have the list of all subprocesses involved, and info about
            // either the ACTIVE or WORKSPACE EASet to be actually edited.

            // We now want to build any needed workspaces, i.e. if we are looking
            // at an EASet of status "ACTIVE".
            //
            // CAREFUL!!! Before 13 July, there was a BUG here.  It was possible to have
            // the EASet be an ACTIVE one (if the workspace for that subpr simply didn't
            // have any ref to the target entitlement), which would cause construction
            // of an unneeded workspace.
            // BEFORE CONSTRUCTING ANY WORKSPACE, AN EXTRA CHECK MUST BE PERFORMED
            // TO ENSURE THERE IS NOT ALREADY A WS FOR THAT SUBPR!!!!

            Dictionary <int, HELPERS.infoEASet> readyToUseWorkspaces = new Dictionary <int, HELPERS.infoEASet>();
            Dictionary <int, HELPERS.infoEASet> lockedWorkspaces     = new Dictionary <int, HELPERS.infoEASet>();
            String messages = "";

            HELPERS.AutoGenWorkspacesInBulk(idThisUser, ref messages, MAPsubprToEASet, readyToUseWorkspaces, lockedWorkspaces,
                                            "facilitate retirement of an entitlement");
            theResponse.Write(messages);

            // We are now ready to do the processing of the EAssignments.
            // There are two situations.
            // If the EA's own status is "N", the proper thing to do is to delete the EA entirely.
            // If the EA's status is "A", the proper thing to do is turn it to "X".
            // No change should be made of course if it's already "X".
            // Running these updates multiple times is no problem, as it will turn into a no-op
            //   after the first time.
            //
            // ON SECOND THOUGHT: I want to turn even status "N" to "X" because that is self-documenting
            // and better for auditing.  We want it to appear with a verboten sign in the designer view.

            Dictionary <int, int> MAPsubprToNumAffected = new Dictionary <int, int>();

            while (queueOfEA.Count > 0)
            {
                HELPERS.infoEA curEA   = (HELPERS.infoEA)(queueOfEA.Dequeue());
                int            idSubpr = curEA.idSubpr;
                if (MAPsubprToNumAffected.ContainsKey(idSubpr))
                {
                    continue;
                }
                if (readyToUseWorkspaces.ContainsKey(idSubpr))
                {
                    HELPERS.infoEASet curWS = readyToUseWorkspaces[idSubpr];

                    // Handling status="A" and "N"
                    string cmdsql =
                        "UPDATE t_RBSR_AUFW_u_EntAssignment " +
                        " SET c_u_Status='X' WHERE c_u_Status IN ('A','N','P') AND " +
                        " c_r_EntAssignmentSet=" + curWS.idEntAssSet + " AND " +
                        " c_r_Entitlement=" + curEA.idEntitlement;
                    int resultRunSql = HELPERS.RunSql(cmdsql);
                    MAPsubprToNumAffected[idSubpr] = resultRunSql;
                    theResponse.Write(
                        "OK: " + curEA.nameSubprocess + ": " + resultRunSql + " business roles affected.\n");
                }
                else
                {
                    HELPERS.infoEASet lockedWS = lockedWorkspaces[idSubpr];
                    theResponse.Write(
                        "<B>ERROR: </B> Entitlement #" + curEA.idEntitlement + " could not be removed from " + curEA.nameBusRole +
                        " -- workspace locked by " + lockedWS.nameEntAssSetCreator + ".\n");
                }
            }
        }
Esempio n. 3
0
        /* This is called when the user submits the page's changes.
         * It is called once for each checkbox change being submitted.
         * If necessary, a workspace is launched for the relevant subprocess.
         * If the subprocess already contains a workspace but it's owned
         * by some other user, the change is not made and the user
         * is alerted, but the process of executing the set of changes is
         * not aborted.
         *
         * mimic this to create the automatic workspace creation:
         * AutoRemoveEntitlementStatus in GuidedEditor/...
         */

        public void OnAfterCallback(object sender, EventArgs oArgs)
        {
            if (this.boolMustAbort)
            {
                Grid1.CallbackParameter = "OPERATION ABORTED:\n" + messages;
                return;
            }


            Dictionary <int, HELPERS.infoEASet> readyToUseWorkspaces = new Dictionary <int, HELPERS.infoEASet>();
            Dictionary <int, HELPERS.infoEASet> lockedWorkspaces     = new Dictionary <int, HELPERS.infoEASet>();

            if (messages.Length > 0)
            {
                messages += "\n-------------------------\n\n";
            }

            HELPERS.AutoGenWorkspacesInBulk
                (session.idUser, ref messages, MAPsubprToEASet, readyToUseWorkspaces, lockedWorkspaces,
                "facilitate bulk role assignment/unassignment for a particular entitlement");

            // If any problem occurred at all, we abort!
            if (lockedWorkspaces.Count > 0)
            {
                Grid1.CallbackParameter = messages;
                return;
            }


            // We now proceed with the actual edits.
            IEntAssignment ENGINEentass = new IEntAssignment(HELPERS.NewOdbcConn());

            while (QUEUEidsBusrolesToREMOVE.Count > 0)
            {
                int idBusrole = QUEUEidsBusrolesToREMOVE.Dequeue();
                int idSubpr   = MAPbroleToSubproc[idBusrole];
                messages += "Detaching from this role: " + MAPbroleIdToName[idBusrole] + "\n";
                HELPERS.infoEASet wstouse = readyToUseWorkspaces[idSubpr];

                returnListEntAssignmentByEntAssignmentSet[] theEAss =
                    ENGINEentass.ListEntAssignmentByEntAssignmentSet
                        (null, "\"BusRole\" = ? AND \"Entitlement\" = ? ", new string[] { idBusrole.ToString(), IDentitlement.ToString() }, "", wstouse.idEntAssSet);

                ENGINEentass.SetEntAssignment
                    (theEAss[0].ID, theEAss[0].EntAssignmentSetID, theEAss[0].BusRoleID,
                    theEAss[0].EntitlementID, "X");
            }
            while (QUEUEidsBusrolesToADD.Count > 0)
            {
                int idBusrole = QUEUEidsBusrolesToADD.Dequeue();
                int idSubpr   = MAPbroleToSubproc[idBusrole];
                messages += "Attaching to this role: " + MAPbroleIdToName[idBusrole] + "\n";
                HELPERS.infoEASet wstouse = readyToUseWorkspaces[idSubpr];

                returnListEntAssignmentByEntAssignmentSet[] theEAss =
                    ENGINEentass.ListEntAssignmentByEntAssignmentSet
                        (null, "\"BusRole\" = ? AND \"Entitlement\" = ? ", new string[] { idBusrole.ToString(), IDentitlement.ToString() }, "", wstouse.idEntAssSet);

                if (theEAss.GetLength(0) > 1)
                {
                    throw new Exception("Workspace " + wstouse.idEntAssSet + " contains multiple entitlement assignment records for business role " + idBusrole);
                }
                else if (theEAss.GetLength(0) == 1)
                {
                    switch (theEAss[0].Status)
                    {
                    case "A":
                        messages += "Nothing to do. Workspace already has this match in place.\n";
                        break;

                    case "N":
                        messages += "Nothing to do. Workspace already has this match in place.\n";
                        break;

                    case "X":
                        ENGINEentass.SetEntAssignment
                            (theEAss[0].ID, theEAss[0].EntAssignmentSetID, theEAss[0].BusRoleID,
                            theEAss[0].EntitlementID, "N");
                        break;
                    }
                }
                else
                {
                    int baby = ENGINEentass.NewEntAssignment
                                   (wstouse.idEntAssSet, idBusrole, IDentitlement, "N");
                }
            }



            if (messages.Length == 0)
            {
                messages = "NO MESSAGES TO REPORT.";
            }
            Grid1.CallbackParameter = messages;
        }