Search in sources :

Example 1 with LogicExpressionResult

use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.

the class JSONDocument method createIncludedTabInfo.

private static JSONIncludedTabInfo createIncludedTabInfo(final DocumentChanges.IncludedDetailInfo includedDetailInfo) {
    final JSONIncludedTabInfo tabInfo = JSONIncludedTabInfo.newInstance(includedDetailInfo.getDetailId());
    if (includedDetailInfo.isStale()) {
        tabInfo.setStale();
    }
    final LogicExpressionResult allowCreateNew = includedDetailInfo.getAllowNew();
    if (allowCreateNew != null) {
        tabInfo.setAllowCreateNew(allowCreateNew.booleanValue(), allowCreateNew.getName());
    }
    final LogicExpressionResult allowDelete = includedDetailInfo.getAllowDelete();
    if (allowDelete != null) {
        tabInfo.setAllowDelete(allowDelete.booleanValue(), allowDelete.getName());
    }
    return tabInfo;
}
Also used : LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult)

Example 2 with LogicExpressionResult

use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.

the class JSONDocument method createIncludedTabInfo.

private static JSONIncludedTabInfo createIncludedTabInfo(final IIncludedDocumentsCollection includedDocumentsCollection) {
    final JSONIncludedTabInfo tabInfo = JSONIncludedTabInfo.newInstance(includedDocumentsCollection.getDetailId());
    if (includedDocumentsCollection.isStale()) {
        tabInfo.setStale();
    }
    final LogicExpressionResult allowCreateNew = includedDocumentsCollection.getAllowCreateNewDocument();
    if (allowCreateNew != null) {
        tabInfo.setAllowCreateNew(allowCreateNew.booleanValue(), allowCreateNew.getName());
    }
    final LogicExpressionResult allowDelete = includedDocumentsCollection.getAllowDeleteDocument();
    if (allowDelete != null) {
        tabInfo.setAllowDelete(allowDelete.booleanValue(), allowDelete.getName());
    }
    return tabInfo;
}
Also used : LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult)

Example 3 with LogicExpressionResult

use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.

the class JSONDocumentField method ofDocumentFieldChangedEvent.

public static JSONDocumentField ofDocumentFieldChangedEvent(final DocumentFieldChange event, final JSONOptions jsonOpts) {
    final JSONLayoutWidgetType widgetType = JSONLayoutWidgetType.fromNullable(event.getWidgetType());
    final JSONDocumentField jsonField = new JSONDocumentField(event.getFieldName(), widgetType);
    if (event.isValueSet()) {
        jsonField.setValue(event.getValueAsJsonObject(), ReasonSupplier.toDebugString(event.getValueReason()));
    }
    final LogicExpressionResult readonly = event.getReadonly();
    if (readonly != null) {
        jsonField.setReadonly(readonly.booleanValue(), ReasonSupplier.toDebugString(event.getReadonlyReason()));
    }
    final LogicExpressionResult mandatory = event.getMandatory();
    if (mandatory != null) {
        jsonField.setMandatory(mandatory.booleanValue(), ReasonSupplier.toDebugString(event.getMandatoryReason()));
    }
    final LogicExpressionResult displayed = event.getDisplayed();
    if (displayed != null) {
        jsonField.setDisplayed(displayed.booleanValue(), ReasonSupplier.toDebugString(event.getDisplayedReason()));
    }
    final Boolean lookupValuesStale = event.getLookupValuesStale();
    if (lookupValuesStale != null) {
        jsonField.setLookupValuesStale(lookupValuesStale, ReasonSupplier.toDebugString(event.getLookupValuesStaleReason()));
    }
    final DocumentValidStatus validStatus = event.getValidStatus();
    if (validStatus != null) {
        jsonField.setValidStatus(validStatus);
    }
    jsonField.setFieldWarning(JSONDocumentFieldWarning.ofNullable(event.getFieldWarning(), jsonOpts.getAD_Language()));
    jsonField.putDebugProperties(event.getDebugProperties());
    return jsonField;
}
Also used : DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult)

Example 4 with LogicExpressionResult

use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.

the class DocumentChanges method collectFrom.

private boolean collectFrom(final IDocumentFieldView documentField, final ReasonSupplier reason) {
    final DocumentFieldChange toEvent = fieldChangesOf(documentField);
    boolean collected = false;
    // Value
    if (!toEvent.isValueSet()) {
        final Object value = documentField.getValue();
        toEvent.setValue(value, reason);
        collected = true;
    } else {
        final Object value = documentField.getValue();
        final Object previousValue = toEvent.getValue();
        if (!DataTypes.equals(value, previousValue)) {
            final ReasonSupplier reasonNew = reason.addPreviousReason(toEvent.getValueReason(), previousValue == null ? "<NULL>" : previousValue);
            toEvent.setValue(value, reasonNew);
            collected = true;
        }
    }
    // 
    // Readonly
    final LogicExpressionResult readonly = documentField.getReadonly();
    if (!readonly.equals(toEvent.getReadonly())) {
        final ReasonSupplier reasonNew = reason.add("readonly", readonly).addPreviousReason(toEvent.getReadonlyReason());
        toEvent.setReadonly(readonly, reasonNew);
        collected = true;
    }
    // 
    // Mandatory
    final LogicExpressionResult mandatory = documentField.getMandatory();
    if (!mandatory.equals(toEvent.getMandatory())) {
        final ReasonSupplier reasonNew = reason.add("mandatory", mandatory).addPreviousReason(toEvent.getMandatoryReason());
        toEvent.setMandatory(mandatory, reasonNew);
        collected = true;
    }
    // 
    // Displayed
    final LogicExpressionResult displayed = documentField.getDisplayed();
    if (!displayed.equals(toEvent.getDisplayed())) {
        final ReasonSupplier reasonNew = reason.add("displayed", displayed).addPreviousReason(toEvent.getDisplayedReason());
        toEvent.setDisplayed(displayed, reasonNew);
        collected = true;
    }
    return collected;
}
Also used : LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) ReasonSupplier(de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier)

Example 5 with LogicExpressionResult

use of org.adempiere.ad.expression.api.LogicExpressionResult in project metasfresh-webui-api by metasfresh.

the class DocumentCollection method assertDeleteDocumentAllowed.

private void assertDeleteDocumentAllowed(final DocumentEntityDescriptor entityDescriptor) {
    final Evaluatee evalCtx = Evaluatees.mapBuilder().put(WindowConstants.FIELDNAME_Processed, false).build().andComposeWith(userSession.toEvaluatee());
    final ILogicExpression allowExpr = entityDescriptor.getAllowDeleteLogic();
    final LogicExpressionResult allow = allowExpr.evaluateToResult(evalCtx, OnVariableNotFound.ReturnNoResult);
    if (allow.isFalse()) {
        throw new AdempiereException("Delete not allowed");
    }
}
Also used : ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) AdempiereException(org.adempiere.exceptions.AdempiereException) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Evaluatee(org.compiere.util.Evaluatee)

Aggregations

LogicExpressionResult (org.adempiere.ad.expression.api.LogicExpressionResult)17 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)6 AdempiereException (org.adempiere.exceptions.AdempiereException)6 DocumentProcessingException (de.metas.document.exceptions.DocumentProcessingException)4 DocumentFieldNotFoundException (de.metas.ui.web.window.exceptions.DocumentFieldNotFoundException)4 DocumentFieldReadonlyException (de.metas.ui.web.window.exceptions.DocumentFieldReadonlyException)4 DocumentNotFoundException (de.metas.ui.web.window.exceptions.DocumentNotFoundException)4 InvalidDocumentStateException (de.metas.ui.web.window.exceptions.InvalidDocumentStateException)4 ReasonSupplier (de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier)2 DocumentValidStatus (de.metas.ui.web.window.model.DocumentValidStatus)1 Evaluatee (org.compiere.util.Evaluatee)1