Search in sources :

Example 1 with UriInfo

use of org.apache.olingo.server.api.uri.UriInfo in project teiid by teiid.

the class ReferenceUpdateSQLBuilder method updateReference.

public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
    try {
        if (referenceId != null) {
            UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
            UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
            if (this.collection) {
                this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
            } else {
                this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
            }
        }
    } catch (UriParserException e) {
        throw new SQLException(e);
    } catch (URISyntaxException e) {
        throw new SQLException(e);
    } catch (UriValidationException e) {
        throw new SQLException(e);
    }
    try {
        Update update = new Update();
        update.setGroup(this.updateTable.getGroupSymbol());
        List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
        for (int i = 0; i < columnNames.size(); i++) {
            Column column = this.updateTable.getFk().getColumns().get(i);
            String columnName = columnNames.get(i);
            ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
            EdmEntityType entityType = this.updateTable.getEdmEntityType();
            EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
            // reference table keys will be null for delete scenario
            Object value = null;
            if (!delete) {
                UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
                value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
            }
            if (prepared) {
                update.addChange(symbol, new Reference(i++));
                this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
            } else {
                update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
            }
        }
        Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
        update.setCriteria(criteria);
        return update;
    } catch (TeiidException e) {
        throw new SQLException(e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SQLException(java.sql.SQLException) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) URISyntaxException(java.net.URISyntaxException) Criteria(org.teiid.query.sql.lang.Criteria) Update(org.teiid.query.sql.lang.Update) TeiidException(org.teiid.core.TeiidException) UriValidationException(org.apache.olingo.server.core.uri.validator.UriValidationException) Column(org.teiid.metadata.Column) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) UriResourceEntitySet(org.apache.olingo.server.api.uri.UriResourceEntitySet) UriInfo(org.apache.olingo.server.api.uri.UriInfo) UriParserException(org.apache.olingo.server.core.uri.parser.UriParserException) UriParameter(org.apache.olingo.server.api.uri.UriParameter)

Example 2 with UriInfo

use of org.apache.olingo.server.api.uri.UriInfo in project arctic-sea by 52North.

the class ODataFesParser method decode.

@Override
public Filter<?> decode(String objectToDecode) throws DecodingException {
    LOG.debug("Parsing filter: {}", objectToDecode);
    if (objectToDecode == null || objectToDecode.isEmpty()) {
        return null;
    }
    try {
        String encode = urlEscaper.escape(objectToDecode);
        // >=4.4.0
        // UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT, BASE_URI);
        // >=4.2.0 <4.4.0
        // UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT);
        // >=4.0.0 <4.2.0
        UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT, this.edm);
        return parseUri.getFilterOption().getExpression().accept(new ExpressionGenerator()).accept(new RenamingVisitor(csdlProvider::mapProperty)).accept(new FilterGenerator());
    } catch (ODataException ex) {
        throw new DecodingException(ex);
    }
}
Also used : ODataException(org.apache.olingo.commons.api.ex.ODataException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) UriInfo(org.apache.olingo.server.api.uri.UriInfo)

Aggregations

UriInfo (org.apache.olingo.server.api.uri.UriInfo)2 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)1 EdmProperty (org.apache.olingo.commons.api.edm.EdmProperty)1 ODataException (org.apache.olingo.commons.api.ex.ODataException)1 UriParameter (org.apache.olingo.server.api.uri.UriParameter)1 UriResourceEntitySet (org.apache.olingo.server.api.uri.UriResourceEntitySet)1 UriParserException (org.apache.olingo.server.core.uri.parser.UriParserException)1 UriValidationException (org.apache.olingo.server.core.uri.validator.UriValidationException)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 TeiidException (org.teiid.core.TeiidException)1 Column (org.teiid.metadata.Column)1 Criteria (org.teiid.query.sql.lang.Criteria)1 Update (org.teiid.query.sql.lang.Update)1 Constant (org.teiid.query.sql.symbol.Constant)1 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)1 Reference (org.teiid.query.sql.symbol.Reference)1