use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitQuery.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Query visitQuery(@NotNull SiddhiQLParser.QueryContext ctx) {
try {
Query query = Query.query().from((InputStream) visit(ctx.query_input()));
if (ctx.query_section() != null) {
query.select((Selector) visit(ctx.query_section()));
}
if (ctx.output_rate() != null) {
query.output((OutputRate) visit(ctx.output_rate()));
}
for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
query.annotation((Annotation) visit(annotationContext));
}
if (ctx.query_output() != null) {
query.outStream((OutputStream) visit(ctx.query_output()));
}
populateQueryContext(query, ctx);
return query;
} finally {
activeStreams.clear();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream 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.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiDAOImpl method addDocumentFileContent.
/**
* @see ApiDAO#addDocumentFileContent(String, InputStream, String, String)
*/
@Override
public void addDocumentFileContent(String resourceID, InputStream content, String dataType, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
if (ApiResourceDAO.updateBinaryResource(connection, resourceID, content, dataType, updatedBy) == 0) {
String msg = "Cannot add file content for non existing document: " + resourceID + ", updated by: " + updatedBy;
throw new APIMgtDAOException(msg, ExceptionCodes.DOCUMENT_NOT_FOUND);
}
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "adding document file content for document: " + resourceID + ", updatedBy: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "adding document file content for document: " + resourceID + ", updatedBy: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getCustomPolicies.
@Override
public List<CustomPolicy> getCustomPolicies() throws APIMgtDAOException {
List<CustomPolicy> customPolicyList = new ArrayList<>();
String getQuery = "SELECT NAME, DESCRIPTION, UUID, KEY_TEMPLATE, IS_DEPLOYED, SIDDHI_QUERY FROM " + "AM_CUSTOM_POLICY";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(getQuery)) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String siddhiQuery = null;
CustomPolicy customPolicy = new CustomPolicy(resultSet.getString("NAME"));
customPolicy.setDescription(resultSet.getString("DESCRIPTION"));
customPolicy.setUuid(resultSet.getString("UUID"));
customPolicy.setKeyTemplate(resultSet.getString("KEY_TEMPLATE"));
customPolicy.setDeployed(resultSet.getBoolean("IS_DEPLOYED"));
InputStream siddhiQueryBlob = resultSet.getBinaryStream("SIDDHI_QUERY");
if (siddhiQueryBlob != null) {
try {
siddhiQuery = IOUtils.toString(siddhiQueryBlob);
} catch (IOException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "reading siddhi query stream", e);
}
}
customPolicy.setSiddhiQuery(siddhiQuery);
customPolicyList.add(customPolicy);
}
}
return customPolicyList;
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting custom policies", e);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class APIFileUtils method extractUploadedArchive.
/**
* Extracts the APIs to the file system by reading the incoming {@link InputStream} object
* uploadedApiArchiveInputStream
*
* @param uploadedApiArchiveInputStream Incoming {@link InputStream}
* @param importedDirectoryName directory to extract the archive
* @param apiArchiveLocation full path of the archive location
* @param extractLocation full path to the location to which the archive will be written
* @return location to which APIs were extracted
* @throws APIMgtDAOException if an error occurs while extracting the archive
*/
public static String extractUploadedArchive(InputStream uploadedApiArchiveInputStream, String importedDirectoryName, String apiArchiveLocation, String extractLocation) throws APIMgtDAOException {
String archiveExtractLocation;
try {
// create api import directory structure
APIFileUtils.createDirectory(extractLocation);
// create archive
createArchiveFromInputStream(uploadedApiArchiveInputStream, apiArchiveLocation);
// extract the archive
archiveExtractLocation = extractLocation + File.separator + importedDirectoryName;
extractArchive(apiArchiveLocation, archiveExtractLocation);
} catch (APIMgtDAOException e) {
APIFileUtils.deleteDirectory(extractLocation);
String errorMsg = "Error in accessing uploaded API archive";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
return archiveExtractLocation;
}
Aggregations