Search in sources :

Example 1 with MetadataException

use of org.teiid.metadata.MetadataException in project teiid by teiid.

the class DDLFileMetadataRepository method loadMetadata.

@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
    String ddlFile = factory.getModelProperties().getProperty("ddl-file");
    if (ddlFile != null) {
        text = ddlFile;
    }
    if (text != null) {
        VDBResource resource = factory.getVDBResources().get(text);
        if (resource == null) {
            throw new MetadataException(Event.TEIID31137, QueryPlugin.Util.gs(Event.TEIID31137, text));
        }
        InputStream is;
        try {
            is = resource.openStream();
        } catch (IOException e1) {
            throw new MetadataException(e1);
        }
        try {
            // TODO: could allow for a property driven encoding
            // $NON-NLS-1$
            factory.parse(new InputStreamReader(is, Charset.forName("UTF-8")));
        } finally {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : VDBResource(org.teiid.metadata.VDBResource) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) MetadataException(org.teiid.metadata.MetadataException)

Example 2 with MetadataException

use of org.teiid.metadata.MetadataException in project teiid by teiid.

the class TestVisitor method queryMetadataInterface.

private static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("couchbase");
        CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
        MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        Table customer = createTable(mf, KEYSPACE, "Customer");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
        Table order = createTable(mf, KEYSPACE, "Oder");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
        Table t2 = createTable(mf, "T2", "T2");
        mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
        Table t3 = createTable(mf, "T3", "T3");
        mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
        mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
        mp.addProcedures(mf, null);
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (MetadataException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TestCouchbaseMetadataProcessor(org.teiid.translator.couchbase.TestCouchbaseMetadataProcessor) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 3 with MetadataException

use of org.teiid.metadata.MetadataException in project teiid by teiid.

the class VDBRepository method getODBCMetadataStore.

private MetadataStore getODBCMetadataStore() {
    try {
        PgCatalogMetadataStore pg = new PgCatalogMetadataStore(CoreConstants.ODBC_MODEL, getRuntimeTypeMap());
        // $NON-NLS-1$
        ValidatorReport report = new ValidatorReport("Function Validation");
        FunctionMetadataValidator.validateFunctionMethods(pg.getSchema().getFunctions().values(), report);
        if (report.hasItems()) {
            throw new MetadataException(report.getFailureMessage());
        }
        return pg.asMetadataStore();
    } catch (MetadataException e) {
        this.odbcException = e;
        LogManager.logError(LogConstants.CTX_DQP, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40002));
    }
    return null;
}
Also used : ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException)

Example 4 with MetadataException

use of org.teiid.metadata.MetadataException in project teiid by teiid.

the class TestSQLConversionVisitor method queryMetadataInterface.

private static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("prestodbModel");
        MetadataFactory mf = new MetadataFactory("prestodb", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sample.ddl")));
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (MetadataException | FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 5 with MetadataException

use of org.teiid.metadata.MetadataException in project teiid by teiid.

the class SwaggerMetadataProcessor method addProcedureParameters.

private void addProcedureParameters(final MetadataFactory mf, final Swagger swagger, final Procedure procedure, final Operation operation) throws TranslatorException {
    for (final Parameter parameter : operation.getParameters()) {
        if (parameter instanceof BodyParameter) {
            PropertyAction pa = new PropertyAction() {

                @Override
                public void execute(String name, String nameInSource, Property property, boolean array) {
                    String type = getPropertyType(property, array);
                    if (procedure.getParameterByName(nameInSource) == null) {
                        ProcedureParameter param = mf.addProcedureParameter(name, type, Type.In, procedure);
                        param.setProperty(PARAMETER_TYPE, parameter.getIn());
                        if (property != null && !property.getRequired()) {
                            param.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
                        }
                        param.setNullType(NullType.No_Nulls);
                        param.setAnnotation(property != null ? property.getDescription() : null);
                        if (!name.equalsIgnoreCase(nameInSource)) {
                            param.setNameInSource(nameInSource);
                        }
                    }
                }
            };
            Model model = ((BodyParameter) parameter).getSchema();
            if (model instanceof RefModel) {
                RefModel refModel = (RefModel) model;
                if (refModel.getProperties() != null) {
                    walkProperties(swagger, refModel.getProperties(), null, null, pa);
                } else if (refModel.getReference() != null) {
                    Model m = swagger.getDefinitions().get(refModel.getSimpleRef());
                    walkProperties(swagger, m.getProperties(), null, null, pa);
                }
            } else {
                if ((model instanceof ModelImpl) && model.getProperties() != null) {
                    walkProperties(swagger, model.getProperties(), null, null, pa);
                } else {
                    ProcedureParameter p = mf.addProcedureParameter(parameter.getName(), DataTypeManager.DefaultDataTypes.CLOB, Type.In, procedure);
                    p.setProperty(PARAMETER_TYPE, parameter.getIn());
                    p.setNullType(NullType.No_Nulls);
                    p.setAnnotation(parameter.getDescription());
                }
            }
        } else {
            String name = parameter.getName();
            ProcedureParameter pp = null;
            String type = null;
            Object defaultValue = null;
            String collectionFormat = null;
            if (parameter instanceof AbstractSerializableParameter) {
                AbstractSerializableParameter p = (AbstractSerializableParameter) parameter;
                type = p.getType();
                if (p.getType().equalsIgnoreCase("array")) {
                    Property ap = p.getItems();
                    type = ap.getType();
                }
                type = SwaggerTypeManager.teiidType(type, p.getFormat(), p.getItems() != null);
                defaultValue = p.getDefaultValue();
                collectionFormat = p.getCollectionFormat();
            } else {
                // $NON-NLS-1$
                throw new MetadataException("Unknown property type" + parameter.getClass().getName());
            }
            pp = mf.addProcedureParameter(name, type, Type.In, procedure);
            pp.setProperty(PARAMETER_TYPE, parameter.getIn());
            boolean required = parameter.getRequired();
            if (!required) {
                pp.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
            }
            pp.setNullType(NullType.No_Nulls);
            pp.setAnnotation(parameter.getDescription());
            if (defaultValue != null) {
                pp.setDefaultValue(defaultValue.toString());
            }
            if (collectionFormat != null) {
                pp.setProperty(COLLECION_FORMAT, collectionFormat);
            }
            // extended properties
            for (Entry<String, Object> extension : parameter.getVendorExtensions().entrySet()) {
                pp.setProperty(extension.getKey(), extension.getValue().toString());
            }
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RefModel(io.swagger.models.RefModel) BodyParameter(io.swagger.models.parameters.BodyParameter) MetadataException(org.teiid.metadata.MetadataException) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ProcedureParameter(org.teiid.metadata.ProcedureParameter) ModelImpl(io.swagger.models.ModelImpl) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) TranslatorProperty(org.teiid.translator.TranslatorProperty) ExtensionMetadataProperty(org.teiid.metadata.ExtensionMetadataProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) FileProperty(io.swagger.models.properties.FileProperty)

Aggregations

MetadataException (org.teiid.metadata.MetadataException)8 ValidatorReport (org.teiid.query.validator.ValidatorReport)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 MetadataFactory (org.teiid.metadata.MetadataFactory)3 MetadataValidator (org.teiid.query.metadata.MetadataValidator)3 QueryParser (org.teiid.query.parser.QueryParser)2 Model (io.swagger.models.Model)1 ModelImpl (io.swagger.models.ModelImpl)1 RefModel (io.swagger.models.RefModel)1 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 ArrayProperty (io.swagger.models.properties.ArrayProperty)1 FileProperty (io.swagger.models.properties.FileProperty)1 MapProperty (io.swagger.models.properties.MapProperty)1 ObjectProperty (io.swagger.models.properties.ObjectProperty)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1