Search in sources :

Example 1 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project jaggery by wso2.

the class RegistryHostObject method jsFunction_get.

public static Scriptable jsFunction_get(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    RegistryHostObject rho = (RegistryHostObject) thisObj;
    if (arguments.length == 1) {
        if (arguments[0] instanceof String) {
            try {
                Scriptable hostObject;
                Resource resource = rho.registry.get((String) arguments[0]);
                if (resource instanceof Collection) {
                    hostObject = cx.newObject(rho, "Collection", new Object[] { resource });
                } else {
                    hostObject = cx.newObject(rho, "Resource", new Object[] { resource });
                }
                return hostObject;
            } catch (RegistryException e) {
                throw new ScriptException("Registry error occurred while executing get() operation", e);
            }
        } else {
            throw new ScriptException("Path argument of method get() should be a string");
        }
    } else if (arguments.length == 3) {
        if (arguments[0] instanceof String && arguments[1] instanceof Number && arguments[2] instanceof Number) {
            try {
                Collection collection = rho.registry.get((String) arguments[0], ((Number) arguments[1]).intValue(), ((Number) arguments[2]).intValue());
                CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
                return cho;
            } catch (RegistryException e) {
                throw new ScriptException("Registry error occurred while executing get() operation", e);
            }
        } else {
            throw new ScriptException("Invalid argument types for get() method");
        }
    } else {
        throw new ScriptException("Invalid no. of arguments for get() method");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 2 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project siddhi by wso2.

the class SetUpdateOrInsertInMemoryTableTestCase method updateFromTableTest5.

@Test
public void updateFromTableTest5() throws InterruptedException, SQLException {
    log.info("SET-InMemory-update-or-insert test case 5: assignment expression containing an output attribute " + "with a basic arithmatic operation.");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update or insert into StockTable " + "set StockTable.price = price + 100 " + "   on StockTable.symbol == symbol ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    updateStockStream.send(new Object[] { "IBM", 100f, 100L });
    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 3 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.

the class ApiDAOImpl method updateEndpoint.

/**
 * Update an Endpoint
 *
 * @param endpoint Endpoint Object.
 * @return Success of the update operation.
 * @throws APIMgtDAOException If failed to update endpoint.
 */
@Override
public boolean updateEndpoint(Endpoint endpoint) throws APIMgtDAOException {
    final String query = "UPDATE AM_ENDPOINT SET ENDPOINT_CONFIGURATION = ?,TPS = ?,TYPE = " + "?,SECURITY_CONFIGURATION =?, LAST_UPDATED_TIME = ?, GATEWAY_CONFIG = ? WHERE UUID = ?";
    try (Connection connection = DAOUtil.getConnection()) {
        connection.setAutoCommit(false);
        try (PreparedStatement statement = connection.prepareStatement(query)) {
            InputStream byteArrayInputStream = IOUtils.toInputStream(endpoint.getEndpointConfig());
            statement.setBinaryStream(1, byteArrayInputStream);
            if (endpoint.getMaxTps() != null) {
                statement.setLong(2, endpoint.getMaxTps());
            } else {
                statement.setNull(2, Types.INTEGER);
            }
            statement.setString(3, endpoint.getType());
            statement.setBinaryStream(4, IOUtils.toInputStream(endpoint.getSecurity()));
            statement.setTimestamp(5, Timestamp.valueOf(LocalDateTime.now()));
            statement.setBinaryStream(6, IOUtils.toInputStream(endpoint.getConfig()));
            statement.setString(7, endpoint.getId());
            statement.execute();
            connection.commit();
            return true;
        } catch (SQLException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating Endpoint: " + endpoint.getName(), e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating Endpoint: " + endpoint.getName(), e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 4 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.

the class ApiDAOImpl method deleteEndpoint.

/**
 * Delete an Endpoint
 *
 * @param endpointId UUID of the endpoint.
 * @return Success of the delete operation.
 * @throws APIMgtDAOException If failed to delete endpoint.
 */
@Override
public boolean deleteEndpoint(String endpointId) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            deleteEndpoint(connection, endpointId);
            connection.commit();
            return true;
        } catch (SQLException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 5 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.

/**
 * Extract properties in Operation entry and assign them to api resource builder properties.
 *
 * @param operationEntry     Map entry to be extracted properties
 * @param uriTemplateBuilder Uri template builder to assign related properties
 * @param resourcePath       resource path
 * @return APIResource.Builder object
 */
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
    Operation operation = operationEntry.getValue();
    APIResource.Builder apiResourceBuilder = new APIResource.Builder();
    List<String> producesList = operation.getProduces();
    if (producesList != null) {
        String produceSeparatedString = "\"";
        produceSeparatedString += String.join("\",\"", producesList) + "\"";
        apiResourceBuilder.produces(produceSeparatedString);
    }
    List<String> consumesList = operation.getConsumes();
    if (consumesList != null) {
        String consumesSeparatedString = "\"";
        consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
        apiResourceBuilder.consumes(consumesSeparatedString);
    }
    if (operation.getOperationId() != null) {
        uriTemplateBuilder.templateId(operation.getOperationId());
    } else {
        uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
    }
    uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
    apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
    return apiResourceBuilder;
}
Also used : APIResource(org.wso2.carbon.apimgt.core.models.APIResource) Operation(io.swagger.models.Operation)

Aggregations

Test (org.testng.annotations.Test)34 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)12 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)11 List (java.util.List)10 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)9 Map (java.util.Map)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Operation (io.swagger.models.Operation)7 Attribute (org.wso2.charon3.core.attributes.Attribute)7 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)7 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)7 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)7 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)6