use of org.wso2.siddhi.query.api.expression.math.Add 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.expression.math.Add in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @param updatedBy user who performs the action
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.siddhi.query.api.expression.math.Add in project carbon-apimgt by wso2.
the class PolicyDAOImpl method addAPIPipeline.
/**
* Adding pipelines of API policy to database
*
* @param connection connection to db
* @param uuid policy id/ uuid of the policy
* @throws SQLException if error occurred while inserting pipeline to db
*/
private static void addAPIPipeline(Connection connection, List<Pipeline> pipelines, String uuid) throws SQLException, APIMgtDAOException {
final String query = "INSERT INTO AM_CONDITION_GROUP (UUID, QUOTA_TYPE, UNIT_TIME, TIME_UNIT, DESCRIPTION, QUOTA, " + "QUOTA_UNIT) VALUES (?,?,?,?,?,?,?)";
String dbProductName = connection.getMetaData().getDatabaseProductName();
try (PreparedStatement statement = connection.prepareStatement(query, new String[] { DAOUtil.getConvertedAutoGeneratedColumnName(dbProductName, APIMgtConstants.ThrottlePolicyConstants.COLUMN_CONDITION_GROUP_ID) })) {
for (Pipeline pipeline : pipelines) {
statement.setString(1, uuid);
statement.setString(2, pipeline.getQuotaPolicy().getType());
statement.setLong(3, pipeline.getQuotaPolicy().getLimit().getUnitTime());
statement.setString(4, pipeline.getQuotaPolicy().getLimit().getTimeUnit());
statement.setString(5, pipeline.getDescription());
Limit limit = pipeline.getQuotaPolicy().getLimit();
setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement);
statement.executeUpdate();
ResultSet rs = statement.getGeneratedKeys();
if (rs.next()) {
// get the auto increment id
int conditionId = rs.getInt(1);
List<Condition> conditionList = pipeline.getConditions();
for (Condition condition : conditionList) {
if (PolicyConstants.IP_CONDITION_TYPE.equals(condition.getType()) || PolicyConstants.IP_SPECIFIC_TYPE.equals(condition.getType()) || PolicyConstants.IP_RANGE_TYPE.equals(condition.getType())) {
addIPCondition(connection, condition, conditionId);
} else if (PolicyConstants.HEADER_CONDITION_TYPE.equals(condition.getType())) {
addHeaderCondition(connection, condition, conditionId);
} else if (PolicyConstants.JWT_CLAIMS_CONDITION_TYPE.equals(condition.getType())) {
addJWTClaimCondition(connection, condition, conditionId);
} else if (PolicyConstants.QUERY_PARAMS_CONDITION_TYPE.equals(condition.getType())) {
addParamCondition(connection, condition, conditionId);
} else {
// unsupported Condition
throw new IllegalArgumentException("Unsupported Condition type: " + condition.getType());
}
}
} else {
String errorMsg = "Unable to retrieve auto incremented id, hence unable to add Pipeline Condition";
throw new IllegalStateException(errorMsg);
}
}
}
}
use of org.wso2.siddhi.query.api.expression.math.Add in project carbon-apimgt by wso2.
the class PolicyDAOImpl method setJWTClaimConditions.
/**
* Add JWT claim conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
* provided {@link Condition} array
*
* @param pipelineId Id of the pipeline
* @param conditions condition array to populate
* @throws SQLException
*/
private void setJWTClaimConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
final String query = "SELECT " + "CLAIM_URI, " + "CLAIM_ATTRIB , IS_CLAIM_MAPPING " + "FROM " + "AM_JWT_CLAIM_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setInt(1, pipelineId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
jwtClaimsCondition.setClaimUrl(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_URI));
jwtClaimsCondition.setAttribute(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_CLAIM_ATTRIBUTE));
jwtClaimsCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_CLAIM_MAPPING));
conditions.add(jwtClaimsCondition);
}
}
}
}
use of org.wso2.siddhi.query.api.expression.math.Add in project carbon-apimgt by wso2.
the class PolicyDAOImpl method setIPCondition.
/**
* Retrieve IP condition from pipeline
*
* @param pipelineId id of the pipeline to get ip condition
* @param conditions condition list to add each ip condition
* @param connection connection to db
* @throws SQLException If error occurred while getting ip condition form db
*/
private void setIPCondition(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
final String sqlQuery = "SELECT " + "STARTING_IP, " + "ENDING_IP, " + "SPECIFIC_IP,WITHIN_IP_RANGE " + "FROM " + "" + "AM_IP_CONDITION " + "WHERE " + "CONDITION_GROUP_ID = ? ";
String startingIP;
String endingIP;
String specificIP;
boolean invert;
try (PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setInt(1, pipelineId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
startingIP = resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_STARTING_IP);
endingIP = resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_ENDING_IP);
specificIP = resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_SPECIFIC_IP);
invert = resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_WITHIN_IP_RANGE);
if (specificIP != null && !"".equals(specificIP)) {
IPCondition ipCondition = new IPCondition(PolicyConstants.IP_SPECIFIC_TYPE);
ipCondition.setSpecificIP(specificIP);
ipCondition.setInvertCondition(invert);
conditions.add(ipCondition);
} else if (startingIP != null && !"".equals(startingIP)) {
/*
Assumes availability of starting ip means ip range is enforced.
Therefore availability of ending ip is not checked.
*/
IPCondition ipRangeCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
ipRangeCondition.setStartingIP(startingIP);
ipRangeCondition.setEndingIP(endingIP);
ipRangeCondition.setInvertCondition(invert);
conditions.add(ipRangeCondition);
}
}
}
}
}
Aggregations