From 03fb5cbda73eb6f3f0f2f00b7f07fa069492ccdd Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 16 Jan 2015 18:44:33 -0500 Subject: [PATCH] IDEMPIERE-2405 Implement SaaS support for Setup Wizard --- .../oracle/201501161751_IDEMPIERE-2405.sql | 11 +++ .../201501161751_IDEMPIERE-2405.sql | 8 +++ .../webui/apps/form/WSetupWizard.java | 49 ++++++++++--- .../org/compiere/apps/form/SetupWizard.java | 70 +++++++++---------- 4 files changed, 92 insertions(+), 46 deletions(-) create mode 100644 migration/i2.1/oracle/201501161751_IDEMPIERE-2405.sql create mode 100644 migration/i2.1/postgresql/201501161751_IDEMPIERE-2405.sql diff --git a/migration/i2.1/oracle/201501161751_IDEMPIERE-2405.sql b/migration/i2.1/oracle/201501161751_IDEMPIERE-2405.sql new file mode 100644 index 0000000000..7ec30c2324 --- /dev/null +++ b/migration/i2.1/oracle/201501161751_IDEMPIERE-2405.sql @@ -0,0 +1,11 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jan 16, 2015 5:50:47 PM COT +-- IDEMPIERE-2405 Implement SaaS support for Setup Wizard +UPDATE AD_Val_Rule SET Code='AD_Workflow.WorkflowType IN (''G'',''W'')',Updated=TO_DATE('2015-01-16 17:50:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Val_Rule_ID=52006 +; + +SELECT register_migration_script('201501161751_IDEMPIERE-2405.sql') FROM dual +; + diff --git a/migration/i2.1/postgresql/201501161751_IDEMPIERE-2405.sql b/migration/i2.1/postgresql/201501161751_IDEMPIERE-2405.sql new file mode 100644 index 0000000000..979843b2ee --- /dev/null +++ b/migration/i2.1/postgresql/201501161751_IDEMPIERE-2405.sql @@ -0,0 +1,8 @@ +-- Jan 16, 2015 5:50:47 PM COT +-- IDEMPIERE-2405 Implement SaaS support for Setup Wizard +UPDATE AD_Val_Rule SET Code='AD_Workflow.WorkflowType IN (''G'',''W'')',Updated=TO_TIMESTAMP('2015-01-16 17:50:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Val_Rule_ID=52006 +; + +SELECT register_migration_script('201501161751_IDEMPIERE-2405.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSetupWizard.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSetupWizard.java index ac35b5c42e..9ef0ce458d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSetupWizard.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSetupWizard.java @@ -43,6 +43,7 @@ import org.adempiere.webui.util.TreeUtils; import org.compiere.apps.form.SetupWizard; import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; +import org.compiere.model.MRole; import org.compiere.model.X_AD_CtxHelp; import org.compiere.util.DisplayType; import org.compiere.util.Env; @@ -68,6 +69,7 @@ import org.zkoss.zul.Treechildren; import org.zkoss.zul.Treeitem; import org.zkoss.zul.Treerow; import org.zkoss.zul.Vbox; + /** * View for Setup Wizard * @@ -88,6 +90,8 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL private Treeitem firstOpenNode = null; private Treeitem firstOpenWF = null; private Treeitem firstWF = null; + private int cntNodes = 0; + private int cntSolved = 0; private Label pretitleLabel = new Label(Msg.getMsg(Env.getCtx(), "SetupTask")); private Label titleLabel = new Label(); @@ -181,6 +185,8 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL * Load Wizard Nodes */ private void loadWizardNodes() { + cntNodes = 0; + cntSolved = 0; nextItems.removeAll(nextItems); Treechildren treeChildren = wfnodeTree.getTreechildren(); List wfwizards = getWfWizards(); @@ -200,9 +206,19 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL protected void addWfEntry(MWorkflow wfwizard) { allFinished = true; allPending = true; - Treechildren treeChildren = wfnodeTree.getTreechildren(); Treeitem treeitemwf = new Treeitem(); + Treechildren treeChildren = wfnodeTree.getTreechildren(); treeChildren.appendChild(treeitemwf); + addNodes(wfwizard, treeitemwf); + if ( treeitemwf.getTreechildren() == null + || treeitemwf.getTreechildren().getChildren() == null + || treeitemwf.getTreechildren().getChildren().size() == 0) { + // no nodes + treeChildren.removeChild(treeitemwf); + treeitemwf = null; + return; + } + if (firstWF == null) firstWF = treeitemwf; @@ -211,7 +227,6 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL Div div = new Div(); div.setStyle("display:inline;"); div.appendChild(wizardLabel); - Treerow treerow = new Treerow(); treerow.setStyle("vertical-align:top;"); treeitemwf.appendChild(treerow); @@ -222,7 +237,6 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL nextItems.add(treeitemwf); if (openNodes.contains(wfwizard.getAD_Workflow_ID())) treeitemwf.setOpen(true); - addNodes(wfwizard, treeitemwf); if (firstOpenWF == treeitemwf && allPending) { firstOpenNode = firstOpenWF; } @@ -251,6 +265,20 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL } private void addWfNode(MWFNode node, Treeitem treeitemwf) { + if (MWFNode.ACTION_UserWindow.equals(node.getAction()) && node.getAD_Window_ID() > 0) { + if (MRole.getDefault().getWindowAccess(node.getAD_Window_ID()) == null) + return; + } else if (MWFNode.ACTION_UserForm.equals(node.getAction()) && node.getAD_Form_ID() > 0) { + if (MRole.getDefault().getFormAccess(node.getAD_Form_ID()) == null) + return; + } else if ((MWFNode.ACTION_AppsProcess.equals(node.getAction()) || MWFNode.ACTION_AppsReport.equals(node.getAction())) && node.getAD_Process_ID() > 0) { + if (MRole.getDefault().getProcessAccess(node.getAD_Process_ID()) == null) + return; + } else if (MWFNode.ACTION_AppsTask.equals(node.getAction()) && node.getAD_Task_ID() > 0) { + if (MRole.getDefault().getTaskAccess(node.getAD_Task_ID()) == null) + return; + } + /* Color of node according to wizard status */ Label nodeLabel = new Label(node.getName(true)); MWizardProcess wp = MWizardProcess.get(Env.getCtx(), node.getAD_WF_Node_ID(), Env.getAD_Client_ID(Env.getCtx())); @@ -270,9 +298,11 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL nodeLabel.setZclass("tree-setupwizard-nostatus"); } } + cntNodes++; if ( MWizardProcess.WIZARDSTATUS_Finished.equals(status) || MWizardProcess.WIZARDSTATUS_Skipped.equals(status)) { allPending = false; + cntSolved++; } else { allFinished = false; } @@ -465,14 +495,12 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL } // jbInit private void refreshProgress() { - int nodes = getNodesCnt(); - int solved = getWizardCnt(); - int percent = solved * 100; - if (nodes > 0) - percent = percent / nodes; + int percent = cntSolved * 100; + if (cntNodes > 0) + percent = percent / cntNodes; else percent = 0; - Object[] args = new Object[] {solved, nodes, percent}; + Object[] args = new Object[] {cntSolved, cntNodes, percent}; String msg = Msg.getMsg(Env.getCtx(), "SetupWizardProgress", args); progressLabel.setText(msg); progressbar.setValue(percent); @@ -496,7 +524,7 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL if (e.getTarget() == wfnodeTree) { onTreeSelection(e); } else if (e.getTarget() == bRefresh) { - showInRightPanel(0, m_node.getAD_WF_Node_ID()); + repaintTree(); } else if (e.getTarget() == bOK) { int userid = 0; allFinished=true; @@ -672,7 +700,6 @@ public class WSetupWizard extends SetupWizard implements IFormController, EventL private void setNotesPanelVisible(boolean visible) { notesLabel.setVisible(visible); notesField.setVisible(visible); - bRefresh.setVisible(visible); bOK.setVisible(visible); statusLabel.setVisible(visible); statusField.setVisible(visible); diff --git a/org.adempiere.ui/src/org/compiere/apps/form/SetupWizard.java b/org.adempiere.ui/src/org/compiere/apps/form/SetupWizard.java index 96401d2eca..9e5dbd18c0 100644 --- a/org.adempiere.ui/src/org/compiere/apps/form/SetupWizard.java +++ b/org.adempiere.ui/src/org/compiere/apps/form/SetupWizard.java @@ -18,9 +18,9 @@ package org.compiere.apps.form; import java.util.List; import org.adempiere.model.MWizardProcess; +import org.compiere.model.MClient; import org.compiere.model.Query; import org.compiere.util.CLogger; -import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.wf.MWFNode; import org.compiere.wf.MWorkflow; @@ -39,41 +39,41 @@ public class SetupWizard public MWFNode m_node; - /** - * Get the number of workflow wizard nodes - */ - public int getNodesCnt() { - /* TODO: SaaS filter */ - final String sql = "SELECT COUNT(1) " + - "FROM AD_Workflow w " + - "JOIN AD_WF_Node n ON (n.AD_Workflow_ID=w.AD_Workflow_ID) " + - "WHERE w.WorkflowType='W' " + // Wizard - "AND w.IsActive='Y' " + - "AND n.IsActive='Y'"; - return DB.getSQLValue(null, sql); - } - - /** - * Get the number of wizard nodes that has been finished or skipped by user - */ - public int getWizardCnt() { - /* TODO: SaaS filter */ - final String sql = "SELECT COUNT(DISTINCT z.AD_WF_Node_ID) " + - "FROM AD_Workflow w " + - "JOIN AD_WF_Node n ON (n.AD_Workflow_ID=w.AD_Workflow_ID) " + - "JOIN AD_WizardProcess z ON (n.AD_WF_Node_ID=z.AD_WF_Node_ID) " + - "WHERE w.WorkflowType='W' " + // Wizard - "AND w.IsActive='Y' " + - "AND n.IsActive='Y' " + - "AND z.AD_Client_ID=" + Env.getAD_Client_ID(Env.getCtx()) + - " AND z.IsActive='Y' " + - "AND z.WizardStatus IN ('F','S')"; // Finished/Skipped - return DB.getSQLValue(null, sql); - } - public List getWfWizards() { - /* TODO: SaaS filter */ - return new Query(Env.getCtx(), MWorkflow.Table_Name, "WorkflowType=? AND IsActive='Y' AND AD_Client_ID IN (0, ?)", null) + MClient client = MClient.get(Env.getCtx()); + String ASPFilter = ""; + if (client.isUseASP()) + ASPFilter = + " AND ( AD_Workflow.AD_Workflow_ID IN ( " + // Just ASP subscribed workflows for client " + + " SELECT w.AD_Workflow_ID " + + " FROM ASP_Workflow w, ASP_Level l, ASP_ClientLevel cl " + + " WHERE w.ASP_Level_ID = l.ASP_Level_ID " + + " AND cl.AD_Client_ID = " + client.getAD_Client_ID() + + " AND cl.ASP_Level_ID = l.ASP_Level_ID " + + " AND w.IsActive = 'Y' " + + " AND l.IsActive = 'Y' " + + " AND cl.IsActive = 'Y' " + + " AND w.ASP_Status = 'S') " // Show + + " OR AD_Workflow.AD_Workflow_ID IN ( " + // + show ASP exceptions for client + + " SELECT AD_Workflow_ID " + + " FROM ASP_ClientException ce " + + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + + " AND ce.IsActive = 'Y' " + + " AND ce.AD_Workflow_ID IS NOT NULL " + + " AND ce.ASP_Status = 'S') " // Show + + " ) " + + " AND AD_Workflow.AD_Workflow_ID NOT IN ( " + // minus hide ASP exceptions for client + + " SELECT AD_Workflow_ID " + + " FROM ASP_ClientException ce " + + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + + " AND ce.IsActive = 'Y' " + + " AND ce.AD_Workflow_ID IS NOT NULL " + + " AND ce.ASP_Status = 'H')"; // Hide + String where = "WorkflowType=? AND IsActive='Y' AND AD_Client_ID IN (0, ?)" + ASPFilter; + return new Query(Env.getCtx(), MWorkflow.Table_Name, where, null) .setParameters(MWorkflow.WORKFLOWTYPE_Wizard, Env.getAD_Client_ID(Env.getCtx())) .setOnlyActiveRecords(true) .setOrderBy(MWorkflow.COLUMNNAME_Priority)