Search in sources :

Example 1 with NullMetadataKey

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

the class MetadataKeyIdObjectResolver method reconstructKeyFromType.

/**
 * Given a {@link Object} representing the resolved value for a {@link MetadataKey}, generates the {@link MetadataKey} object.
 *
 * @param resolvedKey
 * @return {@link MetadataKey} reconstructed from the resolved object key
 * @throws MetadataResolvingException
 */
MetadataKey reconstructKeyFromType(Object resolvedKey, ReflectionCache reflectionCache) throws MetadataResolvingException {
    if (isKeyLess() || resolvedKey == null) {
        return new NullMetadataKey();
    }
    if (keyParts.size() == 1) {
        return newKey(valueOf(resolvedKey)).build();
    }
    MetadataKeyBuilder rootBuilder = null;
    MetadataKeyBuilder childBuilder = null;
    for (ParameterModel p : keyParts) {
        try {
            if (p.getModelProperty(DeclaringMemberModelProperty.class).isPresent()) {
                MetadataKeyBuilder fieldBuilder = getKeyFromField(resolvedKey, p.getModelProperty(DeclaringMemberModelProperty.class).get(), reflectionCache);
                if (rootBuilder == null) {
                    rootBuilder = fieldBuilder;
                    childBuilder = rootBuilder;
                } else {
                    childBuilder.withChild(fieldBuilder);
                    childBuilder = fieldBuilder;
                }
            }
        } catch (Exception e) {
            throw new MetadataResolvingException("Could not construct Metadata Key part for parameter " + p.getName(), FailureCode.INVALID_METADATA_KEY, e);
        }
    }
    return rootBuilder != null ? rootBuilder.build() : new NullMetadataKey();
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Example 2 with NullMetadataKey

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

Aggregations

ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 NullMetadataKey (org.mule.runtime.extension.api.metadata.NullMetadataKey)2 MetadataKey (org.mule.runtime.api.metadata.MetadataKey)1 MetadataKeyBuilder (org.mule.runtime.api.metadata.MetadataKeyBuilder)1 MetadataKeysContainerBuilder (org.mule.runtime.api.metadata.MetadataKeysContainerBuilder)1 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 PartialTypeKeysResolver (org.mule.runtime.api.metadata.resolving.PartialTypeKeysResolver)1 TypeKeysResolver (org.mule.runtime.api.metadata.resolving.TypeKeysResolver)1 DeclaringMemberModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty)1