Skip to content

Commit

Permalink
interceptors to validate MandatoryLogic, ReadonlyLogic and DisplayLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Oct 23, 2018
1 parent 828a231 commit 97d0b53
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
@@ -1,5 +1,6 @@
package org.adempiere.ad.column.model.interceptor;

import org.adempiere.ad.expression.api.impl.LogicExpressionCompiler;
import org.adempiere.ad.modelvalidator.annotations.Interceptor;
import org.adempiere.ad.modelvalidator.annotations.ModelChange;
import org.compiere.model.AccessSqlParser;
Expand All @@ -21,11 +22,11 @@
*
* 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
* 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, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -39,7 +40,7 @@ public class AD_Column
public void lowerCaseWhereClause(final I_AD_Column column)
{
final String columnSQL = column.getColumnSQL();
if(Check.isEmpty(columnSQL, true))
if (Check.isEmpty(columnSQL, true))
{
// nothing to do
return;
Expand All @@ -50,4 +51,19 @@ public void lowerCaseWhereClause(final I_AD_Column column)

column.setColumnSQL(adaptedWhereClause);
}

@ModelChange(timings = { ModelValidator.TYPE_BEFORE_NEW, ModelValidator.TYPE_BEFORE_CHANGE }, //
ifColumnsChanged = { I_AD_Column.COLUMNNAME_MandatoryLogic, I_AD_Column.COLUMNNAME_ReadOnlyLogic })
public void validateLogicExpressions(final I_AD_Column column)
{
if (!Check.isEmpty(column.getReadOnlyLogic(), true))
{
LogicExpressionCompiler.instance.compile(column.getReadOnlyLogic());
}

if (!Check.isEmpty(column.getMandatoryLogic(), true))
{
LogicExpressionCompiler.instance.compile(column.getMandatoryLogic());
}
}
}
Expand Up @@ -2,6 +2,7 @@

import java.sql.SQLException;

import org.adempiere.ad.expression.api.impl.LogicExpressionCompiler;
import org.adempiere.ad.modelvalidator.annotations.Interceptor;
import org.adempiere.ad.modelvalidator.annotations.ModelChange;
import org.compiere.model.I_AD_Column;
Expand All @@ -11,6 +12,7 @@
import org.springframework.stereotype.Component;

import de.metas.translation.api.IElementTranslationBL;
import de.metas.util.Check;
import de.metas.util.Services;

/*
Expand Down Expand Up @@ -93,4 +95,15 @@ public void updateTranslationsForElement(final I_AD_Field field)
// in the end, make sure the translation fields are also updated
Services.get(IElementTranslationBL.class).updateFieldTranslationsFromAD_Name(fieldElement.getAD_Element_ID());
}

@ModelChange(timings = { ModelValidator.TYPE_BEFORE_NEW, ModelValidator.TYPE_BEFORE_CHANGE }, //
ifColumnsChanged = { I_AD_Field.COLUMNNAME_DisplayLogic })
public void validateLogicExpressions(final I_AD_Field field)
{
if (!Check.isEmpty(field.getDisplayLogic(), true))
{
LogicExpressionCompiler.instance.compile(field.getDisplayLogic());
}
}

}

0 comments on commit 97d0b53

Please sign in to comment.