use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetGlobalPolicyByUUID.
@Test
public void testGetGlobalPolicyByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GlobalPolicy globalPolicy = Mockito.mock(GlobalPolicy.class);
Mockito.when(apimgtDAO.getGlobalPolicyByUUID("1111")).thenReturn(globalPolicy, null);
apiProvider.getGlobalPolicyByUUID("1111");
try {
assertNotNull(apiProvider.getGlobalPolicyByUUID("1111"));
} catch (APIManagementException e) {
assertEquals("Global Policy: 1111 was not found.", e.getMessage());
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetGlobalPolicy.
@Test
public void testGetGlobalPolicy() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
GlobalPolicy globalPolicy = Mockito.mock(GlobalPolicy.class);
Mockito.when(apimgtDAO.getGlobalPolicy("testName")).thenReturn(globalPolicy);
assertNotNull(apiProvider.getGlobalPolicy("testName"));
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class GlobalPoliciesApiServiceImpl method globalPoliciesGet.
public Response globalPoliciesGet(String xWSO2Tenant, String policyName, MessageContext messageContext) {
SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
if (StringUtils.isNotEmpty(xWSO2Tenant)) {
if (APIConstants.CHAR_ASTERIX.equals(xWSO2Tenant)) {
return Response.ok().entity(SubscriptionValidationDataUtil.fromGlobalPolicyToGlobalPolicyListDTO(subscriptionValidationDAO.getAllGlobalPolicies())).build();
} else if (StringUtils.isNotEmpty(policyName)) {
List<GlobalPolicy> model = new ArrayList<>();
GlobalPolicy globalPolicy = subscriptionValidationDAO.getGlobalPolicyByNameForTenant(policyName, xWSO2Tenant);
if (globalPolicy != null) {
model.add(globalPolicy);
}
return Response.ok().entity(SubscriptionValidationDataUtil.fromGlobalPolicyToGlobalPolicyListDTO(model)).build();
} else {
return Response.ok().entity(SubscriptionValidationDataUtil.fromGlobalPolicyToGlobalPolicyListDTO(subscriptionValidationDAO.getAllGlobalPolicies(xWSO2Tenant))).build();
}
} else {
if (StringUtils.isNotEmpty(policyName)) {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
}
}
return Response.ok().entity(SubscriptionValidationDataUtil.fromGlobalPolicyToGlobalPolicyListDTO(subscriptionValidationDAO.getAllGlobalPolicies())).build();
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class ApiMgtDAO method getGlobalPolicyByUUID.
/**
* Get a particular Global level policy given UUID.
*
* @param uuid name of the global polixy
* @return {@link GlobalPolicy}
* @throws APIManagementException
*/
public GlobalPolicy getGlobalPolicyByUUID(String uuid) throws APIManagementException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sqlQuery = SQLConstants.GET_GLOBAL_POLICY_BY_UUID;
GlobalPolicy globalPolicy = null;
try {
conn = APIMgtDBUtil.getConnection();
ps = conn.prepareStatement(sqlQuery);
ps.setString(1, uuid);
rs = ps.executeQuery();
if (rs.next()) {
String siddhiQuery = null;
globalPolicy = new GlobalPolicy(rs.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicy.setDescription(rs.getString(ThrottlePolicyConstants.COLUMN_DESCRIPTION));
globalPolicy.setPolicyId(rs.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicy.setUUID(rs.getString(ThrottlePolicyConstants.COLUMN_UUID));
globalPolicy.setTenantId(rs.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
globalPolicy.setKeyTemplate(rs.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
globalPolicy.setDeployed(rs.getBoolean(ThrottlePolicyConstants.COLUMN_DEPLOYED));
InputStream siddhiQueryBlob = rs.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicy.setSiddhiQuery(siddhiQuery);
}
} catch (SQLException e) {
handleException("Error while retrieving global policy by uuid " + uuid, e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, rs);
}
return globalPolicy;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy in project carbon-apimgt by wso2.
the class ApiMgtDAO method getGlobalPolicy.
/**
* Get a particular Global level policy.
*
* @param policyName name of the global polixy
* @return {@link GlobalPolicy}
* @throws APIManagementException
*/
public GlobalPolicy getGlobalPolicy(String policyName) throws APIManagementException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sqlQuery = SQLConstants.GET_GLOBAL_POLICY;
GlobalPolicy globalPolicy = null;
try {
conn = APIMgtDBUtil.getConnection();
ps = conn.prepareStatement(sqlQuery);
ps.setString(1, policyName);
rs = ps.executeQuery();
if (rs.next()) {
String siddhiQuery = null;
globalPolicy = new GlobalPolicy(rs.getString(ThrottlePolicyConstants.COLUMN_NAME));
globalPolicy.setDescription(rs.getString(ThrottlePolicyConstants.COLUMN_DESCRIPTION));
globalPolicy.setPolicyId(rs.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
globalPolicy.setUUID(rs.getString(ThrottlePolicyConstants.COLUMN_UUID));
globalPolicy.setTenantId(rs.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
globalPolicy.setKeyTemplate(rs.getString(ThrottlePolicyConstants.COLUMN_KEY_TEMPLATE));
globalPolicy.setDeployed(rs.getBoolean(ThrottlePolicyConstants.COLUMN_DEPLOYED));
InputStream siddhiQueryBlob = rs.getBinaryStream(ThrottlePolicyConstants.COLUMN_SIDDHI_QUERY);
if (siddhiQueryBlob != null) {
siddhiQuery = APIMgtDBUtil.getStringFromInputStream(siddhiQueryBlob);
}
globalPolicy.setSiddhiQuery(siddhiQuery);
}
} catch (SQLException e) {
handleException("Error while executing SQL", e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, rs);
}
return globalPolicy;
}
Aggregations