return parameterRequired ? parameterizedDeclarer.onDefaultParameterGroup().withRequiredParameter(parameterName) : parameterizedDeclarer.onDefaultParameterGroup().withOptionalParameter(parameterName) .defaultingTo(parameterDefaultValue);
@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()); } }
if (declarer.getDeclaration().getModelProperty(ParameterGroupModelProperty.class).isPresent()) { throw new IllegalParameterModelDefinitionException(format("Parameter group '%s' has already been declared on %s '%s'", groupName, .getName())); } else { declarer.withModelProperty(new ParameterGroupModelProperty( new ParameterGroupDescriptor(groupName, type, groupParameter.getType() .collect(toSet()); declarer.withExclusiveOptionals(optionalParamNames, annotation.isOneRequired()); }); declarer.withDslInlineRepresentation(groupAnnotation.showInDsl()); .ifPresent(displayName -> declarer.withDisplayModel(DisplayModel.builder().displayName(displayName.value()).build())); declarer.withModelProperty(new ExtensionParameterDescriptorModelProperty(groupParameter));
/** * 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); } }
private void declareAsync(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer async = extensionDeclarer.withConstruct("async") .describedAs("Processes the nested list of message processors asynchronously using a thread pool"); async.withChain(); async.onDefaultParameterGroup() .withOptionalParameter("name") .withExpressionSupport(NOT_SUPPORTED) .ofType(typeLoader.load(String.class)) .describedAs("Name that will be used to name the async scheduler"); }
/** * 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)); }
.withDslInlineRepresentation(true) .withLayout(getLayout(1)); .build(); message.withOptionalParameter(BODY_PARAM).ofDynamicType(binaryType) .withRole(PRIMARY_CONTENT) .defaultingTo(PAYLOAD) .build()); message.withOptionalParameter(HEADERS_PARAM).ofDynamicType(binaryType) .withRole(CONTENT) .withLayout(getLayout(4)) .build()); message.withOptionalParameter(ATTACHMENTS_PARAM).ofDynamicType(attachments) .withRole(CONTENT) .withLayout(getLayout(5)) .build()); operation.onParameterGroup(TRANSPORT_GROUP).withLayout(getLayout(2)) .withOptionalParameter(TRANSPORT_HEADERS_PARAM) .ofType(TYPE_BUILDER.objectType() .openWith(loader.load(String.class))
private void parseExclusiveOptional(ExtensionParameter extensionParameter, ParameterGroupDeclarer parameterGroupDeclarer, ParameterDeclarer parameter) { ParameterGroupDeclaration groupDeclaration = (ParameterGroupDeclaration) parameterGroupDeclarer.getDeclaration(); List<ExclusiveParametersDeclaration> exclusiveParameters = groupDeclaration.getExclusiveParameters(); exclusiveParameters.stream() .filter(group -> group.getParameterNames().contains(extensionParameter.getAlias())) .findFirst() .ifPresent(exclusiveParametersDeclaration -> { ExclusiveParametersModel exclusiveParametersModel = new ImmutableExclusiveParametersModel(exclusiveParametersDeclaration.getParameterNames(), exclusiveParametersDeclaration.isRequiresOne()); parameter.withModelProperty(new ExclusiveOptionalModelProperty(exclusiveParametersModel)); }); }
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(); }
private void declareOnErrorRoute(ClassTypeLoader typeLoader, NestedRouteDeclarer onError) { onError.withChain(); onError.onDefaultParameterGroup() .withOptionalParameter("when") .ofType(typeLoader.load(String.class)) .describedAs("The expression that will be evaluated to determine if this exception strategy should be executed. " + "This should always be a boolean expression."); onError.onDefaultParameterGroup() .withOptionalParameter("type") .ofType(BaseTypeBuilder.create(JAVA).stringType() .enumOf("ANY", "REDELIVERY_EXHAUSTED", "TRANSFORMATION", "EXPRESSION", "SECURITY", "CLIENT_SECURITY", "SERVER_SECURITY", "ROUTING", "CONNECTIVITY", "RETRY_EXHAUSTED", "TIMEOUT") .build()) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The full name of the error type to match against or a comma separated list of full names, " + "to match against any of them."); onError.onDefaultParameterGroup() .withOptionalParameter("logException") .ofType(typeLoader.load(boolean.class)) .defaultingTo(true) .describedAs("Determines whether the handled exception will be logged to its standard logger in the ERROR " + "level before being handled. Default is true."); onError.onDefaultParameterGroup() .withOptionalParameter("enableNotifications") .ofType(typeLoader.load(boolean.class)) .defaultingTo(true) .withExpressionSupport(NOT_SUPPORTED) .describedAs("Determines whether ExceptionNotifications will be fired from this strategy when an exception occurs." + " Default is true."); }
private void parseExclusiveOptional(ExtensionParameter extensionParameter, ParameterGroupDeclarer parameterGroupDeclarer, ParameterDeclarer parameter) { ParameterGroupDeclaration groupDeclaration = (ParameterGroupDeclaration) parameterGroupDeclarer.getDeclaration(); List<ExclusiveParametersDeclaration> exclusiveParameters = groupDeclaration.getExclusiveParameters(); exclusiveParameters.stream() .filter(group -> group.getParameterNames().contains(extensionParameter.getAlias())) .findFirst() .ifPresent(exclusiveParametersDeclaration -> { ExclusiveParametersModel exclusiveParametersModel = new ImmutableExclusiveParametersModel(exclusiveParametersDeclaration.getParameterNames(), exclusiveParametersDeclaration.isRequiresOne()); parameter.withModelProperty(new ExclusiveOptionalModelProperty(exclusiveParametersModel)); }); }
parameter = groupDeclarer.withRequiredParameter(extensionParameter.getAlias()); } else { parameter = groupDeclarer.withOptionalParameter(extensionParameter.getAlias()) .defaultingTo(extensionParameter.defaultValue().isPresent() ? extensionParameter.defaultValue().get() : null);
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 declareUntilSuccessful(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer untilSuccessful = extensionDeclarer.withConstruct("untilSuccessful") .describedAs("Attempts to route a message to the message processor it contains in an asynchronous manner. " + "Routing is considered successful if no exception has been raised and, optionally, if the response matches an expression"); untilSuccessful.withChain(); untilSuccessful.onDefaultParameterGroup() .withOptionalParameter("maxRetries") .ofType(typeLoader.load(Integer.class)) .defaultingTo(5) .withExpressionSupport(NOT_SUPPORTED) .describedAs("Specifies the maximum number of processing retries that will be performed."); untilSuccessful.onDefaultParameterGroup() .withOptionalParameter("millisBetweenRetries") .ofType(typeLoader.load(Integer.class)) .defaultingTo(60000) .withExpressionSupport(NOT_SUPPORTED) .describedAs("Specifies the minimum time interval between two process retries in milliseconds.\n" + " The actual time interval depends on the previous execution but should not exceed twice this number.\n" + " Default value is 60000 (one minute)"); }
@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()); } }
if (declarer.getDeclaration().getModelProperty(ParameterGroupModelProperty.class).isPresent()) { throw new IllegalParameterModelDefinitionException(format("Parameter group '%s' has already been declared on %s '%s'", groupName, .getName())); } else { declarer.withModelProperty(new ParameterGroupModelProperty( new ParameterGroupDescriptor(groupName, type, groupParameter.getType() .collect(toSet()); declarer.withExclusiveOptionals(optionalParamNames, annotation.isOneRequired()); }); declarer.withDslInlineRepresentation(groupAnnotation.showInDsl()); .ifPresent(displayName -> declarer.withDisplayModel(DisplayModel.builder().displayName(displayName.value()).build())); declarer.withModelProperty(new ExtensionParameterDescriptorModelProperty(groupParameter));
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."); }
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 declareForEach(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer forEach = extensionDeclarer.withConstruct("foreach") .describedAs("The foreach Processor allows iterating over a collection payload, or any collection obtained by an expression," + " generating a message for each element."); forEach.withChain(); forEach.onDefaultParameterGroup() .withOptionalParameter("collection") .ofType(typeLoader.load(new TypeToken<Iterable<Object>>() { }.getType())) .defaultingTo("#[payload]") .withExpressionSupport(REQUIRED) .describedAs("An expression to that returns a java collection, object array, map or DOM nodes."); forEach.onDefaultParameterGroup() .withOptionalParameter("batchSize") .ofType(typeLoader.load(Integer.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("An expression to that returns a java collection, object array, map or DOM nodes."); forEach.onDefaultParameterGroup() .withOptionalParameter("rootMessageVariableName") .ofType(typeLoader.load(String.class)) .defaultingTo("rootMessage") .withExpressionSupport(NOT_SUPPORTED) .describedAs("Property name where the parent message is stored."); forEach.onDefaultParameterGroup() .withOptionalParameter("counterVariableName") .ofType(typeLoader.load(String.class)) .defaultingTo("counter") .withExpressionSupport(NOT_SUPPORTED) .describedAs("Property name used to store the number of message being iterated."); }
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"); }