use of org.odata4j.core.ODataVersion in project teiid by teiid.
the class BaseQueryExecution method getDataServiceVersion.
protected static ODataVersion getDataServiceVersion(String headerValue) {
ODataVersion version = ODataConstants.DATA_SERVICE_VERSION;
if (headerValue != null) {
// $NON-NLS-1$
String[] str = headerValue.split(";");
version = ODataVersion.parse(str[0]);
}
return version;
}
use of org.odata4j.core.ODataVersion in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
String URI = this.visitor.buildURL();
Schema schema = visitor.getProcedure().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
if (this.visitor.hasCollectionReturn()) {
if (this.visitor.isReturnComplexType()) {
// complex return
this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
} else {
// entity type return
this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
}
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
} else {
try {
BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
if (execution.getResponseCode() != Status.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
ODataVersion version = getODataVersion(execution);
// if the procedure is not void
if (this.visitor.getReturnType() != null) {
FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
null, // isResponse
true, ODataTypeManager.odataType(this.visitor.getReturnType())));
OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
}
use of org.odata4j.core.ODataVersion in project teiid by teiid.
the class BaseQueryExecution method executeWithReturnEntity.
protected ODataEntitiesResponse executeWithReturnEntity(String method, String uri, String payload, String entityTable, EdmDataServices edsMetadata, String eTag, Status... expectedStatus) throws TranslatorException {
Map<String, List<String>> headers = getDefaultHeaders();
if (eTag != null) {
// $NON-NLS-1$
headers.put("If-Match", Arrays.asList(eTag));
}
if (payload != null) {
// $NON-NLS-1$ //$NON-NLS-2$
headers.put("Content-Type", Arrays.asList("application/atom+xml"));
}
BinaryWSProcedureExecution execution = executeDirect(method, uri, payload, headers);
for (Status status : expectedStatus) {
if (status.getStatusCode() == execution.getResponseCode()) {
if (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode() && execution.getResponseCode() != Status.NOT_FOUND.getStatusCode()) {
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
ODataVersion version = getODataVersion(execution);
Feed feed = parse(blob, version, entityTable, edsMetadata);
return new ODataEntitiesResponse(uri, feed, entityTable, edsMetadata);
}
// this is success with no-data
return new ODataEntitiesResponse();
}
}
// throw an error
return new ODataEntitiesResponse(buildError(execution));
}
Aggregations