From 4f7c3dad402d836c29ec7a48027e15c042974681 Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Fri, 12 Jan 2024 16:01:02 +0100 Subject: [PATCH 1/7] modelled expressions endpoint - v1 --- .../datatypes/expression/Expression.xml | 22 + .../datatypes/expression/Expression1Arg.xml | 22 + .../datatypes/expression/Expression2Args.xml | 29 + .../expression/ExpressionVariable.xml | 29 + .../expression/FunctionExpression.xml | 30 + .../expression/LiteralExpression.xml | 27 + .../expression/LocalExpressionVariable.xml | 23 + .../expression/ModelledExpression.xml | 24 + .../datatypes/expression/NotExpression.xml | 23 + .../expression/SingleVarExpression.xml | 23 + .../expression/VariableAccessPart.xml | 28 + .../VariableInstanceFunctionIncovation.xml | 23 + .../GetModelledExpressionsResponse.xml | 23 + modules/xmcp/guihttp/application.xml | 57 +- .../gip/xyna/xact/filter/H5XdevFilter.java | 3 + .../xact/filter/actions/PathElements.java | 1 + ...sPathNameObjectsIdModelledExpressions.java | 67 +++ .../session/ModelledExpressionConverter.java | 515 ++++++++++++++++++ .../xact/filter/session/SessionBasedData.java | 15 +- .../xact/filter/session/XMOMGuiRequest.java | 3 +- 20 files changed, 984 insertions(+), 3 deletions(-) create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression1Arg.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression2Args.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ExpressionVariable.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/FunctionExpression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LiteralExpression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ModelledExpression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/NotExpression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/SingleVarExpression.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableAccessPart.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableInstanceFunctionIncovation.xml create mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/response/GetModelledExpressionsResponse.xml create mode 100644 modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/WorkflowsPathNameObjectsIdModelledExpressions.java create mode 100644 modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression.xml new file mode 100644 index 000000000..c44919bf8 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression.xml @@ -0,0 +1,22 @@ + + + + false + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression1Arg.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression1Arg.xml new file mode 100644 index 000000000..c596e0524 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression1Arg.xml @@ -0,0 +1,22 @@ + + + + false + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression2Args.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression2Args.xml new file mode 100644 index 000000000..4f5e43277 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/Expression2Args.xml @@ -0,0 +1,29 @@ + + + + false + + + + + + String + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ExpressionVariable.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ExpressionVariable.xml new file mode 100644 index 000000000..57ff80566 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ExpressionVariable.xml @@ -0,0 +1,29 @@ + + + + false + + + + int + + + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/FunctionExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/FunctionExpression.xml new file mode 100644 index 000000000..305dfbef4 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/FunctionExpression.xml @@ -0,0 +1,30 @@ + + + + false + + + + + String + + + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LiteralExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LiteralExpression.xml new file mode 100644 index 000000000..1cdec929c --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LiteralExpression.xml @@ -0,0 +1,27 @@ + + + + false + + + + String + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml new file mode 100644 index 000000000..e622947d2 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml @@ -0,0 +1,23 @@ + + + + false + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ModelledExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ModelledExpression.xml new file mode 100644 index 000000000..839ae4028 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/ModelledExpression.xml @@ -0,0 +1,24 @@ + + + + false + + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/NotExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/NotExpression.xml new file mode 100644 index 000000000..88f35937c --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/NotExpression.xml @@ -0,0 +1,23 @@ + + + + false + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/SingleVarExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/SingleVarExpression.xml new file mode 100644 index 000000000..a333cd3c8 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/SingleVarExpression.xml @@ -0,0 +1,23 @@ + + + + false + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableAccessPart.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableAccessPart.xml new file mode 100644 index 000000000..468f10ab1 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableAccessPart.xml @@ -0,0 +1,28 @@ + + + + false + + + + String + + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableInstanceFunctionIncovation.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableInstanceFunctionIncovation.xml new file mode 100644 index 000000000..49fa31171 --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/VariableInstanceFunctionIncovation.xml @@ -0,0 +1,23 @@ + + + + false + + + diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/response/GetModelledExpressionsResponse.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/response/GetModelledExpressionsResponse.xml new file mode 100644 index 000000000..1daae04fb --- /dev/null +++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/response/GetModelledExpressionsResponse.xml @@ -0,0 +1,23 @@ + + + + false + + + diff --git a/modules/xmcp/guihttp/application.xml b/modules/xmcp/guihttp/application.xml index 8426ec8d1..10033a1fc 100644 --- a/modules/xmcp/guihttp/application.xml +++ b/modules/xmcp/guihttp/application.xml @@ -17,7 +17,7 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> - + GuiHTTPFilter GuiHTTPFilter @@ -2541,6 +2541,61 @@ DATATYPE + + + + xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse + DATATYPE + + + xmcp.processmodeller.datatypes.expression.ModelledExpression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.Expression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.VariableAccessPart + DATATYPE + + + xmcp.processmodeller.datatypes.expression.Expression1Arg + DATATYPE + + + xmcp.processmodeller.datatypes.expression.Expression2Args + DATATYPE + + + xmcp.processmodeller.datatypes.expression.ExpressionVariable + DATATYPE + + + xmcp.processmodeller.datatypes.expression.FunctionExpression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.LiteralExpression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.LocalExpressionVariable + DATATYPE + + + xmcp.processmodeller.datatypes.expression.NotExpression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.SingleVarExpression + DATATYPE + + + xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation + DATATYPE + + diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/H5XdevFilter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/H5XdevFilter.java index 9ff3180d7..3653eaf7d 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/H5XdevFilter.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/H5XdevFilter.java @@ -338,6 +338,9 @@ public void onDeployment(EventListener triggerInstance) { allFilterActions.add(new WorkflowsPathNameObjectsIdConstant(xmomGui)); allFilterActions.add(new WorkflowsPathNameObjectsIdConstantDelete(xmomGui)); + + allFilterActions.add(new WorkflowsPathNameObjectsIdModelledExpressions(xmomGui)); + allFilterActions.add(new ClipboardAction(xmomGui)); allFilterActions.add(new ClipboardClearAction(xmomGui)); diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/PathElements.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/PathElements.java index 4b3a17aef..adeb60162 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/PathElements.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/PathElements.java @@ -49,6 +49,7 @@ public class PathElements { public static final String PROJECT_EVENTS_UNSUBSCRIBE = "unsubscribeProjectEvents"; public static final String ENCODE = "encode"; public static final String DECODE = "decode"; + public static final String MODELLED_EXPRESSIONS = "modelledExpressions"; // sub path elements public static final String SAVE = "save"; diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/WorkflowsPathNameObjectsIdModelledExpressions.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/WorkflowsPathNameObjectsIdModelledExpressions.java new file mode 100644 index 000000000..7fbebb618 --- /dev/null +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/actions/WorkflowsPathNameObjectsIdModelledExpressions.java @@ -0,0 +1,67 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2024 Xyna GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ +package com.gip.xyna.xact.filter.actions; + + + +import com.gip.xyna.xact.filter.URLPath; +import com.gip.xyna.xact.filter.XmomGuiAction; +import com.gip.xyna.xact.filter.HTMLBuilder.HTMLPart; +import com.gip.xyna.xact.filter.json.ObjectIdentifierJson.Type; +import com.gip.xyna.xact.filter.session.XMOMGui; +import com.gip.xyna.xact.filter.session.XMOMGuiRequest.Operation; +import com.gip.xyna.xact.trigger.HTTPTriggerConnection.Method; + + + +public class WorkflowsPathNameObjectsIdModelledExpressions extends XmomGuiAction { + + private static final String BASE_PATH = "/" + PathElements.XMOM + "/" + PathElements.WORKFLOWS; + + + public WorkflowsPathNameObjectsIdModelledExpressions(XMOMGui xmomGui) { + super(xmomGui, 2, 3, 5, Operation.ModelledExpressions, Type.workflow, false); + } + + + @Override + protected boolean matchRuntimeContextIndependent( URLPath url, Method method) { + return url.getPath().startsWith(BASE_PATH) + && url.getPathLength() == 7 + && url.getPathElement(4).equals(PathElements.OBJECTS) + && url.getPathElement(6).equals(PathElements.MODELLED_EXPRESSIONS) + && method == Method.GET; + } + + + @Override + public String getTitle() { + return "XMOM-Workflows-TypePath-TypeName-Objects-Id-modelledExpressions"; + } + + + @Override + public void appendIndexPage(HTMLPart body) { + } + + + @Override + public boolean hasIndexPageChanged() { + return false; + } +} diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java new file mode 100644 index 000000000..1696f3d90 --- /dev/null +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java @@ -0,0 +1,515 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2024 Xyna GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ +package com.gip.xyna.xact.filter.session; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; +import java.util.function.Function; + +import org.apache.log4j.Logger; + +import com.gip.xyna.CentralFactoryLogging; +import com.gip.xyna.xact.filter.session.exceptions.UnknownObjectIdException; +import com.gip.xyna.xact.filter.session.gb.ObjectId; +import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; +import com.gip.xyna.xprc.xfractwfe.formula.Expression; +import com.gip.xyna.xprc.xfractwfe.formula.Expression2Args; +import com.gip.xyna.xprc.xfractwfe.formula.FunctionExpression; +import com.gip.xyna.xprc.xfractwfe.formula.LiteralExpression; +import com.gip.xyna.xprc.xfractwfe.formula.Not; +import com.gip.xyna.xprc.xfractwfe.formula.Operator; +import com.gip.xyna.xprc.xfractwfe.formula.SingleVarExpression; +import com.gip.xyna.xprc.xfractwfe.formula.Variable; +import com.gip.xyna.xprc.xfractwfe.formula.VariableAccessPart; +import com.gip.xyna.xprc.xfractwfe.formula.VariableInstanceFunctionIncovation; +import com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression; +import com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression.Visitor; +import com.gip.xyna.xprc.xfractwfe.generation.Step; +import com.gip.xyna.xprc.xfractwfe.generation.StepChoice; +import com.gip.xyna.xprc.xfractwfe.generation.StepFunction; +import com.gip.xyna.xprc.xfractwfe.generation.StepMapping; + +import xmcp.processmodeller.datatypes.expression.ExpressionVariable; +import xmcp.processmodeller.datatypes.expression.NotExpression; +import xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse; + +public class ModelledExpressionConverter { + + private static final Logger logger = CentralFactoryLogging.getLogger(ModelledExpressionConverter.class); + + public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String stepId) { + GetModelledExpressionsResponse result = new GetModelledExpressionsResponse(); + List expressions = new ArrayList<>(); + List backendExpressions = null; + Step step; + try { + step = gbo.getStep(ObjectId.parse(stepId).getBaseId()); + } catch (UnknownObjectIdException e) { + throw new RuntimeException("unkown id"); + } + + if(step instanceof StepMapping) { + backendExpressions = ((StepMapping)step).getParsedExpressions(); + } else if(step instanceof StepChoice) { + backendExpressions = ((StepChoice)step).getParsedFormulas(); + } else if(step instanceof StepFunction) { + //if it is a query, return expressions of mapping + return result; + } + + for(ModelledExpression backendExpression : backendExpressions) { + xmcp.processmodeller.datatypes.expression.ModelledExpression expression = convert(backendExpression); + expressions.add(expression); + } + + result.unversionedSetModelledExpressions(expressions); + return result; + } + + public xmcp.processmodeller.datatypes.expression.ModelledExpression convert(ModelledExpression backendExpression) { + logger.debug("convert: " + backendExpression.getExpression()); + xmcp.processmodeller.datatypes.expression.ModelledExpression result = new xmcp.processmodeller.datatypes.expression.ModelledExpression(); + ConverterVisitor visitor = new ConverterVisitor(); + backendExpression.visitSourceExpression(visitor); + result.unversionedSetSourceExpression(visitor.getAndReset()); + backendExpression.visitTargetExpression(visitor); + result.unversionedSetTargetExpression(visitor.getAndReset()); + return result; + } + + + private static interface ExpressionAssigner { + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp); + } + + private static class RootExpressionAssigner implements ExpressionAssigner { + + private ConverterVisitor visitor; + + public RootExpressionAssigner(ConverterVisitor visitor) { + this.visitor = visitor; + } + + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + visitor.result = exp; + } + + } + + private static class VariableExpressionAssigner implements ExpressionAssigner { + + private ExpressionVariable variable; + + public VariableExpressionAssigner(ExpressionVariable var) { + variable = var; + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + variable.unversionedSetIndexDef(exp); + } + } + + private static class Expression2ArgsExpressionAssigner implements ExpressionAssigner { + + private xmcp.processmodeller.datatypes.expression.Expression2Args toAssign; + private boolean assignedFirstAlready; + + public Expression2ArgsExpressionAssigner(xmcp.processmodeller.datatypes.expression.Expression2Args toAssign) { + this.toAssign = toAssign; + assignedFirstAlready = false; + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + if(!assignedFirstAlready) { + toAssign.unversionedSetVar1(exp); + assignedFirstAlready = true; + } else { + toAssign.unversionedSetVar2(exp); + } + } + + } + + private static class NotExpressionAssigner implements ExpressionAssigner { + + private NotExpression toAssign; + + public NotExpressionAssigner(NotExpression toAssign) { + this.toAssign = toAssign; + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + toAssign.unversionedSetExpression(exp); + } + + } + + private static class VariableInstanceFunctionInvocationExpressionAssigner implements ExpressionAssigner { + + xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation invocation; + boolean assigningParameters; + + + public VariableInstanceFunctionInvocationExpressionAssigner(xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation invocation) { + this.invocation = invocation; + this.assigningParameters = true; + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + if(assigningParameters) { + List oldParts = invocation.getFunctionParameter(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(exp); + invocation.unversionedSetFunctionParameter(parts); + } else { + invocation.setIndexDef(exp); + } + } + + public void endAssigningParameters() { + assigningParameters = false; + } + + } + + private static class VariableAccessPathExpressionAssigner implements ExpressionAssigner { + + private xmcp.processmodeller.datatypes.expression.VariableAccessPart vap; + + + public VariableAccessPathExpressionAssigner(xmcp.processmodeller.datatypes.expression.VariableAccessPart vap) { + this.vap = vap; + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + vap.unversionedSetIndexDef(exp); + } + + } + + private static class FunctionExpressionAssigner implements ExpressionAssigner { + //only assigns index definition. + private xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression; + + + public FunctionExpressionAssigner(xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression) { + this.functionExpression = functionExpression; + + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + functionExpression.setIndexDef(exp); + } + } + + private static class FunctionSubExpressionAssigner implements ExpressionAssigner { + private xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression; + + public FunctionSubExpressionAssigner(xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression) { + this.functionExpression = functionExpression; + + } + + @Override + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { + List oldParts = functionExpression.getSubExpressions(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(exp); + functionExpression.setSubExpressions(parts); + } + + } + + private static class ConverterVisitor implements Visitor { + + private xmcp.processmodeller.datatypes.expression.Expression result; + private Stack context; + private Map objects; + private static Map, Function> assignerCreatorMap = createAssignerCreatorMap(); + + + private static Map, Function> createAssignerCreatorMap() { + Map, Function> map = new HashMap<>(); + map.put(ExpressionVariable.class, (x) -> new VariableExpressionAssigner((ExpressionVariable)x)); + map.put(xmcp.processmodeller.datatypes.expression.Expression2Args.class, (x) -> new Expression2ArgsExpressionAssigner((xmcp.processmodeller.datatypes.expression.Expression2Args)x)); + map.put(NotExpression.class, (x) -> new NotExpressionAssigner((NotExpression)x)); + map.put(xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation.class, (x) -> new VariableInstanceFunctionInvocationExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation)x)); + map.put(xmcp.processmodeller.datatypes.expression.VariableAccessPart.class, (x) -> new VariableAccessPathExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableAccessPart)x)); + map.put(xmcp.processmodeller.datatypes.expression.FunctionExpression.class, (x) -> new FunctionExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression)x)); + return map; + } + + + public ConverterVisitor() { + reset(); + } + + private void reset() { + result = null; + context = new Stack(); + objects = new HashMap(); + context.push(new RootExpressionAssigner(this)); + } + + public xmcp.processmodeller.datatypes.expression.Expression getAndReset() { + xmcp.processmodeller.datatypes.expression.Expression localResult = result; + reset(); + return localResult; + } + + @Override + public void expression2ArgsStarts(Expression2Args expression) { + logger.debug("expression2ArgsStarts"); + xmcp.processmodeller.datatypes.expression.Expression2Args exp = new xmcp.processmodeller.datatypes.expression.Expression2Args(); + assignExpression(exp); + ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + context.push(assigner); + objects.put(assigner, exp); + } + + @Override + public void functionEnds(FunctionExpression fe) { + logger.debug("functionEnds"); + } + + @Override + public void functionSubExpressionEnds(FunctionExpression fe, int parameterCnt) { + logger.debug("functionSubExpressionEnds"); + context.pop(); + } + + @Override + public void functionSubExpressionStarts(FunctionExpression fe, int parameterCnt) { + logger.debug("functionSubExpressionStarts"); + Object obj = context.peek(); + GeneralXynaObject xo = objects.get(obj); + FunctionSubExpressionAssigner cur = new FunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo); + context.push(cur); + } + + @Override + public void functionStarts(FunctionExpression fe) { + logger.debug("functionStarts"); + + xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(); + exp.unversionedSetFunction(fe.getFunction().getName()); + assignExpression(exp); + ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + context.push(assigner); + objects.put(assigner, exp); + } + + @Override + public void instanceFunctionStarts(VariableInstanceFunctionIncovation vifi) { + logger.debug("instanceFunctionStarts"); + } + + @Override + public void instanceFunctionEnds(VariableInstanceFunctionIncovation vifi) { + logger.debug("instanceFunctionEnds"); + Object obj = context.peek(); + if(obj instanceof VariableInstanceFunctionInvocationExpressionAssigner) { + ((VariableInstanceFunctionInvocationExpressionAssigner)obj).endAssigningParameters(); + } else { + logger.error("Cound not stop assigning parameters. " + obj); + } + } + + @Override + public void instanceFunctionSubExpressionEnds(Expression fe, int parameterCnt) { + logger.debug("instanceFunctionSubExpressionEnds"); + } + + @Override + public void instanceFunctionSubExpressionStarts(Expression fe, int parameterCnt) { + logger.debug("instanceFunctionSubExpressionStarts"); + } + + @Override + public void allPartsOfVariableFinished(Variable variable) { + logger.debug("allPartsOfVariableFinished"); + context.pop(); + } + + @Override + public void expression2ArgsEnds(Expression2Args expression) { + logger.debug("expression2ArgsEnds"); + context.pop(); + } + + @Override + public void literalExpression(LiteralExpression expression) { + logger.debug("literalExpression - " + expression.getValue()); + xmcp.processmodeller.datatypes.expression.LiteralExpression exp = new xmcp.processmodeller.datatypes.expression.LiteralExpression(); + exp.unversionedSetValue(expression.getValue()); + assignExpression(exp); + } + + + + + @Override + public void notStarts(Not not) { + logger.debug("notStarts"); + xmcp.processmodeller.datatypes.expression.NotExpression exp = new xmcp.processmodeller.datatypes.expression.NotExpression(); + assignExpression(exp); + ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + context.push(assigner); + objects.put(assigner, exp); + } + + @Override + public void notEnds(Not not) { + logger.debug("notEnds"); + context.pop(); + } + + @Override + public void operator(Operator operator) { + logger.debug("operator"); + //we are visiting an expression2Args + Object obj = context.peek(); + GeneralXynaObject xo = objects.get(obj); + ((xmcp.processmodeller.datatypes.expression.Expression2Args)xo).unversionedSetOperator(operator.getOperatorAsString()); + + } + + @Override + public void variableStarts(Variable variable) { + logger.debug("variableStarts"); + Object obj = context.peek(); + GeneralXynaObject xo = objects.get(obj); + context.push(variable); + ExpressionVariable cur = new ExpressionVariable(); + cur.unversionedSetVarNum(variable.getVarNum()); + objects.put(variable, cur); + + if(xo instanceof xmcp.processmodeller.datatypes.expression.SingleVarExpression) { + ((xmcp.processmodeller.datatypes.expression.SingleVarExpression)xo).setVariable(cur); + } else { + throw new RuntimeException("Unexpected variableStarts Context: " + obj + "/"+ xo + " - expected: SingleVarExpression"); + } + } + + @Override + public void variableEnds(Variable variable) { + logger.debug("variableEnds"); + } + + @Override + public void variablePartStarts(VariableAccessPart part) { + logger.debug("variablePartStarts"); + Object currentContext = context.peek(); + GeneralXynaObject xo = objects.get(currentContext); + + xmcp.processmodeller.datatypes.expression.VariableAccessPart cur = null; + Object toPush = null; + if(part instanceof VariableInstanceFunctionIncovation) { + cur = new xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation(); + toPush = assignerCreatorMap.get(cur.getClass()).apply(cur); + } else { + cur = new xmcp.processmodeller.datatypes.expression.VariableAccessPart(); + toPush = part; + } + context.push(toPush); + objects.put(toPush, cur); + cur.unversionedSetName(part.getName()); + if(xo instanceof ExpressionVariable) { + List oldParts = ((ExpressionVariable)xo).getParts(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(cur); + ((ExpressionVariable)xo).unversionedSetParts(parts); + } else if(xo instanceof xmcp.processmodeller.datatypes.expression.FunctionExpression) { + List oldParts = ((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo).getParts(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(cur); + ((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo).unversionedSetParts(parts); + } else { + throw new RuntimeException("Unexpected vairablePart Context: " + currentContext + "/"+ xo + " - expected: ExpressionVariable"); + } + + } + + @Override + public void variablePartEnds(VariableAccessPart part) { + logger.debug("variablePartEnds"); + context.pop(); + } + + @Override + public void variablePartSubContextEnds(VariableAccessPart p) { + logger.debug("variablePartSubContextEnds"); + } + + @Override + public void allPartsOfFunctionFinished(FunctionExpression fe) { + logger.debug("allPartsOfFunctionFinished"); + } + + @Override + public void indexDefStarts() { + logger.debug("indexDefStarts"); + Object obj = context.peek(); + GeneralXynaObject xo = objects.get(obj); + ExpressionAssigner assigner = assignerCreatorMap.get(xo.getClass()).apply(xo); + context.push(assigner); + } + + @Override + public void indexDefEnds() { + logger.debug("indexDefEnds"); + context.pop(); + } + + + @Override + public void singleVarExpressionStarts(SingleVarExpression expression) { + logger.debug("singleVarExpressionStarts"); + xmcp.processmodeller.datatypes.expression.SingleVarExpression exp = new xmcp.processmodeller.datatypes.expression.SingleVarExpression(); + assignExpression(exp); + context.push(expression); + objects.put(expression, exp); + } + + @Override + public void singleVarExpressionEnds(SingleVarExpression expression) { + logger.debug("singleVarExpressionEnds"); + context.pop(); + } + + private void assignExpression(xmcp.processmodeller.datatypes.expression.Expression exp) { + Object obj = context.peek(); + if(obj instanceof ExpressionAssigner) { + ((ExpressionAssigner)obj).assign(exp); + } else { + logger.error("Could not assign expression. " + obj + " is not an ExpressionAssigner"); + } + } + } +} diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/SessionBasedData.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/SessionBasedData.java index 7fb803460..916325b38 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/SessionBasedData.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/SessionBasedData.java @@ -1,6 +1,6 @@ /* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Copyright 2022 Xyna GmbH, Germany + * Copyright 2024 Xyna GmbH, Germany * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -179,6 +179,7 @@ import xmcp.processmodeller.datatypes.response.GetClipboardResponse; import xmcp.processmodeller.datatypes.response.GetDataflowResponse; import xmcp.processmodeller.datatypes.response.GetIssuesResponse; +import xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse; import xmcp.processmodeller.datatypes.response.GetObjectXMLResponse; import xmcp.processmodeller.datatypes.response.GetOrderInputSourcesResponse; import xmcp.processmodeller.datatypes.response.GetRelationsResponse; @@ -390,6 +391,8 @@ private XMOMGuiReply createXMOMGuiReply(XMOMGuiRequest request) { return copyXml(request); case Warnings: return getWarnings(request); + case ModelledExpressions: + return getModelledExpressions(request); default: if( request.getOperation().isModification() ) { return objectModification(request); @@ -413,6 +416,16 @@ private XMOMGuiReply createXMOMGuiReply(XMOMGuiRequest request) { } + private XMOMGuiReply getModelledExpressions(XMOMGuiRequest request) { + FQName fqn = request.getFQName(); + GenerationBaseObject gbo = gbos.get(fqn); + XMOMGuiReply reply = new XMOMGuiReply(); + ModelledExpressionConverter converter = new ModelledExpressionConverter(); + GetModelledExpressionsResponse response = converter.convert(gbo, request.getObjectId()); + reply.setXynaObject(response); + return reply; + } + private XMOMGuiReply getWarnings(XMOMGuiRequest request) { FQName fqn = request.getFQName(); WorkflowWarningsHandler handler = getOrCreateWFWarningsHandler(fqn); diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/XMOMGuiRequest.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/XMOMGuiRequest.java index cfc7c7e35..617cc16f8 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/XMOMGuiRequest.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/XMOMGuiRequest.java @@ -72,7 +72,8 @@ public static enum Operation { SubscribeProjectPollEvents, UnsubscribeProjectPollEvents, CopyXml, - Warnings + Warnings, + ModelledExpressions ; private boolean isModification; From 61b2f3812b7e40720fcd83fe635f34d8231fbcab Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Mon, 15 Jan 2024 09:44:59 +0100 Subject: [PATCH 2/7] combine converters --- .../session/ModelledExpressionConverter.java | 200 ++---------------- .../expressions/ExpressionAssigners.java | 191 +++++++++++++++++ 2 files changed, 208 insertions(+), 183 deletions(-) create mode 100644 modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java index 1696f3d90..6ea5f3d06 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java @@ -22,12 +22,15 @@ import java.util.List; import java.util.Map; import java.util.Stack; -import java.util.function.Function; - import org.apache.log4j.Logger; import com.gip.xyna.CentralFactoryLogging; import com.gip.xyna.xact.filter.session.exceptions.UnknownObjectIdException; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.FunctionSubExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.VariableInstanceFunctionInvocationExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ConsumerExpressionAssigner; import com.gip.xyna.xact.filter.session.gb.ObjectId; import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; import com.gip.xyna.xprc.xfractwfe.formula.Expression; @@ -48,7 +51,6 @@ import com.gip.xyna.xprc.xfractwfe.generation.StepMapping; import xmcp.processmodeller.datatypes.expression.ExpressionVariable; -import xmcp.processmodeller.datatypes.expression.NotExpression; import xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse; public class ModelledExpressionConverter { @@ -96,174 +98,15 @@ public xmcp.processmodeller.datatypes.expression.ModelledExpression convert(Mode } - private static interface ExpressionAssigner { - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp); - } - - private static class RootExpressionAssigner implements ExpressionAssigner { - - private ConverterVisitor visitor; - - public RootExpressionAssigner(ConverterVisitor visitor) { - this.visitor = visitor; - } - - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - visitor.result = exp; - } - - } - - private static class VariableExpressionAssigner implements ExpressionAssigner { - - private ExpressionVariable variable; - - public VariableExpressionAssigner(ExpressionVariable var) { - variable = var; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - variable.unversionedSetIndexDef(exp); - } - } - - private static class Expression2ArgsExpressionAssigner implements ExpressionAssigner { - - private xmcp.processmodeller.datatypes.expression.Expression2Args toAssign; - private boolean assignedFirstAlready; - - public Expression2ArgsExpressionAssigner(xmcp.processmodeller.datatypes.expression.Expression2Args toAssign) { - this.toAssign = toAssign; - assignedFirstAlready = false; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - if(!assignedFirstAlready) { - toAssign.unversionedSetVar1(exp); - assignedFirstAlready = true; - } else { - toAssign.unversionedSetVar2(exp); - } - } - - } - - private static class NotExpressionAssigner implements ExpressionAssigner { - - private NotExpression toAssign; - - public NotExpressionAssigner(NotExpression toAssign) { - this.toAssign = toAssign; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - toAssign.unversionedSetExpression(exp); - } - - } - - private static class VariableInstanceFunctionInvocationExpressionAssigner implements ExpressionAssigner { - - xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation invocation; - boolean assigningParameters; - - - public VariableInstanceFunctionInvocationExpressionAssigner(xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation invocation) { - this.invocation = invocation; - this.assigningParameters = true; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - if(assigningParameters) { - List oldParts = invocation.getFunctionParameter(); - List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); - parts.add(exp); - invocation.unversionedSetFunctionParameter(parts); - } else { - invocation.setIndexDef(exp); - } - } - - public void endAssigningParameters() { - assigningParameters = false; - } - - } - - private static class VariableAccessPathExpressionAssigner implements ExpressionAssigner { - - private xmcp.processmodeller.datatypes.expression.VariableAccessPart vap; - - - public VariableAccessPathExpressionAssigner(xmcp.processmodeller.datatypes.expression.VariableAccessPart vap) { - this.vap = vap; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - vap.unversionedSetIndexDef(exp); - } - - } - - private static class FunctionExpressionAssigner implements ExpressionAssigner { - //only assigns index definition. - private xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression; - - - public FunctionExpressionAssigner(xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression) { - this.functionExpression = functionExpression; - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - functionExpression.setIndexDef(exp); - } - } - private static class FunctionSubExpressionAssigner implements ExpressionAssigner { - private xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression; - - public FunctionSubExpressionAssigner(xmcp.processmodeller.datatypes.expression.FunctionExpression functionExpression) { - this.functionExpression = functionExpression; - - } - - @Override - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp) { - List oldParts = functionExpression.getSubExpressions(); - List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); - parts.add(exp); - functionExpression.setSubExpressions(parts); - } - - } + private static class ConverterVisitor implements Visitor { private xmcp.processmodeller.datatypes.expression.Expression result; private Stack context; private Map objects; - private static Map, Function> assignerCreatorMap = createAssignerCreatorMap(); - - - private static Map, Function> createAssignerCreatorMap() { - Map, Function> map = new HashMap<>(); - map.put(ExpressionVariable.class, (x) -> new VariableExpressionAssigner((ExpressionVariable)x)); - map.put(xmcp.processmodeller.datatypes.expression.Expression2Args.class, (x) -> new Expression2ArgsExpressionAssigner((xmcp.processmodeller.datatypes.expression.Expression2Args)x)); - map.put(NotExpression.class, (x) -> new NotExpressionAssigner((NotExpression)x)); - map.put(xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation.class, (x) -> new VariableInstanceFunctionInvocationExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation)x)); - map.put(xmcp.processmodeller.datatypes.expression.VariableAccessPart.class, (x) -> new VariableAccessPathExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableAccessPart)x)); - map.put(xmcp.processmodeller.datatypes.expression.FunctionExpression.class, (x) -> new FunctionExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression)x)); - return map; - } public ConverterVisitor() { @@ -274,7 +117,7 @@ private void reset() { result = null; context = new Stack(); objects = new HashMap(); - context.push(new RootExpressionAssigner(this)); + context.push(new ConsumerExpressionAssigner(x -> this.result = x)); } public xmcp.processmodeller.datatypes.expression.Expression getAndReset() { @@ -288,7 +131,7 @@ public void expression2ArgsStarts(Expression2Args expression) { logger.debug("expression2ArgsStarts"); xmcp.processmodeller.datatypes.expression.Expression2Args exp = new xmcp.processmodeller.datatypes.expression.Expression2Args(); assignExpression(exp); - ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); context.push(assigner); objects.put(assigner, exp); } @@ -320,7 +163,7 @@ public void functionStarts(FunctionExpression fe) { xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(); exp.unversionedSetFunction(fe.getFunction().getName()); assignExpression(exp); - ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); context.push(assigner); objects.put(assigner, exp); } @@ -336,8 +179,6 @@ public void instanceFunctionEnds(VariableInstanceFunctionIncovation vifi) { Object obj = context.peek(); if(obj instanceof VariableInstanceFunctionInvocationExpressionAssigner) { ((VariableInstanceFunctionInvocationExpressionAssigner)obj).endAssigningParameters(); - } else { - logger.error("Cound not stop assigning parameters. " + obj); } } @@ -379,7 +220,7 @@ public void notStarts(Not not) { logger.debug("notStarts"); xmcp.processmodeller.datatypes.expression.NotExpression exp = new xmcp.processmodeller.datatypes.expression.NotExpression(); assignExpression(exp); - ExpressionAssigner assigner = assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); context.push(assigner); objects.put(assigner, exp); } @@ -393,11 +234,11 @@ public void notEnds(Not not) { @Override public void operator(Operator operator) { logger.debug("operator"); - //we are visiting an expression2Args Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - ((xmcp.processmodeller.datatypes.expression.Expression2Args)xo).unversionedSetOperator(operator.getOperatorAsString()); - + if (xo instanceof xmcp.processmodeller.datatypes.expression.Expression2Args) { + ((xmcp.processmodeller.datatypes.expression.Expression2Args) xo).unversionedSetOperator(operator.getOperatorAsString()); + } } @Override @@ -412,8 +253,6 @@ public void variableStarts(Variable variable) { if(xo instanceof xmcp.processmodeller.datatypes.expression.SingleVarExpression) { ((xmcp.processmodeller.datatypes.expression.SingleVarExpression)xo).setVariable(cur); - } else { - throw new RuntimeException("Unexpected variableStarts Context: " + obj + "/"+ xo + " - expected: SingleVarExpression"); } } @@ -432,13 +271,11 @@ public void variablePartStarts(VariableAccessPart part) { Object toPush = null; if(part instanceof VariableInstanceFunctionIncovation) { cur = new xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation(); - toPush = assignerCreatorMap.get(cur.getClass()).apply(cur); + toPush = ExpressionAssigners.assignerCreatorMap.get(cur.getClass()).apply(cur); } else { cur = new xmcp.processmodeller.datatypes.expression.VariableAccessPart(); toPush = part; } - context.push(toPush); - objects.put(toPush, cur); cur.unversionedSetName(part.getName()); if(xo instanceof ExpressionVariable) { List oldParts = ((ExpressionVariable)xo).getParts(); @@ -450,10 +287,9 @@ public void variablePartStarts(VariableAccessPart part) { List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); parts.add(cur); ((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo).unversionedSetParts(parts); - } else { - throw new RuntimeException("Unexpected vairablePart Context: " + currentContext + "/"+ xo + " - expected: ExpressionVariable"); } - + context.push(toPush); + objects.put(toPush, cur); } @Override @@ -477,7 +313,7 @@ public void indexDefStarts() { logger.debug("indexDefStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - ExpressionAssigner assigner = assignerCreatorMap.get(xo.getClass()).apply(xo); + ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(xo.getClass()).apply(xo); context.push(assigner); } @@ -507,8 +343,6 @@ private void assignExpression(xmcp.processmodeller.datatypes.expression.Expressi Object obj = context.peek(); if(obj instanceof ExpressionAssigner) { ((ExpressionAssigner)obj).assign(exp); - } else { - logger.error("Could not assign expression. " + obj + " is not an ExpressionAssigner"); } } } diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java new file mode 100644 index 000000000..7272cc7af --- /dev/null +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java @@ -0,0 +1,191 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2024 Xyna GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ +package com.gip.xyna.xact.filter.session.expressions; + + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; + +import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; + +import xmcp.processmodeller.datatypes.expression.Expression; +import xmcp.processmodeller.datatypes.expression.Expression2Args; +import xmcp.processmodeller.datatypes.expression.ExpressionVariable; +import xmcp.processmodeller.datatypes.expression.FunctionExpression; +import xmcp.processmodeller.datatypes.expression.NotExpression; +import xmcp.processmodeller.datatypes.expression.VariableAccessPart; +import xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation; + + + +public class ExpressionAssigners { + + public interface ExpressionAssigner { + + public void assign(xmcp.processmodeller.datatypes.expression.Expression exp); + } + + + public final static Map, Function> assignerCreatorMap = + createAssignerCreatorMap(); + + + private static Map, Function> createAssignerCreatorMap() { + Map, Function> map = new HashMap<>(); + map.put(NotExpression.class, (x) -> new NotExpressionAssigner((NotExpression) x)); + map.put(Expression2Args.class, (x) -> new Expression2ArgsExpressionAssigner((Expression2Args) x)); + map.put(FunctionExpression.class, (x) -> new FunctionExpressionAssigner((FunctionExpression) x)); + map.put(ExpressionVariable.class, (x) -> new VariableExpressionAssigner((ExpressionVariable) x)); + map.put(VariableAccessPart.class, (x) -> new VariableAccessPathExpressionAssigner((VariableAccessPart) x)); + map.put(VariableInstanceFunctionIncovation.class, (x) -> new VariableInstanceFunctionInvocationExpressionAssigner((VariableInstanceFunctionIncovation) x)); + return Collections.unmodifiableMap(map); + } + + + public static class ConsumerExpressionAssigner implements ExpressionAssigner { + + private Consumer consumer; + + + public ConsumerExpressionAssigner(Consumer consumer) { + this.consumer = consumer; + } + + + @Override + public void assign(Expression exp) { + consumer.accept(exp); + } + + } + + public static class VariableExpressionAssigner extends ConsumerExpressionAssigner { + + public VariableExpressionAssigner(ExpressionVariable var) { + super(x -> var.unversionedSetIndexDef(x)); + } + } + + public static class Expression2ArgsExpressionAssigner implements ExpressionAssigner { + + private Expression2Args toAssign; + private boolean assignedFirstAlready; + + + public Expression2ArgsExpressionAssigner(Expression2Args toAssign) { + this.toAssign = toAssign; + assignedFirstAlready = false; + } + + + @Override + public void assign(Expression exp) { + if (!assignedFirstAlready) { + toAssign.unversionedSetVar1(exp); + assignedFirstAlready = true; + } else { + toAssign.unversionedSetVar2(exp); + } + } + + } + + public static class NotExpressionAssigner extends ConsumerExpressionAssigner { + + public NotExpressionAssigner(NotExpression toAssign) { + super(x -> toAssign.unversionedSetExpression(x)); + } + + } + + public static class VariableInstanceFunctionInvocationExpressionAssigner implements ExpressionAssigner { + + VariableInstanceFunctionIncovation invocation; + boolean assigningParameters; + + + public VariableInstanceFunctionInvocationExpressionAssigner(VariableInstanceFunctionIncovation invocation) { + this.invocation = invocation; + this.assigningParameters = true; + } + + + @Override + public void assign(Expression exp) { + if (assigningParameters) { + List oldParts = invocation.getFunctionParameter(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(exp); + invocation.unversionedSetFunctionParameter(parts); + } else { + invocation.setIndexDef(exp); + } + } + + + public void endAssigningParameters() { + assigningParameters = false; + } + + } + + public static class VariableAccessPathExpressionAssigner extends ConsumerExpressionAssigner { + + + public VariableAccessPathExpressionAssigner(VariableAccessPart vap) { + super(x -> vap.unversionedSetIndexDef(x)); + } + + } + + public static class FunctionExpressionAssigner extends ConsumerExpressionAssigner { + + //only assigns index definition. + public FunctionExpressionAssigner(FunctionExpression functionExpression) { + super(x -> functionExpression.setIndexDef(x)); + + } + + } + + public static class FunctionSubExpressionAssigner implements ExpressionAssigner { + + private FunctionExpression functionExpression; + + + public FunctionSubExpressionAssigner(FunctionExpression functionExpression) { + this.functionExpression = functionExpression; + + } + + + @Override + public void assign(Expression exp) { + List oldParts = functionExpression.getSubExpressions(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(exp); + functionExpression.setSubExpressions(parts); + } + } +} From 51a4688e50f0ffa0271cbcb8a5e17423d6b8a626 Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Mon, 15 Jan 2024 10:40:18 +0100 Subject: [PATCH 3/7] clean up expression list assigners --- .../session/ModelledExpressionConverter.java | 16 +++-- .../expressions/ExpressionAssigners.java | 67 ++++++++----------- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java index 6ea5f3d06..2c6d738d8 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java @@ -29,8 +29,9 @@ import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ExpressionAssigner; import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners; import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.FunctionSubExpressionAssigner; -import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.VariableInstanceFunctionInvocationExpressionAssigner; import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ConsumerExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.InstanceFunctionSubExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.VariableAccessPathExpressionAssigner; import com.gip.xyna.xact.filter.session.gb.ObjectId; import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; import com.gip.xyna.xprc.xfractwfe.formula.Expression; @@ -171,15 +172,17 @@ public void functionStarts(FunctionExpression fe) { @Override public void instanceFunctionStarts(VariableInstanceFunctionIncovation vifi) { logger.debug("instanceFunctionStarts"); + + Object obj = context.peek(); + GeneralXynaObject xo = objects.get(obj); + InstanceFunctionSubExpressionAssigner cur = new InstanceFunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation)xo); + context.push(cur); } @Override public void instanceFunctionEnds(VariableInstanceFunctionIncovation vifi) { logger.debug("instanceFunctionEnds"); - Object obj = context.peek(); - if(obj instanceof VariableInstanceFunctionInvocationExpressionAssigner) { - ((VariableInstanceFunctionInvocationExpressionAssigner)obj).endAssigningParameters(); - } + context.pop(); } @Override @@ -271,11 +274,12 @@ public void variablePartStarts(VariableAccessPart part) { Object toPush = null; if(part instanceof VariableInstanceFunctionIncovation) { cur = new xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation(); - toPush = ExpressionAssigners.assignerCreatorMap.get(cur.getClass()).apply(cur); + toPush = new VariableAccessPathExpressionAssigner(cur); } else { cur = new xmcp.processmodeller.datatypes.expression.VariableAccessPart(); toPush = part; } + cur.unversionedSetName(part.getName()); if(xo instanceof ExpressionVariable) { List oldParts = ((ExpressionVariable)xo).getParts(); diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java index 7272cc7af..d44e22d04 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; @@ -58,7 +59,7 @@ private static Map, Function new FunctionExpressionAssigner((FunctionExpression) x)); map.put(ExpressionVariable.class, (x) -> new VariableExpressionAssigner((ExpressionVariable) x)); map.put(VariableAccessPart.class, (x) -> new VariableAccessPathExpressionAssigner((VariableAccessPart) x)); - map.put(VariableInstanceFunctionIncovation.class, (x) -> new VariableInstanceFunctionInvocationExpressionAssigner((VariableInstanceFunctionIncovation) x)); + map.put(VariableInstanceFunctionIncovation.class, (x) -> new VariableAccessPathExpressionAssigner((VariableAccessPart) x)); return Collections.unmodifiableMap(map); } @@ -119,37 +120,6 @@ public NotExpressionAssigner(NotExpression toAssign) { } - public static class VariableInstanceFunctionInvocationExpressionAssigner implements ExpressionAssigner { - - VariableInstanceFunctionIncovation invocation; - boolean assigningParameters; - - - public VariableInstanceFunctionInvocationExpressionAssigner(VariableInstanceFunctionIncovation invocation) { - this.invocation = invocation; - this.assigningParameters = true; - } - - - @Override - public void assign(Expression exp) { - if (assigningParameters) { - List oldParts = invocation.getFunctionParameter(); - List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); - parts.add(exp); - invocation.unversionedSetFunctionParameter(parts); - } else { - invocation.setIndexDef(exp); - } - } - - - public void endAssigningParameters() { - assigningParameters = false; - } - - } - public static class VariableAccessPathExpressionAssigner extends ConsumerExpressionAssigner { @@ -161,7 +131,6 @@ public VariableAccessPathExpressionAssigner(VariableAccessPart vap) { public static class FunctionExpressionAssigner extends ConsumerExpressionAssigner { - //only assigns index definition. public FunctionExpressionAssigner(FunctionExpression functionExpression) { super(x -> functionExpression.setIndexDef(x)); @@ -169,23 +138,43 @@ public FunctionExpressionAssigner(FunctionExpression functionExpression) { } - public static class FunctionSubExpressionAssigner implements ExpressionAssigner { - private FunctionExpression functionExpression; + public static class ExpressionListAssigner implements ExpressionAssigner { + private Supplier> getter; + private Consumer> setter; - public FunctionSubExpressionAssigner(FunctionExpression functionExpression) { - this.functionExpression = functionExpression; + public ExpressionListAssigner(Supplier> getter, Consumer> setter) { + this.getter = getter; + this.setter = setter; } @Override public void assign(Expression exp) { - List oldParts = functionExpression.getSubExpressions(); + List oldParts = getter.get(); List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); parts.add(exp); - functionExpression.setSubExpressions(parts); + setter.accept(parts); + } + + } + + + public static class InstanceFunctionSubExpressionAssigner extends ExpressionListAssigner { + + public InstanceFunctionSubExpressionAssigner(VariableInstanceFunctionIncovation invocation) { + super(() -> invocation.getFunctionParameter(), (exp) -> invocation.unversionedSetFunctionParameter(exp)); } + + } + + public static class FunctionSubExpressionAssigner extends ExpressionListAssigner { + + public FunctionSubExpressionAssigner(FunctionExpression funExp) { + super(() -> funExp.getSubExpressions(), (exp) -> funExp.unversionedSetSubExpressions(exp)); + } + } } From 21e85ae11aa2832c6dc1db6e5dd619d5bef3def4 Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Tue, 16 Jan 2024 15:10:29 +0100 Subject: [PATCH 4/7] refactor + test --- .../expression/LocalExpressionVariable.xml | 23 - modules/xmcp/guihttp/application.xml | 4 - .../session/ModelledExpressionConverter.java | 139 +++--- .../expressions/ExpressionAssigners.java | 8 +- .../expressions/VarAccessPartAssigners.java | 101 ++++ .../test/expressions/ExpressionTests.java | 449 ++++++++++++++++++ 6 files changed, 628 insertions(+), 96 deletions(-) delete mode 100644 modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml create mode 100644 modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java create mode 100644 modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml deleted file mode 100644 index e622947d2..000000000 --- a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/LocalExpressionVariable.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - false - - - diff --git a/modules/xmcp/guihttp/application.xml b/modules/xmcp/guihttp/application.xml index 10033a1fc..815d6b8d1 100644 --- a/modules/xmcp/guihttp/application.xml +++ b/modules/xmcp/guihttp/application.xml @@ -2579,10 +2579,6 @@ xmcp.processmodeller.datatypes.expression.LiteralExpression DATATYPE - - xmcp.processmodeller.datatypes.expression.LocalExpressionVariable - DATATYPE - xmcp.processmodeller.datatypes.expression.NotExpression DATATYPE diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java index 2c6d738d8..d39f38151 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java @@ -17,6 +17,8 @@ */ package com.gip.xyna.xact.filter.session; + + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -31,8 +33,9 @@ import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.FunctionSubExpressionAssigner; import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ConsumerExpressionAssigner; import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.InstanceFunctionSubExpressionAssigner; -import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.VariableAccessPathExpressionAssigner; +import com.gip.xyna.xact.filter.session.expressions.VarAccessPartAssigners; import com.gip.xyna.xact.filter.session.gb.ObjectId; +import com.gip.xyna.xact.filter.util.QueryUtils; import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; import com.gip.xyna.xprc.xfractwfe.formula.Expression; import com.gip.xyna.xprc.xfractwfe.formula.Expression2Args; @@ -54,10 +57,13 @@ import xmcp.processmodeller.datatypes.expression.ExpressionVariable; import xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse; + + public class ModelledExpressionConverter { private static final Logger logger = CentralFactoryLogging.getLogger(ModelledExpressionConverter.class); - + + public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String stepId) { GetModelledExpressionsResponse result = new GetModelledExpressionsResponse(); List expressions = new ArrayList<>(); @@ -68,25 +74,25 @@ public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String s } catch (UnknownObjectIdException e) { throw new RuntimeException("unkown id"); } - - if(step instanceof StepMapping) { - backendExpressions = ((StepMapping)step).getParsedExpressions(); - } else if(step instanceof StepChoice) { - backendExpressions = ((StepChoice)step).getParsedFormulas(); - } else if(step instanceof StepFunction) { - //if it is a query, return expressions of mapping - return result; - } - - for(ModelledExpression backendExpression : backendExpressions) { + + if (step instanceof StepMapping) { + backendExpressions = ((StepMapping) step).getParsedExpressions(); + } else if (step instanceof StepChoice) { + backendExpressions = ((StepChoice) step).getParsedFormulas(); + } else if (step instanceof StepFunction) { + backendExpressions = QueryUtils.findQueryHelperMapping((StepFunction)step).getParsedExpressions(); + } + + for (ModelledExpression backendExpression : backendExpressions) { xmcp.processmodeller.datatypes.expression.ModelledExpression expression = convert(backendExpression); expressions.add(expression); } - + result.unversionedSetModelledExpressions(expressions); return result; } + public xmcp.processmodeller.datatypes.expression.ModelledExpression convert(ModelledExpression backendExpression) { logger.debug("convert: " + backendExpression.getExpression()); xmcp.processmodeller.datatypes.expression.ModelledExpression result = new xmcp.processmodeller.datatypes.expression.ModelledExpression(); @@ -97,116 +103,124 @@ public xmcp.processmodeller.datatypes.expression.ModelledExpression convert(Mode result.unversionedSetTargetExpression(visitor.getAndReset()); return result; } - - - - - + private static class ConverterVisitor implements Visitor { - + private xmcp.processmodeller.datatypes.expression.Expression result; private Stack context; private Map objects; - - + + public ConverterVisitor() { reset(); } - + + private void reset() { result = null; context = new Stack(); objects = new HashMap(); context.push(new ConsumerExpressionAssigner(x -> this.result = x)); } - + + public xmcp.processmodeller.datatypes.expression.Expression getAndReset() { xmcp.processmodeller.datatypes.expression.Expression localResult = result; reset(); return localResult; } + @Override public void expression2ArgsStarts(Expression2Args expression) { logger.debug("expression2ArgsStarts"); xmcp.processmodeller.datatypes.expression.Expression2Args exp = new xmcp.processmodeller.datatypes.expression.Expression2Args(); assignExpression(exp); - ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp); context.push(assigner); objects.put(assigner, exp); } + @Override public void functionEnds(FunctionExpression fe) { logger.debug("functionEnds"); } + @Override public void functionSubExpressionEnds(FunctionExpression fe, int parameterCnt) { logger.debug("functionSubExpressionEnds"); context.pop(); } + @Override public void functionSubExpressionStarts(FunctionExpression fe, int parameterCnt) { logger.debug("functionSubExpressionStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - FunctionSubExpressionAssigner cur = new FunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo); - context.push(cur); + FunctionSubExpressionAssigner cur = new FunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression) xo); + context.push(cur); } + @Override public void functionStarts(FunctionExpression fe) { logger.debug("functionStarts"); - - xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(); + xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(null, null, null, null); exp.unversionedSetFunction(fe.getFunction().getName()); assignExpression(exp); - ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp); context.push(assigner); objects.put(assigner, exp); } + @Override public void instanceFunctionStarts(VariableInstanceFunctionIncovation vifi) { logger.debug("instanceFunctionStarts"); - Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - InstanceFunctionSubExpressionAssigner cur = new InstanceFunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation)xo); - context.push(cur); + InstanceFunctionSubExpressionAssigner cur = new InstanceFunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation) xo); + context.push(cur); } + @Override public void instanceFunctionEnds(VariableInstanceFunctionIncovation vifi) { logger.debug("instanceFunctionEnds"); context.pop(); } + @Override public void instanceFunctionSubExpressionEnds(Expression fe, int parameterCnt) { logger.debug("instanceFunctionSubExpressionEnds"); } + @Override public void instanceFunctionSubExpressionStarts(Expression fe, int parameterCnt) { logger.debug("instanceFunctionSubExpressionStarts"); } + @Override public void allPartsOfVariableFinished(Variable variable) { logger.debug("allPartsOfVariableFinished"); context.pop(); } + @Override public void expression2ArgsEnds(Expression2Args expression) { logger.debug("expression2ArgsEnds"); context.pop(); } + @Override public void literalExpression(LiteralExpression expression) { logger.debug("literalExpression - " + expression.getValue()); @@ -216,111 +230,102 @@ public void literalExpression(LiteralExpression expression) { } - - @Override public void notStarts(Not not) { logger.debug("notStarts"); xmcp.processmodeller.datatypes.expression.NotExpression exp = new xmcp.processmodeller.datatypes.expression.NotExpression(); assignExpression(exp); - ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(exp.getClass()).apply(exp); + ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp); context.push(assigner); objects.put(assigner, exp); } + @Override public void notEnds(Not not) { logger.debug("notEnds"); context.pop(); } + @Override public void operator(Operator operator) { logger.debug("operator"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - if (xo instanceof xmcp.processmodeller.datatypes.expression.Expression2Args) { - ((xmcp.processmodeller.datatypes.expression.Expression2Args) xo).unversionedSetOperator(operator.getOperatorAsString()); - } + ((xmcp.processmodeller.datatypes.expression.Expression2Args) xo).unversionedSetOperator(operator.getOperatorAsString()); } + @Override public void variableStarts(Variable variable) { logger.debug("variableStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); context.push(variable); - ExpressionVariable cur = new ExpressionVariable(); - cur.unversionedSetVarNum(variable.getVarNum()); + ExpressionVariable cur = new ExpressionVariable(variable.getVarNum(), null, null); objects.put(variable, cur); - - if(xo instanceof xmcp.processmodeller.datatypes.expression.SingleVarExpression) { - ((xmcp.processmodeller.datatypes.expression.SingleVarExpression)xo).setVariable(cur); - } + ((xmcp.processmodeller.datatypes.expression.SingleVarExpression) xo).setVariable(cur); } + @Override public void variableEnds(Variable variable) { logger.debug("variableEnds"); } + @Override public void variablePartStarts(VariableAccessPart part) { logger.debug("variablePartStarts"); Object currentContext = context.peek(); GeneralXynaObject xo = objects.get(currentContext); - xmcp.processmodeller.datatypes.expression.VariableAccessPart cur = null; Object toPush = null; - if(part instanceof VariableInstanceFunctionIncovation) { - cur = new xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation(); - toPush = new VariableAccessPathExpressionAssigner(cur); + if (part instanceof VariableInstanceFunctionIncovation) { + cur = new xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation(null, null, null); + toPush = ExpressionAssigners.createAssigner(cur); } else { cur = new xmcp.processmodeller.datatypes.expression.VariableAccessPart(); toPush = part; } - + cur.unversionedSetName(part.getName()); - if(xo instanceof ExpressionVariable) { - List oldParts = ((ExpressionVariable)xo).getParts(); - List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); - parts.add(cur); - ((ExpressionVariable)xo).unversionedSetParts(parts); - } else if(xo instanceof xmcp.processmodeller.datatypes.expression.FunctionExpression) { - List oldParts = ((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo).getParts(); - List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); - parts.add(cur); - ((xmcp.processmodeller.datatypes.expression.FunctionExpression)xo).unversionedSetParts(parts); - } + VarAccessPartAssigners.assign(xo, cur); context.push(toPush); objects.put(toPush, cur); } + @Override public void variablePartEnds(VariableAccessPart part) { logger.debug("variablePartEnds"); context.pop(); } + @Override public void variablePartSubContextEnds(VariableAccessPart p) { logger.debug("variablePartSubContextEnds"); } + @Override public void allPartsOfFunctionFinished(FunctionExpression fe) { logger.debug("allPartsOfFunctionFinished"); } + @Override public void indexDefStarts() { logger.debug("indexDefStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); - ExpressionAssigner assigner = ExpressionAssigners.assignerCreatorMap.get(xo.getClass()).apply(xo); + ExpressionAssigner assigner = ExpressionAssigners.createAssigner(xo); context.push(assigner); } + @Override public void indexDefEnds() { logger.debug("indexDefEnds"); @@ -337,17 +342,17 @@ public void singleVarExpressionStarts(SingleVarExpression expression) { objects.put(expression, exp); } + @Override - public void singleVarExpressionEnds(SingleVarExpression expression) { + public void singleVarExpressionEnds(SingleVarExpression expression) { logger.debug("singleVarExpressionEnds"); context.pop(); } - + + private void assignExpression(xmcp.processmodeller.datatypes.expression.Expression exp) { Object obj = context.peek(); - if(obj instanceof ExpressionAssigner) { - ((ExpressionAssigner)obj).assign(exp); - } + ((ExpressionAssigner) obj).assign(exp); } } } diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java index d44e22d04..d5668cac8 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java @@ -44,11 +44,15 @@ public class ExpressionAssigners { public interface ExpressionAssigner { - public void assign(xmcp.processmodeller.datatypes.expression.Expression exp); + public void assign(Expression exp); } + + public static ExpressionAssigner createAssigner(GeneralXynaObject assignTo) { + return assignerCreatorMap.get(assignTo.getClass()).apply(assignTo); + } - public final static Map, Function> assignerCreatorMap = + private final static Map, Function> assignerCreatorMap = createAssignerCreatorMap(); diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java new file mode 100644 index 000000000..c2cfe99a2 --- /dev/null +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java @@ -0,0 +1,101 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2024 Xyna GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ +package com.gip.xyna.xact.filter.session.expressions; + + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject; + +import xmcp.processmodeller.datatypes.expression.ExpressionVariable; +import xmcp.processmodeller.datatypes.expression.FunctionExpression; +import xmcp.processmodeller.datatypes.expression.VariableAccessPart; + + + +public class VarAccessPartAssigners { + + public interface VariableAccessPartAssigner { + + public void assign(VariableAccessPart part); + } + + + public static void assign(GeneralXynaObject container, VariableAccessPart part) { + assignerCreatorMap.get(container.getClass()).apply(container).assign(part); + } + + private final static Map, Function> assignerCreatorMap = + createAssignerCreatorMap(); + + + private static Map, Function> createAssignerCreatorMap() { + Map, Function> map = new HashMap<>(); + map.put(ExpressionVariable.class, (x) -> new ExpressionVariableAccessPartAssigner((ExpressionVariable) x)); + map.put(FunctionExpression.class, (x) -> new FunctionExpressionAccessPartAssigner((FunctionExpression) x)); + return Collections.unmodifiableMap(map); + } + + + private static class AccessPartListAssigner implements VariableAccessPartAssigner { + + private Supplier> getter; + private Consumer> setter; + + + public AccessPartListAssigner(Supplier> getter, Consumer> setter) { + this.getter = getter; + this.setter = setter; + } + + + @Override + public void assign(VariableAccessPart part) { + List oldParts = getter.get(); + List parts = oldParts == null ? new ArrayList<>() : new ArrayList<>(oldParts); + parts.add(part); + setter.accept(parts); + } + + } + + private static class FunctionExpressionAccessPartAssigner extends AccessPartListAssigner { + + public FunctionExpressionAccessPartAssigner(FunctionExpression exp) { + super(() -> exp.getParts(), (x) -> exp.unversionedSetParts(x)); + } + + + } + + private static class ExpressionVariableAccessPartAssigner extends AccessPartListAssigner { + + + public ExpressionVariableAccessPartAssigner(ExpressionVariable exp) { + super(() -> exp.getParts(), (x) -> exp.unversionedSetParts(x)); + } + } +} diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java new file mode 100644 index 000000000..2eac1a99b --- /dev/null +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java @@ -0,0 +1,449 @@ +package expressions; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.function.BiFunction; + +import com.gip.xyna.xact.filter.session.ModelledExpressionConverter; +import com.gip.xyna.xprc.exceptions.XPRC_InvalidVariableIdException; +import com.gip.xyna.xprc.exceptions.XPRC_InvalidVariableMemberNameException; +import com.gip.xyna.xprc.exceptions.XPRC_ParsingModelledExpressionException; +import com.gip.xyna.xprc.xfractwfe.formula.TypeInfo; +import com.gip.xyna.xprc.xfractwfe.formula.Variable; +import com.gip.xyna.xprc.xfractwfe.generation.VariableContextIdentification; + +import junit.framework.TestCase; +import xmcp.processmodeller.datatypes.expression.Expression; +import xmcp.processmodeller.datatypes.expression.ExpressionVariable; +import xmcp.processmodeller.datatypes.expression.FunctionExpression; +import xmcp.processmodeller.datatypes.expression.LiteralExpression; +import xmcp.processmodeller.datatypes.expression.LocalExpressionVariable; +import xmcp.processmodeller.datatypes.expression.ModelledExpression; +import xmcp.processmodeller.datatypes.expression.NotExpression; +import xmcp.processmodeller.datatypes.expression.SingleVarExpression; +import xmcp.processmodeller.datatypes.expression.VariableAccessPart; +import xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation; +import xmcp.processmodeller.datatypes.expression.Expression2Args; + +public class ExpressionTests extends TestCase { + + + public void testBasicExpressions() { + ModelledExpression exp = convert("%1%.text=%0%.test"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("test", null) + }), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) + }), + null) + ) + ); + assertTrue(compare(exp, expectedResult)); + } + + public void testIndexExpressionOfVariable() { + ModelledExpression exp = convert("%1%[\"0\"].text=%0%.test"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("test", null) + }), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) + }), + new LiteralExpression("0") + ) + ) + ); + assertTrue(compare(exp, expectedResult)); + } + + public void testExp2Args() { + ModelledExpression exp = convert("%0%.text!=\"test\""); + ModelledExpression expectedResult = new ModelledExpression(null, + new Expression2Args( + new SingleVarExpression( + new ExpressionVariable(0, Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) + }), null)), + new LiteralExpression("test"), "!=") + ); + assertTrue(compare(exp, expectedResult)); + } + + public void testNotExpression() { + ModelledExpression exp = convert("!\"False\""); + ModelledExpression expectedResult = new ModelledExpression(null, + new NotExpression(new LiteralExpression("False"))); + assertTrue(compare(exp, expectedResult)); + } + + public void testInstanceFunction() { + ModelledExpression exp = convert("%1%.bData=%0%.isNullOrEmpty()"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableInstanceFunctionIncovation("isNullOrEmpty", null, null) }), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null))); + assertTrue(compare(exp, expectedResult)); + } + + public void testInstanceFunctionParameter() { + ModelledExpression exp = convert("%1%.bData=%0%.singleVarMethod(\"test\")"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableInstanceFunctionIncovation("singleVarMethod", null, + Arrays.asList(new Expression[] { + new LiteralExpression("test") + })) }), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null))); + + assertTrue(compare(exp, expectedResult)); + } + + public void testInstanceFunctionIndexDefinition() { + ModelledExpression exp = convert("%1%.bData=%0%.singleVarMethod(\"test\")[\"5\"]"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableInstanceFunctionIncovation("singleVarMethod", + new LiteralExpression("5"), + Arrays.asList(new Expression[] { + new LiteralExpression("test") + })) }), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null))); + + assertTrue(compare(exp, expectedResult)); + } + + public void testInstanceFunctionComplexMember() { + ModelledExpression exp = convert("%1%.bData=%0%.singleVarMethod(\"test\", %0%.other[\"1\"])[\"2\"]"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableInstanceFunctionIncovation("singleVarMethod", + new LiteralExpression("2"), + Arrays.asList(new Expression[] { + new LiteralExpression("test"), + new SingleVarExpression(new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("other", new LiteralExpression("1")) + }), null)) + }))}), + null) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null))); + + assertTrue(compare(exp, expectedResult)); + + } + + public void testInstanceFunctionComplexMemberListVar() { + ModelledExpression exp = convert("%1%.bData=%0%[\"4\"].singleVarMethod(\"test\", %0%.other[\"1\"])[\"2\"]"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableInstanceFunctionIncovation("singleVarMethod", + new LiteralExpression("2"), + Arrays.asList(new Expression[] { + new LiteralExpression("test"), + new SingleVarExpression(new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("other", new LiteralExpression("1")) + }), null)) + }))}), + new LiteralExpression("4")) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null))); + + assertTrue(compare(exp, expectedResult)); + + } + + public void testConcat() { + + ModelledExpression exp = convert( "%2%.bData=concat(%0%.text, %1%.text2)"); + ModelledExpression expectedResult = new ModelledExpression( + new FunctionExpression( + Arrays.asList(new Expression[] { + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) }), + null)), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text2", null) }), + null)) + }), + "concat", + null, + null), + new SingleVarExpression( + new ExpressionVariable(2, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null)) + ); + + + assertTrue(compare(exp, expectedResult)); + } + + public void testConcatListsWithIndex() { + + ModelledExpression exp = convert("%2%.bData=concatlists(%0%.text, %1%.text2)[\"5\"]"); + ModelledExpression expectedResult = new ModelledExpression( + new FunctionExpression( + Arrays.asList(new Expression[] { + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) }), + null)), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text2", null) }), + null)) + }), + "concatlists", + new LiteralExpression("5"), + null), + new SingleVarExpression( + new ExpressionVariable(2, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("bData", null) }), + null)) + ); + + assertTrue(compare(exp, expectedResult)); + } + + public void testDynamicResultTypeFunction() { + ModelledExpression exp = convert("%1%=new(\"lf.tests.DTWithBoolean\").test"); + ModelledExpression expectedResult = new ModelledExpression( + new FunctionExpression( + Arrays.asList(new Expression[] {new LiteralExpression("lf.tests.DTWithBoolean")}), + "new", + null, + Arrays.asList(new VariableAccessPart[] {new VariableAccessPart("test", null)}) + ), + new SingleVarExpression(new ExpressionVariable(1, null, null)) + ); + assertTrue(compare(exp, expectedResult)); + } + + + public void testVariableAccessPartMultiWithIndexDef() { + ModelledExpression exp = convert("%1%.text=%0%.test[\"0\"].text2"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression( + new ExpressionVariable(0, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("test", new LiteralExpression("0")), + new VariableAccessPart("text2", null) + }), + null + ) + ), + new SingleVarExpression( + new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { + new VariableAccessPart("text", null) }), + null)) + ); + + assertTrue(compare(exp, expectedResult)); + } + + public void testVarIndexDefIsVarExp() { + ModelledExpression exp = convert("%2%.text=%0%[%1%.count]"); + ModelledExpression expectedResult = new ModelledExpression( + new SingleVarExpression(new ExpressionVariable(0, + null, + new SingleVarExpression(new ExpressionVariable(1, + Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("count", null) }) + , null)) + )), + new SingleVarExpression( + new ExpressionVariable(2, + Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("text", null) }), + null)) + ); + + + assertTrue(compare(exp, expectedResult)); + } + + private static ModelledExpression convert(String expression) { + com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression me; + try { + me = com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression.parse(helperContext(), expression); + ModelledExpressionConverter converter = new ModelledExpressionConverter(); + xmcp.processmodeller.datatypes.expression.ModelledExpression out = converter.convert(me); + return out; + } catch (XPRC_ParsingModelledExpressionException e) { + throw new RuntimeException("Invalid Modelled Expression"); + } + } + + + private static VariableContextIdentification helperContext() { + return new VariableContextIdentification() { + public VariableInfo createVariableInfo(Variable v, boolean followAccessParts) throws XPRC_InvalidVariableIdException, XPRC_InvalidVariableMemberNameException { + throw new RuntimeException(); + } + public TypeInfo getTypeInfo(String originalXmlName) { + throw new RuntimeException(); + } + public Long getRevision() { + return null; + } + public VariableInfo createVariableInfo(TypeInfo resultType) { + throw new RuntimeException(); + } + }; + } + + private boolean objCmp(Object obj1, Object obj2) { + return Objects.isNull(obj1) == Objects.isNull(obj2) && (Objects.isNull(obj1) || obj1.getClass() == obj2.getClass()); + } + + private boolean compare(ModelledExpression obj1, ModelledExpression obj2) { + return objCmp(obj1, obj2) && + compare(obj1.getSourceExpression(), obj2.getSourceExpression()) && + compare(obj1.getTargetExpression(), obj2.getTargetExpression()); + } + + + private boolean compare(Expression obj1, Expression obj2) { + return objCmp(obj1, obj2) && (Objects.isNull(obj1) + || (obj1.getClass().equals(FunctionExpression.class) && compare((FunctionExpression)obj1, (FunctionExpression)obj2)) + || (obj1.getClass().equals(Expression2Args.class) && compare((Expression2Args)obj1, (Expression2Args)obj2)) + || (obj1.getClass().equals(LiteralExpression.class) && compare((LiteralExpression)obj1, (LiteralExpression)obj2)) + || (obj1.getClass().equals(LocalExpressionVariable.class) && compare((LocalExpressionVariable)obj1, (LocalExpressionVariable)obj2)) + || (obj1.getClass().equals(NotExpression.class) && compare((NotExpression)obj1, (NotExpression)obj2)) + || (obj1.getClass().equals(SingleVarExpression.class) && compare((SingleVarExpression)obj1, (SingleVarExpression)obj2)) + + ) ; + } + + private boolean compare(FunctionExpression obj1, FunctionExpression obj2) { + return objCmp(obj1, obj2) && Objects.isNull(obj1) + || (Objects.equals(obj1.getFunction(), obj2.getFunction()) + && compare(obj1.getIndexDef(), obj2.getIndexDef()) + && compareLists(obj1.getParts(), obj2.getParts(), this::compare) + && compareLists(obj1.getSubExpressions(), obj2.getSubExpressions(), this::compare)); + } + + private boolean compareLists(List obj1, List obj2, BiFunction cmp) { + if(objCmp(obj1, obj2)) { + if(obj1 == null) { + return true; + } + if(obj1.size() != obj2.size()) { + return false; + } + for(int i=0; i Date: Wed, 17 Jan 2024 07:50:36 +0100 Subject: [PATCH 5/7] set copyright header, update version in blackedition_lib.sh --- blackedition/blackedition_lib.sh | 4 ++-- .../test/expressions/ExpressionTests.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/blackedition/blackedition_lib.sh b/blackedition/blackedition_lib.sh index b54c02786..3b42699e9 100755 --- a/blackedition/blackedition_lib.sh +++ b/blackedition/blackedition_lib.sh @@ -1,7 +1,7 @@ #!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Copyright 2022 Xyna GmbH, Germany +# Copyright 2024 Xyna GmbH, Germany # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ ALL_DATAMODELTYPES=("mib","tr069","xsd"); #ACHTUNG: Version auch bei addRequirement zu default workspace berücksichtigen ALL_APPLICATIONS="Base Processing"; #Default-Applications, die immer installiert sein sollten APPMGMTVERSION=1.0.10 -GUIHTTPVERSION=1.1.373 +GUIHTTPVERSION=1.1.374 SNMPSTATVERSION=1.0.3 PROCESSINGVERSION=1.0.18 ALL_REPOSITORYACCESSES=("svn"); diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java index 2eac1a99b..6d84db9dd 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java @@ -1,3 +1,20 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2024 Xyna GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ package expressions; import java.util.Arrays; From 96f6f70dc57a929a4cef6db8e583f8293a35e8db Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Wed, 17 Jan 2024 07:53:24 +0100 Subject: [PATCH 6/7] update reference to guihttp application --- modules/xmcp/gitIntegration/application.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/xmcp/gitIntegration/application.xml b/modules/xmcp/gitIntegration/application.xml index 385ef9206..c02424b50 100644 --- a/modules/xmcp/gitIntegration/application.xml +++ b/modules/xmcp/gitIntegration/application.xml @@ -20,7 +20,7 @@ GuiHttp - 1.1.373 + 1.1.374 From 21cb5061280e7585f1d371ab01779610f84401a2 Mon Sep 17 00:00:00 2001 From: Lukas Fey Date: Tue, 23 Jan 2024 08:50:15 +0100 Subject: [PATCH 7/7] handle invalid expressions, remove debug output --- .../session/ModelledExpressionConverter.java | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java index d39f38151..67ef26319 100644 --- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java +++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java @@ -84,6 +84,9 @@ public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String s } for (ModelledExpression backendExpression : backendExpressions) { + if(backendExpression == null) { + continue; + } xmcp.processmodeller.datatypes.expression.ModelledExpression expression = convert(backendExpression); expressions.add(expression); } @@ -94,7 +97,6 @@ public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String s public xmcp.processmodeller.datatypes.expression.ModelledExpression convert(ModelledExpression backendExpression) { - logger.debug("convert: " + backendExpression.getExpression()); xmcp.processmodeller.datatypes.expression.ModelledExpression result = new xmcp.processmodeller.datatypes.expression.ModelledExpression(); ConverterVisitor visitor = new ConverterVisitor(); backendExpression.visitSourceExpression(visitor); @@ -134,7 +136,6 @@ public xmcp.processmodeller.datatypes.expression.Expression getAndReset() { @Override public void expression2ArgsStarts(Expression2Args expression) { - logger.debug("expression2ArgsStarts"); xmcp.processmodeller.datatypes.expression.Expression2Args exp = new xmcp.processmodeller.datatypes.expression.Expression2Args(); assignExpression(exp); ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp); @@ -145,20 +146,17 @@ public void expression2ArgsStarts(Expression2Args expression) { @Override public void functionEnds(FunctionExpression fe) { - logger.debug("functionEnds"); } @Override public void functionSubExpressionEnds(FunctionExpression fe, int parameterCnt) { - logger.debug("functionSubExpressionEnds"); context.pop(); } @Override public void functionSubExpressionStarts(FunctionExpression fe, int parameterCnt) { - logger.debug("functionSubExpressionStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); FunctionSubExpressionAssigner cur = new FunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression) xo); @@ -168,7 +166,6 @@ public void functionSubExpressionStarts(FunctionExpression fe, int parameterCnt) @Override public void functionStarts(FunctionExpression fe) { - logger.debug("functionStarts"); xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(null, null, null, null); exp.unversionedSetFunction(fe.getFunction().getName()); assignExpression(exp); @@ -180,7 +177,6 @@ public void functionStarts(FunctionExpression fe) { @Override public void instanceFunctionStarts(VariableInstanceFunctionIncovation vifi) { - logger.debug("instanceFunctionStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); InstanceFunctionSubExpressionAssigner cur = new InstanceFunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation) xo); @@ -190,40 +186,34 @@ public void instanceFunctionStarts(VariableInstanceFunctionIncovation vifi) { @Override public void instanceFunctionEnds(VariableInstanceFunctionIncovation vifi) { - logger.debug("instanceFunctionEnds"); context.pop(); } @Override public void instanceFunctionSubExpressionEnds(Expression fe, int parameterCnt) { - logger.debug("instanceFunctionSubExpressionEnds"); } @Override public void instanceFunctionSubExpressionStarts(Expression fe, int parameterCnt) { - logger.debug("instanceFunctionSubExpressionStarts"); } @Override public void allPartsOfVariableFinished(Variable variable) { - logger.debug("allPartsOfVariableFinished"); context.pop(); } @Override public void expression2ArgsEnds(Expression2Args expression) { - logger.debug("expression2ArgsEnds"); context.pop(); } @Override public void literalExpression(LiteralExpression expression) { - logger.debug("literalExpression - " + expression.getValue()); xmcp.processmodeller.datatypes.expression.LiteralExpression exp = new xmcp.processmodeller.datatypes.expression.LiteralExpression(); exp.unversionedSetValue(expression.getValue()); assignExpression(exp); @@ -232,7 +222,6 @@ public void literalExpression(LiteralExpression expression) { @Override public void notStarts(Not not) { - logger.debug("notStarts"); xmcp.processmodeller.datatypes.expression.NotExpression exp = new xmcp.processmodeller.datatypes.expression.NotExpression(); assignExpression(exp); ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp); @@ -243,14 +232,12 @@ public void notStarts(Not not) { @Override public void notEnds(Not not) { - logger.debug("notEnds"); context.pop(); } @Override public void operator(Operator operator) { - logger.debug("operator"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); ((xmcp.processmodeller.datatypes.expression.Expression2Args) xo).unversionedSetOperator(operator.getOperatorAsString()); @@ -259,7 +246,6 @@ public void operator(Operator operator) { @Override public void variableStarts(Variable variable) { - logger.debug("variableStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); context.push(variable); @@ -271,13 +257,11 @@ public void variableStarts(Variable variable) { @Override public void variableEnds(Variable variable) { - logger.debug("variableEnds"); } @Override public void variablePartStarts(VariableAccessPart part) { - logger.debug("variablePartStarts"); Object currentContext = context.peek(); GeneralXynaObject xo = objects.get(currentContext); xmcp.processmodeller.datatypes.expression.VariableAccessPart cur = null; @@ -299,26 +283,22 @@ public void variablePartStarts(VariableAccessPart part) { @Override public void variablePartEnds(VariableAccessPart part) { - logger.debug("variablePartEnds"); context.pop(); } @Override public void variablePartSubContextEnds(VariableAccessPart p) { - logger.debug("variablePartSubContextEnds"); } @Override public void allPartsOfFunctionFinished(FunctionExpression fe) { - logger.debug("allPartsOfFunctionFinished"); } @Override public void indexDefStarts() { - logger.debug("indexDefStarts"); Object obj = context.peek(); GeneralXynaObject xo = objects.get(obj); ExpressionAssigner assigner = ExpressionAssigners.createAssigner(xo); @@ -328,14 +308,12 @@ public void indexDefStarts() { @Override public void indexDefEnds() { - logger.debug("indexDefEnds"); context.pop(); } @Override public void singleVarExpressionStarts(SingleVarExpression expression) { - logger.debug("singleVarExpressionStarts"); xmcp.processmodeller.datatypes.expression.SingleVarExpression exp = new xmcp.processmodeller.datatypes.expression.SingleVarExpression(); assignExpression(exp); context.push(expression); @@ -345,7 +323,6 @@ public void singleVarExpressionStarts(SingleVarExpression expression) { @Override public void singleVarExpressionEnds(SingleVarExpression expression) { - logger.debug("singleVarExpressionEnds"); context.pop(); }