Search in sources :

Example 21 with ProcedureParameter

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

the class SalesForceMetadataProcessor method addProcedrues.

public static void addProcedrues(MetadataFactory metadataFactory) {
    // $NON-NLS-1$
    Procedure p1 = metadataFactory.addProcedure("GetUpdated");
    // $NON-NLS-1$
    p1.setAnnotation("Gets the updated objects");
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("ObjectName", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p1);
    // $NON-NLS-1$
    param.setAnnotation("ObjectName");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("StartDate", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p1);
    // $NON-NLS-1$
    param.setAnnotation("Start Time");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("EndDate", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p1);
    // $NON-NLS-1$
    param.setAnnotation("End Time");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("LatestDateCovered", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p1);
    // $NON-NLS-1$
    param.setAnnotation("Latest Date Covered");
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("ID", TypeFacility.RUNTIME_NAMES.STRING, p1);
    // $NON-NLS-1$
    Procedure p2 = metadataFactory.addProcedure("GetDeleted");
    // $NON-NLS-1$
    p2.setAnnotation("Gets the deleted objects");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("ObjectName", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("ObjectName");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("StartDate", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("Start Time");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("EndDate", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("End Time");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("EarliestDateAvailable", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("Earliest Date Available");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("LatestDateCovered", TypeFacility.RUNTIME_NAMES.TIMESTAMP, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("Latest Date Covered");
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("ID", TypeFacility.RUNTIME_NAMES.STRING, p2);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("DeletedDate", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p2);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 22 with ProcedureParameter

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

the class ODataProcedureVisitor method visit.

@Override
public void visit(Call obj) {
    Procedure proc = obj.getMetadataObject();
    this.method = proc.getProperty(ODataMetadataProcessor.HTTP_METHOD, false);
    this.procedure = proc;
    this.buffer.append(obj.getProcedureName());
    final List<Argument> params = obj.getArguments();
    if (params != null && params.size() != 0) {
        // $NON-NLS-1$
        this.buffer.append("?");
        Argument param = null;
        StringBuilder temp = new StringBuilder();
        for (int i = 0; i < params.size(); i++) {
            param = params.get(i);
            if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) {
                if (i != 0) {
                    // $NON-NLS-1$
                    this.buffer.append("&");
                }
                this.buffer.append(WSConnection.Util.httpURLEncode(param.getMetadataObject().getName()));
                this.buffer.append(Tokens.EQ);
                this.executionFactory.convertToODataInput(param.getArgumentValue(), temp);
                this.buffer.append(WSConnection.Util.httpURLEncode(temp.toString()));
                temp.setLength(0);
            }
        }
    }
    // this is collection based result
    if (proc.getResultSet() != null) {
        this.returnsTable = true;
        this.returnEntityTypeName = proc.getProperty(ODataMetadataProcessor.ENTITY_TYPE, false);
        this.entity = getTableWithEntityType(proc.getParent(), returnEntityTypeName);
        this.isComplexReturnType = (this.entity == null);
        this.returnColumns = proc.getResultSet().getColumns();
    } else {
        for (ProcedureParameter param : proc.getParameters()) {
            if (param.getType().equals(ProcedureParameter.Type.ReturnValue)) {
                this.returnType = param.getRuntimeType();
                this.returnTypeClass = param.getJavaType();
            }
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Argument(org.teiid.language.Argument) Procedure(org.teiid.metadata.Procedure)

Example 23 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter 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)

Example 24 with ProcedureParameter

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

the class TestSwaggerMetadataProcessor method testRefToProcedureParam.

@Test
public void testRefToProcedureParam() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = petstoreMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("addPet");
    assertNotNull(p);
    assertEquals("POST", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://petstore.swagger.io/v2/pet", p.getProperty(RestMetadataExtension.URI, false));
    ProcedureParameter pa = p.getParameterByName("id");
    assertNull(pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    pa = p.getParameterByName("category_id");
    assertEquals("category/id", pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    pa = p.getParameterByName("tags_Tag_id");
    assertEquals("tags[]/Tag/id", pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    // TODO: the logic could support this as a long array as well
    assertEquals("long", pa.getRuntimeType());
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 25 with ProcedureParameter

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

the class TestSwaggerMetadataProcessor method testSwaggerINParameterTypes.

@Test
public void testSwaggerINParameterTypes() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    for (Procedure p : mf.getSchema().getProcedures().values()) {
        // multiple in parameter
        if (p.getName().equals("getByNumCityCountry")) {
            List<ProcedureParameter> params = p.getParameters();
            for (ProcedureParameter param : params) {
                assertEquals(RestMetadataExtension.ParameterType.QUERY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
            assertEquals(3, params.size());
            assertTrue(params.get(0).getName().equalsIgnoreCase("customernumber"));
            assertTrue(params.get(1).getName().equalsIgnoreCase("city"));
            assertTrue(params.get(2).getName().equalsIgnoreCase("country"));
        } else // QueryParameter and  PathParameter
        if (p.getName().equals("getCustomerByCity") || p.getName().equals("getCustomerByCountry") && p.getName().equals("getByNumCityCountry")) {
            for (ProcedureParameter param : p.getParameters()) {
                assertEquals(RestMetadataExtension.ParameterType.QUERY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
        } else if (p.getName().equals("getCustomerByNumber") || p.getName().equals("getCustomerByName")) {
            for (ProcedureParameter param : p.getParameters()) {
                assertEquals(RestMetadataExtension.ParameterType.PATH.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
        } else // Post parameter
        if (p.getName().equals("addCustomer") || p.getName().equals("addOneCustomer") || p.getName().equals("addCustomerList")) {
            ProcedureParameter param = p.getParameters().get(0);
            assertEquals(RestMetadataExtension.ParameterType.BODY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
        }
        if (p.getName().equals("addCustomer")) {
            List<ProcedureParameter> params = p.getParameters();
            assertEquals(13, params.size());
            assertEquals("customernumber", params.get(0).getName());
            assertEquals("creditlimit", params.get(12).getName());
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Aggregations

ProcedureParameter (org.teiid.metadata.ProcedureParameter)43 Procedure (org.teiid.metadata.Procedure)35 Test (org.junit.Test)12 MetadataFactory (org.teiid.metadata.MetadataFactory)9 Schema (org.teiid.metadata.Schema)8 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)8 MetadataStore (org.teiid.metadata.MetadataStore)7 Column (org.teiid.metadata.Column)6 ArrayList (java.util.ArrayList)5 QueryNode (org.teiid.query.mapping.relational.QueryNode)5 List (java.util.List)4 Table (org.teiid.metadata.Table)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 EdmPrimitiveTypeKind (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)2 FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)2 Argument (org.teiid.language.Argument)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 TranslatorException (org.teiid.translator.TranslatorException)2 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)2