details: https://code.openbravo.com/erp/devel/pi/rev/ef4fec56e3b9 changeset: 30618:ef4fec56e3b9 user: David Miguelez <david.miguelez <at> openbravo.com> date: Thu Jul 28 10:38:32 2016 +0200 summary: [srv-dl] Display logic evaluated at server level inital commit. Adds the posibility to define a Display Logic that is going to be evaluated at Server Level, when the code for the Window is generated.
details: https://code.openbravo.com/erp/devel/pi/rev/5cb24c06ea48 changeset: 30619:5cb24c06ea48 user: David Miguelez <david.miguelez <at> openbravo.com> date: Mon Oct 17 11:19:00 2016 +0200 summary: [srv-dl] Code Review changes applied. Adds missing javadoc. Do not take into account Preferences that are not of Property type. Do not show column in grid if the expression does not return true. details: https://code.openbravo.com/erp/devel/pi/rev/399148fd3dc1 changeset: 30620:399148fd3dc1 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Oct 18 18:01:21 2016 +0200 summary: [srv-dl] Code Review changes. Improves test class by generalizing code. Changes call to function with boolean with different function in CachedPreference class. Returns string instead of an object in Query in ViewComponent. details: https://code.openbravo.com/erp/devel/pi/rev/2ac67e7ef519 changeset: 30621:2ac67e7ef519 user: David Miguelez <david.miguelez <at> openbravo.com> date: Wed Oct 19 10:03:26 2016 +0200 summary: [srv-dl] Remove unnecessary log added by mistake in previous commit. details: https://code.openbravo.com/erp/devel/pi/rev/ac61e976e438 changeset: 30622:ac61e976e438 user: David Miguelez <david.miguelez <at> openbravo.com> date: Wed Oct 19 10:03:41 2016 +0200 summary: [srv-dl] Synchronize Terminology. details: https://code.openbravo.com/erp/devel/pi/rev/4ebb1c4b124e changeset: 30623:4ebb1c4b124e user: David Miguelez <david.miguelez <at> openbravo.com> date: Mon Oct 31 16:29:55 2016 +0100 summary: [srv-dl] Changes visibility of method to private and modifies tests to call it using reflection details: https://code.openbravo.com/erp/devel/pi/rev/8a1ec28f2472 changeset: 30624:8a1ec28f2472 user: David Miguelez <david.miguelez <at> openbravo.com> date: Mon Oct 31 18:06:05 2016 +0100 summary: [srv-dl] Move Patter to a global variable in DynamicExpressionParser. Modify query in ViewComponent to avoid loop. details: https://code.openbravo.com/erp/devel/pi/rev/b71bb0fa21ab changeset: 30625:b71bb0fa21ab user: David Miguelez <david.miguelez <at> openbravo.com> date: Fri Nov 04 12:06:50 2016 +0100 summary: [srv-dl] Create only one instance of Calendar instead of several ones. details: https://code.openbravo.com/erp/devel/pi/rev/56884e6db3f2 changeset: 30626:56884e6db3f2 user: David Miguelez <david.miguelez <at> openbravo.com> date: Fri Nov 04 12:07:15 2016 +0100 summary: [srv-dl] Remove unnecesary change in Preferences. details: https://code.openbravo.com/erp/devel/pi/rev/d703908717f8 changeset: 30627:d703908717f8 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Nov 08 10:43:07 2016 +0100 summary: [srv-dl] Code Review changes. Adds missing javadoc Change printStackTrace for log Extract duplicated code into a different method, two new methods created for this. details: https://code.openbravo.com/erp/devel/pi/rev/ead25792c152 changeset: 30628:ead25792c152 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Nov 08 10:43:52 2016 +0100 summary: [srv-dl] Code review changes. Constant renamed to be upperCase, also changed to be final. details: https://code.openbravo.com/erp/devel/pi/rev/42497d373c9a changeset: 30629:42497d373c9a user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Nov 08 10:44:41 2016 +0100 summary: [srv-dl] Code Review changes. Changed preferences.size() to preferences.isEmpty() details: https://code.openbravo.com/erp/devel/pi/rev/ecd8bb77e66f changeset: 30630:ecd8bb77e66f user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Nov 08 12:34:25 2016 +0100 summary: [srv-dl] Modified error message in Test. details: https://code.openbravo.com/erp/devel/pi/rev/7acec5407733 changeset: 30631:7acec5407733 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Nov 08 12:34:44 2016 +0100 summary: [srv-dl] Added Tests to Ant Tasks. details: https://code.openbravo.com/erp/devel/pi/rev/65e9c589a623 changeset: 30632:65e9c589a623 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Wed Nov 09 17:16:22 2016 +0100 summary: [srv-dl] code clean up Removed unneded param Throw exception in case of failure, the test will also fail Make fields private diffstat: modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/DisplayLogicAtServerLevelTest.java | 163 ++++++++++ modules/org.openbravo.client.application/src/org/openbravo/client/application/CachedPreference.java | 18 +- modules/org.openbravo.client.application/src/org/openbravo/client/application/DynamicExpressionParser.java | 25 +- modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java | 73 ++++ modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java | 51 ++- src-db/database/model/tables/AD_FIELD.xml | 4 + src-db/database/sourcedata/AD_COLUMN.xml | 40 ++- src-db/database/sourcedata/AD_ELEMENT.xml | 14 + src-db/database/sourcedata/AD_FIELD.xml | 29 + src-test/src/org/openbravo/test/AllAntTaskTests.java | 2 + src/org/openbravo/erpCommon/businessUtility/Preferences.java | 5 +- 11 files changed, 415 insertions(+), 9 deletions(-) diffs (truncated from 605 to 300 lines): diff -r e11aa29da8c9 -r 65e9c589a623 modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/DisplayLogicAtServerLevelTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/DisplayLogicAtServerLevelTest.java Wed Nov 09 17:16:22 2016 +0100 @@ -0,0 +1,163 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2016 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.client.application.test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.Before; +import org.junit.Test; +import org.openbravo.base.weld.test.WeldBaseTest; +import org.openbravo.client.application.CachedPreference; +import org.openbravo.client.application.DynamicExpressionParser; +import org.openbravo.client.application.window.OBViewFieldHandler; +import org.openbravo.client.application.window.OBViewFieldHandler.OBViewField; +import org.openbravo.dal.service.OBDal; +import org.openbravo.model.ad.ui.Tab; + +/** + * + * This class is used to test the correct behavior of the Display Logic Evaluated at Server Level + * functionality + * + */ +public class DisplayLogicAtServerLevelTest extends WeldBaseTest { + private CachedPreference cachedPreference; + private Tab tab; + private OBViewField field; + + /** + * Initializes the global variables for the rest of the tests + */ + @Before + public void initializeTest() { + setSystemAdministratorContext(); + + cachedPreference = org.openbravo.base.weld.WeldUtils + .getInstanceFromStaticBeanManager(CachedPreference.class); + tab = OBDal.getInstance().get(Tab.class, "270"); + + OBViewFieldHandler handler = new OBViewFieldHandler(); + handler.setTab(tab); + field = handler.new OBViewField(); + } + + /** + * Tests that the replacement of the DisplayLogic at Server level works correctly + */ + @Test + public void replaceSystemPreferencesInDisplayLogic() { + cachedPreference.addCachedPreference("enableNegativeStockCorrections"); + cachedPreference.setPreferenceValue("enableNegativeStockCorrections", "Y"); + cachedPreference.addCachedPreference("uomManagement"); + cachedPreference.setPreferenceValue("uomManagement", "Y"); + + String displayLogicEvaluatedInServerExpression = "@uomManagement@ = 'Y' & @enableNegativeStockCorrections@ = 'Y'"; + String expectedTranslatedDisplayLogic = "'Y' = 'Y' & 'Y' = 'Y'"; + + testTranslationOfDisplayLogic(displayLogicEvaluatedInServerExpression, + expectedTranslatedDisplayLogic); + } + + /** + * Tests that the replacement of the DisplayLogic at Server level works correctly containing null + * values + */ + @Test + public void replaceSystemPreferencesInDisplayLogicWithNullValue() { + cachedPreference.addCachedPreference("enableNegativeStockCorrections"); + cachedPreference.setPreferenceValue("enableNegativeStockCorrections", "Y"); + + String displayLogicEvaluatedInServerExpression = "@uomManagement@ = 'Y' & @enableNegativeStockCorrections@ = 'N'"; + String expectedTranslatedDisplayLogic = "'null' = 'Y' & 'Y' = 'N'"; + + testTranslationOfDisplayLogic(displayLogicEvaluatedInServerExpression, + expectedTranslatedDisplayLogic); + } + + /** + * Tests that the evaluation of the DisplayLogic at Server level works correctly + */ + @Test + public void evaluatePreferencesInDisplayLogic() { + cachedPreference.addCachedPreference("enableNegativeStockCorrections"); + cachedPreference.setPreferenceValue("enableNegativeStockCorrections", "Y"); + cachedPreference.addCachedPreference("uomManagement"); + cachedPreference.setPreferenceValue("uomManagement", "Y"); + + String displayLogicEvaluatedInServerExpression = "@uomManagement@ = 'Y' & @enableNegativeStockCorrections@ = 'Y'"; + + boolean expectedEvaluatedDisplayLogic = true; + + testEvaluationOfDisplayLogic(displayLogicEvaluatedInServerExpression, + expectedEvaluatedDisplayLogic); + } + + /** + * Tests that the evaluation of the DisplayLogic at Server level works correctly containing null + * values + */ + @Test + public void evaluatePreferencesInDisplayLogicWithNullValue() { + cachedPreference.addCachedPreference("enableNegativeStockCorrections"); + cachedPreference.setPreferenceValue("enableNegativeStockCorrections", "N"); + + String displayLogicEvaluatedInServerExpression = "@uomManagement@ = 'Y' & @enableNegativeStockCorrections@ = 'Y'"; + + boolean expectedEvaluatedDisplayLogic = false; + + testEvaluationOfDisplayLogic(displayLogicEvaluatedInServerExpression, + expectedEvaluatedDisplayLogic); + } + + private void testTranslationOfDisplayLogic(String displayLogicEvaluatedInServerExpression, + String expectedTranslatedDisplayLogic) { + String translatedDisplayLogic = DynamicExpressionParser + .replaceSystemPreferencesInDisplayLogic(displayLogicEvaluatedInServerExpression); + + assertThat( + "The translation from the Display Logic Evaluated at Server Level expression was different than expected: ", + translatedDisplayLogic, equalTo(expectedTranslatedDisplayLogic)); + } + + private void testEvaluationOfDisplayLogic(String displayLogicEvaluatedInServerExpression, + boolean expectedEvaluatedDisplayLogic) { + Class<?> clazz = field.getClass(); + Method evaluateDisplayLogicAtServerLevel; + try { + evaluateDisplayLogicAtServerLevel = clazz + .getDeclaredMethod("evaluateDisplayLogicAtServerLevel", String.class, String.class); + boolean originallyAccessible = evaluateDisplayLogicAtServerLevel.isAccessible(); + evaluateDisplayLogicAtServerLevel.setAccessible(true); + boolean evaluatedDisplayLogic = (boolean) evaluateDisplayLogicAtServerLevel.invoke(field, + displayLogicEvaluatedInServerExpression, "0"); + evaluateDisplayLogicAtServerLevel.setAccessible(originallyAccessible); + assertThat( + "The result of the evaluation of the Display Logic Evaluated at Server Level expression was different than expected: ", + evaluatedDisplayLogic, equalTo(expectedEvaluatedDisplayLogic)); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } +} diff -r e11aa29da8c9 -r 65e9c589a623 modules/org.openbravo.client.application/src/org/openbravo/client/application/CachedPreference.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/CachedPreference.java Thu Nov 10 09:42:06 2016 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/CachedPreference.java Wed Nov 09 17:16:22 2016 +0100 @@ -59,7 +59,8 @@ private static final Logger log = LoggerFactory.getLogger(CachedPreference.class); private List<String> propertyList = new ArrayList<String>(Arrays.asList( - ALLOW_UNPAGED_DS_MANUAL_REQUEST, ALLOW_UNSECURED_DS_REQUEST, ALLOW_WHERE_PARAMETER, RESTRICT_ERP_ACCESS_IN_STORE_SERVER)); + ALLOW_UNPAGED_DS_MANUAL_REQUEST, ALLOW_UNSECURED_DS_REQUEST, ALLOW_WHERE_PARAMETER, + RESTRICT_ERP_ACCESS_IN_STORE_SERVER)); private Map<String, String> cachedPreference = new HashMap<String, String>(); /** @@ -94,6 +95,21 @@ } /** + * Return the Preference value and store it into the cached variable + * + * @param propertyName + * The name of the property related to the preference + * @param cachePreference + * true if the propertyName must be cached, false if not + * @return The preference value of the propertyName given + */ + public String getPreferenceValueAndStoreInCache(String propertyName) { + String result = getPreferenceValue(propertyName); + addCachedPreference(propertyName); + return result; + } + + /** * Checks if the preference related to the property name entered as parameter is contained in the * list of cached preferences. * diff -r e11aa29da8c9 -r 65e9c589a623 modules/org.openbravo.client.application/src/org/openbravo/client/application/DynamicExpressionParser.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/DynamicExpressionParser.java Thu Nov 10 09:42:06 2016 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/DynamicExpressionParser.java Wed Nov 09 17:16:22 2016 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2011-2014 Openbravo SLU + * All portions are Copyright (C) 2011-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -83,6 +83,8 @@ private ApplicationDictionaryCachedStructures cachedStructures; + public static final String REPLACE_DISPLAY_LOGIC_SERVER_PATTERN = "@(.*?)@"; + public DynamicExpressionParser(String code, Process process, boolean parameterDisplayLogic) { this.code = code; this.process = process; @@ -440,6 +442,27 @@ isBoolean); } + /** + * Given the Display logic expression, it replaces the preferences properties with its values + * + * @param displayLogic + * DisplayLogic to be replaced + * @return Returns the Display logic expression with the properties replaced + */ + public static String replaceSystemPreferencesInDisplayLogic(String displayLogic) { + String result = displayLogic; + CachedPreference cachedPreference = org.openbravo.base.weld.WeldUtils + .getInstanceFromStaticBeanManager(CachedPreference.class); + + Pattern pattern = Pattern.compile(REPLACE_DISPLAY_LOGIC_SERVER_PATTERN); + Matcher matcher = pattern.matcher(displayLogic); + while (matcher.find()) { + result = result.replaceAll("@" + matcher.group(1) + "@", + "'" + cachedPreference.getPreferenceValueAndStoreInCache(matcher.group(1)) + "'"); + } + return result; + } + private Field lookForFieldInAncestorTabs(String fieldName) { Field aField = null; Tab parentTab = KernelUtils.getInstance().getParentTab(tab); diff -r e11aa29da8c9 -r 65e9c589a623 modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java Thu Nov 10 09:42:06 2016 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java Wed Nov 09 17:16:22 2016 +0100 @@ -18,8 +18,13 @@ */ package org.openbravo.client.application; +import java.util.Calendar; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -27,6 +32,7 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.hibernate.Query; +import org.hibernate.Session; import org.hibernate.criterion.Restrictions; import org.openbravo.base.exception.OBException; import org.openbravo.base.util.OBClassLoader; @@ -301,10 +307,77 @@ viewVersions += t.getTable().isFullyAudited() + "|"; } viewVersions += getLastGridConfigurationChange(window) + "|"; + viewVersions += getLastSystemPrefrenceChage(window) + "|"; viewVersionHash = DigestUtils.md5Hex(viewVersions); } finally { OBContext.restorePreviousMode(); } return viewVersionHash; } + + private String getLastSystemPrefrenceChage(Window window) { + Date lastModification = new Date(0); + + Set<String> preferences = new HashSet<String>(); + + Pattern p = Pattern.compile(DynamicExpressionParser.REPLACE_DISPLAY_LOGIC_SERVER_PATTERN); + for (String displayLogic : getFieldsWithDisplayLogicAtServerLevel(window.getId())) { + Matcher m = p.matcher(displayLogic); + while (m.find()) { + preferences.add(m.group(1)); + } + } ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits