Search in sources :

Example 1 with MetadataKeysContainerBuilder

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

the class MetadataKeysDelegate method getMetadataKeys.

MetadataResult<MetadataKeysContainer> getMetadataKeys(MetadataContext context, Object partialKey, ReflectionCache reflectionCache) {
    final TypeKeysResolver keyResolver = resolverFactory.getKeyResolver();
    final String componentResolverName = keyResolver.getCategoryName();
    final MetadataKeysContainerBuilder keysContainer = MetadataKeysContainerBuilder.getInstance();
    if (keyParts.isEmpty()) {
        return success(keysContainer.add(componentResolverName, ImmutableSet.of(new NullMetadataKey())).build());
    }
    try {
        final Map<Integer, ParameterModel> partsByOrder = getPartOrderMapping(keyParts);
        Set<MetadataKey> metadataKeys;
        if (keyResolver instanceof PartialTypeKeysResolver && hasInitialLevel(partialKey, partsByOrder, reflectionCache)) {
            metadataKeys = singleton(((PartialTypeKeysResolver) keyResolver).resolveChilds(context, partialKey));
        } else {
            metadataKeys = keyResolver.getKeys(context);
        }
        final Set<MetadataKey> enrichedMetadataKeys = metadataKeys.stream().map(metadataKey -> cloneAndEnrichMetadataKey(metadataKey, partsByOrder)).map(MetadataKeyBuilder::build).collect(toSet());
        keysContainer.add(componentResolverName, enrichedMetadataKeys);
        return success(keysContainer.build());
    } catch (Exception e) {
        return failure(newFailure(e).onKeys());
    }
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeysContainerBuilder(org.mule.runtime.api.metadata.MetadataKeysContainerBuilder) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver) TypeKeysResolver(org.mule.runtime.api.metadata.resolving.TypeKeysResolver) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) PartialTypeKeysResolver(org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver)

Example 2 with MetadataKeysContainerBuilder

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

the class ConfigurationProviderToolingAdapter method getMetadataKeys.

/**
 * {@inheritDoc}
 */
@Override
public MetadataResult<MetadataKeysContainer> getMetadataKeys() throws MetadataResolvingException {
    MetadataKeysContainerBuilder keysBuilder = MetadataKeysContainerBuilder.getInstance();
    try {
        MetadataContext metadataContext = getMetadataContext();
        addComponentKeys(getConfigurationModel().getOperationModels(), metadataContext, keysBuilder);
        addComponentKeys(getConfigurationModel().getSourceModels(), metadataContext, keysBuilder);
        metadataContext.dispose();
    } catch (Exception e) {
        return failure(newFailure(e).onKeys());
    }
    return success(keysBuilder.build());
}
Also used : MetadataKeysContainerBuilder(org.mule.runtime.api.metadata.MetadataKeysContainerBuilder) DefaultMetadataContext(org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext) MetadataContext(org.mule.runtime.api.metadata.MetadataContext) ValueResolvingException(org.mule.runtime.extension.api.values.ValueResolvingException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Example 3 with MetadataKeysContainerBuilder

use of org.mule.runtime.api.metadata.MetadataKeysContainerBuilder 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)

Aggregations

MetadataKeysContainerBuilder (org.mule.runtime.api.metadata.MetadataKeysContainerBuilder)3 MetadataKey (org.mule.runtime.api.metadata.MetadataKey)2 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 MetadataContext (org.mule.runtime.api.metadata.MetadataContext)1 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 PartialTypeKeysResolver (org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver)1 QueryEntityResolver (org.mule.runtime.api.metadata.resolving.QueryEntityResolver)1 TypeKeysResolver (org.mule.runtime.api.metadata.resolving.TypeKeysResolver)1 NullMetadataKey (org.mule.runtime.extension.api.metadata.NullMetadataKey)1 ValueResolvingException (org.mule.runtime.extension.api.values.ValueResolvingException)1 DefaultMetadataContext (org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext)1