From 41bd5c2955640ee6bca0c89209d9bd78b745c08c Mon Sep 17 00:00:00 2001 From: yamelsenih Date: Tue, 18 Jun 2024 19:11:43 -0400 Subject: [PATCH] Remove Menu from node --- .../process/ExportDictionaryDefinition.java | 28 ++- .../util/queue/ApplicationDictionary.java | 6 +- .../util/support/DictionaryDocument.java | 10 +- .../eca56/util/support/documents/Menu.java | 219 ------------------ .../util/support/documents/MenuTree.java | 5 + .../eca56/util/support/documents/Role.java | 142 ++++++++++++ 6 files changed, 185 insertions(+), 225 deletions(-) delete mode 100644 src/main/java/org/spin/eca56/util/support/documents/Menu.java create mode 100644 src/main/java/org/spin/eca56/util/support/documents/Role.java diff --git a/src/main/java/org/spin/eca56/process/ExportDictionaryDefinition.java b/src/main/java/org/spin/eca56/process/ExportDictionaryDefinition.java index c18003d..b04dff9 100644 --- a/src/main/java/org/spin/eca56/process/ExportDictionaryDefinition.java +++ b/src/main/java/org/spin/eca56/process/ExportDictionaryDefinition.java @@ -27,6 +27,7 @@ import org.adempiere.core.domains.models.I_AD_Form; import org.adempiere.core.domains.models.I_AD_Menu; import org.adempiere.core.domains.models.I_AD_Process; +import org.adempiere.core.domains.models.I_AD_Role; import org.adempiere.core.domains.models.I_AD_Tree; import org.adempiere.core.domains.models.I_AD_Window; import org.adempiere.model.MBrowse; @@ -34,6 +35,7 @@ import org.compiere.model.MForm; import org.compiere.model.MMenu; import org.compiere.model.MProcess; +import org.compiere.model.MRole; import org.compiere.model.MTree; import org.compiere.model.MTreeNode; import org.compiere.model.MWindow; @@ -85,7 +87,6 @@ protected String doIt() throws Exception { private void exportMenuDefinition() { exportTree(); - exportMenuItemDefinition(); // Old implementation if (this.getMenuId() > 0) { addLog("@AD_Menu_ID@"); @@ -129,6 +130,7 @@ private void exportMenuDefinition() { } private void exportTree() { + exportRoleDefinition(); new Query( getCtx(), I_AD_Tree.Table_Name, @@ -149,6 +151,30 @@ private void exportTree() { counter.incrementAndGet(); }) ; + exportMenuItemDefinition(); + } + + private void exportRoleDefinition() { + addLog("@AD_Role_ID@"); + new Query( + getCtx(), + I_AD_Role.Table_Name, + null, + get_TrxName() + ) + .setOnlyActiveRecords(true) + .getIDsAsList() + .forEach(roleId -> { + MRole role = MRole.get(getCtx(), roleId); + QueueLoader.getInstance() + .getQueueManager(ApplicationDictionary.CODE) + .withEntity(role) + .addToQueue() + ; + addLog(role.getAD_Role_ID() + " - " + role.getName()); + counter.incrementAndGet(); + }) + ; } private void exportMenuItemDefinition() { diff --git a/src/main/java/org/spin/eca56/util/queue/ApplicationDictionary.java b/src/main/java/org/spin/eca56/util/queue/ApplicationDictionary.java index 065e2ad..8071677 100644 --- a/src/main/java/org/spin/eca56/util/queue/ApplicationDictionary.java +++ b/src/main/java/org/spin/eca56/util/queue/ApplicationDictionary.java @@ -37,10 +37,10 @@ import org.spin.eca56.util.support.IGenericSender; import org.spin.eca56.util.support.documents.Browser; import org.spin.eca56.util.support.documents.Form; -import org.spin.eca56.util.support.documents.Menu; import org.spin.eca56.util.support.documents.MenuItem; import org.spin.eca56.util.support.documents.MenuTree; import org.spin.eca56.util.support.documents.Process; +import org.spin.eca56.util.support.documents.Role; import org.spin.eca56.util.support.documents.Window; import org.spin.queue.model.MADQueue; import org.spin.queue.util.QueueManager; @@ -136,6 +136,8 @@ public IGenericDictionaryDocument getDocumentManager(PO entity) { } if(tableName.equals(I_AD_Tree.Table_Name)) { return MenuTree.newInstance().withEntity(entity); + } else if(tableName.equals(I_AD_Role.Table_Name)) { + return Role.newInstance().withClientId(Env.getAD_Client_ID(entity.getCtx())).withEntity(entity); } return null; } @@ -173,7 +175,7 @@ public IGenericDictionaryDocument getDocumentManagerByRole(PO entity, String lan } else if(tableName.equals(I_AD_Window.Table_Name)) { return null;//Window.newInstance().withLanguage(language).withClientId(Env.getAD_Client_ID(entity.getCtx())).withEntity(entity); } else if(tableName.equals(I_AD_Menu.Table_Name)) { - return Menu.newInstance().withLanguage(language).withClientId(Env.getAD_Client_ID(entity.getCtx())).withRoleId(roleId).withEntity(entity); + return null;//Menu.newInstance().withLanguage(language).withClientId(Env.getAD_Client_ID(entity.getCtx())).withRoleId(roleId).withEntity(entity); } return null; } diff --git a/src/main/java/org/spin/eca56/util/support/DictionaryDocument.java b/src/main/java/org/spin/eca56/util/support/DictionaryDocument.java index 943a92f..7e1a90e 100644 --- a/src/main/java/org/spin/eca56/util/support/DictionaryDocument.java +++ b/src/main/java/org/spin/eca56/util/support/DictionaryDocument.java @@ -22,6 +22,7 @@ import org.compiere.model.PO; import org.compiere.util.Env; +import org.compiere.util.Util; /** * Interface for determinate if is a document to send, note that this is a mapping of values. @@ -60,7 +61,9 @@ public Map getValues() { public void putDocument(Map document) { // Generic Detail - document.put("language", getLanguage()); + if(!Util.isEmpty(getLanguage())) { + document.put("language", getLanguage()); + } if(getClientId() >= 0) { document.put("client_id", getClientId()); } @@ -112,8 +115,9 @@ public String getLanguage() { private String getIndexValue() { StringBuffer channel = new StringBuffer(getChannel()); - - channel.append("_").append(getLanguage()); + if(!Util.isEmpty(getLanguage())) { + channel.append("_").append(getLanguage()); + } if(getClientId() >= 0) { channel.append("_").append(getClientId()); } diff --git a/src/main/java/org/spin/eca56/util/support/documents/Menu.java b/src/main/java/org/spin/eca56/util/support/documents/Menu.java deleted file mode 100644 index b0aced0..0000000 --- a/src/main/java/org/spin/eca56/util/support/documents/Menu.java +++ /dev/null @@ -1,219 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 or later of the * - * GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2023 E.R.P. Consultores y Asociados, C.A. * - * All Rights Reserved. * - * Contributor(s): Yamel Senih www.erpya.com * - *****************************************************************************/ -package org.spin.eca56.util.support.documents; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.adempiere.core.domains.models.I_AD_Browse; -import org.adempiere.core.domains.models.I_AD_Form; -import org.adempiere.core.domains.models.I_AD_Menu; -import org.adempiere.core.domains.models.I_AD_Process; -import org.adempiere.core.domains.models.I_AD_Window; -import org.adempiere.core.domains.models.I_AD_Workflow; -import org.adempiere.model.MBrowse; -import org.compiere.model.MClientInfo; -import org.compiere.model.MForm; -import org.compiere.model.MMenu; -import org.compiere.model.MProcess; -import org.compiere.model.MRole; -import org.compiere.model.MTree; -import org.compiere.model.MTreeNode; -import org.compiere.model.MWindow; -import org.compiere.model.PO; -import org.compiere.util.Env; -import org.compiere.util.Util; -import org.compiere.wf.MWorkflow; -import org.spin.eca56.util.support.DictionaryDocument; - -/** - * The document class for Menu sender - * @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com - */ -public class Menu extends DictionaryDocument { - - public static final String CHANNEL = "menu"; - public static final String KEY = "new"; - - @Override - public String getKey() { - return KEY; - } - - /** - * Add children to menu - * @param context - * @param builder - * @param node - */ - private void addChildren(MTreeNode node, Map parent) { - Enumeration childrens = node.children(); - List> children = new ArrayList<>(); - while (childrens.hasMoreElements()) { - MTreeNode childNode = (MTreeNode)childrens.nextElement(); - Map child = convertNode(childNode); - addChildren(childNode, child); - children.add(child); - } - parent.put("children", children); - } - - private Map convertNode(MTreeNode node) { - MMenu menu = MMenu.getFromId(Env.getCtx(), node.getNode_ID()); - Map detail = new HashMap<>(); - detail.put("id", menu.getAD_Menu_ID()); - detail.put("uuid", menu.getUUID()); - detail.put("name", menu.get_Translation(I_AD_Menu.COLUMNNAME_Name, getLanguage())); - detail.put("description", menu.get_Translation(I_AD_Menu.COLUMNNAME_Description, getLanguage())); - detail.put("parent_id", node.getParent_ID()); - detail.put("sequence", Integer.parseInt(node.getSeqNo())); - detail.put("is_read_only", menu.isReadOnly()); - detail.put("is_sales_transaction", menu.isSOTrx()); - detail.put("is_summary", menu.isSummary()); - detail.put("action", menu.getAction()); - // - if(!Util.isEmpty(menu.getAction())) { - if(menu.getAction().equals(MMenu.ACTION_Form)) { - if(menu.getAD_Form_ID() > 0) { - MForm form = new MForm(menu.getCtx(), menu.getAD_Form_ID(), null); - Map referenceDetail = new HashMap<>(); - referenceDetail.put("id", form.getAD_Form_ID()); - referenceDetail.put("uuid", form.getUUID()); - referenceDetail.put("name", form.get_Translation(I_AD_Form.COLUMNNAME_Name, getLanguage())); - referenceDetail.put("description", form.get_Translation(I_AD_Form.COLUMNNAME_Description, getLanguage())); - referenceDetail.put("help", form.get_Translation(I_AD_Form.COLUMNNAME_Help, getLanguage())); - detail.put("form", referenceDetail); - detail.put("action_id", form.getAD_Form_ID()); - detail.put("action_uuid", form.getUUID()); - } - } else if(menu.getAction().equals(MMenu.ACTION_Window)) { - if(menu.getAD_Window_ID() > 0) { - MWindow window = new MWindow(menu.getCtx(), menu.getAD_Window_ID(), null); - Map referenceDetail = new HashMap<>(); - referenceDetail.put("id", window.getAD_Window_ID()); - referenceDetail.put("uuid", window.getUUID()); - referenceDetail.put("name", window.get_Translation(I_AD_Window.COLUMNNAME_Name, getLanguage())); - referenceDetail.put("description", window.get_Translation(I_AD_Window.COLUMNNAME_Description, getLanguage())); - referenceDetail.put("help", window.get_Translation(I_AD_Window.COLUMNNAME_Help, getLanguage())); - detail.put("window", referenceDetail); - detail.put("action_id", window.getAD_Window_ID()); - detail.put("action_uuid", window.getUUID()); - } - } else if(menu.getAction().equals(MMenu.ACTION_Process) - || menu.getAction().equals(MMenu.ACTION_Report)) { - if(menu.getAD_Process_ID() > 0) { - MProcess process = MProcess.get(menu.getCtx(), menu.getAD_Process_ID()); - Map referenceDetail = new HashMap<>(); - referenceDetail.put("id", process.getAD_Process_ID()); - referenceDetail.put("uuid", process.getUUID()); - referenceDetail.put("name", process.get_Translation(I_AD_Process.COLUMNNAME_Name, getLanguage())); - referenceDetail.put("description", process.get_Translation(I_AD_Process.COLUMNNAME_Description, getLanguage())); - referenceDetail.put("help", process.get_Translation(I_AD_Process.COLUMNNAME_Help, getLanguage())); - detail.put("process", referenceDetail); - detail.put("action_id", process.getAD_Process_ID()); - detail.put("action_uuid", process.getUUID()); - } - } else if(menu.getAction().equals(MMenu.ACTION_SmartBrowse)) { - if(menu.getAD_Browse_ID() > 0) { - MBrowse smartBrowser = MBrowse.get(menu.getCtx(), menu.getAD_Browse_ID()); - Map referenceDetail = new HashMap<>(); - referenceDetail.put("id", smartBrowser.getAD_Browse_ID()); - referenceDetail.put("uuid", smartBrowser.getUUID()); - referenceDetail.put("name", smartBrowser.get_Translation(I_AD_Browse.COLUMNNAME_Name, getLanguage())); - referenceDetail.put("description", smartBrowser.get_Translation(I_AD_Browse.COLUMNNAME_Description, getLanguage())); - referenceDetail.put("help", smartBrowser.get_Translation(I_AD_Browse.COLUMNNAME_Help, getLanguage())); - detail.put("browser", referenceDetail); - detail.put("action_id", smartBrowser.getAD_Browse_ID()); - detail.put("action_uuid", smartBrowser.getUUID()); - } - } else if(menu.getAction().equals(MMenu.ACTION_WorkFlow)) { - if(menu.getAD_Workflow_ID() > 0) { - MWorkflow workflow = MWorkflow.get(menu.getCtx(), menu.getAD_Workflow_ID()); - Map referenceDetail = new HashMap<>(); - referenceDetail.put("id", workflow.getAD_Workflow_ID()); - referenceDetail.put("uuid", workflow.getUUID()); - referenceDetail.put("name", workflow.get_Translation(I_AD_Workflow.COLUMNNAME_Name, getLanguage())); - referenceDetail.put("description", workflow.get_Translation(I_AD_Workflow.COLUMNNAME_Description, getLanguage())); - referenceDetail.put("help", workflow.get_Translation(I_AD_Workflow.COLUMNNAME_Help, getLanguage())); - detail.put("workflow", referenceDetail); - detail.put("action_id", workflow.getAD_Workflow_ID()); - detail.put("action_uuid", workflow.getUUID()); - } - } - } - return detail; - } - - @Override - public DictionaryDocument withEntity(PO entity) { - MMenu menu = (MMenu) entity; - MClientInfo clientInfo = MClientInfo.get(menu.getCtx()); - int currentRoleId = Env.getAD_Role_ID(menu.getCtx()); - if(getRoleId() >= 0) { - Env.setContext(Env.getCtx(), "#AD_Role_ID", getRoleId()); - } - MRole role = MRole.getDefault(menu.getCtx(), true); - int treeId = role.getAD_Tree_Menu_ID(); - if(treeId == 0) { - treeId = clientInfo.getAD_Tree_Menu_ID(); - } - MTree tree = new MTree(menu.getCtx(), treeId, false, false, null, null); - Env.setContext(Env.getCtx(), "#AD_Role_ID", currentRoleId); - MTreeNode rootNode = tree.getRoot(); - return withNode(rootNode.findNode(menu.getAD_Menu_ID())); - } - - public Menu withNode(MTreeNode node) { - if(node == null) { - return this; - } - Enumeration childrens = node.children(); - Map documentDetail = convertNode(node); - List> children = new ArrayList<>(); - while (childrens.hasMoreElements()) { - MTreeNode childNode = (MTreeNode)childrens.nextElement(); - Map child = convertNode(childNode); - // Explode child - addChildren(childNode, child); - children.add(child); - } - documentDetail.put("children", children); - putDocument(documentDetail); - return this; - } - - private Menu() { - super(); - } - - /** - * Default instance - * @return - */ - public static Menu newInstance() { - return new Menu(); - } - - @Override - public String getChannel() { - return CHANNEL; - } -} diff --git a/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java b/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java index 62b9856..e2cdc2f 100644 --- a/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java +++ b/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java @@ -105,6 +105,11 @@ private MenuTree() { public static MenuTree newInstance() { return new MenuTree(); } + + @Override + public String getLanguage() { + return null; + } @Override public String getChannel() { diff --git a/src/main/java/org/spin/eca56/util/support/documents/Role.java b/src/main/java/org/spin/eca56/util/support/documents/Role.java new file mode 100644 index 0000000..75cd356 --- /dev/null +++ b/src/main/java/org/spin/eca56/util/support/documents/Role.java @@ -0,0 +1,142 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 or later of the * + * GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * Copyright (C) 2003-2023 E.R.P. Consultores y Asociados, C.A. * + * All Rights Reserved. * + * Contributor(s): Yamel Senih www.erpya.com * + *****************************************************************************/ +package org.spin.eca56.util.support.documents; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.adempiere.core.domains.models.I_AD_Browse; +import org.adempiere.core.domains.models.I_AD_Form; +import org.adempiere.core.domains.models.I_AD_Process; +import org.adempiere.core.domains.models.I_AD_Window; +import org.adempiere.core.domains.models.I_AD_Workflow; +import org.adempiere.core.domains.models.I_PA_DashboardContent; +import org.compiere.model.MClientInfo; +import org.compiere.model.MRole; +import org.compiere.model.PO; +import org.compiere.model.Query; +import org.spin.eca56.util.support.DictionaryDocument; + +/** + * The document class for Role sender + * @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com + */ +public class Role extends DictionaryDocument { + + public static final String CHANNEL = "role"; + public static final String KEY = "new"; + + @Override + public String getKey() { + return KEY; + } + + private Map convertRole(MRole role) { + Map detail = new HashMap<>(); + detail.put("id", role.getAD_Role_ID()); + detail.put("uuid", role.getUUID()); + detail.put("name", role.getName()); + detail.put("description", role.getDescription()); + MClientInfo clientInfo = MClientInfo.get(role.getCtx()); + int treeId = role.getAD_Tree_Menu_ID(); + if(treeId == 0) { + treeId = clientInfo.getAD_Tree_Menu_ID(); + } + detail.put("tree_id", treeId); + detail.put("window_access", getWindowAccess(role)); + detail.put("process_access", getProcessAccess(role)); + detail.put("form_access", getFormAccess(role)); + detail.put("browser_access", getBrowserAccess(role)); + detail.put("workflow_access", getWorkflowAccess(role)); + detail.put("dashboard_access", getDashboardAccess(role)); + return detail; + } + + private List getWindowAccess(MRole role) { + return new Query(role.getCtx(), I_AD_Window.Table_Name, "EXISTS(SELECT 1 FROM AD_Window_Access wa WHERE wa.AD_Window_ID = AD_Window.AD_Window_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + private List getProcessAccess(MRole role) { + return new Query(role.getCtx(), I_AD_Process.Table_Name, "EXISTS(SELECT 1 FROM AD_Process_Access wa WHERE wa.AD_Process_ID = AD_Process.AD_Process_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + private List getFormAccess(MRole role) { + return new Query(role.getCtx(), I_AD_Form.Table_Name, "EXISTS(SELECT 1 FROM AD_Form_Access wa WHERE wa.AD_Form_ID = AD_Form.AD_Form_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + private List getBrowserAccess(MRole role) { + return new Query(role.getCtx(), I_AD_Browse.Table_Name, "EXISTS(SELECT 1 FROM AD_Browse_Access wa WHERE wa.AD_Browse_ID = AD_Browse.AD_Browse_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + private List getWorkflowAccess(MRole role) { + return new Query(role.getCtx(), I_AD_Workflow.Table_Name, "EXISTS(SELECT 1 FROM AD_Workflow_Access wa WHERE wa.AD_Workflow_ID = AD_Workflow.AD_Workflow_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + private List getDashboardAccess(MRole role) { + return new Query(role.getCtx(), I_PA_DashboardContent.Table_Name, "EXISTS(SELECT 1 FROM AD_Dashboard_Access wa WHERE wa.PA_DashboardContent_ID = PA_DashboardContent.PA_DashboardContent_ID AND wa.AD_Role_ID = ?)", null) + .setParameters(role.getAD_Role_ID()) + .setOnlyActiveRecords(true) + .getIDsAsList(); + } + + @Override + public DictionaryDocument withEntity(PO entity) { + MRole role = (MRole) entity; + Map documentDetail = convertRole(role); + putDocument(documentDetail); + return this; + } + + private Role() { + super(); + } + + /** + * Default instance + * @return + */ + public static Role newInstance() { + return new Role(); + } + + @Override + public String getLanguage() { + return null; + } + + @Override + public String getChannel() { + return CHANNEL; + } +}