Search in sources :

Example 11 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class InvokeKeysResolver method getKeys.

/**
 * {@inheritDoc}
 *
 * Resolves multi-level metadata keys with the services available to hit and for each of the services exposes all
 * available operations.
 */
@Override
public Set<MetadataKey> getKeys(MetadataContext context) throws MetadataResolvingException, ConnectionException {
    ForwardingSoapClient connection = getConnection(context);
    ImmutableSet.Builder<MetadataKey> keys = ImmutableSet.builder();
    connection.getAllWebServices().forEach(ws -> keys.add(buildServiceKey(connection, ws)));
    return keys.build();
}
Also used : ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) ImmutableSet(com.google.common.collect.ImmutableSet) MetadataKey(org.mule.runtime.api.metadata.MetadataKey)

Example 12 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class EntityMetadataMediator method getEntityKeys.

public MetadataResult<MetadataKeysContainer> getEntityKeys(MetadataContext context) {
    try {
        QueryEntityResolver queryEntityResolver = resolverFactory.getQueryEntityResolver();
        Set<MetadataKey> entityKeys = queryEntityResolver.getEntityKeys(context);
        final MetadataKeysContainerBuilder keyBuilder = MetadataKeysContainerBuilder.getInstance();
        if (entityKeys.stream().anyMatch(key -> key.getChilds().size() > 0)) {
            return failure(newFailure().withMessage("Error retrieving entity keys, Only single level keys are supported for entity metadata").withReason("There are at least one key that contains childs").withFailureCode(INVALID_METADATA_KEY).onKeys());
        }
        return success(keyBuilder.add(queryEntityResolver.getResolverName(), entityKeys).build());
    } catch (Exception e) {
        return failure(newFailure(e).onKeys());
    }
}
Also used : QueryEntityResolver(org.mule.runtime.api.metadata.resolving.QueryEntityResolver) MetadataKeysContainerBuilder(org.mule.runtime.api.metadata.MetadataKeysContainerBuilder) MetadataKey(org.mule.runtime.api.metadata.MetadataKey)

Example 13 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataExtensionFunctionalTestCase method assertResolvedKey.

protected <T extends ComponentModel> void assertResolvedKey(MetadataResult<ComponentMetadataDescriptor<T>> result, MetadataKey metadataKey) {
    assertThat(result.get().getMetadataAttributes().getKey().isPresent(), is(true));
    MetadataKey resultKey = result.get().getMetadataAttributes().getKey().get();
    assertSameKey(metadataKey, resultKey);
    MetadataKey child = metadataKey.getChilds().stream().findFirst().orElseGet(() -> null);
    MetadataKey otherChild = resultKey.getChilds().stream().findFirst().orElseGet(() -> null);
    while (child != null && otherChild != null) {
        assertSameKey(child, otherChild);
        child = child.getChilds().stream().findFirst().orElseGet(() -> null);
        otherChild = otherChild.getChilds().stream().findFirst().orElseGet(() -> null);
    }
    assertThat(child == null && otherChild == null, is(true));
}
Also used : MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey)

Example 14 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataKeyIdObjectResolverTestCase method failToResolveWithMultipleChildren.

@Test
public void failToResolveWithMultipleChildren() throws MetadataResolvingException {
    exception.expect(MetadataResolvingException.class);
    exception.expectMessage("MetadataKey used for Metadata resolution must only have one child per level.");
    final MetadataKey invalidMetadataKey = newKey(AMERICA, CONTINENT).withChild(newKey(USA, COUNTRY).withChild(newKey(SFO, CITY)).withChild(newKey(NY, CITY))).build();
    setParameters(continentParam, countryParam, cityParam);
    setMetadataKeyIdModelProperty(LocationKey.class);
    keyIdObjectResolver = new MetadataKeyIdObjectResolver(componentModel);
    keyIdObjectResolver.resolve(invalidMetadataKey);
}
Also used : MetadataKey(org.mule.runtime.api.metadata.MetadataKey) Test(org.junit.Test)

Example 15 with MetadataKey

use of org.mule.runtime.api.metadata.MetadataKey in project mule by mulesoft.

the class MetadataKeyIdObjectResolverTestCase method resolveDsql.

@Test
public void resolveDsql() throws MetadataResolvingException {
    ParameterModel queryParam = mock(ParameterModel.class);
    when(queryParam.getModelProperty(QueryParameterModelProperty.class)).thenReturn(Optional.of(new QueryParameterModelProperty(QueryTranslator.class)));
    mockMetadataKeyModelProp(queryParam, 1);
    setParameters(queryParam);
    setMetadataKeyIdModelProperty(String.class);
    MetadataKey dsqlKey = newKey("dsql:SELECT id FROM Circle WHERE (diameter < 18)").build();
    keyIdObjectResolver = new MetadataKeyIdObjectResolver(componentModel);
    final Object resolvedKey = keyIdObjectResolver.resolve(dsqlKey);
    assertThat(resolvedKey, is(instanceOf(DsqlQuery.class)));
    DsqlQuery query = (DsqlQuery) resolvedKey;
    assertThat(query.getFields(), hasSize(1));
    assertThat(query.getType().getName(), is("Circle"));
}
Also used : QueryParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.QueryParameterModelProperty) DsqlQuery(org.mule.runtime.extension.api.dsql.DsqlQuery) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) Test(org.junit.Test)

Aggregations

MetadataKey (org.mule.runtime.api.metadata.MetadataKey)19 Test (org.junit.Test)13 ComponentMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor)9 NullMetadataKey (org.mule.runtime.extension.api.metadata.NullMetadataKey)7 MetadataType (org.mule.metadata.api.model.MetadataType)5 MetadataKeysContainer (org.mule.runtime.api.metadata.MetadataKeysContainer)4 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)3 ExtensionsTestUtils.toMetadataType (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Set (java.util.Set)2 ArrayType (org.mule.metadata.api.model.ArrayType)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 TypeKeysResolver (org.mule.runtime.api.metadata.resolving.TypeKeysResolver)2 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 BiConsumer (java.util.function.BiConsumer)1 Collectors.joining (java.util.stream.Collectors.joining)1 Inject (javax.inject.Inject)1