use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.
the class APIProviderImplTest method getPolicyAPILevelPerUser.
private APIPolicy getPolicyAPILevelPerUser() {
APIPolicy policy = new APIPolicy("custom1");
policy.setUserLevel(PolicyConstants.PER_USER);
policy.setDescription("Description");
// policy.setPolicyLevel("api");
policy.setTenantDomain("carbon.super");
RequestCountLimit defaultLimit = new RequestCountLimit();
defaultLimit.setTimeUnit("min");
defaultLimit.setUnitTime(5);
defaultLimit.setRequestCount(400);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setLimit(defaultLimit);
defaultQuotaPolicy.setType("RequestCount");
policy.setDefaultQuotaPolicy(defaultQuotaPolicy);
List<Pipeline> pipelines;
Pipeline p;
QuotaPolicy quotaPolicy;
List<Condition> condition;
RequestCountLimit countlimit;
Condition cond;
pipelines = new ArrayList<Pipeline>();
// /////////pipeline item start//////
p = new Pipeline();
quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("RequestCount");
countlimit = new RequestCountLimit();
countlimit.setTimeUnit("min");
countlimit.setUnitTime(5);
countlimit.setRequestCount(100);
quotaPolicy.setLimit(countlimit);
condition = new ArrayList<Condition>();
HTTPVerbCondition verbCond = new HTTPVerbCondition();
verbCond.setHttpVerb("POST");
condition.add(verbCond);
p.setQuotaPolicy(quotaPolicy);
p.setConditions(condition);
pipelines.add(p);
// /////////pipeline item end//////
policy.setPipelines(pipelines);
return policy;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.
the class ApiMgtDAO method getSubscriptionBlockCondition.
/**
* Get details of the subscription block condition by condition value and tenant domain
*
* @param conditionValue condition value of the block condition
* @param tenantDomain tenant domain of the block condition
* @return Block condition
* @throws APIManagementException
*/
public BlockConditionsDTO getSubscriptionBlockCondition(String conditionValue, String tenantDomain) throws APIManagementException {
Connection connection = null;
PreparedStatement selectPreparedStatement = null;
ResultSet resultSet = null;
BlockConditionsDTO blockCondition = null;
try {
String query = SQLConstants.ThrottleSQLConstants.GET_SUBSCRIPTION_BLOCK_CONDITION_BY_VALUE_AND_DOMAIN_SQL;
connection = APIMgtDBUtil.getConnection();
connection.setAutoCommit(true);
selectPreparedStatement = connection.prepareStatement(query);
selectPreparedStatement.setString(1, conditionValue);
selectPreparedStatement.setString(2, tenantDomain);
resultSet = selectPreparedStatement.executeQuery();
if (resultSet.next()) {
blockCondition = new BlockConditionsDTO();
blockCondition.setEnabled(resultSet.getBoolean("ENABLED"));
blockCondition.setConditionType(resultSet.getString("TYPE"));
blockCondition.setConditionValue(resultSet.getString("BLOCK_CONDITION"));
blockCondition.setConditionId(resultSet.getInt("CONDITION_ID"));
blockCondition.setTenantDomain(resultSet.getString("DOMAIN"));
blockCondition.setUUID(resultSet.getString("UUID"));
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException ex) {
handleException("Failed to rollback getting Subscription Block condition with condition value " + conditionValue + " of tenant " + tenantDomain, ex);
}
}
handleException("Failed to get Subscription Block condition with condition value " + conditionValue + " of tenant " + tenantDomain, e);
} finally {
APIMgtDBUtil.closeAllConnections(selectPreparedStatement, connection, resultSet);
}
return blockCondition;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.
the class ApiMgtDAO method setQueryParameterConditions.
/**
* Add Query parameter 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 APIManagementException
*/
private void setQueryParameterConditions(int pipelineId, ArrayList<Condition> conditions) throws APIManagementException {
Connection connection = null;
PreparedStatement conditionsStatement = null;
ResultSet resultSet = null;
try {
connection = APIMgtDBUtil.getConnection();
conditionsStatement = connection.prepareStatement(SQLConstants.ThrottleSQLConstants.GET_QUERY_PARAMETER_CONDITIONS_SQL);
conditionsStatement.setInt(1, pipelineId);
resultSet = conditionsStatement.executeQuery();
while (resultSet.next()) {
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition.setParameter(resultSet.getString(ThrottlePolicyConstants.COLUMN_PARAMETER_NAME));
queryParameterCondition.setValue(resultSet.getString(ThrottlePolicyConstants.COLUMN_PARAMETER_VALUE));
queryParameterCondition.setInvertCondition(resultSet.getBoolean(ThrottlePolicyConstants.COLUMN_IS_PARAM_MAPPING));
conditions.add(queryParameterCondition);
}
} catch (SQLException e) {
handleException("Failed to get query parameter conditions for pipelineId: " + pipelineId, e);
} finally {
APIMgtDBUtil.closeAllConnections(conditionsStatement, connection, resultSet);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.
the class ApiMgtDAO method getPipelines.
/**
* Retrieves list of pipelines for the policy with policy Id: <code>policyId</code>
*
* @param policyId policy id of the pipelines
* @return list of pipelines
* @throws APIManagementException
*/
private ArrayList<Pipeline> getPipelines(int policyId) throws APIManagementException {
Connection connection = null;
PreparedStatement pipelinesStatement = null;
ResultSet resultSet = null;
ArrayList<Pipeline> pipelines = new ArrayList<Pipeline>();
try {
connection = APIMgtDBUtil.getConnection();
pipelinesStatement = connection.prepareStatement(SQLConstants.ThrottleSQLConstants.GET_PIPELINES_SQL);
int unitTime = 0;
int quota = 0;
int pipelineId = -1;
String timeUnit = null;
String quotaUnit = null;
String description;
pipelinesStatement.setInt(1, policyId);
resultSet = pipelinesStatement.executeQuery();
while (resultSet.next()) {
Pipeline pipeline = new Pipeline();
ArrayList<Condition> conditions = null;
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType(resultSet.getString(ThrottlePolicyConstants.COLUMN_QUOTA_POLICY_TYPE));
timeUnit = resultSet.getString(ThrottlePolicyConstants.COLUMN_TIME_UNIT);
quotaUnit = resultSet.getString(ThrottlePolicyConstants.COLUMN_QUOTA_UNIT);
unitTime = resultSet.getInt(ThrottlePolicyConstants.COLUMN_UNIT_TIME);
quota = resultSet.getInt(ThrottlePolicyConstants.COLUMN_QUOTA);
pipelineId = resultSet.getInt(ThrottlePolicyConstants.COLUMN_CONDITION_ID);
description = resultSet.getString(ThrottlePolicyConstants.COLUMN_DESCRIPTION);
if (PolicyConstants.REQUEST_COUNT_TYPE.equals(quotaPolicy.getType())) {
RequestCountLimit requestCountLimit = new RequestCountLimit();
requestCountLimit.setUnitTime(unitTime);
requestCountLimit.setTimeUnit(timeUnit);
requestCountLimit.setRequestCount(quota);
quotaPolicy.setLimit(requestCountLimit);
} else if (PolicyConstants.BANDWIDTH_TYPE.equals(quotaPolicy.getType())) {
BandwidthLimit bandwidthLimit = new BandwidthLimit();
bandwidthLimit.setUnitTime(unitTime);
bandwidthLimit.setTimeUnit(timeUnit);
bandwidthLimit.setDataUnit(quotaUnit);
bandwidthLimit.setDataAmount(quota);
quotaPolicy.setLimit(bandwidthLimit);
}
conditions = getConditions(pipelineId);
pipeline.setConditions(conditions);
pipeline.setQuotaPolicy(quotaPolicy);
pipeline.setId(pipelineId);
pipeline.setDescription(description);
pipelines.add(pipeline);
}
} catch (SQLException e) {
handleException("Failed to get pipelines for policyId: " + policyId, e);
} finally {
APIMgtDBUtil.closeAllConnections(pipelinesStatement, connection, resultSet);
}
return pipelines;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.
the class ApiMgtDAO method setHeaderConditions.
/**
* Add Header 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 APIManagementException
*/
private void setHeaderConditions(int pipelineId, ArrayList<Condition> conditions) throws APIManagementException {
Connection connection = null;
PreparedStatement conditionsStatement = null;
ResultSet resultSet = null;
try {
connection = APIMgtDBUtil.getConnection();
conditionsStatement = connection.prepareStatement(SQLConstants.ThrottleSQLConstants.GET_HEADER_CONDITIONS_SQL);
conditionsStatement.setInt(1, pipelineId);
resultSet = conditionsStatement.executeQuery();
while (resultSet.next()) {
HeaderCondition headerCondition = new HeaderCondition();
headerCondition.setHeader(resultSet.getString(ThrottlePolicyConstants.COLUMN_HEADER_FIELD_NAME));
headerCondition.setValue(resultSet.getString(ThrottlePolicyConstants.COLUMN_HEADER_FIELD_VALUE));
headerCondition.setInvertCondition(resultSet.getBoolean(ThrottlePolicyConstants.COLUMN_IS_HEADER_FIELD_MAPPING));
conditions.add(headerCondition);
}
} catch (SQLException e) {
handleException("Failed to get header conditions for pipelineId: " + pipelineId, e);
} finally {
APIMgtDBUtil.closeAllConnections(conditionsStatement, connection, resultSet);
}
}
Aggregations