use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class PolicyDAOImpl method getAllPolicies.
@Override
public Set<PolicyValidationData> getAllPolicies() throws APIMgtDAOException {
Set<PolicyValidationData> policyValidationDataList = new LinkedHashSet();
final String apiPolicyQuery = "SELECT UUID,NAME FROM AM_API_POLICY";
final String applicationPolicyQuery = "SELECT UUID,NAME FROM AM_APPLICATION_POLICY";
final String subscriptionPolicyQuery = "SELECT UUID,NAME,STOP_ON_QUOTA_REACH FROM AM_SUBSCRIPTION_POLICY";
try (Connection connection = DAOUtil.getConnection()) {
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery(apiPolicyQuery)) {
while (resultSet.next()) {
policyValidationDataList.add(new PolicyValidationData(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME), false));
}
}
try (ResultSet resultSet = statement.executeQuery(applicationPolicyQuery)) {
while (resultSet.next()) {
policyValidationDataList.add(new PolicyValidationData(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME), false));
}
}
try (ResultSet resultSet = statement.executeQuery(subscriptionPolicyQuery)) {
while (resultSet.next()) {
policyValidationDataList.add(new PolicyValidationData(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME), resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_STOP_ON_QUOTA_REACH)));
}
}
}
} catch (SQLException e) {
String msg = "Error while retrieving policies";
log.error(msg, e);
throw new APIMgtDAOException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return policyValidationDataList;
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deletePolicy.
@Override
public void deletePolicy(PolicyValidationData policyValidationData) throws GatewayException {
if (policyValidationData != null) {
PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_DELETE);
policyEvent.setId(policyValidationData.getId());
policyEvent.setName(policyValidationData.getName());
policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
publishToThrottleTopic(policyEvent);
if (log.isDebugEnabled()) {
log.debug("Policy : " + policyValidationData.getName() + " delete event has been successfully " + "published " + "to broker");
}
}
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addPolicy.
@Override
public void addPolicy(PolicyValidationData policyValidationData) throws GatewayException {
if (policyValidationData != null) {
PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_CREATE);
policyEvent.setId(policyValidationData.getId());
policyEvent.setName(policyValidationData.getName());
policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
publishToThrottleTopic(policyEvent);
if (log.isDebugEnabled()) {
log.debug("Policy : " + policyValidationData.getName() + " add event has been successfully published " + "to broker");
}
}
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApiPolicy.
@Override
public String addApiPolicy(APIPolicy policy) throws APIManagementException {
try {
String policyUuid = policy.getUuid();
if (policyUuid == null) {
if (log.isDebugEnabled()) {
log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
}
policyUuid = UUID.randomUUID().toString();
policy.setUuid(policyUuid);
}
policyDAO.addApiPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add API policy for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApplicationPolicy.
@Override
public String addApplicationPolicy(ApplicationPolicy policy) throws APIManagementException {
try {
String policyUuid = policy.getUuid();
if (policyUuid == null) {
if (log.isDebugEnabled()) {
log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
}
policyUuid = UUID.randomUUID().toString();
policy.setUuid(policyUuid);
}
policyDAO.addApplicationPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add Application for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
Aggregations