Skip to content

Commit

Permalink
[guihttp] instance method validation
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFey-GIP committed Dec 19, 2024
1 parent e2d6dce commit b2c17c0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@



import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -61,7 +62,8 @@
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.DomOrExceptionGenerationBase;
import com.gip.xyna.xprc.xfractwfe.generation.DomOrExceptionGenerationBase;
import com.gip.xyna.xprc.xfractwfe.generation.GenerationBase;
import com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression;
import com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression.EmptyVisitor;
import com.gip.xyna.xprc.xfractwfe.generation.Operation;
Expand Down Expand Up @@ -513,11 +515,11 @@ private TypeInfo determineFunctionExpressionResultType(FunctionExpression fe) {
private TypeInfo determineTypeOfFollowAbleVariable(Variable var) {
TypeInfo ti;
try {
ti = var.getFollowedVariable().getTypeInfo(true);
ti = var.getFollowedVariable().getTypeInfo(true);
boolean isList = var.getFollowedVariable().getTypeInfo(false).isList();
if (ti.isBaseType()) {
return ti;
return new TypeInfo(ti.getBaseType(), isList);
} else if (ti.isModelledType()) {
boolean isList = var.getFollowedVariable().getTypeInfo(false).isList();
if(isList && var.lastPartOfVariableHasListAccess()) {
isList = false;
}
Expand Down Expand Up @@ -656,13 +658,34 @@ private List<AVariable> getOperationInputs(Step step, Variable var, String opera
}

DOM dom = (DOM)doe;
try {
result = dom.getOperationByName(operationName).getInputVars();
try {
if (GenerationBase.isReservedServerObjectByFqClassName(dom.getFqClassName())) {
result = getInputOfReservedOperation(dom, GenerationBase.getReservedClass(dom.getOriginalFqName()), operationName);
} else {
result = dom.getOperationByName(operationName).getInputVars();
}
} catch (XPRC_OperationUnknownException e) {
throw new InvalidFunctionException();
}

return result;
}

private List<AVariable> getInputOfReservedOperation(DOM dom, Class<?> clazz, String operationName) throws XPRC_OperationUnknownException {
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals(operationName)) {
List<AVariable> result = new ArrayList<AVariable>();
Class<?>[] inputs = method.getParameterTypes();
for (Class<?> input : inputs) {
AVariable var = TypeToAVariableConverter.convert(dom, input);
result.add(var);
}
return result;
}
}
throw new XPRC_OperationUnknownException(operationName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* 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.workflowissues;



import com.gip.xyna.xprc.exceptions.XPRC_InvalidPackageNameException;
import com.gip.xyna.xprc.xfractwfe.generation.AVariable;
import com.gip.xyna.xprc.xfractwfe.generation.AVariable.PrimitiveType;
import com.gip.xyna.xprc.xfractwfe.generation.DOM;
import com.gip.xyna.xprc.xfractwfe.generation.DatatypeVariable;
import com.gip.xyna.xprc.xfractwfe.generation.GenerationBase;



public class TypeToAVariableConverter {


public static AVariable convert(DOM dom, Class<?> clazz) {
AVariable result;

PrimitiveType primitiveType = AVariable.PrimitiveType.createOrNull(clazz.getCanonicalName());
if (primitiveType != null) {
result = createPrimitiveTypeAVariable(dom, primitiveType);
} else {
result = createModelledTypeAvariable(dom, clazz);
}

return result;
}


private static AVariable createPrimitiveTypeAVariable(DOM dom, PrimitiveType type) {
DatatypeVariable result = new DatatypeVariable(dom);
result.create(type);
return result;
}


private static AVariable createModelledTypeAvariable(DOM dom, Class<?> clazz) {
DatatypeVariable result = new DatatypeVariable(dom);
try {
boolean isReserved = GenerationBase.isReservedServerObjectByFqClassName(clazz.getCanonicalName());
String fqOriginalName = isReserved ? GenerationBase.getXmlNameForReservedClass(clazz) : clazz.getCanonicalName();
result.create(fqOriginalName);
} catch (XPRC_InvalidPackageNameException e) {
throw new RuntimeException(e);
}
return result;
}
}

0 comments on commit b2c17c0

Please sign in to comment.