private void declareOutputEncodingParameter(ParameterGroupDeclaration group, boolean shouldAddSinceMuleVersionModelProperty) { group.addParameter(newParameter(ENCODING_PARAMETER_NAME, "The encoding of the payload that this operation outputs.", shouldAddSinceMuleVersionModelProperty)); }
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 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())); }
public static ParameterGroupDeclaration mockParameters(ParameterizedDeclaration declaration, String groupName, ParameterDeclaration... parameters) { ParameterGroupDeclaration group = mock(ParameterGroupDeclaration.class); when(group.getName()).thenReturn(groupName); when(declaration.getParameterGroups()).thenReturn(asList(group)); when(declaration.getParameterGroup(groupName)).thenReturn(group); List<ParameterDeclaration> params = new ArrayList<>(asList(parameters)); when(group.getParameters()).thenReturn(params); when(declaration.getAllParameters()).thenReturn(params); return group; }
private Map<ParameterDeclaration, Integer> getParts(ParameterGroupDeclaration paramDeclaration) { Map<ParameterDeclaration, Integer> parts = new HashMap<>(); paramDeclaration.getParameters().forEach(param -> getAnnotation(param, ValuePart.class) .ifPresent(part -> parts.put(param, part.order()))); return parts; }
@Test public void exclusiveOptionals() { OperationDeclaration operation = getOperation(extensionDeclaration, "convinceAnimalKiller"); assertThat(operation.getParameterGroups(), hasSize(2)); ParameterGroupDeclaration group = operation.getParameterGroups().get(0); assertThat(group.getName(), equalTo("arguments")); assertThat(group.getExclusiveParameters(), hasSize(1)); ExclusiveParametersDeclaration exclusive = group.getExclusiveParameters().get(0); assertThat(exclusive.isRequiresOne(), is(false)); assertThat(exclusive.getParameterNames(), containsInAnyOrder("argument1", "argument2", "argument3")); }
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 assertParameterPlacement(Pair<ParameterGroupDeclaration, ParameterDeclaration> pair, String groupName, Integer order) { ParameterGroupDeclaration group = pair.getFirst(); assertThat(group.getName(), equalTo(groupName)); assertParameterPlacement(pair.getSecond(), order); }
@Test public void groupLayout() { OperationDeclaration operation = getOperation(extensionDeclaration, "convinceAnimalKiller"); assertThat(operation.getParameterGroups(), hasSize(2)); ParameterGroupDeclaration group = operation.getParameterGroups().get(0); assertThat(group.getLayoutModel().getTabName().get(), is(ARGUMENTS_TAB)); }
/** * Given a list of {@link ParameterGroupDeclaration}, introspect it and finds all the considered parameters with an associated * {@link ValueProvider} * * @param parameterGroups parameter groups to introspect * @return a Map containing all the {@link ParameterGroupDeclaration} with their correspondent {@link ValueProvider} */ private Map<ParameterGroupDeclaration, OfValues> introspectParameterGroups(List<ParameterGroupDeclaration> parameterGroups) { Map<ParameterGroupDeclaration, OfValues> optionResolverEnabledParameters = new HashMap<>(); parameterGroups .forEach(paramGroup -> paramGroup.getModelProperty(ParameterGroupModelProperty.class) .ifPresent(modelProperty -> { AnnotatedElement container = modelProperty.getDescriptor().getContainer(); if (container != null) { OfValues annotation = container.getAnnotation(OfValues.class); if (annotation != null) { optionResolverEnabledParameters.put(paramGroup, annotation); } } })); return optionResolverEnabledParameters; }
@Before public void before() { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getOperations()).thenReturn(singletonList(operation)); when(extensionDeclaration.getMessageSources()).thenReturn(singletonList(source)); when(source.getSuccessCallback()).thenReturn(empty()); when(source.getErrorCallback()).thenReturn(empty()); when(source.getModelProperty(ExtensionTypeDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getModelProperty(ExtensionOperationDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); when(source.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); mockMediaType(operation, false); mockMediaType(source, false); }
private Optional<MetadataKeyIdModelProperty> findMetadataKeyIdInParameters( ComponentDeclaration<? extends ComponentDeclaration> component, String categoryName) { return component.getParameterGroups().stream() .flatMap(g -> g.getParameters().stream()) .filter(p -> getExtensionParameter(p).map(element -> element.isAnnotatedWith(MetadataKeyId.class)).orElse(false)) .map(p -> new MetadataKeyIdModelProperty(p.getType(), p.getName(), categoryName)) .findFirst(); }
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; }
/** * The method will look for parameters of the given {@link ParameterizedDeclaration declaration} and is a parameter or * parameter group annotated with {@link OfValues} if found, a {@link ValueProviderModel} will be added to this element * to communicate that values can be provided. * <p> * Also the {@link ParameterDeclaration parameters} of the {@link ParameterizedDeclaration declaration} will be * enriched. * * @param containerDeclaration declaration to introspect their parameters */ private void enrichContainerModel(ParameterizedDeclaration<?> containerDeclaration) { List<ParameterDeclaration> allParameters = containerDeclaration.getAllParameters(); Map<String, String> parameterNames = getContainerParameterNames(allParameters); Map<ParameterGroupDeclaration, OfValues> dynamicGroupOptions = introspectParameterGroups(containerDeclaration.getParameterGroups()); Map<ParameterDeclaration, OfValues> dynamicOptions = introspectParameters(allParameters); dynamicOptions.forEach((paramDeclaration, resolverClass) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, 1, parameterNames, paramDeclaration.getName())); dynamicGroupOptions .forEach((paramGroupDeclaration, resolverClass) -> getParts(paramGroupDeclaration) .forEach((paramDeclaration, order) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, order, parameterNames, paramGroupDeclaration.getName()))); }
private Optional<MetadataKeyIdModelProperty> findMetadataKeyIdInGroups( ComponentDeclaration<? extends ComponentDeclaration> component, String categoryName) { return component.getParameterGroups().stream() .map(group -> group.getModelProperty(ParameterGroupModelProperty.class).orElse(null)) .filter(Objects::nonNull) .filter(group -> group.getDescriptor().getAnnotatedContainer().isAnnotatedWith(MetadataKeyId.class)) .map(group -> new MetadataKeyIdModelProperty(group.getDescriptor().getMetadataType(), group.getDescriptor().getName(), categoryName)) .findFirst(); }
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 List<ParameterDeclaration> getGroupParameters(ComponentDeclaration declaration) { return declaration.getParameterGroup(DEFAULT_GROUP_NAME).getParameters(); } }
private void declareOutputMimeTypeParameter(ParameterGroupDeclaration group, boolean shouldAddSinceMuleVersionModelProperty) { group.addParameter(newParameter(MIME_TYPE_PARAMETER_NAME, "The mime type of the payload that this operation outputs.", shouldAddSinceMuleVersionModelProperty)); }
/** * The method will look for parameters of the given {@link ParameterizedDeclaration declaration} and is a parameter or * parameter group annotated with {@link OfValues} if found, a {@link ValueProviderModel} will be added to this element * to communicate that values can be provided. * <p> * Also the {@link ParameterDeclaration parameters} of the {@link ParameterizedDeclaration declaration} will be * enriched. * * @param containerDeclaration declaration to introspect their parameters */ private void enrichContainerModel(ParameterizedDeclaration<?> containerDeclaration) { List<ParameterDeclaration> allParameters = containerDeclaration.getAllParameters(); Map<String, String> parameterNames = getContainerParameterNames(allParameters); Map<ParameterGroupDeclaration, OfValues> dynamicGroupOptions = introspectParameterGroups(containerDeclaration.getParameterGroups()); Map<ParameterDeclaration, OfValues> dynamicOptions = introspectParameters(allParameters); dynamicOptions.forEach((paramDeclaration, resolverClass) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, 1, parameterNames, paramDeclaration.getName())); dynamicGroupOptions .forEach((paramGroupDeclaration, resolverClass) -> getParts(paramGroupDeclaration) .forEach((paramDeclaration, order) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, order, parameterNames, paramGroupDeclaration.getName()))); }
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)); }); }