Search in sources :

Example 1 with EdmPrimitiveTypeException

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.

the class AtomGeoValueSerializer method points.

private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap) throws XMLStreamException {
    while (itor.hasNext()) {
        final Point point = itor.next();
        if (wrap) {
            writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
        }
        writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML);
        try {
            writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null) + " " + EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
        } catch (EdmPrimitiveTypeException e) {
            throw new XMLStreamException("While serializing point coordinates as double", e);
        }
        writer.writeEndElement();
        if (wrap) {
            writer.writeEndElement();
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) MultiPoint(org.apache.olingo.commons.api.edm.geo.MultiPoint) Point(org.apache.olingo.commons.api.edm.geo.Point) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)

Example 2 with EdmPrimitiveTypeException

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.

the class ODataTypeManager method parseLiteral.

public static Object parseLiteral(String odataType, String value) throws TeiidException {
    EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(odataType.substring(4)));
    int maxLength = DataTypeManager.MAX_STRING_LENGTH;
    if (primitiveType instanceof EdmBinary || primitiveType instanceof EdmStream) {
        maxLength = DataTypeManager.MAX_VARBINARY_BYTES;
    }
    int precision = 4;
    int scale = 3;
    if (primitiveType instanceof EdmDecimal) {
        precision = 38;
        scale = 9;
    }
    Class<?> expectedClass = primitiveType.getDefaultType();
    try {
        if (EdmString.getInstance().equals(primitiveType)) {
            value = EdmString.getInstance().fromUriLiteral(value);
        }
        Object converted = primitiveType.valueOfString(value, false, maxLength, precision, scale, true, expectedClass);
        if (primitiveType instanceof EdmTimeOfDay) {
            Calendar ts = (Calendar) converted;
            return new Time(ts.getTimeInMillis());
        } else if (primitiveType instanceof EdmDate) {
            Calendar ts = (Calendar) converted;
            return new Date(ts.getTimeInMillis());
        }
        return converted;
    } catch (EdmPrimitiveTypeException e) {
        throw new TeiidException(e);
    }
}
Also used : EdmPrimitiveType(org.apache.olingo.commons.api.edm.EdmPrimitiveType) EdmBinary(org.apache.olingo.commons.core.edm.primitivetype.EdmBinary) EdmStream(org.apache.olingo.commons.core.edm.primitivetype.EdmStream) Calendar(java.util.Calendar) Time(java.sql.Time) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) EdmDate(org.apache.olingo.commons.core.edm.primitivetype.EdmDate) EdmDate(org.apache.olingo.commons.core.edm.primitivetype.EdmDate) Date(java.sql.Date) EdmDecimal(org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal) TeiidException(org.teiid.core.TeiidException) EdmTimeOfDay(org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay)

Example 3 with EdmPrimitiveTypeException

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        String parameters = getQueryParameters(this.command);
        InputStream response = null;
        Procedure procedure = this.command.getMetadataObject();
        if (isFunction(procedure)) {
            String URI = buildFunctionURL(this.command, parameters);
            response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        } else {
            String URI = this.command.getProcedureName();
            response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new TranslatorException(e);
    }
}
Also used : InputStream(java.io.InputStream) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)

Example 4 with EdmPrimitiveTypeException

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.

the class ODataTypeManager method convertToODataURIValue.

public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException {
    if (val == null) {
        // is this correct? //$NON-NLS-1$
        return "null";
    }
    if (odataType.startsWith("Edm.")) {
        // $NON-NLS-1$
        odataType = odataType.substring(4);
    }
    if (val instanceof GeometryType) {
        Geometry g;
        try {
            g = GeometryUtils.getGeometry((GeometryType) val);
        } catch (FunctionExecutionException e1) {
            throw new EdmPrimitiveTypeException(e1.getMessage(), e1);
        }
        StringWriter sw = new StringWriter();
        // $NON-NLS-1$
        sw.write("geometry'SRID=");
        sw.write(String.valueOf(g.getSRID()));
        // $NON-NLS-1$
        sw.write(";");
        ODataWKTWriter writer = new ODataWKTWriter();
        try {
            writer.write(g, sw);
        } catch (IOException e) {
            throw new TeiidRuntimeException(e);
        }
        // $NON-NLS-1$
        sw.write("'");
        return sw.toString();
    }
    EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType);
    String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString(val, true, null, null, Integer.MAX_VALUE, true);
    if (kind == EdmPrimitiveTypeKind.String) {
        return EdmString.getInstance().toUriLiteral(value);
    }
    return value;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) StringWriter(java.io.StringWriter) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind) EdmString(org.apache.olingo.commons.core.edm.primitivetype.EdmString)

Example 5 with EdmPrimitiveTypeException

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.

the class TeiidServiceHandler method createEntity.

@Override
public void createEntity(DataRequest request, Entity entity, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
    EdmEntityType entityType = request.getEntitySet().getEntityType();
    String txn;
    try {
        txn = getClient().startTransaction();
    } catch (SQLException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    }
    boolean success = false;
    try {
        List<ExpandNode> expands = new ArrayList<TeiidServiceHandler.ExpandNode>();
        int insertDepth = insertDepth(entityType, entity);
        // don't count the root
        ODataSQLBuilder.checkExpandLevel(insertDepth - 1);
        UpdateResponse updateResponse = performDeepInsert(request.getODataRequest().getRawBaseUri(), request.getUriInfo(), entityType, entity, expands);
        if (updateResponse != null && updateResponse.getUpdateCount() == 1) {
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), true, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            Query query = visitor.selectWithEntityKey(entityType, entity, updateResponse.getGeneratedKeys(), expands);
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logDetail(LogConstants.CTX_ODATA, null, "created entity = ", entityType.getName(), " with key=", query.getCriteria().toString());
            EntityCollectionResponse result = new EntityCollectionResponse(request.getODataRequest().getRawBaseUri(), visitor.getContext());
            getClient().executeSQL(query, visitor.getParameters(), false, null, null, null, 1, result);
            if (!result.getEntities().isEmpty()) {
                entity = result.getEntities().get(0);
                String location = EntityResponse.buildLocation(request.getODataRequest().getRawBaseUri(), entity, request.getEntitySet().getName(), entityType);
                entity.setId(new URI(location));
            }
            response.writeCreatedEntity(request.getEntitySet(), entity);
        } else {
            response.writeNotModified();
        }
        getClient().commit(txn);
        success = true;
    } catch (EdmPrimitiveTypeException | TeiidException | SQLException | URISyntaxException e) {
        throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
    } finally {
        if (!success) {
            try {
                getClient().rollback(txn);
            } catch (SQLException e1) {
            // ignore
            }
        }
    }
}
Also used : Query(org.teiid.query.sql.lang.Query) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException) UpdateResponse(org.teiid.odata.api.UpdateResponse)

Aggregations

EdmPrimitiveTypeException (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)6 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 SQLException (java.sql.SQLException)2 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)2 EdmStream (org.apache.olingo.commons.core.edm.primitivetype.EdmStream)2 TeiidException (org.teiid.core.TeiidException)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Date (java.sql.Date)1 Time (java.sql.Time)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 LinkedHashMap (java.util.LinkedHashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ODataDeserializerException (org.apache.olingo.client.api.serialization.ODataDeserializerException)1 Entity (org.apache.olingo.commons.api.data.Entity)1 Link (org.apache.olingo.commons.api.data.Link)1