use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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();
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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);
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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);
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.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;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.
@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
Swagger swagger = new Swagger();
Info info = new Info();
info.setTitle(api.getName());
info.setDescription(api.getDescription());
info.setVersion(api.getVersion());
swagger.setInfo(info);
Map<String, Path> stringPathMap = new HashMap();
for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
String uriTemplateString = uriTemplate.getUriTemplate();
List<Parameter> parameterList = getParameters(uriTemplateString);
if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
parameterList.add(getDefaultBodyParameter());
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.setOperationId(uriTemplate.getTemplateId());
operation.addResponse("200", getDefaultResponse());
if (stringPathMap.containsKey(uriTemplateString)) {
Path path = stringPathMap.get(uriTemplateString);
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
} else {
Path path = new Path();
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
stringPathMap.put(uriTemplateString, path);
}
}
swagger.setPaths(stringPathMap);
swagger.setPaths(stringPathMap);
return Json.pretty(swagger);
}
Aggregations