From 54e2cb4dcc275f0d9424297c414620f6665bdfcc Mon Sep 17 00:00:00 2001 From: Argenis Date: Thu, 19 Jan 2023 11:15:15 -0400 Subject: [PATCH 1/7] Add support for version 10 --- .../template/target-platform-template.xml | 2 +- .../com.ingeint.template.test/META-INF/MANIFEST.MF | 2 +- .../com.ingeint.template/META-INF/MANIFEST.MF | 2 +- .../template/target-platform-template.xml | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/idempiere-plugin-template/com.ingeint.template.targetplatform/template/target-platform-template.xml b/idempiere-plugin-template/com.ingeint.template.targetplatform/template/target-platform-template.xml index dd5c9ab..5e8302f 100755 --- a/idempiere-plugin-template/com.ingeint.template.targetplatform/template/target-platform-template.xml +++ b/idempiere-plugin-template/com.ingeint.template.targetplatform/template/target-platform-template.xml @@ -1,5 +1,5 @@ - + diff --git a/idempiere-plugin-template/com.ingeint.template.test/META-INF/MANIFEST.MF b/idempiere-plugin-template/com.ingeint.template.test/META-INF/MANIFEST.MF index 02390d9..ad4dac2 100755 --- a/idempiere-plugin-template/com.ingeint.template.test/META-INF/MANIFEST.MF +++ b/idempiere-plugin-template/com.ingeint.template.test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: iDempiere Plugin Template Test Bundle-SymbolicName: com.ingeint.template.test -Bundle-Version: 9.0.0.qualifier +Bundle-Version: 10.0.0.qualifier Bundle-Vendor: INGEINT Fragment-Host: com.ingeint.template Bundle-ClassPath: ., diff --git a/idempiere-plugin-template/com.ingeint.template/META-INF/MANIFEST.MF b/idempiere-plugin-template/com.ingeint.template/META-INF/MANIFEST.MF index d327e44..0f31a58 100755 --- a/idempiere-plugin-template/com.ingeint.template/META-INF/MANIFEST.MF +++ b/idempiere-plugin-template/com.ingeint.template/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-Category: idempiere-plugin Bundle-ManifestVersion: 2 Bundle-Name: iDempiere Plugin Template Bundle-SymbolicName: com.ingeint.template -Bundle-Version: 9.0.0.qualifier +Bundle-Version: 10.0.0.qualifier Bundle-Vendor: INGEINT Bundle-ActivationPolicy: lazy Require-Bundle: org.apache.commons.lang3, diff --git a/template/plugin.symbolic.name.targetplatform/template/target-platform-template.xml b/template/plugin.symbolic.name.targetplatform/template/target-platform-template.xml index 43839b1..61bd9c0 100644 --- a/template/plugin.symbolic.name.targetplatform/template/target-platform-template.xml +++ b/template/plugin.symbolic.name.targetplatform/template/target-platform-template.xml @@ -25,6 +25,11 @@ 4.8.138 jar + + + + + From f3b6ea95a3a4847aac679d885d6e5727e83fbc9a Mon Sep 17 00:00:00 2001 From: Argenis Date: Fri, 17 Feb 2023 09:09:22 -0400 Subject: [PATCH 2/7] Add support for fix error in File Template Builder --- .../src/plugin.root/util/FileTemplateBuilderTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template/plugin.symbolic.name.test/src/plugin.root/util/FileTemplateBuilderTest.java b/template/plugin.symbolic.name.test/src/plugin.root/util/FileTemplateBuilderTest.java index 9e575ae..792e0e6 100755 --- a/template/plugin.symbolic.name.test/src/plugin.root/util/FileTemplateBuilderTest.java +++ b/template/plugin.symbolic.name.test/src/plugin.root/util/FileTemplateBuilderTest.java @@ -21,6 +21,7 @@ import static ${plugin.root}.test.util.RandomTestUtil.*; import static org.assertj.core.api.Assertions.assertThat; +import java.text.NumberFormat; import java.util.Arrays; import java.util.List; @@ -51,10 +52,11 @@ public void setup() { @Test public void createFileTemplate() { + String priceStr = NumberFormat.getInstance().format(randomPrice); String result = builder.file("resources/xml/xml-invoice.xml").inject("invoice", invoice).build(); assertThat(result).contains("" + randomName + ""); assertThat(result).contains("" + randomId + ""); - assertThat(result).contains(""); + assertThat(result).contains(""); } public class Invoice { From b66ad461559a6310b9d7cc871656edceaaf58bb8 Mon Sep 17 00:00:00 2001 From: Argenis Date: Wed, 22 Feb 2023 13:20:19 -0400 Subject: [PATCH 3/7] Add support for annotated methods in column callout --- .../plugin.root/annotation/ColumnCallout.java | 14 ++ .../src/plugin.root/base/CustomCallout.java | 167 ++++++++++++++++-- .../src/plugin.root/util/StringUtils.java | 13 ++ 3 files changed, 178 insertions(+), 16 deletions(-) create mode 100644 template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java create mode 100644 template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java diff --git a/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java b/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java new file mode 100644 index 0000000..42a1996 --- /dev/null +++ b/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java @@ -0,0 +1,14 @@ +package ${plugin.root}.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(METHOD) +public @interface ColumnCallout { + public String[] columnNames() default ""; + public int order() default 0; +} diff --git a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java index 1f6521b..4a38279 100644 --- a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java +++ b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java @@ -18,24 +18,32 @@ package ${plugin.root}.base; +import java.lang.reflect.Method; import java.util.Properties; +import java.util.Arrays; +import java.util.Optional; import org.adempiere.base.IColumnCallout; import org.compiere.model.GridField; import org.compiere.model.GridTab; +import org.adempiere.exceptions.AdempiereException; +import org.compiere.util.Util; + +import ${plugin.root}.annotation.ColumnCallout; +import ${plugin.root}.util.StringUtils; /** * Custom IColumnCallout */ -public abstract class CustomCallout implements IColumnCallout { - +public class CustomCallout implements IColumnCallout { + private Properties ctx; private int WindowNo; private GridTab mTab; private GridField mField; private Object value; private Object oldValue; - + /** * Gets the context * @@ -44,7 +52,7 @@ public abstract class CustomCallout implements IColumnCallout { public Properties getCtx() { return ctx; } - + /** * Gets the Window No * @@ -53,7 +61,7 @@ public Properties getCtx() { public int getWindowNo() { return WindowNo; } - + /** * Gets the Tab * @@ -62,7 +70,7 @@ public int getWindowNo() { public GridTab getTab() { return mTab; } - + /** * Gets the field * @@ -71,7 +79,7 @@ public GridTab getTab() { public GridField getField() { return mField; } - + /** * Gets de current value of field * @@ -80,7 +88,7 @@ public GridField getField() { public Object getValue() { return value; } - + /** * Gets the old value of field * @@ -89,7 +97,7 @@ public Object getValue() { public Object getOldValue() { return oldValue; } - + /** * Gets the table name * @@ -98,7 +106,7 @@ public Object getOldValue() { public String getTableName() { return mTab.getTableName(); } - + /** * Gets the column name * @@ -107,7 +115,7 @@ public String getTableName() { public String getColumnName() { return mField.getColumnName(); } - + /** * Set a new value to the current column * @@ -117,7 +125,7 @@ public String getColumnName() { public String setValue(Object newValue) { return mTab.setValue(getColumnName(), newValue); } - + /** * Set a new value to the selected column * @@ -128,7 +136,100 @@ public String setValue(Object newValue) { public String setValue(String columnName, Object newValue) { return mTab.setValue(columnName, newValue); } - + + /** + * + * @return the int value + */ + public int getValueAsInt() { + return Optional.ofNullable((Integer) value) + .orElse(0); + } + + /** + * + * @return the old value as int + */ + public int getOldValueAsInt() { + return Optional.ofNullable((Integer) oldValue) + .orElse(0); + } + + /** + * + * @param columnName Column to get as int + * @return the int value + */ + public int getValueAsInt(String columnName) { + return Optional.ofNullable((Integer) getValue(columnName)) + .orElse(0); + } + + /** + * + * @param columnName Column to get + * @return the value + */ + public Object getValue(String columnName) { + return getTab().getValue(columnName); + } + + /** + * + * @return the value as boolean + */ + public boolean getValueAsBoolean() { + return Optional.ofNullable((Boolean) value) + .orElse(false); + } + + /** + * + * @return the old value as boolean + */ + public boolean getOldValueAsBoolean() { + return Optional.ofNullable((Boolean) oldValue) + .orElse(false); + } + + /** + * + * @param columnName Column to get + * @return the value as boolean + */ + public boolean getValueAsBoolean(String columnName) { + return Optional.ofNullable((Boolean) getValue(columnName)) + .orElse(false); + } + + /** + * + * @param columnName Column to get + * @return the value as string + */ + public String getValueAsString(String columnName) { + return Optional.ofNullable((String) getValue(columnName)) + .orElse(""); + } + + /** + * + * @return the value as string + */ + public String getValueAsString() { + return Optional.ofNullable((String) value) + .orElse(""); + } + + /** + * + * @return the old value as string + */ + public String getOldValueAsString() { + return Optional.ofNullable((String) oldValue) + .orElse(""); + } + @Override public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { this.ctx = ctx; @@ -139,12 +240,46 @@ public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField this.oldValue = oldValue; return start(); } - + /** * Custom event execution * * @return null if no error */ - protected abstract String start(); - + protected String start() { + String columnName = getColumnName(); + + Method[] methods = Arrays.stream(getClass().getDeclaredMethods()) + .filter(method -> method.isAnnotationPresent(ColumnCallout.class) + && StringUtils.isValuePresent(method.getAnnotation(ColumnCallout.class).columnNames(), columnName) + && method.getReturnType().equals(String.class)) + .sorted(CustomCallout::sort) + .toArray(Method[]::new); + + for (Method method: methods) + { + String error = execute(method); + + if (!Util.isEmpty(error, true)) + return error; + } + + return ""; + } + + private static int sort(Method method1, Method method2) { + ColumnCallout columnCallout1 = method1.getAnnotation(ColumnCallout.class); + ColumnCallout columnCallout2 = method2.getAnnotation(ColumnCallout.class); + + return columnCallout1.order() > columnCallout2.order() ? 1 + : (columnCallout1.order() == columnCallout2.order() ? 0 : -1); + } + + private String execute(Method method) { + try { + return (String) method.invoke(this); + } catch (Exception e) { + throw new AdempiereException(e.getLocalizedMessage(), e); + } + } } diff --git a/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java b/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java new file mode 100644 index 0000000..8013682 --- /dev/null +++ b/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java @@ -0,0 +1,13 @@ +package dev.itechsolutions.util; + +import java.util.Arrays; + +public class StringUtils { + + public static boolean isValuePresent(String[] strs, String value) { + return Arrays.stream(strs) + .filter(str -> str != null && str.equals(value)) + .findFirst() + .isPresent(); + } +} From 9eed8634b3d887ddbfe75d572d768be21e656188 Mon Sep 17 00:00:00 2001 From: Argenis Date: Wed, 22 Feb 2023 13:28:27 -0400 Subject: [PATCH 4/7] Added support for making the customcallout class abstract --- .../src/plugin.root/base/CustomCallout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java index 4a38279..c85fbd2 100644 --- a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java +++ b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java @@ -35,7 +35,7 @@ /** * Custom IColumnCallout */ -public class CustomCallout implements IColumnCallout { +public abstract class CustomCallout implements IColumnCallout { private Properties ctx; private int WindowNo; From fd6cc5b29d499317697d1b4b6de1f45f9199bd3f Mon Sep 17 00:00:00 2001 From: Argenis Date: Wed, 22 Feb 2023 14:20:34 -0400 Subject: [PATCH 5/7] Fix get boolean value method --- .../src/plugin.root/base/CustomCallout.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java index c85fbd2..9e00538 100644 --- a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java +++ b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java @@ -179,6 +179,8 @@ public Object getValue(String columnName) { * @return the value as boolean */ public boolean getValueAsBoolean() { + if (value instanceof String) + return "Y".equals(value); return Optional.ofNullable((Boolean) value) .orElse(false); } @@ -188,6 +190,8 @@ public boolean getValueAsBoolean() { * @return the old value as boolean */ public boolean getOldValueAsBoolean() { + if (oldValue instanceof String) + return "Y".equals(oldValue); return Optional.ofNullable((Boolean) oldValue) .orElse(false); } @@ -198,8 +202,7 @@ public boolean getOldValueAsBoolean() { * @return the value as boolean */ public boolean getValueAsBoolean(String columnName) { - return Optional.ofNullable((Boolean) getValue(columnName)) - .orElse(false); + return getTab().getValueAsBoolean(columnName); } /** From 1dfa5d6020a4bce4fc4a7d54a957cd51565e67ac Mon Sep 17 00:00:00 2001 From: Argenis Date: Wed, 22 Feb 2023 14:59:24 -0400 Subject: [PATCH 6/7] Change attribute to singular name --- .../src/plugin.root/annotation/ColumnCallout.java | 2 +- .../src/plugin.root/base/CustomCallout.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java b/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java index 42a1996..3c6dd45 100644 --- a/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java +++ b/template/plugin.symbolic.name/src/plugin.root/annotation/ColumnCallout.java @@ -9,6 +9,6 @@ @Retention(RUNTIME) @Target(METHOD) public @interface ColumnCallout { - public String[] columnNames() default ""; + public String[] columnName() default ""; public int order() default 0; } diff --git a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java index 9e00538..75a83d4 100644 --- a/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java +++ b/template/plugin.symbolic.name/src/plugin.root/base/CustomCallout.java @@ -254,7 +254,7 @@ protected String start() { Method[] methods = Arrays.stream(getClass().getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(ColumnCallout.class) - && StringUtils.isValuePresent(method.getAnnotation(ColumnCallout.class).columnNames(), columnName) + && StringUtils.isValuePresent(method.getAnnotation(ColumnCallout.class).columnName(), columnName) && method.getReturnType().equals(String.class)) .sorted(CustomCallout::sort) .toArray(Method[]::new); From 79201eae5b5c46e2ae764c30fa5ba8d82112980c Mon Sep 17 00:00:00 2001 From: argenis Date: Tue, 21 Mar 2023 12:31:13 -0400 Subject: [PATCH 7/7] Fix package in StringUtils --- .../plugin.symbolic.name/src/plugin.root/util/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java b/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java index 8013682..4fd8198 100644 --- a/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java +++ b/template/plugin.symbolic.name/src/plugin.root/util/StringUtils.java @@ -1,4 +1,4 @@ -package dev.itechsolutions.util; +package ${plugin.root}.util; import java.util.Arrays;