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();
}
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());
}
}
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));
}
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);
}
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"));
}
Aggregations