private void extractParameter(ParameterizedDeclarer parameterizedDeclarer, ComponentModel param, ParameterRole role) { Map<String, String> parameters = param.getParameters(); String receivedInputType = parameters.get(TYPE_ATTRIBUTE); final LayoutModel.LayoutModelBuilder layoutModelBuilder = builder(); if (parseBoolean(parameters.get(PASSWORD))) { layoutModelBuilder.asPassword(); } layoutModelBuilder.order(getOrder(parameters.get(ORDER_ATTRIBUTE))); layoutModelBuilder.tabName(getTab(parameters.get(TAB_ATTRIBUTE))); final DisplayModel displayModel = getDisplayModel(param); MetadataType parameterType = extractType(receivedInputType); ParameterDeclarer parameterDeclarer = getParameterDeclarer(parameterizedDeclarer, parameters); parameterDeclarer.describedAs(getDescription(param)) .withLayout(layoutModelBuilder.build()) .withDisplayModel(displayModel) .withRole(role) .ofType(parameterType); }
@Override public void accept(ExtensionDeclarer extensionDeclarer, ExtensionLoadingContext context) { ConfigurationDeclarer configurationDeclarer = extensionDeclarer.named(EXTENSION_NAME) .describedAs("Crafted Config Properties Extension") .onVersion("1.0.0") .withCategory(COMMUNITY) .fromVendor("Mulesoft") .withConfig("secure-configuration-properties"); ParameterGroupDeclarer defaultParameterGroup = configurationDeclarer.onDefaultParameterGroup(); defaultParameterGroup .withRequiredParameter("file").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); ParameterGroupDeclarer parameterGroupDeclarer = configurationDeclarer.onParameterGroup("encrypt").withDslInlineRepresentation(true); parameterGroupDeclarer.withRequiredParameter("algorithm").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); parameterGroupDeclarer.withRequiredParameter("mode").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); } }
/** * Contributes to a {@link ParameterDeclarer} if the type of the given parameter is one of the registered * as {@link StackableType wrapper types} * * @param parameter {@link ExtensionParameter} with introspected information of the Java parameter * @param declarer declarer to be enriched * @param declarationContext context of the parameter to be declared */ @Override public void contribute(ExtensionParameter parameter, ParameterDeclarer declarer, ParameterDeclarationContext declarationContext) { LazyValue<StackedTypesModelProperty.Builder> stackedTypesModelPropertyBuilder = new LazyValue<>(StackedTypesModelProperty::builder); doContribute(parameter, declarationContext, parameter.getType(), stackedTypesModelPropertyBuilder); declarer.ofType(parameter.getType().asMetadataType()); stackedTypesModelPropertyBuilder.ifComputed(builder -> declarer.withModelProperty(builder.build())); }
/** * Given the Invoke Operation Declarer declares all the parameters that the operation has. * * @param operation the invoke operation declarer. */ private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) { TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader); ParameterGroupDeclarer group = operation .onParameterGroup(KEYS_GROUP) .withModelProperty( new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType))); StringType stringType = TYPE_BUILDER.stringType().build(); group.withRequiredParameter(SERVICE_PARAM) .withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache) .get())) .ofType(stringType) .withModelProperty(new MetadataKeyPartModelProperty(1)) .withLayout(getLayout(1)); group.withRequiredParameter(OPERATION_PARAM) .ofType(stringType) .withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache) .get())) .withModelProperty(new MetadataKeyPartModelProperty(2)) .withLayout(getLayout(2)); }
parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription()); parseParameterRole(extensionParameter, parameter); parseExpressionSupport(extensionParameter, parameter);
/** * Declares a new connection provider for a configuration given a {@link SoapServiceProviderWrapper} declaration. * * @param configDeclarer the configuration declarer that will own the provider * @param provider a {@link SoapServiceProviderWrapper} that describes the {@link SoapServiceProvider} Type. * @param hasCustomTransports if declares custom transport or not. */ public void declare(ConfigurationDeclarer configDeclarer, SoapServiceProviderWrapper provider, boolean hasCustomTransports) { String description = provider.getDescription(); // Declares the Service Provider as a Connection Provider. ConnectionProviderDeclarer providerDeclarer = configDeclarer.withConnectionProvider(provider.getAlias()) .describedAs(description) .withModelProperty(new ConnectionTypeModelProperty(ForwardingSoapClient.class)) //TODO - MULE-14311 - Make loader work in compile time .withModelProperty(new ImplementingTypeModelProperty(provider.getDeclaringClass().get())) .withConnectionManagementType(POOLING) .supportsConnectivityTesting(provider.supportsConnectivityTesting()); ParameterDeclarationContext context = new ParameterDeclarationContext("Service Provider", providerDeclarer.getDeclaration()); parametersLoader.declare(providerDeclarer, provider.getParameters(), context); if (hasCustomTransports) { providerDeclarer.onParameterGroup(TRANSPORT_GROUP) .withRequiredParameter(TRANSPORT_PARAM) .withDisplayModel(DisplayModel.builder().displayName(TRANSPORT_GROUP).build()) .ofType(typeLoader.load(MessageDispatcherProvider.class)) .withLayout(LayoutModel.builder().order(1).tabName(TRANSPORT).build()) .withExpressionSupport(NOT_SUPPORTED); } }
@Override public void accept(ExtensionDeclarer extensionDeclarer, ExtensionLoadingContext context) { ConfigurationDeclarer configurationDeclarer = extensionDeclarer.named(EXTENSION_NAME) .describedAs("Crafted Config Properties Extension") .onVersion("1.0.0") .withCategory(COMMUNITY) .fromVendor("Mulesoft") .withConfig("secure-configuration-properties"); ParameterGroupDeclarer defaultParameterGroup = configurationDeclarer.onDefaultParameterGroup(); defaultParameterGroup .withRequiredParameter("file").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); ParameterGroupDeclarer parameterGroupDeclarer = configurationDeclarer.onParameterGroup("encrypt").withDslInlineRepresentation(true); parameterGroupDeclarer.withRequiredParameter("algorithm").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); parameterGroupDeclarer.withRequiredParameter("mode").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); } }
/** * Contributes to a {@link ParameterDeclarer} if the type of the given parameter is one of the registered * as {@link StackableType wrapper types} * * @param parameter {@link ExtensionParameter} with introspected information of the Java parameter * @param declarer declarer to be enriched * @param declarationContext context of the parameter to be declared */ @Override public void contribute(ExtensionParameter parameter, ParameterDeclarer declarer, ParameterDeclarationContext declarationContext) { LazyValue<StackedTypesModelProperty.Builder> stackedTypesModelPropertyBuilder = new LazyValue<>(StackedTypesModelProperty::builder); doContribute(parameter, declarationContext, parameter.getType(), stackedTypesModelPropertyBuilder); declarer.ofType(parameter.getType().asMetadataType()); stackedTypesModelPropertyBuilder.ifComputed(builder -> declarer.withModelProperty(builder.build())); }
private void declareChoice(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer choice = extensionDeclarer.withConstruct("choice") .describedAs("Sends the message to the first message processor whose condition has been satisfied. " + "If no conditions were satisfied, sends to the configured default message processor if configured, " + "or throws an exception if not configured.") .withErrorModel(routingError); NestedRouteDeclarer when = choice.withRoute("when").withMinOccurs(1); when.withChain(); when.onDefaultParameterGroup() .withRequiredParameter("expression") .ofType(typeLoader.load(boolean.class)) .describedAs("The expression to evaluate."); choice.withRoute("otherwise").withMaxOccurs(1).withChain(); }
parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription()); parseParameterRole(extensionParameter, parameter); parseExpressionSupport(extensionParameter, parameter);
private void declareConfigurationProperties(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer configuration = extensionDeclarer.withConstruct("configurationProperties") .allowingTopLevelDefinition() .withStereotype(APP_CONFIG) .describedAs("References a file with configuration properties. Each property has a key and a value. \n" + "The key can be referenced from the mule configuration files using the following semantics: \n" + "${key_name}. This allows to externalize configuration and change it based\n" + "on the environment the application is being deployed to."); configuration.onDefaultParameterGroup() .withRequiredParameter("file") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .withDisplayModel(DisplayModel.builder().path(new PathModel(FILE, false, EMBEDDED, new String[] {"properties"})).build()) .describedAs(" The location of the file with the configuration properties to use. " + "It may be a location in the classpath or an absolute location. The file location\n" + " value may also contains references to properties that will only be resolved based on " + "system properties or properties set at deployment time."); }
private void declareFlowRef(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer flowRef = extensionDeclarer.withOperation("flowRef") .describedAs("Allows a \u0027flow\u0027 to be referenced such that the message processing will continue in the referenced flow " + "before returning. Message processing in the referenced \u0027flow\u0027 will occur within the context of the " + "referenced flow and will therefore use its exception strategy etc.") .withErrorModel(routingError); flowRef.withOutput().ofType(BaseTypeBuilder.create(JAVA).anyType().build()); flowRef.withOutputAttributes().ofType(BaseTypeBuilder.create(JAVA).anyType().build()); flowRef.onDefaultParameterGroup() .withRequiredParameter("name") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The name of the flow to call"); }
private void declareRaiseError(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer raiseError = extensionDeclarer.withOperation("raiseError") .describedAs("Throws an error with the specified type and description."); raiseError.withOutput().ofType(typeLoader.load(void.class)); raiseError.withOutputAttributes().ofType(typeLoader.load(void.class)); raiseError.onDefaultParameterGroup() .withRequiredParameter("type") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The error type to raise."); raiseError.onDefaultParameterGroup() .withOptionalParameter("description") .ofType(typeLoader.load(String.class)) .describedAs("The description of this error."); }
.ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The name of the error handler to reuse.");
private void declareScheduler(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { SourceDeclarer scheduler = extensionDeclarer.withMessageSource("scheduler") .hasResponse(false) .describedAs("Source that schedules periodic execution of a flow."); scheduler.withOutput().ofType(typeLoader.load(Object.class)); scheduler.withOutputAttributes().ofType(typeLoader.load(Object.class)); MetadataType baseSchedulingStrategy = typeLoader.load(Scheduler.class); scheduler.onDefaultParameterGroup() .withRequiredParameter("schedulingStrategy") .ofType(baseSchedulingStrategy) .withExpressionSupport(NOT_SUPPORTED); MetadataType fixedFrequencyScheduler = typeLoader.load(FixedFrequencyScheduler.class); MetadataType cronScheduler = typeLoader.load(CronScheduler.class); extensionDeclarer.withSubType(baseSchedulingStrategy, fixedFrequencyScheduler); extensionDeclarer.withSubType(baseSchedulingStrategy, cronScheduler); // workaround for an "org.mule.runtime" package and still export the type in the extension model extensionDeclarer.getDeclaration().addType((ObjectType) baseSchedulingStrategy); extensionDeclarer.getDeclaration().addType((ObjectType) fixedFrequencyScheduler); extensionDeclarer.getDeclaration().addType((ObjectType) cronScheduler); }
ParameterGroupDeclarer parameterGroupDeclarer = springConfig.onDefaultParameterGroup(); parameterGroupDeclarer.withRequiredParameter("files").withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeLoader.load(String.class)); .describedAs("This is the security provider type that is used to configure spring-security related functionality."); securityManager.onDefaultParameterGroup().withRequiredParameter("providers").withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeBuilder.arrayType().of(typeLoader.load(SecurityProvider.class)).build()); authorizationFilter.onDefaultParameterGroup().withRequiredParameter("requiredAuthorities") .withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeLoader.load(String.class));
private void declareSetPayload(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer setPayload = extensionDeclarer.withOperation("setPayload") .describedAs("A transformer that sets the payload with the provided value."); setPayload.withOutput().ofType(typeLoader.load(void.class)); setPayload.withOutputAttributes().ofType(typeLoader.load(void.class)); setPayload.onDefaultParameterGroup() .withOptionalParameter("encoding") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The encoding of the value assigned to the payload."); setPayload.onDefaultParameterGroup() .withRequiredParameter("value") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The value to be set on the payload. Supports expressions."); setPayload.onDefaultParameterGroup() .withOptionalParameter("mimeType") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The mime type, e.g. text/plain or application/json"); }
private void declareSetVariable(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer setVariable = extensionDeclarer.withOperation("setVariable") .describedAs("A processor that adds variables."); setVariable.withOutput().ofType(typeLoader.load(void.class)); setVariable.withOutputAttributes().ofType(typeLoader.load(void.class)); setVariable.onDefaultParameterGroup() .withOptionalParameter("variableName") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The variable name."); setVariable.onDefaultParameterGroup() .withRequiredParameter("value") .ofType(typeLoader.load(String.class)) .withExpressionSupport(SUPPORTED) .describedAs("The variable value."); setVariable.onDefaultParameterGroup() .withOptionalParameter("encoding") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The encoding of the value assigned to the payload."); setVariable.onDefaultParameterGroup() .withOptionalParameter("mimeType") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The mime type, e.g. text/plain or application/json"); }