use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method populateGlobalPolicyList.
private List<GlobalPolicy> populateGlobalPolicyList(ResultSet resultSet) throws SQLException {
List<GlobalPolicy> globalPolicies = new ArrayList<>();
if (resultSet != null) {
while (resultSet.next()) {
GlobalPolicy globalPolicyDTO = new GlobalPolicy();
globalPolicyDTO.setId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicyDTO.setName(resultSet.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicyDTO.setTenantId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
String tenantDomain = APIUtil.getTenantDomainFromTenantId(globalPolicyDTO.getTenantId());
globalPolicyDTO.setTenantDomain(tenantDomain);
globalPolicyDTO.setKeyTemplate(resultSet.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
InputStream siddhiQueryBlob = resultSet.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
String siddhiQuery = null;
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicyDTO.setSiddhiQuery(siddhiQuery);
globalPolicies.add(globalPolicyDTO);
}
}
return globalPolicies;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method getAllGlobalPolicies.
public List<GlobalPolicy> getAllGlobalPolicies(String tenantDomain) {
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(SubscriptionValidationSQLConstants.GET_TENANT_GLOBAL_POLICIES_SQL)) {
int tenantId = 0;
try {
tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
log.error("Error in loading Global Policies for tenantDomain : " + tenantDomain, e);
}
ps.setInt(1, tenantId);
try (ResultSet resultSet = ps.executeQuery()) {
return populateGlobalPolicyList(resultSet);
}
} catch (SQLException e) {
log.error("Error in loading global policies for tenantId : " + tenantDomain, e);
}
return null;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method getGlobalPolicyByNameForTenant.
public GlobalPolicy getGlobalPolicyByNameForTenant(String policyName, String tenantDomain) {
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(SubscriptionValidationSQLConstants.GET_GLOBAL_POLICY_SQL)) {
int tenantId = 0;
try {
tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
log.error("Error in loading Global Policy for tenantDomain : " + tenantDomain, e);
}
ps.setString(1, policyName);
ps.setInt(2, tenantId);
try (ResultSet resultSet = ps.executeQuery()) {
if (resultSet.next()) {
GlobalPolicy globalPolicyDTO = new GlobalPolicy();
globalPolicyDTO.setId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicyDTO.setName(resultSet.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicyDTO.setTenantId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
globalPolicyDTO.setTenantDomain(tenantDomain);
globalPolicyDTO.setKeyTemplate(resultSet.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
InputStream siddhiQueryBlob = resultSet.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
String siddhiQuery = null;
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicyDTO.setSiddhiQuery(siddhiQuery);
return globalPolicyDTO;
}
}
} catch (SQLException e) {
log.error("Error in loading global policies by policyId : " + policyName + " of " + policyName, e);
}
return null;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class APIProviderImplTest method getPolicyGlobalLevel.
private GlobalPolicy getPolicyGlobalLevel() {
GlobalPolicy policy = new GlobalPolicy("1");
policy.setDescription("Description");
String siddhiQuery = "FROM RequestStream\n" + "SELECT 'global_1' AS rule, messageID, true AS isEligible, (cast(map:get(propertiesMap,’ip’),’string’)" + " == 3232235778) as isLocallyThrottled," + " 'global_1_key' AS throttle_key\n" + "INSERT INTO EligibilityStream;";
policy.setSiddhiQuery(siddhiQuery);
return policy;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class APIProviderImplTest method testIsGlobalPolicyKeyTemplateExists.
@Test
public void testIsGlobalPolicyKeyTemplateExists() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GlobalPolicy globalPolicy = Mockito.mock(GlobalPolicy.class);
Mockito.when(apimgtDAO.isKeyTemplatesExist(globalPolicy)).thenReturn(true);
assertTrue(apiProvider.isGlobalPolicyKeyTemplateExists(globalPolicy));
}
Aggregations