Skip to content

Commit

Permalink
Revert "[NU-7164] Add basic parser for fragment input definitions (#7167
Browse files Browse the repository at this point in the history
)" (#7202)

This reverts commit d5154a3.
  • Loading branch information
mslabek authored Nov 21, 2024
1 parent d5154a3 commit 383b4d5
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand All @@ -121,7 +97,7 @@ export const Table = ({ expressionObj, onValueChange, className, fieldErrors }:
}
}, [expressionObj.expression, onValueChange, rawExpression]);

const { defaultTypeOption, orderedTypeOptions } = useTableEditorTypeOptions();
const { defaultTypeOption, orderedTypeOptions } = useTypeOptions<SupportedType>();
const supportedTypes = useMemo(() => orderedTypeOptions.filter(({ value }) => SUPPORTED_TYPES.includes(value)), [orderedTypeOptions]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ interface Props extends Omit<MapVariableProps<FragmentInputParameter>, "readOnly
isEditMode?: boolean;
}

export function useFragmentInputDefinitionTypeOptions() {
export function useTypeOptions<Value = string>() {
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],
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, _)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, _)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class ComponentGroupsPreparerSpec
new BuiltInComponentsDefinitionsPreparer(new ComponentsUiConfig(Map.empty, groupNameMapping)),
new FragmentComponentDefinitionExtractor(
getClass.getClassLoader,
Set.empty,
Some(_),
DesignerWideComponentId.default("Streaming", _)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.{
Expand Down Expand Up @@ -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)
Expand All @@ -63,8 +61,7 @@ abstract class StubbedFlinkProcessCompilerDataFactory(
}

val fragmentParametersDefinitionExtractor = new FragmentParametersDefinitionExtractor(
definitionContext.userCodeClassLoader,
classDefinitions
definitionContext.userCodeClassLoader
)
val fragmentSourceDefinitionPreparer = new StubbedFragmentSourceDefinitionPreparer(
fragmentParametersDefinitionExtractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ object ProcessValidator {

val nodeCompiler = new NodeCompiler(
modelDefinition,
new FragmentParametersDefinitionExtractor(classLoader, definitionWithTypes.classDefinitions.all),
new FragmentParametersDefinitionExtractor(classLoader),
expressionCompiler,
classLoader,
Seq.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -196,7 +195,7 @@ class NodeCompiler(

val fixedValuesErrors = fragmentInputDefinition.parameters
.map { param =>
fragmentParameterValidator.validateFixedExpressionValues(
FragmentParameterValidator.validateFixedExpressionValues(
param,
validationContext,
expressionCompiler
Expand All @@ -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(_ => ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

This file was deleted.

Loading

0 comments on commit 383b4d5

Please sign in to comment.