Search in sources :

Example 41 with ObjectType

use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.

the class DsqlQueryMetadataResolverTestCase method getFullOutputMetadata.

@Test
public void getFullOutputMetadata() throws MetadataResolvingException, ConnectionException {
    DsqlQuery dsqlQuery = dsqlParser.parse("dsql:SELECT * FROM Circle WHERE (diameter < 18)");
    MetadataType outputMetadata = getQueryMetadataResolver().getOutputType(context, dsqlQuery);
    ObjectType type = getAndAssertTypeOf(outputMetadata);
    assertThat(type.getFields(), hasSize(3));
    type.getFields().forEach(f -> {
        String name = f.getKey().getName().getLocalPart();
        assertThat(name, isIn(asList("color", "id", "diameter")));
    });
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) DsqlQuery(org.mule.runtime.extension.api.dsql.DsqlQuery) MetadataType(org.mule.metadata.api.model.MetadataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 42 with ObjectType

use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.

the class ImportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
    final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!extensionType.isPresent()) {
        return;
    }
    Type type = extensionType.get().getType();
    final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
    if (!importTypes.isEmpty()) {
        if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
            throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
        }
        importTypes.forEach(imported -> {
            MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
            if (!(importedType instanceof ObjectType)) {
                throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
            }
            extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
        });
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectType(org.mule.metadata.api.model.ObjectType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Example 43 with ObjectType

use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.

the class MetadataOperationTestCase method attributesDynamicPersonTypeMetadata.

@Test
public void attributesDynamicPersonTypeMetadata() throws Exception {
    location = Location.builder().globalName(OUTPUT_ATTRIBUTES_WITH_DYNAMIC_METADATA).addProcessorsPart().addIndexPart(0).build();
    final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY);
    final OperationModel typedModel = metadataDescriptor.getModel();
    MetadataType type = typedModel.getOutputAttributes().getType();
    assertThat(type, is(instanceOf(ObjectType.class)));
    ObjectType dictionary = (ObjectType) type;
    assertThat(dictionary.getOpenRestriction().get(), is(instanceOf(StringType.class)));
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) MetadataType(org.mule.metadata.api.model.MetadataType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 44 with ObjectType

use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.

the class MetadataOperationTestCase method metadataKeyDefaultValue.

@Test
public void metadataKeyDefaultValue() throws Exception {
    location = Location.builder().globalName(METADATA_KEY_DEFAULT_VALUE).addProcessorsPart().addIndexPart(0).build();
    MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location);
    assertSuccessResult(result);
    MetadataType type = result.get().getModel().getOutput().getType();
    assertThat(type, is(instanceOf(ObjectType.class)));
    ObjectType objectType = (ObjectType) type;
    assertThat(objectType.getFields(), hasSize(2));
    objectType.getFields().forEach(f -> assertThat(f.getKey().getName().getLocalPart(), isOneOf(TIRES, BRAND)));
    Optional<MetadataKey> metadataKeyOptional = result.get().getMetadataAttributes().getKey();
    assertThat(metadataKeyOptional.isPresent(), is(true));
    assertThat(metadataKeyOptional.get().getId(), is(CAR));
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) MetadataType(org.mule.metadata.api.model.MetadataType) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) Test(org.junit.Test)

Aggregations

ObjectType (org.mule.metadata.api.model.ObjectType)44 MetadataType (org.mule.metadata.api.model.MetadataType)32 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)21 ArrayType (org.mule.metadata.api.model.ArrayType)19 Optional (java.util.Optional)17 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)17 Reference (org.mule.runtime.api.util.Reference)17 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)16 List (java.util.List)15 String.format (java.lang.String.format)14 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)14 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)14 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)14 Set (java.util.Set)13 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)13 Map (java.util.Map)12 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)12 Collectors.toList (java.util.stream.Collectors.toList)11 HashSet (java.util.HashSet)10 ExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory)10