From 47987c03141399a8a6f5e858bb4c2f3951a71ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:10:15 +0100 Subject: [PATCH] IDEMPIERE-5538 - Add isValid to Drill Rule allow validate parameters with beforesave (#1632) * IDEMPIERE-5538 - Add isValid to Drill Rule allow validate parameters with beforesave * IDEMPIERE-5538 - beforeSave, capture process parameters * IDEMPIERE-5538 - validate only through process * IDEMPIERE-5538 - isValid check in getByTable method * IDEMPIERE-5538 - add validation to before save/after delete * IDEMPIERE-5538 - validate system drill rules * IDEMPIERE-5538 - fix validation logic The mandatory validation have to skip the key parameter since it is not loaded from Drill Rule Para. * IDEMPIERE-5538 - fix Drill Rule window definition * IDEMPIERE-5538 - bug fix scripts to iD10 * IDEMPIERE-5538 - fix missing read only logic * IDEMPIERE-5538 - all scripts to iD10 --- .../oracle/202301091502_IDEMPIERE-5538.sql | 46 +++++++++++++ .../oracle/202302281202_IDEMPIERE-5538.sql | 14 ++++ .../oracle/202303101612_IDEMPIERE-5538.sql | 26 +++++++ .../202301091502_IDEMPIERE-5538.sql | 43 ++++++++++++ .../202302281202_IDEMPIERE-5538.sql | 11 +++ .../202303101612_IDEMPIERE-5538.sql | 23 +++++++ .../compiere/process/DrillRuleValidate.java | 67 ++++++++++++++++++ .../model/I_AD_Process_DrillRule.java | 15 +++- .../org/compiere/model/MProcessDrillRule.java | 68 +++++++++++++++++-- .../compiere/model/MProcessDrillRulePara.java | 31 +++++++++ .../model/X_AD_Process_DrillRule.java | 31 ++++++++- .../webui/apps/form/WProcessParameter.java | 3 + .../org/compiere/print/DrillReportCtl.java | 11 +-- 13 files changed, 375 insertions(+), 14 deletions(-) create mode 100644 migration/iD10/oracle/202301091502_IDEMPIERE-5538.sql create mode 100644 migration/iD10/oracle/202302281202_IDEMPIERE-5538.sql create mode 100644 migration/iD10/oracle/202303101612_IDEMPIERE-5538.sql create mode 100644 migration/iD10/postgresql/202301091502_IDEMPIERE-5538.sql create mode 100644 migration/iD10/postgresql/202302281202_IDEMPIERE-5538.sql create mode 100644 migration/iD10/postgresql/202303101612_IDEMPIERE-5538.sql create mode 100644 org.adempiere.base.process/src/org/compiere/process/DrillRuleValidate.java diff --git a/migration/iD10/oracle/202301091502_IDEMPIERE-5538.sql b/migration/iD10/oracle/202301091502_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..d55faa22b0 --- /dev/null +++ b/migration/iD10/oracle/202301091502_IDEMPIERE-5538.sql @@ -0,0 +1,46 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202301091502_IDEMPIERE-5538.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jan 9, 2023, 3:02:37 PM CET +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (215738,0,'Valid','Element is valid','The element passed the validation check',200335,'IsValid','N',1,'N','N','Y','N','N',0,'N',20,0,0,'Y',TO_TIMESTAMP('2023-01-09 15:02:36','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 15:02:36','YYYY-MM-DD HH24:MI:SS'),100,2002,'Y','N','D','N','N','N','Y','8b4d9a1c-ef04-4b39-bab3-d35ebbbaa399','Y',0,'N','N','N') +; + +-- Jan 9, 2023, 3:02:49 PM CET +ALTER TABLE AD_Process_DrillRule ADD IsValid CHAR(1) DEFAULT 'N' CHECK (IsValid IN ('Y','N')) NOT NULL +; + +-- Jan 9, 2023, 3:03:06 PM CET +INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,XPosition,ColumnSpan) VALUES (207523,'Valid','Element is valid','The element passed the validation check',200308,215738,'Y',1,120,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-01-09 15:03:06','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 15:03:06','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','aa4a1aca-cf2c-4754-bbd2-c84ab8b6934c','Y',110,2,2) +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET IsDisplayed='Y', SeqNo=100, XPosition=5,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207523 +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET SeqNo=110,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206930 +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET SeqNo=120,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207109 +; + +-- Jan 9, 2023, 3:29:30 PM CET +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2023-01-09 15:29:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207523 +; + +-- Jan 9, 2023, 4:27:35 PM CET +INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,ShowHelp,AD_Process_UU) VALUES (200147,0,0,'Y',TO_TIMESTAMP('2023-01-09 16:27:35','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 16:27:35','YYYY-MM-DD HH24:MI:SS'),100,'Validate','Validate Drill Rule Parameters','Validate the Drill Rule, if all mandatory parameters are set.','N','AD_Process_DrillRule_Validate','N','org.compiere.process.DrillRuleValidate','6','D',0,0,'N','Y','858ac391-3f7e-498d-bbef-caa1ad94e5f6') +; + +-- Jan 9, 2023, 4:29:11 PM CET +INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,AD_ToolBarButton_UU,Action,AD_Tab_ID,AD_Process_ID,SeqNo,EntityType) VALUES (0,0,TO_TIMESTAMP('2023-01-09 16:29:10','YYYY-MM-DD HH24:MI:SS'),100,'Validate','Y',200128,'Validate',TO_TIMESTAMP('2023-01-09 16:29:10','YYYY-MM-DD HH24:MI:SS'),100,'N','b739ac8e-704e-4c34-8eab-87e3eb087dba','W',200308,200147,20,'D') +; + +-- Jan 9, 2023, 4:31:45 PM CET +UPDATE AD_ToolBarButton SET DisplayLogic='@AD_Client_ID@=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-01-09 16:31:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200128 +; + diff --git a/migration/iD10/oracle/202302281202_IDEMPIERE-5538.sql b/migration/iD10/oracle/202302281202_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..b0a814c517 --- /dev/null +++ b/migration/iD10/oracle/202302281202_IDEMPIERE-5538.sql @@ -0,0 +1,14 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202302281202_IDEMPIERE-5538.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Feb 28, 2023, 12:02:28 PM CET +UPDATE AD_Message SET MsgText='Cannot find any valid Drill Rules for the selected Column.', MsgTip='You can define new definitions in Drill Rule window, then run the ''Validate'' process.',Updated=TO_TIMESTAMP('2023-02-28 12:02:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200762 +; + +-- Feb 28, 2023, 12:04:40 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','All Drill Rules in System which have at least one Drill Rule Parameter with a mandatory Process Parameter must have the Show Help field set to value ''Show Help''',0,0,'Y',TO_TIMESTAMP('2023-02-28 12:04:39','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-28 12:04:39','YYYY-MM-DD HH24:MI:SS'),100,200823,'DrillParameterTenantCheck','D','c93f3c2c-4d1f-4a13-a41d-05b31402453d') +; + diff --git a/migration/iD10/oracle/202303101612_IDEMPIERE-5538.sql b/migration/iD10/oracle/202303101612_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..9f20afe00a --- /dev/null +++ b/migration/iD10/oracle/202303101612_IDEMPIERE-5538.sql @@ -0,0 +1,26 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202303101612_IDEMPIERE-5538.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Mar 10, 2023, 4:12:07 PM CET +UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2023-03-10 16:12:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=214733 +; + +-- Mar 10, 2023, 4:13:51 PM CET +UPDATE AD_Field SET IsAdvancedField='Y',Updated=TO_TIMESTAMP('2023-03-10 16:13:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206939 +; + +-- Mar 10, 2023, 4:13:56 PM CET +UPDATE AD_Field SET IsAdvancedField='Y',Updated=TO_TIMESTAMP('2023-03-10 16:13:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206941 +; + +-- Mar 15, 2023, 1:35:41 PM CET +UPDATE AD_ToolBarButton SET DisplayLogic='@AD_Client_ID@=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-03-15 13:35:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200123 +; + +-- Mar 15, 2023, 3:27:28 PM CET +UPDATE AD_Tab SET ReadOnlyLogic='@AD_Client_ID@!@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-03-15 15:27:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=200309 +; + diff --git a/migration/iD10/postgresql/202301091502_IDEMPIERE-5538.sql b/migration/iD10/postgresql/202301091502_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..fe066d3040 --- /dev/null +++ b/migration/iD10/postgresql/202301091502_IDEMPIERE-5538.sql @@ -0,0 +1,43 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202301091502_IDEMPIERE-5538.sql') FROM dual; + +-- Jan 9, 2023, 3:02:37 PM CET +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (215738,0,'Valid','Element is valid','The element passed the validation check',200335,'IsValid','N',1,'N','N','Y','N','N',0,'N',20,0,0,'Y',TO_TIMESTAMP('2023-01-09 15:02:36','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 15:02:36','YYYY-MM-DD HH24:MI:SS'),100,2002,'Y','N','D','N','N','N','Y','8b4d9a1c-ef04-4b39-bab3-d35ebbbaa399','Y',0,'N','N','N') +; + +-- Jan 9, 2023, 3:02:49 PM CET +ALTER TABLE AD_Process_DrillRule ADD COLUMN IsValid CHAR(1) DEFAULT 'N' CHECK (IsValid IN ('Y','N')) NOT NULL +; + +-- Jan 9, 2023, 3:03:06 PM CET +INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,XPosition,ColumnSpan) VALUES (207523,'Valid','Element is valid','The element passed the validation check',200308,215738,'Y',1,120,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-01-09 15:03:06','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 15:03:06','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','aa4a1aca-cf2c-4754-bbd2-c84ab8b6934c','Y',110,2,2) +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET IsDisplayed='Y', SeqNo=100, XPosition=5,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207523 +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET SeqNo=110,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206930 +; + +-- Jan 9, 2023, 3:03:46 PM CET +UPDATE AD_Field SET SeqNo=120,Updated=TO_TIMESTAMP('2023-01-09 15:03:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207109 +; + +-- Jan 9, 2023, 3:29:30 PM CET +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2023-01-09 15:29:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207523 +; + +-- Jan 9, 2023, 4:27:35 PM CET +INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,ShowHelp,AD_Process_UU) VALUES (200147,0,0,'Y',TO_TIMESTAMP('2023-01-09 16:27:35','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-01-09 16:27:35','YYYY-MM-DD HH24:MI:SS'),100,'Validate','Validate Drill Rule Parameters','Validate the Drill Rule, if all mandatory parameters are set.','N','AD_Process_DrillRule_Validate','N','org.compiere.process.DrillRuleValidate','6','D',0,0,'N','Y','858ac391-3f7e-498d-bbef-caa1ad94e5f6') +; + +-- Jan 9, 2023, 4:29:11 PM CET +INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,AD_ToolBarButton_UU,"action",AD_Tab_ID,AD_Process_ID,SeqNo,EntityType) VALUES (0,0,TO_TIMESTAMP('2023-01-09 16:29:10','YYYY-MM-DD HH24:MI:SS'),100,'Validate','Y',200128,'Validate',TO_TIMESTAMP('2023-01-09 16:29:10','YYYY-MM-DD HH24:MI:SS'),100,'N','b739ac8e-704e-4c34-8eab-87e3eb087dba','W',200308,200147,20,'D') +; + +-- Jan 9, 2023, 4:31:45 PM CET +UPDATE AD_ToolBarButton SET DisplayLogic='@AD_Client_ID@=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-01-09 16:31:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200128 +; + diff --git a/migration/iD10/postgresql/202302281202_IDEMPIERE-5538.sql b/migration/iD10/postgresql/202302281202_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..1518f52e83 --- /dev/null +++ b/migration/iD10/postgresql/202302281202_IDEMPIERE-5538.sql @@ -0,0 +1,11 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202302281202_IDEMPIERE-5538.sql') FROM dual; + +-- Feb 28, 2023, 12:02:28 PM CET +UPDATE AD_Message SET MsgText='Cannot find any valid Drill Rules for the selected Column.', MsgTip='You can define new definitions in Drill Rule window, then run the ''Validate'' process.',Updated=TO_TIMESTAMP('2023-02-28 12:02:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200762 +; + +-- Feb 28, 2023, 12:04:40 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','All Drill Rules in System which have at least one Drill Rule Parameter with a mandatory Process Parameter must have the Show Help field set to value ''Show Help''',0,0,'Y',TO_TIMESTAMP('2023-02-28 12:04:39','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-28 12:04:39','YYYY-MM-DD HH24:MI:SS'),100,200823,'DrillParameterTenantCheck','D','c93f3c2c-4d1f-4a13-a41d-05b31402453d') +; + diff --git a/migration/iD10/postgresql/202303101612_IDEMPIERE-5538.sql b/migration/iD10/postgresql/202303101612_IDEMPIERE-5538.sql new file mode 100644 index 0000000000..add95c8353 --- /dev/null +++ b/migration/iD10/postgresql/202303101612_IDEMPIERE-5538.sql @@ -0,0 +1,23 @@ +-- IDEMPIERE-5538 +SELECT register_migration_script('202303101612_IDEMPIERE-5538.sql') FROM dual; + +-- Mar 10, 2023, 4:12:07 PM CET +UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2023-03-10 16:12:07','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=214733 +; + +-- Mar 10, 2023, 4:13:51 PM CET +UPDATE AD_Field SET IsAdvancedField='Y',Updated=TO_TIMESTAMP('2023-03-10 16:13:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206939 +; + +-- Mar 10, 2023, 4:13:56 PM CET +UPDATE AD_Field SET IsAdvancedField='Y',Updated=TO_TIMESTAMP('2023-03-10 16:13:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206941 +; + +-- Mar 15, 2023, 1:35:41 PM CET +UPDATE AD_ToolBarButton SET DisplayLogic='@AD_Client_ID@=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-03-15 13:35:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200123 +; + +-- Mar 15, 2023, 3:27:28 PM CET +UPDATE AD_Tab SET ReadOnlyLogic='@AD_Client_ID@!@#AD_Client_ID@',Updated=TO_TIMESTAMP('2023-03-15 15:27:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=200309 +; + diff --git a/org.adempiere.base.process/src/org/compiere/process/DrillRuleValidate.java b/org.adempiere.base.process/src/org/compiere/process/DrillRuleValidate.java new file mode 100644 index 0000000000..828b1c2795 --- /dev/null +++ b/org.adempiere.base.process/src/org/compiere/process/DrillRuleValidate.java @@ -0,0 +1,67 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* 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., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Peter Takacs, Cloudempiere * +**********************************************************************/ +package org.compiere.process; + +import org.compiere.model.MProcessDrillRule; +import org.compiere.util.Msg; + +/** + * Validate Drill Rule Parameters + * + * @author Peter Takacs, Cloudempiere + */ +@org.adempiere.base.annotation.Process +public class DrillRuleValidate extends SvrProcess +{ + /** Drill Rule */ + private int p_AD_Process_DrillRule_ID = 0; + + /** + * Prepare + */ + protected void prepare () + { + p_AD_Process_DrillRule_ID = getRecord_ID(); + } // prepare + + /** + * Process + * @return info + * @throws Exception + */ + protected String doIt () + throws Exception + { + MProcessDrillRule drillRule = new MProcessDrillRule(getCtx(), p_AD_Process_DrillRule_ID, null); + drillRule.validate(); + drillRule.saveEx(); + if(getAD_Client_ID() == 0 && drillRule.hasMandatoryProcessPara() + && !MProcessDrillRule.SHOWHELP_ShowHelp.equalsIgnoreCase(drillRule.getShowHelp())) { + return "@NotValid@" + ": " + Msg.getMsg(getCtx(), "DrillParameterTenantCheck"); + } + return drillRule.isValid() ? "@OK@" : "@NotValid@"; + } + +} diff --git a/org.adempiere.base/src/org/compiere/model/I_AD_Process_DrillRule.java b/org.adempiere.base/src/org/compiere/model/I_AD_Process_DrillRule.java index c86cc2b5e4..3c68bd5b92 100644 --- a/org.adempiere.base/src/org/compiere/model/I_AD_Process_DrillRule.java +++ b/org.adempiere.base/src/org/compiere/model/I_AD_Process_DrillRule.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for AD_Process_DrillRule * @author iDempiere (generated) - * @version Release 10 + * @version Release 11 */ public interface I_AD_Process_DrillRule { @@ -193,6 +193,19 @@ public interface I_AD_Process_DrillRule */ public boolean isActive(); + /** Column name IsValid */ + public static final String COLUMNNAME_IsValid = "IsValid"; + + /** Set Valid. + * Element is valid + */ + public void setIsValid (boolean IsValid); + + /** Get Valid. + * Element is valid + */ + public boolean isValid(); + /** Column name Name */ public static final String COLUMNNAME_Name = "Name"; diff --git a/org.adempiere.base/src/org/compiere/model/MProcessDrillRule.java b/org.adempiere.base/src/org/compiere/model/MProcessDrillRule.java index d02a0ec8ec..7716d58aa0 100644 --- a/org.adempiere.base/src/org/compiere/model/MProcessDrillRule.java +++ b/org.adempiere.base/src/org/compiere/model/MProcessDrillRule.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Properties; import org.compiere.util.Env; +import org.compiere.util.Util; import org.idempiere.cache.ImmutableIntPOCache; import org.idempiere.cache.ImmutablePOSupport; @@ -135,10 +136,9 @@ public class MProcessDrillRule extends X_AD_Process_DrillRule implements Immutab */ public static MProcessDrillRule[] getByTable(Properties ctx, int AD_Table_ID, String trxName) { - String whereClause = " AD_Table_ID = ? "; + String whereClause = " AD_Table_ID = ? AND IsValid = 'Y' AND " + MProcessDrillRule.Table_Name + "." + MProcessDrillRule.COLUMNNAME_AD_Client_ID + " IN (0,?)"; List processDrillRules = new Query(ctx, MProcessDrillRule.Table_Name, whereClause, trxName) - .setParameters(AD_Table_ID) - .setClient_ID() + .setParameters(AD_Table_ID, Env.getAD_Client_ID(ctx)) .setOnlyActiveRecords(true) .list(); @@ -154,13 +154,12 @@ public class MProcessDrillRule extends X_AD_Process_DrillRule implements Immutab */ public static MProcessDrillRule[] getByColumnName(Properties ctx, String columnName, String trxName) { - String whereClause = ""; + String whereClause = " IsValid = 'Y' AND " + MProcessDrillRule.Table_Name + "." + MProcessDrillRule.COLUMNNAME_AD_Client_ID + " IN (0,?)"; List processDrillRules = new Query(ctx, MProcessDrillRule.Table_Name, whereClause, trxName) .addJoinClause(" INNER JOIN AD_Process_Para pp ON " + MProcessDrillRule.Table_Name + "." + MProcessDrillRule.COLUMNNAME_AD_Process_Para_ID + " = pp." + MProcessPara.COLUMNNAME_AD_Process_Para_ID + " AND " + MProcessPara.COLUMNNAME_ColumnName + " = ?") - .setParameters(columnName) - .setClient_ID() + .setParameters(columnName, Env.getAD_Client_ID(ctx)) .setOnlyActiveRecords(true) .list(); @@ -178,9 +177,10 @@ public class MProcessDrillRule extends X_AD_Process_DrillRule implements Immutab setAD_Table_ID(reportView.getAD_Table_ID()); } } + validate(); return super.beforeSave(newRecord); } - + /** * Get Parameters * @param reload reload @@ -211,4 +211,58 @@ public class MProcessDrillRule extends X_AD_Process_DrillRule implements Immutab makeImmutable(); return this; } + + /** + * Are all mandatory parameters defined among the Drill Rule Parameters + * @return true - all mandatory parameters are set; false - at least one mandatory parameter is not set + */ + private boolean allMandatoryParaSet() { + boolean isValid = false; + MProcess process = new MProcess(Env.getCtx(), getAD_Process_ID(), get_TrxName()); + for(MProcessPara processPara : process.getParameters()) { + if(processPara.isMandatory() && processPara.getAD_Process_Para_ID() != getAD_Process_Para_ID()) { + for(MProcessDrillRulePara drillRulePara : getParameters(true)) { + if(drillRulePara.getAD_Process_Para_ID() == processPara.getAD_Process_Para_ID()) { + String defPara = drillRulePara.getParameterDefault(); + String defParaTo = drillRulePara.getParameterToDefault(); + isValid = (processPara.isRange() && (!Util.isEmpty(defPara)) || (!Util.isEmpty(defParaTo))) || + (!processPara.isRange() && (!Util.isEmpty(defPara))); + break; + } + } + if(!isValid) + return false; + isValid = false; + } + } + return true; + } + + /** + * Has any Drill Rule Parameters with a mandatory Process Parameter + * @return boolean true if has at least one Drill Rule Parameter with a mandatory Process Parameter + */ + public boolean hasMandatoryProcessPara() { + MProcess process = new MProcess(Env.getCtx(), getAD_Process_ID(), null); + for(MProcessPara processPara : process.getParameters()) { + if(processPara.isMandatory()) + return true; + } + return false; + } + + /** + * Validate Drill Rule - set IsValid + */ + public void validate() { + if(getAD_Client_ID() == 0 && hasMandatoryProcessPara() && !SHOWHELP_ShowHelp.equalsIgnoreCase(getShowHelp())) { + setIsValid(false); + } + else if(SHOWHELP_ShowHelp.equalsIgnoreCase(getShowHelp())) { + setIsValid(true); + } + else { + setIsValid(allMandatoryParaSet()); + } + } } \ No newline at end of file diff --git a/org.adempiere.base/src/org/compiere/model/MProcessDrillRulePara.java b/org.adempiere.base/src/org/compiere/model/MProcessDrillRulePara.java index 1fa8a5e66b..73820615fd 100644 --- a/org.adempiere.base/src/org/compiere/model/MProcessDrillRulePara.java +++ b/org.adempiere.base/src/org/compiere/model/MProcessDrillRulePara.java @@ -58,6 +58,8 @@ public class MProcessDrillRulePara extends X_AD_Process_DrillRule_Para implement /** Parameter Column Name */ private MProcessPara m_parameter = null; + /** Parent */ + private MProcessDrillRule m_parent = null; /** @@ -95,4 +97,33 @@ public class MProcessDrillRulePara extends X_AD_Process_DrillRule_Para implement public void setParentID(int id) { setAD_Process_DrillRule_ID(id); } + + /** + * Get Parent + * @return parent + */ + public MProcessDrillRule getParent() + { + if (m_parent == null) + m_parent = new MProcessDrillRule(getCtx(), getAD_Process_DrillRule_ID(), get_TrxName()); + return m_parent; + } // getParent + + @Override + protected boolean afterSave(boolean newRecord, boolean success) { + if(success) { + getParent().validate(); + getParent().saveEx(get_TrxName()); + } + return super.afterSave(newRecord, success); + } + + @Override + protected boolean afterDelete (boolean success) { + if(success) { + getParent().validate(); + getParent().saveEx(get_TrxName()); + } + return super.afterDelete(success); + } } \ No newline at end of file diff --git a/org.adempiere.base/src/org/compiere/model/X_AD_Process_DrillRule.java b/org.adempiere.base/src/org/compiere/model/X_AD_Process_DrillRule.java index 99491e48c1..1aa4e8007c 100644 --- a/org.adempiere.base/src/org/compiere/model/X_AD_Process_DrillRule.java +++ b/org.adempiere.base/src/org/compiere/model/X_AD_Process_DrillRule.java @@ -22,7 +22,7 @@ import java.util.Properties; /** Generated Model for AD_Process_DrillRule * @author iDempiere (generated) - * @version Release 10 - $Id$ */ + * @version Release 11 - $Id$ */ @org.adempiere.base.Model(table="AD_Process_DrillRule") public class X_AD_Process_DrillRule extends PO implements I_AD_Process_DrillRule, I_Persistent { @@ -30,7 +30,7 @@ public class X_AD_Process_DrillRule extends PO implements I_AD_Process_DrillRule /** * */ - private static final long serialVersionUID = 20221224L; + private static final long serialVersionUID = 20230109L; /** Standard Constructor */ public X_AD_Process_DrillRule (Properties ctx, int AD_Process_DrillRule_ID, String trxName) @@ -41,6 +41,8 @@ public class X_AD_Process_DrillRule extends PO implements I_AD_Process_DrillRule setAD_Process_DrillRule_ID (0); setAD_Process_ID (0); setAD_Process_Para_ID (0); + setIsValid (false); +// N setName (null); } */ } @@ -54,6 +56,8 @@ public class X_AD_Process_DrillRule extends PO implements I_AD_Process_DrillRule setAD_Process_DrillRule_ID (0); setAD_Process_ID (0); setAD_Process_Para_ID (0); + setIsValid (false); +// N setName (null); } */ } @@ -277,6 +281,29 @@ public class X_AD_Process_DrillRule extends PO implements I_AD_Process_DrillRule return (String)get_Value(COLUMNNAME_Description); } + /** Set Valid. + @param IsValid Element is valid + */ + public void setIsValid (boolean IsValid) + { + set_Value (COLUMNNAME_IsValid, Boolean.valueOf(IsValid)); + } + + /** Get Valid. + @return Element is valid + */ + public boolean isValid() + { + Object oo = get_Value(COLUMNNAME_IsValid); + if (oo != null) + { + if (oo instanceof Boolean) + return ((Boolean)oo).booleanValue(); + return "Y".equals(oo); + } + return false; + } + /** Set Name. @param Name Alphanumeric identifier of the entity */ diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WProcessParameter.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WProcessParameter.java index eb35319e1c..9240b5aeb2 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WProcessParameter.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WProcessParameter.java @@ -137,6 +137,9 @@ public class WProcessParameter implements IFormController { } } poPara.saveEx(); + if(tableName.equalsIgnoreCase(MProcessDrillRule.Table_Name)) { + ((MProcessDrillRule)po).validate(); + } } } } diff --git a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java index f1eba32c84..be337d7c90 100644 --- a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java @@ -590,7 +590,8 @@ public class DrillReportCtl { + " (=" + value + "=) " + value.getClass().getName()); } // Mandatory check - if(processPara.isMandatory() && Util.isEmpty(sPara.getParameterDefault())) { + if(processPara.isMandatory() && Util.isEmpty(sPara.getParameterDefault()) + && !MProcessDrillRule.SHOWHELP_ShowHelp.equalsIgnoreCase(processDrillRule.getShowHelp())) { if((!processPara.isRange()) || (processPara.isRange() && Util.isEmpty(sPara.getParameterToDefault()))) throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@")); } @@ -607,9 +608,11 @@ public class DrillReportCtl { } // Drill Rule Parameter loop // Mandatory check - for(MProcessPara unsetProcessPara : processParasExclDrillRuleParas) { - if(unsetProcessPara.isMandatory()) { - throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@")); + if(!MProcessDrillRule.SHOWHELP_ShowHelp.equalsIgnoreCase(processDrillRule.getShowHelp())) { + for(MProcessPara unsetProcessPara : processParasExclDrillRuleParas) { + if(unsetProcessPara.isMandatory()) { + throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@")); + } } } pi.setParameter(iParams.toArray(new ProcessInfoParameter[0]));