Search in sources :

Example 16 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithFunction.

@Test
public void testCreatingReturnFilterQueryWithFunction() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.function("FooBarCond", Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.function("BarCond", Expression.value(100), Expression.variable("volume")))).function("ext", "Foo", Expression.value(67), Expression.value(89)).window("ext", "lengthFirst10", Expression.value(50)));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("ext", "avg", Expression.variable("symbol"))));
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 17 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getUserDeployedFunctions.

/**
 * {@inheritDoc}
 */
@Override
public List<Function> getUserDeployedFunctions(String userName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    List<Function> functions = new ArrayList<>();
    final String sqlQuery = "SELECT FUNCTION_NAME, FUNCTION_URI " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String functionName = resultSet.getString("FUNCTION_NAME");
                URI endpointURI = new URI(resultSet.getString("FUNCTION_URI"));
                functions.add(new Function(functionName, endpointURI));
            }
        } catch (URISyntaxException e) {
            throw new APIMgtDAOException("Not a URI", e);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving functions of user: " + userName, e);
    }
    return functions;
}
Also used : Function(org.wso2.carbon.apimgt.core.models.Function) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 18 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getUserFunctionsForEvent.

/**
 * {@inheritDoc}
 */
@Override
public List<Function> getUserFunctionsForEvent(String userName, Event event) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (event == null) {
        throw new IllegalArgumentException("Event must not be null");
    }
    List<Function> functions = new ArrayList<>();
    final String sqlQuery = "SELECT FUNCTION_NAME, FUNCTION_URI " + "FROM AM_LAMBDA_FUNCTION JOIN AM_EVENT_FUNCTION_MAPPING " + "ON AM_LAMBDA_FUNCTION.FUNCTION_ID = AM_EVENT_FUNCTION_MAPPING.FUNCTION_ID " + "WHERE USER_NAME = ? AND EVENT = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        preparedStatement.setString(2, event.getEventAsString());
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String functionName = resultSet.getString("FUNCTION_NAME");
                URI endpointURI = new URI(resultSet.getString("FUNCTION_URI"));
                functions.add(new Function(functionName, endpointURI));
            }
        } catch (URISyntaxException e) {
            throw new APIMgtDAOException("Not a URI", e);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving functions for event: " + event + " of user: " + userName, e);
    }
    return functions;
}
Also used : Function(org.wso2.carbon.apimgt.core.models.Function) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 19 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-apimgt by wso2.

the class FunctionDAOImpl method deleteEventFunctionMapping.

/**
 * {@inheritDoc}
 */
@Override
public void deleteEventFunctionMapping(String userName, Event event, String functionName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (event == null) {
        throw new IllegalArgumentException("Event must not be null");
    }
    if (functionName == null) {
        throw new IllegalArgumentException("Function name must not be null");
    }
    final String sqlQuery = "DELETE FROM AM_EVENT_FUNCTION_MAPPING " + "WHERE EVENT = ? AND FUNCTION_ID = " + "(SELECT FUNCTION_ID " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, event.getEventAsString());
        preparedStatement.setString(2, userName);
        preparedStatement.setString(3, functionName);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error deleting event function mapping -event: " + event + " -function: " + functionName + " -user: " + userName, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 20 with Function

use of org.wso2.carbon.apimgt.core.models.Function in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getTriggersForUserFunction.

/**
 * {@inheritDoc}
 */
@Override
public List<Event> getTriggersForUserFunction(String userName, String functionName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (functionName == null) {
        throw new IllegalArgumentException("Function name must not be null");
    }
    List<Event> events = new ArrayList<>();
    final String sqlQuery = "SELECT EVENT " + "FROM AM_LAMBDA_FUNCTION JOIN AM_EVENT_FUNCTION_MAPPING " + "ON AM_LAMBDA_FUNCTION.FUNCTION_ID = AM_EVENT_FUNCTION_MAPPING.FUNCTION_ID " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        preparedStatement.setString(2, functionName);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                events.add(Event.valueOf(resultSet.getString("EVENT")));
            }
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving triggers for function: " + functionName + " of user: " + userName, e);
    }
    return events;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Event(org.wso2.carbon.apimgt.core.models.Event) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Test (org.testng.annotations.Test)94 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)49 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)44 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)39 ArrayList (java.util.ArrayList)37 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)35 BString (org.ballerinalang.model.values.BString)30 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)29 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)20 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)20 BJSON (org.ballerinalang.model.values.BJSON)19 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 List (java.util.List)18 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)18 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)16 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)15 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)14 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14