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);
}
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();
}
}
}
}
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());
}
}
}
}
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());
}
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());
}
}
}
Aggregations