private int addMissingParameterOrders(List<AbstractParameterDeclaration> declarations) { AtomicInteger minOrder = new AtomicInteger(INITIAL_ORDER); Set<Integer> takenOrders = new HashSet<>(); List<AbstractParameterDeclaration> nonOrderedParams = new ArrayList<>(); declarations.forEach(param -> { LayoutModel layoutModel = param.getLayoutModel(); if (layoutModel != null && layoutModel.getOrder().isPresent()) { takenOrders.add(layoutModel.getOrder().get()); minOrder.set(min(layoutModel.getOrder().get(), minOrder.get())); } else { nonOrderedParams.add(param); } }); AtomicInteger currentOrder = new AtomicInteger(INITIAL_ORDER); nonOrderedParams.forEach(param -> param.setLayoutModel( builderFrom(param.getLayoutModel()) .order(getNextOrder(currentOrder, takenOrders)) .build())); return minOrder.get(); }
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); }
private void addQueryModelProperties(OperationDeclaration declaration, Query query) { ParameterDeclaration parameterDeclaration = declaration.getAllParameters() .stream() .filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).isPresent()) .filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).get() .getParameter().isAnnotationPresent(MetadataKeyId.class)) .findFirst() .orElseThrow(() -> new IllegalParameterModelDefinitionException( "Query operation must have a parameter annotated with @MetadataKeyId")); parameterDeclaration.addModelProperty(new QueryParameterModelProperty(query.translator())); parameterDeclaration.setLayoutModel(builderFrom(parameterDeclaration.getLayoutModel()).asQuery().build()); }
.withExpressionSupport(NOT_SUPPORTED) .describedAs(TARGET_PARAMETER_DESCRIPTION) .withLayout(LayoutModel.builder().tabName(ADVANCED_TAB).build()); .withRole(BEHAVIOUR) .withDisplayModel(DisplayModel.builder().displayName(TARGET_VALUE_PARAMETER_DISPLAY_NAME).build()) .withLayout(LayoutModel.builder().tabName(ADVANCED_TAB).build()) .withModelProperty(new TargetModelProperty());
private OperationDeclaration buildUnauthorizeOperation() { OperationDeclaration operation = new OperationDeclaration(UNAUTHORIZE_OPERATION_NAME); operation.setDescription("Deletes all the access token information of a given resource owner id so that it's impossible to " + "execute any operation for that user without doing the authorization dance again"); operation.setBlocking(true); operation.setExecutionType(BLOCKING); operation.setOutput(toDeclaration(voidType)); operation.setOutputAttributes(toDeclaration(voidType)); operation.setRequiresConnection(false); operation.setSupportsStreaming(false); operation.setTransactional(false); operation.addModelProperty(new ComponentExecutorModelProperty((model, params) -> new UnauthorizeOperationExecutor())); ParameterGroupDeclaration group = operation.getParameterGroup(DEFAULT_GROUP_NAME); group.showInDsl(false); ParameterDeclaration parameter = new ParameterDeclaration(RESOURCE_OWNER_ID_PARAMETER_NAME); parameter.setDescription("The id of the resource owner which access should be invalidated"); parameter.setExpressionSupport(SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().build()); parameter.setRequired(false); parameter.setParameterRole(BEHAVIOUR); parameter.setType(stringType, false); group.addParameter(parameter); return operation; }
private void declareTry(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer tryScope = extensionDeclarer.withConstruct("try") .describedAs("Processes the nested list of message processors, " + "within a transaction and with it's own error handler if required."); tryScope.onDefaultParameterGroup() .withOptionalParameter("transactionalAction") .ofType(BaseTypeBuilder.create(JAVA).stringType() .enumOf("INDIFFERENT", "ALWAYS_BEGIN", "BEGIN_OR_JOIN").build()) .defaultingTo("INDIFFERENT") .withExpressionSupport(NOT_SUPPORTED) .withLayout(LayoutModel.builder().tabName("Transactions").build()) .describedAs("The action to take regarding transactions. By default nothing will be done."); tryScope.onDefaultParameterGroup() .withOptionalParameter("transactionType") .ofType(BaseTypeBuilder.create(JAVA).stringType().enumOf("LOCAL", "XA").build()) .defaultingTo("LOCAL") .withExpressionSupport(NOT_SUPPORTED) .describedAs("Transaction type supported. Availability will depend on the runtime version, " + "though LOCAL is always available."); tryScope.withChain(); tryScope.withOptionalComponent("errorHandler") .withAllowedStereotypes(ERROR_HANDLER); }
private int addMissingParameterOrders(List<AbstractParameterDeclaration> declarations) { AtomicInteger minOrder = new AtomicInteger(INITIAL_ORDER); Set<Integer> takenOrders = new HashSet<>(); List<AbstractParameterDeclaration> nonOrderedParams = new ArrayList<>(); declarations.forEach(param -> { LayoutModel layoutModel = param.getLayoutModel(); if (layoutModel != null && layoutModel.getOrder().isPresent()) { takenOrders.add(layoutModel.getOrder().get()); minOrder.set(min(layoutModel.getOrder().get(), minOrder.get())); } else { nonOrderedParams.add(param); } }); AtomicInteger currentOrder = new AtomicInteger(INITIAL_ORDER); nonOrderedParams.forEach(param -> param.setLayoutModel( builderFrom(param.getLayoutModel()) .order(getNextOrder(currentOrder, takenOrders)) .build())); return minOrder.get(); }
private void addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) { ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME); parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(false); parameter.setDefaultValue(property.getDefaultMode()); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build()); MetadataType type = BaseTypeBuilder.create(JAVA).stringType() .id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())) .with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))) .build(); parameter.setType(type, false); sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); }
public static Optional<LayoutModel> parseLayoutAnnotations(AnnotatedElement annotatedElement, LayoutModelBuilder builder) { if (isDisplayAnnotationPresent(annotatedElement)) { doParseLayoutAnnotations(annotatedElement, builder); parsePlacementAnnotation(annotatedElement, builder); return of(builder.build()); } return empty(); }
private static void doParseLayoutAnnotations(AnnotatedElement annotatedElement, LayoutModelBuilder builder) { Password passwordAnnotation = annotatedElement.getAnnotation(Password.class); if (passwordAnnotation != null) { builder.asPassword(); } Text textAnnotation = annotatedElement.getAnnotation(Text.class); if (textAnnotation != null) { builder.asText(); } }
private ParameterDeclaration newParameter(String name, String description) { ParameterDeclaration parameter = new ParameterDeclaration(name); parameter.setRequired(false); parameter.setExpressionSupport(SUPPORTED); parameter.setType(typeLoader.load(String.class), false); parameter.setDescription(description); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB_NAME).build()); return parameter; } }
private static void parsePlacementAnnotation(WithAnnotations annotatedElement, LayoutModelBuilder builder) { java.util.Optional<Placement> placementAnnotation = annotatedElement.getAnnotation(Placement.class); if (placementAnnotation.isPresent()) { Placement placement = placementAnnotation.get(); builder.order(placement.order()).tabName(placement.tab()); } }
public static Optional<LayoutModel> parseLayoutAnnotations(WithAnnotations annotatedElement, LayoutModelBuilder builder) { if (isDisplayAnnotationPresent(annotatedElement)) { doParseLayoutAnnotations(annotatedElement, builder); parsePlacementAnnotation(annotatedElement, builder); return of(builder.build()); } return empty(); }
private void updateGeneralGroupOrder(ParameterizedDeclaration declaration, int minGroupOrder) { Optional<ParameterGroupDeclaration> general = declaration.getParameterGroups().stream() .filter(pg -> ((ParameterGroupDeclaration) pg).getName().equals(DEFAULT_GROUP_NAME)).findFirst(); general.map(ParameterGroupDeclaration::getLayoutModel).flatMap(LayoutModel::getOrder).filter(order -> order > minGroupOrder) .ifPresent(order -> general.get() .setLayoutModel(builderFrom(general.get().getLayoutModel()).order(minGroupOrder - 1).build())); }
private void addQueryModelProperties(OperationDeclaration declaration, Query query) { ParameterDeclaration parameterDeclaration = declaration.getAllParameters() .stream() .filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).isPresent()) .filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).get() .getParameter().isAnnotationPresent(MetadataKeyId.class)) .findFirst() .orElseThrow(() -> new IllegalParameterModelDefinitionException( "Query operation must have a parameter annotated with @MetadataKeyId")); parameterDeclaration.addModelProperty(new QueryParameterModelProperty(query.translator())); parameterDeclaration.setLayoutModel(builderFrom(parameterDeclaration.getLayoutModel()).asQuery().build()); }
private static void doParseLayoutAnnotations(WithAnnotations annotatedElement, LayoutModelBuilder builder) { java.util.Optional<Password> passwordAnnotation = annotatedElement.getAnnotation(Password.class); if (passwordAnnotation.isPresent()) { builder.asPassword(); } java.util.Optional<Text> textAnnotation = annotatedElement.getAnnotation(Text.class); if (textAnnotation.isPresent()) { builder.asText(); } }
/** * 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 OperationDeclaration buildUnauthorizeOperation() { OperationDeclaration operation = new OperationDeclaration(UNAUTHORIZE_OPERATION_NAME); operation.setDescription("Deletes all the access token information of a given resource owner id so that it's impossible to " + "execute any operation for that user without doing the authorization dance again"); operation.setBlocking(true); operation.setExecutionType(BLOCKING); operation.setOutput(toDeclaration(voidType)); operation.setOutputAttributes(toDeclaration(voidType)); operation.setRequiresConnection(false); operation.setSupportsStreaming(false); operation.setTransactional(false); operation.addModelProperty(new ComponentExecutorModelProperty((model, params) -> new UnauthorizeOperationExecutor())); ParameterGroupDeclaration group = operation.getParameterGroup(DEFAULT_GROUP_NAME); group.showInDsl(false); ParameterDeclaration parameter = new ParameterDeclaration(RESOURCE_OWNER_ID_PARAMETER_NAME); parameter.setDescription("The id of the resource owner which access should be invalidated"); parameter.setExpressionSupport(SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().build()); parameter.setRequired(false); parameter.setParameterRole(BEHAVIOUR); parameter.setType(stringType, false); group.addParameter(parameter); return operation; }