use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method getImage.
/**
* @see ApiDAO#getImage(String apiID)
*/
@Override
public InputStream getImage(String apiID) throws APIMgtDAOException {
API api = getAPI(apiID);
if (api == null) {
String errorMsg = "Unable to find API with Id: " + apiID;
log.error(errorMsg);
throw new APIMgtDAOException(errorMsg, ExceptionCodes.API_NOT_FOUND);
}
String thumbnailPath = APIFileUtils.getAPIBaseDirectory(storagePath, new FileApi(api)) + File.separator + APIMgtConstants.APIFileUtilConstants.THUMBNAIL_FILE_NAME;
return APIFileUtils.getThumbnailImage(thumbnailPath);
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getApplicationPolicyByUuid.
@Override
public ApplicationPolicy getApplicationPolicyByUuid(String uuid) throws APIMgtDAOException {
try {
final String query = "SELECT UUID, NAME, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, " + "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED from AM_APPLICATION_POLICY WHERE UUID = ?";
ApplicationPolicy applicationPolicy;
try (Connection conn = DAOUtil.getConnection();
PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, uuid);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
applicationPolicy = new ApplicationPolicy(rs.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME));
setCommonPolicyDetails(applicationPolicy, rs);
InputStream inputStream = rs.getBinaryStream(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CUSTOM_ATTRIB);
if (inputStream != null) {
applicationPolicy.setCustomAttributes(IOUtils.toByteArray(inputStream));
}
return applicationPolicy;
} else {
// not found
String msg = "Application Policy not found for id: " + uuid;
log.warn(msg);
throw new APIMgtDAOException(msg, ExceptionCodes.POLICY_NOT_FOUND);
}
} catch (IOException e) {
// error
throw new APIMgtDAOException("Internal error", e);
}
}
} catch (SQLException e) {
String errorMsg = "Error in retrieving Application Policy with id: " + uuid;
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class PolicyDAOImpl method createSubscriptionPolicyFromResultSet.
/**
* Creates a Subscription Policy from the results set
*
* @param identifier policy id
* @param rs {@link ResultSet} instance
* @return {@link SubscriptionPolicy} instance
* @throws SQLException if any error occurs while creating the Subscription Policy from the result set
* @throws APIMgtDAOException if any error occurs while retrieving custom attributes for this Subscription Policy
*/
private SubscriptionPolicy createSubscriptionPolicyFromResultSet(String identifier, ResultSet rs) throws SQLException, APIMgtDAOException {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(rs.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME));
setCommonPolicyDetails(subscriptionPolicy, rs);
setSubscriptionPolicyDetals(subscriptionPolicy, rs);
InputStream binary = rs.getBinaryStream(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CUSTOM_ATTRIB);
if (binary != null) {
byte[] customAttrib;
try {
customAttrib = IOUtils.toByteArray(binary);
if (customAttrib.length > 0) {
subscriptionPolicy.setCustomAttributes(customAttrib);
}
} catch (IOException e) {
String errorMsg = "An Error occurred while retrieving custom attributes for subscription policy with " + "identifier: " + identifier;
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
return subscriptionPolicy;
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getCustomPolicyByUuid.
@Override
public CustomPolicy getCustomPolicyByUuid(String uuid) throws APIMgtDAOException {
String query = "SELECT NAME, DESCRIPTION, UUID, KEY_TEMPLATE, IS_DEPLOYED, SIDDHI_QUERY FROM AM_CUSTOM_POLICY" + " WHERE UUID = ? ";
CustomPolicy customPolicy = null;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, uuid);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
String siddhiQuery = null;
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);
}
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting custom policy with UUID : " + uuid, e);
}
return customPolicy;
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocumentationContent.
/**
* This method used to get the content of a documentation
*
* @param docId Document ID
* @return {@link InputStream} Input stream for document content
* @throws APIManagementException if the requested documentation content is not available
*/
public DocumentContent getDocumentationContent(String docId) throws APIManagementException {
try {
DocumentInfo documentInfo = getDocumentationSummary(docId);
DocumentContent.Builder documentContentBuilder = new DocumentContent.Builder();
if (documentInfo != null) {
documentContentBuilder.documentInfo(documentInfo);
if (DocumentInfo.SourceType.FILE.equals(documentInfo.getSourceType())) {
InputStream inputStream = getApiDAO().getDocumentFileContent(docId);
if (inputStream != null) {
documentContentBuilder = documentContentBuilder.fileContent(inputStream);
} else {
throw new APIManagementException("Couldn't find file content of document", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND);
}
} else if (documentInfo.getSourceType().equals(DocumentInfo.SourceType.INLINE)) {
String inlineContent = getApiDAO().getDocumentInlineContent(docId);
if (inlineContent != null) {
documentContentBuilder = documentContentBuilder.inlineContent(inlineContent);
} else {
throw new APIManagementException("Couldn't find inline content of document", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND);
}
}
} else {
throw new APIManagementException("Couldn't fnd document", ExceptionCodes.DOCUMENT_NOT_FOUND);
}
return documentContentBuilder.build();
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving document content";
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
Aggregations