From d5ab2417f26993b8466d67d5b3840c5addac2cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Thu, 21 Nov 2024 16:28:02 +0100 Subject: [PATCH] Revert "[NU-7164] Add basic parser for fragment input definitions (#7167)" This reverts commit d5154a3e7053d485fe766a021adee0401986411e. --- .../editors/expression/Table/TableEditor.tsx | 28 +----------- .../FragmentInputDefinition.tsx | 8 ++-- .../AlignedComponentsDefinitionProvider.scala | 1 - .../definition/DefinitionsServiceSpec.scala | 1 - .../ui/definition/EdgeTypesPreparerTest.scala | 1 - .../ComponentGroupsPreparerSpec.scala | 1 - .../component/ComponentsUsageHelperTest.scala | 2 +- .../FlinkProcessCompilerDataFactory.scala | 11 ++--- ...ubbedFlinkProcessCompilerDataFactory.scala | 7 +-- .../engine/compile/ProcessCompiler.scala | 2 +- .../engine/compile/ProcessCompilerData.scala | 2 +- .../FragmentParameterValidator.scala | 20 ++------- .../nodecompilation/NodeCompiler.scala | 9 ++-- .../nodecompilation/NodeDataValidator.scala | 5 +-- ...FragmentComponentDefinitionExtractor.scala | 4 +- .../FragmentParameterTypingParser.scala | 45 ------------------- ...ragmentParametersDefinitionExtractor.scala | 21 +++------ .../test/ModelDataTestInfoProvider.scala | 5 +-- .../FragmentParameterValidatorTest.scala | 8 ++-- ...ompilerDataFactoryWithTestComponents.scala | 4 +- 20 files changed, 36 insertions(+), 149 deletions(-) delete mode 100644 scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala diff --git a/designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx b/designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx index 4d38ca5ffe9..6db395f3fa1 100644 --- a/designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx +++ b/designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx @@ -17,6 +17,7 @@ import { PopoverPosition } from "@mui/material/Popover/Popover"; import i18next from "i18next"; import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; import ValidationLabels from "../../../../../modals/ValidationLabels"; +import { useTypeOptions } from "../../../fragment-input-definition/FragmentInputDefinition"; import { EditorProps, ExtendedEditor } from "../Editor"; import "@glideapps/glide-data-grid/dist/index.css"; import { CellMenu, DeleteColumnMenuItem, DeleteRowMenuItem, ResetColumnWidthMenuItem } from "./CellMenu"; @@ -30,10 +31,6 @@ import { TypesMenu } from "./TypesMenu"; import { customRenderers } from "./customRenderers"; import { isDatePickerCell } from "./customCells"; import type { GetRowThemeCallback } from "@glideapps/glide-data-grid/src/internal/data-grid/render/data-grid-render.cells"; -import { useSelector } from "react-redux"; -import { getProcessDefinitionData } from "../../../../../../reducers/selectors/settings"; -import ProcessUtils from "../../../../../../common/ProcessUtils"; -import { find, head, orderBy } from "lodash"; const SUPPORTED_TYPES = [ "java.lang.String", @@ -90,27 +87,6 @@ const emptySelection = { rows: CompactSelection.empty(), }; -export function useTableEditorTypeOptions() { - const definitionData = useSelector(getProcessDefinitionData); - - const typeOptions = useMemo( - () => - definitionData?.classes?.map((type) => ({ - value: type.refClazzName as SupportedType, - label: ProcessUtils.humanReadableType(type), - })), - [definitionData?.classes], - ); - - const orderedTypeOptions = useMemo(() => orderBy(typeOptions, (item) => [item.label, item.value], ["asc"]), [typeOptions]); - - const defaultTypeOption = useMemo(() => find(typeOptions, { label: "String" }) || head(typeOptions), [typeOptions]); - return { - orderedTypeOptions, - defaultTypeOption, - }; -} - export const Table = ({ expressionObj, onValueChange, className, fieldErrors }: EditorProps) => { const tableDateContext = useTableState(expressionObj); const [{ rows, columns }, dispatch, rawExpression] = tableDateContext; @@ -121,7 +97,7 @@ export const Table = ({ expressionObj, onValueChange, className, fieldErrors }: } }, [expressionObj.expression, onValueChange, rawExpression]); - const { defaultTypeOption, orderedTypeOptions } = useTableEditorTypeOptions(); + const { defaultTypeOption, orderedTypeOptions } = useTypeOptions(); const supportedTypes = useMemo(() => orderedTypeOptions.filter(({ value }) => SUPPORTED_TYPES.includes(value)), [orderedTypeOptions]); useEffect(() => { diff --git a/designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx b/designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx index c0aa32d74b1..54f66ba61ee 100644 --- a/designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx +++ b/designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx @@ -14,13 +14,13 @@ interface Props extends Omit, "readOnly isEditMode?: boolean; } -export function useFragmentInputDefinitionTypeOptions() { +export function useTypeOptions() { const definitionData = useSelector(getProcessDefinitionData); - const typeOptions = useMemo( () => definitionData?.classes?.map((type) => ({ - value: type.display as string, + // TODO: Instead of using type assertion type, set refClazzName as a union of available clazzNames + value: type.refClazzName as Value, label: ProcessUtils.humanReadableType(type), })), [definitionData?.classes], @@ -40,7 +40,7 @@ export default function FragmentInputDefinition(props: Props): JSX.Element { const { node, setProperty, isEditMode, showValidation } = passProps; const readOnly = !isEditMode; - const { orderedTypeOptions, defaultTypeOption } = useFragmentInputDefinitionTypeOptions(); + const { orderedTypeOptions, defaultTypeOption } = useTypeOptions(); const addField = useCallback(() => { addElement("parameters", getDefaultFields(defaultTypeOption.value)); diff --git a/designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala b/designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala index e992a79ad7a..457b17a8871 100644 --- a/designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala +++ b/designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala @@ -59,7 +59,6 @@ object AlignedComponentsDefinitionProvider { new BuiltInComponentsDefinitionsPreparer(designerModelData.modelData.componentsUiConfig), new FragmentComponentDefinitionExtractor( designerModelData.modelData.modelClassLoader.classLoader, - designerModelData.modelData.modelDefinitionWithClasses.classDefinitions.all, designerModelData.modelData.componentsUiConfig.groupName, designerModelData.modelData.determineDesignerWideId ), diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala index 7d1ab6de70f..d38d98406e9 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala @@ -296,7 +296,6 @@ class DefinitionsServiceSpec extends AnyFunSuite with Matchers with PatientScala new BuiltInComponentsDefinitionsPreparer(ComponentsUiConfigParser.parse(model.modelConfig)), new FragmentComponentDefinitionExtractor( getClass.getClassLoader, - model.modelDefinitionWithClasses.classDefinitions.all, Some(_), DesignerWideComponentId.default(processingType.stringify, _) ), diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala index 39f18a8263b..2474ffddf17 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala @@ -22,7 +22,6 @@ class EdgeTypesPreparerTest extends AnyFunSuite with Matchers with ValidatedValu test("return edge types for fragment, filters, switches and components with multiple inputs") { val sampleFragmentDef = new FragmentComponentDefinitionExtractor( getClass.getClassLoader, - Set.empty, Some(_), DesignerWideComponentId.default(Streaming.stringify, _) ) diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala index b76aac15e75..7fd8e20e53a 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala @@ -190,7 +190,6 @@ class ComponentGroupsPreparerSpec new BuiltInComponentsDefinitionsPreparer(new ComponentsUiConfig(Map.empty, groupNameMapping)), new FragmentComponentDefinitionExtractor( getClass.getClassLoader, - Set.empty, Some(_), DesignerWideComponentId.default("Streaming", _) ), diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala index 6e166048a48..ed293efcf95 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala @@ -176,7 +176,7 @@ class ComponentsUsageHelperTest extends AnyFunSuite with Matchers with TableDriv val alignedComponentsDefinitionProvider = new AlignedComponentsDefinitionProvider( new BuiltInComponentsDefinitionsPreparer(new ComponentsUiConfig(Map.empty, Map.empty)), - new FragmentComponentDefinitionExtractor(getClass.getClassLoader, Set.empty, Some(_), determineDesignerWideId), + new FragmentComponentDefinitionExtractor(getClass.getClassLoader, Some(_), determineDesignerWideId), modelDefinition, ProcessingMode.UnboundedStream ) diff --git a/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala b/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala index e515bec72df..dd56b848c8f 100644 --- a/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala +++ b/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala @@ -9,7 +9,7 @@ import pl.touk.nussknacker.engine.api.process.{ComponentUseCase, ProcessConfigCr import pl.touk.nussknacker.engine.api.{JobData, MetaData, ProcessListener, ProcessVersion} import pl.touk.nussknacker.engine.compile._ import pl.touk.nussknacker.engine.compile.nodecompilation.LazyParameterCreationStrategy -import pl.touk.nussknacker.engine.definition.clazz.{ClassDefinition, ClassDefinitionSet} +import pl.touk.nussknacker.engine.definition.clazz.ClassDefinitionSet import pl.touk.nussknacker.engine.definition.globalvariables.ExpressionConfigDefinition import pl.touk.nussknacker.engine.definition.model.{ModelDefinition, ModelDefinitionWithClasses} import pl.touk.nussknacker.engine.dict.DictServicesFactoryLoader @@ -137,18 +137,13 @@ class FlinkProcessCompilerDataFactory( modelDefinitionWithTypes.modelDefinition.expressionConfig, modelDefinitionWithTypes.classDefinitions ) - val adjustedDefinitions = adjustDefinitions( - modelDefinitionWithTypes.modelDefinition, - definitionContext, - modelDefinitionWithTypes.classDefinitions.all - ) + val adjustedDefinitions = adjustDefinitions(modelDefinitionWithTypes.modelDefinition, definitionContext) (ModelDefinitionWithClasses(adjustedDefinitions), dictRegistry) } protected def adjustDefinitions( originalModelDefinition: ModelDefinition, - definitionContext: ComponentDefinitionContext, - classDefinitions: Set[ClassDefinition] + definitionContext: ComponentDefinitionContext ): ModelDefinition = originalModelDefinition private def loadDictRegistry(userCodeClassLoader: ClassLoader) = { diff --git a/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala b/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala index 2ef9887d07e..6cd907bc57c 100644 --- a/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala +++ b/engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala @@ -10,7 +10,6 @@ import pl.touk.nussknacker.engine.api.process.{ComponentUseCase, ProcessConfigCr import pl.touk.nussknacker.engine.api.typed.ReturningType import pl.touk.nussknacker.engine.api.typed.typing.{TypingResult, Unknown} import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess -import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition import pl.touk.nussknacker.engine.definition.component.dynamic.DynamicComponentDefinitionWithImplementation import pl.touk.nussknacker.engine.definition.component.methodbased.MethodBasedComponentDefinitionWithImplementation import pl.touk.nussknacker.engine.definition.component.{ @@ -43,8 +42,7 @@ abstract class StubbedFlinkProcessCompilerDataFactory( override protected def adjustDefinitions( originalModelDefinition: ModelDefinition, - definitionContext: ComponentDefinitionContext, - classDefinitions: Set[ClassDefinition] + definitionContext: ComponentDefinitionContext ): ModelDefinition = { val usedSourceIds = process.allStartNodes .map(_.head.data) @@ -63,8 +61,7 @@ abstract class StubbedFlinkProcessCompilerDataFactory( } val fragmentParametersDefinitionExtractor = new FragmentParametersDefinitionExtractor( - definitionContext.userCodeClassLoader, - classDefinitions + definitionContext.userCodeClassLoader ) val fragmentSourceDefinitionPreparer = new StubbedFragmentSourceDefinitionPreparer( fragmentParametersDefinitionExtractor diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala index 0d19e5b80b4..13cd8b5a6f9 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala @@ -352,7 +352,7 @@ object ProcessValidator { val nodeCompiler = new NodeCompiler( modelDefinition, - new FragmentParametersDefinitionExtractor(classLoader, definitionWithTypes.classDefinitions.all), + new FragmentParametersDefinitionExtractor(classLoader), expressionCompiler, classLoader, Seq.empty, diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala index a75d21914f3..f80282eba93 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala @@ -53,7 +53,7 @@ object ProcessCompilerData { // for testing environment it's important to take classloader from user jar val nodeCompiler = new NodeCompiler( definitionWithTypes.modelDefinition, - new FragmentParametersDefinitionExtractor(userCodeClassLoader, definitionWithTypes.classDefinitions.all), + new FragmentParametersDefinitionExtractor(userCodeClassLoader), expressionCompiler, userCodeClassLoader, listeners, diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala index 4c502316fff..92daaf69c35 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala @@ -3,7 +3,6 @@ package pl.touk.nussknacker.engine.compile.nodecompilation import cats.data.Validated.{Valid, invalid, invalidNel, valid} import cats.data.{NonEmptyList, Validated, ValidatedNel} import cats.implicits.toTraverseOps -import org.apache.commons.lang3.ClassUtils import pl.touk.nussknacker.engine.api.NodeId import pl.touk.nussknacker.engine.api.context.ProcessCompilationError._ import pl.touk.nussknacker.engine.api.context.{PartSubGraphCompilationError, ProcessCompilationError, ValidationContext} @@ -15,12 +14,9 @@ import pl.touk.nussknacker.engine.api.parameter.{ ValueInputWithDictEditor, ValueInputWithFixedValuesProvided } -import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult, Unknown} +import pl.touk.nussknacker.engine.api.typed.typing.{Typed, Unknown} import pl.touk.nussknacker.engine.api.validation.Validations.validateVariableName import pl.touk.nussknacker.engine.compile.ExpressionCompiler -import pl.touk.nussknacker.engine.compile.nodecompilation.FragmentParameterValidator.permittedTypesForEditors -import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition -import pl.touk.nussknacker.engine.definition.fragment.FragmentParameterTypingParser import pl.touk.nussknacker.engine.graph.expression.Expression import pl.touk.nussknacker.engine.graph.expression.Expression.Language import pl.touk.nussknacker.engine.graph.node.FragmentInputDefinition.{FragmentClazzRef, FragmentParameter} @@ -33,8 +29,6 @@ import pl.touk.nussknacker.engine.graph.node.{ } import pl.touk.nussknacker.engine.language.dictWithLabel.DictKeyWithLabelExpressionParser -import scala.util.Try - object FragmentParameterValidator { val permittedTypesForEditors: List[FragmentClazzRef] = List( @@ -43,10 +37,6 @@ object FragmentParameterValidator { FragmentClazzRef[java.lang.Long] ) -} - -case class FragmentParameterValidator(classDefinitions: Set[ClassDefinition] = Set.empty) { - // This method doesn't fully validate valueEditor (see ValueEditorValidator.validateAndGetEditor comments) def validateAgainstClazzRefAndGetEditor( valueEditor: ParameterValueInput, @@ -157,11 +147,9 @@ case class FragmentParameterValidator(classDefinitions: Set[ClassDefinition] = S validateNonEmptyDictId(dictId, fragmentParameter.name).andThen(_ => dictionaries.get(dictId) match { case Some(dictDefinition) => - val fragmentParameterTypingParser = new FragmentParameterTypingParser(classLoader, classDefinitions) - val fragmentParameterTypingResult = fragmentParameterTypingParser - .parseClassNameToTypingResult( - fragmentParameter.typ.refClazzName - ) + val fragmentParameterTypingResult = fragmentParameter.typ + .toRuntimeClass(classLoader) + .map(Typed(_)) .getOrElse(Unknown) val dictValueType = dictDefinition.valueType(dictId) diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala index f82f638f67b..f27793e2795 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala @@ -14,6 +14,7 @@ import pl.touk.nussknacker.engine.api.parameter.ParameterName import pl.touk.nussknacker.engine.api.process.{ComponentUseCase, Source} import pl.touk.nussknacker.engine.api.typed.ReturningType import pl.touk.nussknacker.engine.api.typed.typing.{TypingResult, Unknown} +import pl.touk.nussknacker.engine.compile.nodecompilation.FragmentParameterValidator.validateParameterNames import pl.touk.nussknacker.engine.compile.nodecompilation.NodeCompiler.NodeCompilationResult import pl.touk.nussknacker.engine.compile.{ ComponentExecutorFactory, @@ -99,8 +100,6 @@ class NodeCompiler( new DynamicNodeValidator(expressionCompiler, globalVariablesPreparer, parametersEvaluator) private val builtInNodeCompiler = new BuiltInNodeCompiler(expressionCompiler) - private val fragmentParameterValidator = FragmentParameterValidator(fragmentDefinitionExtractor.classDefinitions) - def compileSource( nodeData: SourceNodeData )(implicit jobData: JobData, nodeId: NodeId): NodeCompilationResult[Source] = nodeData match { @@ -166,7 +165,7 @@ class NodeCompiler( ) } - val parameterNameValidation = fragmentParameterValidator.validateParameterNames(parameterDefinitions.value) + val parameterNameValidation = validateParameterNames(parameterDefinitions.value) // by relying on name for the field names used on FE, we display the same errors under all fields with the // duplicated name @@ -196,7 +195,7 @@ class NodeCompiler( val fixedValuesErrors = fragmentInputDefinition.parameters .map { param => - fragmentParameterValidator.validateFixedExpressionValues( + FragmentParameterValidator.validateFixedExpressionValues( param, validationContext, expressionCompiler @@ -207,7 +206,7 @@ class NodeCompiler( val dictValueEditorErrors = fragmentInputDefinition.parameters .map { param => - fragmentParameterValidator.validateValueInputWithDictEditor(param, expressionConfig.dictionaries, classLoader) + FragmentParameterValidator.validateValueInputWithDictEditor(param, expressionConfig.dictionaries, classLoader) } .sequence .map(_ => ()) diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala index cca96566d05..70266bba303 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala @@ -45,10 +45,7 @@ class NodeDataValidator(modelData: ModelData) { private val compiler = new NodeCompiler( modelData.modelDefinition, - new FragmentParametersDefinitionExtractor( - modelData.modelClassLoader.classLoader, - modelData.modelDefinitionWithClasses.classDefinitions.all - ), + new FragmentParametersDefinitionExtractor(modelData.modelClassLoader.classLoader), expressionCompiler, modelData.modelClassLoader.classLoader, Seq.empty, diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala index e0bd07073c7..c3c426f20a3 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala @@ -10,7 +10,6 @@ import pl.touk.nussknacker.engine.api.component.{ } import pl.touk.nussknacker.engine.api.{FragmentSpecificData, NodeId} import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess -import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition import pl.touk.nussknacker.engine.definition.component.{ ComponentDefinitionWithImplementation, ComponentImplementationInvoker @@ -19,12 +18,11 @@ import pl.touk.nussknacker.engine.util.MetaDataExtractor class FragmentComponentDefinitionExtractor( classLoader: ClassLoader, - classDefinitions: Set[ClassDefinition], translateGroupName: ComponentGroupName => Option[ComponentGroupName], determineDesignerWideId: ComponentId => DesignerWideComponentId ) { - val parametersExtractor = new FragmentParametersDefinitionExtractor(classLoader, classDefinitions) + val parametersExtractor = new FragmentParametersDefinitionExtractor(classLoader) def extractFragmentComponentDefinition( fragment: CanonicalProcess, diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala deleted file mode 100644 index 989e8c5ea13..00000000000 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala +++ /dev/null @@ -1,45 +0,0 @@ -package pl.touk.nussknacker.engine.definition.fragment - -import org.apache.commons.lang3.ClassUtils -import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult} -import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition - -import scala.util.Try - -class FragmentParameterTypingParser(classLoader: ClassLoader, classDefinitions: Set[ClassDefinition]) { - - def parseClassNameToTypingResult(className: String): Try[TypingResult] = { - /* - TODO: Write this parser in a way that handles arbitrary depth expressions - One should not use regexes for doing so and rather build AST - */ - def resolveInnerClass(simpleClassName: String): TypingResult = - classDefinitions - .find(classDefinition => classDefinition.clazzName.display == simpleClassName) - .fold( - // This is fallback - it may be removed and `ClassNotFound` exception may be thrown here after cleaning up the mess with `FragmentClazzRef` class - Typed(ClassUtils.getClass(classLoader, simpleClassName)) - ) { classDefinition => - classDefinition.clazzName - } - - val mapPattern = "Map\\[(.+),(.+)\\]".r - val listPattern = "List\\[(.+)\\]".r - val setPattern = "Set\\[(.+)\\]".r - - Try(className match { - case mapPattern(x, y) => - val resolvedFirstTypeParam = resolveInnerClass(x) - val resolvedSecondTypeParam = resolveInnerClass(y) - Typed.genericTypeClass[java.util.Map[_, _]](List(resolvedFirstTypeParam, resolvedSecondTypeParam)) - case listPattern(x) => - val resolvedTypeParam = resolveInnerClass(x) - Typed.genericTypeClass[java.util.List[_]](List(resolvedTypeParam)) - case setPattern(x) => - val resolvedTypeParam = resolveInnerClass(x) - Typed.genericTypeClass[java.util.Set[_]](List(resolvedTypeParam)) - case simpleClassName => resolveInnerClass(simpleClassName) - }) - } - -} diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala index b595499009a..79352d1f719 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala @@ -5,7 +5,6 @@ import cats.data.Validated.{Invalid, Valid} import cats.data.{Writer, WriterT} import cats.implicits.{catsKernelStdMonoidForList, toTraverseOps} import cats.instances.list._ -import org.apache.commons.lang3.ClassUtils import pl.touk.nussknacker.engine.api.NodeId import pl.touk.nussknacker.engine.api.component.ParameterConfig import pl.touk.nussknacker.engine.api.context.PartSubGraphCompilationError @@ -14,7 +13,6 @@ import pl.touk.nussknacker.engine.api.definition._ import pl.touk.nussknacker.engine.api.parameter.ValueInputWithDictEditor import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult, Unknown} import pl.touk.nussknacker.engine.compile.nodecompilation.FragmentParameterValidator -import pl.touk.nussknacker.engine.definition.clazz.{ClassDefinition, ClassDefinitionSet} import pl.touk.nussknacker.engine.definition.component.parameter.ParameterData import pl.touk.nussknacker.engine.definition.component.parameter.defaults.{ DefaultValueDeterminerChain, @@ -30,18 +28,11 @@ import pl.touk.nussknacker.engine.graph.expression.Expression.Language import pl.touk.nussknacker.engine.graph.node.FragmentInputDefinition.FragmentParameter import pl.touk.nussknacker.engine.graph.node.{FragmentInput, FragmentInputDefinition} -import scala.util.Try - /* * This class doesn't validate the parameters' initialValue and valueEditor (e.g. values can be of incorrect type), as it would require ExpressionCompiler, ValidationContext and declared dictionaries. * They are validated separately when creating fragment in NodeCompiler.compileSource, but if they are not validated it is not a breaking issue anyway as a process using these incorrect values will fail validation. */ -class FragmentParametersDefinitionExtractor( - classLoader: ClassLoader, - val classDefinitions: Set[ClassDefinition] = Set.empty -) { - - private val fragmentParameterTypingParser = new FragmentParameterTypingParser(classLoader, classDefinitions) +class FragmentParametersDefinitionExtractor(classLoader: ClassLoader) { def extractParametersDefinition( fragmentInput: FragmentInput @@ -82,7 +73,7 @@ class FragmentParametersDefinitionExtractor( val (extractedEditor, validationErrors) = fragmentParameter.valueEditor .map(editor => - FragmentParameterValidator(classDefinitions).validateAgainstClazzRefAndGetEditor( + FragmentParameterValidator.validateAgainstClazzRefAndGetEditor( valueEditor = editor, initialValue = fragmentParameter.initialValue, refClazz = fragmentParameter.typ, @@ -142,9 +133,10 @@ class FragmentParametersDefinitionExtractor( private def getParamTypingResult( fragmentParameter: FragmentParameter - )(implicit nodeId: NodeId): Writer[List[PartSubGraphCompilationError], TypingResult] = { - fragmentParameterTypingParser - .parseClassNameToTypingResult(fragmentParameter.typ.refClazzName) + )(implicit nodeId: NodeId): Writer[List[PartSubGraphCompilationError], TypingResult] = + fragmentParameter.typ + .toRuntimeClass(classLoader) + .map(Typed(_)) .map(Writer.value[List[PartSubGraphCompilationError], TypingResult]) .getOrElse( Writer @@ -153,6 +145,5 @@ class FragmentParametersDefinitionExtractor( List(FragmentParamClassLoadError(fragmentParameter.name, fragmentParameter.typ.refClazzName, nodeId.id)) ) ) - } } diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala index d2c0b815744..16c7a45babd 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala @@ -24,10 +24,7 @@ class ModelDataTestInfoProvider(modelData: ModelData) extends TestInfoProvider w private lazy val nodeCompiler = new NodeCompiler( modelData.modelDefinition, - new FragmentParametersDefinitionExtractor( - modelData.modelClassLoader.classLoader, - modelData.modelDefinitionWithClasses.classDefinitions.all - ), + new FragmentParametersDefinitionExtractor(modelData.modelClassLoader.classLoader), expressionCompiler, modelData.modelClassLoader.classLoader, Seq.empty, diff --git a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala index 93d4f501417..359e7c096fd 100644 --- a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala +++ b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala @@ -23,7 +23,7 @@ class FragmentParameterValidatorTest extends AnyFunSuite with Matchers { forAll(permittedTypesForEditors) { fragmentParameterType: FragmentClazzRef => { val dictId = "someDictId" - val result = FragmentParameterValidator().validateAgainstClazzRefAndGetEditor( + val result = FragmentParameterValidator.validateAgainstClazzRefAndGetEditor( valueEditor = ValueInputWithDictEditor(dictId, allowOtherValue = false), initialValue = None, refClazz = fragmentParameterType, @@ -39,7 +39,7 @@ class FragmentParameterValidatorTest extends AnyFunSuite with Matchers { forAll(permittedTypesForEditors) { fragmentParameterType: FragmentClazzRef => { val fixedValuesList = List(FixedExpressionValue("someExpression", "someLabel")) - val result = FragmentParameterValidator().validateAgainstClazzRefAndGetEditor( + val result = FragmentParameterValidator.validateAgainstClazzRefAndGetEditor( valueEditor = ValueInputWithFixedValuesProvided(fixedValuesList, allowOtherValue = false), initialValue = None, refClazz = fragmentParameterType, @@ -55,7 +55,7 @@ class FragmentParameterValidatorTest extends AnyFunSuite with Matchers { val paramName = ParameterName("someParamName") val invalidParameterType = FragmentClazzRef[java.lang.Double] val nodeIds = Set("someNodeId") - val result = FragmentParameterValidator().validateAgainstClazzRefAndGetEditor( + val result = FragmentParameterValidator.validateAgainstClazzRefAndGetEditor( valueEditor = ValueInputWithDictEditor("someDictId", allowOtherValue = false), initialValue = None, refClazz = invalidParameterType, @@ -71,7 +71,7 @@ class FragmentParameterValidatorTest extends AnyFunSuite with Matchers { val paramName = ParameterName("someParamName") val invalidParameterType = FragmentClazzRef[java.lang.Double] val nodeIds = Set("someNodeId") - val result = FragmentParameterValidator().validateAgainstClazzRefAndGetEditor( + val result = FragmentParameterValidator.validateAgainstClazzRefAndGetEditor( valueEditor = ValueInputWithFixedValuesProvided( List(FixedExpressionValue("someExpression", "someLabel")), allowOtherValue = false diff --git a/utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala b/utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala index 57e7cdd376f..15fcd878c7b 100644 --- a/utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala +++ b/utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala @@ -8,7 +8,6 @@ import pl.touk.nussknacker.engine.api._ import pl.touk.nussknacker.engine.api.component.{ComponentAdditionalConfig, DesignerWideComponentId} import pl.touk.nussknacker.engine.api.namespaces.NamingStrategy import pl.touk.nussknacker.engine.api.process._ -import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition import pl.touk.nussknacker.engine.definition.component.ComponentDefinitionWithImplementation import pl.touk.nussknacker.engine.definition.globalvariables.GlobalVariableDefinitionWithImplementation import pl.touk.nussknacker.engine.definition.model.ModelDefinition @@ -62,8 +61,7 @@ object FlinkProcessCompilerDataFactoryWithTestComponents { override protected def adjustDefinitions( originalModelDefinition: ModelDefinition, - definitionContext: ComponentDefinitionContext, - classDefinitions: Set[ClassDefinition] + definitionContext: ComponentDefinitionContext ): ModelDefinition = { val testComponents = ComponentDefinitionWithImplementation.forList(