use of org.wso2.carbon.apimgt.api.model.OperationPolicyData in project carbon-apimgt by wso2.
the class ApiMgtDAO method getLightWeightVersionOfAllOperationPolicies.
/**
* Get the list of all operation policies. If the API UUID is provided, this will return all the operation policies
* for that API. If not, it will return the common operation policies which are not bound to any API.
* This list will include policy specification of each policy and policy ID. It will not contain the
* policy definition as it is not useful for the operation.
*
* @param apiUUID UUID of the API if exists. Null for common operation policies
* @param organization Organization name
* @return List of Operation Policies
* @throws APIManagementException
*/
public List<OperationPolicyData> getLightWeightVersionOfAllOperationPolicies(String apiUUID, String organization) throws APIManagementException {
String dbQuery;
if (apiUUID != null) {
dbQuery = SQLConstants.OperationPolicyConstants.GET_ALL_API_SPECIFIC_OPERATION_POLICIES_WITHOUT_CLONED_POLICIES;
} else {
dbQuery = SQLConstants.OperationPolicyConstants.GET_ALL_COMMON_OPERATION_POLICIES;
}
List<OperationPolicyData> policyDataList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(dbQuery)) {
statement.setString(1, organization);
if (apiUUID != null) {
statement.setString(2, apiUUID);
}
ResultSet rs = statement.executeQuery();
while (rs.next()) {
OperationPolicyData policyData = new OperationPolicyData();
policyData.setOrganization(organization);
policyData.setPolicyId(rs.getString("POLICY_UUID"));
policyData.setMd5Hash(rs.getString("POLICY_MD5"));
policyData.setSpecification(populatePolicySpecificationFromRS(rs));
if (apiUUID != null) {
policyData.setApiUUID(apiUUID);
}
policyDataList.add(policyData);
}
} catch (SQLException e) {
handleException("Failed to get all the operation policy for tenant " + organization, e);
}
return policyDataList;
}
use of org.wso2.carbon.apimgt.api.model.OperationPolicyData in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPISpecificOperationPolicyByPolicyID.
private OperationPolicyData getAPISpecificOperationPolicyByPolicyID(Connection connection, String policyId, String apiUUID, String organization, boolean isWithPolicyDefinition) throws SQLException {
String dbQuery = SQLConstants.OperationPolicyConstants.GET_API_SPECIFIC_OPERATION_POLICY_FROM_POLICY_ID;
OperationPolicyData policyData = null;
PreparedStatement statement = connection.prepareStatement(dbQuery);
statement.setString(1, policyId);
statement.setString(2, organization);
statement.setString(3, apiUUID);
ResultSet rs = statement.executeQuery();
if (rs.next()) {
policyData = new OperationPolicyData();
policyData.setPolicyId(policyId);
policyData.setApiUUID(apiUUID);
policyData.setOrganization(organization);
policyData.setMd5Hash(rs.getString("POLICY_MD5"));
policyData.setRevisionUUID(rs.getString("REVISION_UUID"));
policyData.setClonedCommonPolicyId(rs.getString("CLONED_POLICY_UUID"));
policyData.setSpecification(populatePolicySpecificationFromRS(rs));
}
rs.close();
statement.close();
if (isWithPolicyDefinition && policyData != null) {
if (isWithPolicyDefinition && policyData != null) {
populatePolicyDefinitions(connection, policyId, policyData);
}
}
return policyData;
}
use of org.wso2.carbon.apimgt.api.model.OperationPolicyData in project carbon-apimgt by wso2.
the class ApiMgtDAO method addCommonOperationPolicy.
/**
* Operation policy implementation
*/
/**
* Add a new common operation policy to the database. This will first add the operation policy content to the
* AM_OPERATION_POLICY table and another entry to AM_COMMON_OPERATION_POLICY table.
*
* @param policyData Operation policy data.
* @return UUID of the newly created shared policy
* @throws APIManagementException
*/
public String addCommonOperationPolicy(OperationPolicyData policyData) throws APIManagementException {
String policyUUID = null;
OperationPolicySpecification policySpecification = policyData.getSpecification();
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
policyUUID = addOperationPolicyContent(connection, policyData);
String dbQuery = SQLConstants.OperationPolicyConstants.ADD_COMMON_OPERATION_POLICY;
PreparedStatement statement = connection.prepareStatement(dbQuery);
statement.setString(1, policyUUID);
statement.executeUpdate();
statement.close();
connection.commit();
} catch (SQLException e) {
connection.rollback();
handleException("Failed to add common operation policy " + policySpecification.getName(), e);
}
} catch (SQLException e) {
handleException("Failed to add common operation policy " + policySpecification.getName(), e);
}
return policyUUID;
}
use of org.wso2.carbon.apimgt.api.model.OperationPolicyData in project carbon-apimgt by wso2.
the class ApiMgtDAO method addAPISpecificOperationPolicy.
/**
* Add a new API specific operation policy to the database
*
* @param apiUUID Unique Identifier of API
* @param revisionUUID Unique Identifier of API revision
* @param policyData Unique Identifier of API
* @return UUID of the newly created shared policy
* @throws APIManagementException
*/
public String addAPISpecificOperationPolicy(String apiUUID, String revisionUUID, OperationPolicyData policyData) throws APIManagementException {
OperationPolicySpecification policySpecification = policyData.getSpecification();
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
String policyID = addAPISpecificOperationPolicy(connection, apiUUID, revisionUUID, policyData, null);
connection.commit();
return policyID;
} catch (SQLException e) {
connection.rollback();
handleException("Failed to add API specific operation policy " + policySpecification.getName() + " for API " + apiUUID, e);
}
} catch (SQLException e) {
handleException("Failed to add API specific operation policy " + policySpecification.getName() + " for API " + apiUUID, e);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.OperationPolicyData in project carbon-apimgt by wso2.
the class ApiMgtDAO method updateOperationPolicy.
/**
* Update an existing operation policy
*
* @param connection DB connection
* @param policyId Shared policy UUID
* @param policyData Updated policy definition
* @throws SQLException
*/
private void updateOperationPolicy(Connection connection, String policyId, OperationPolicyData policyData) throws SQLException {
OperationPolicySpecification policySpecification = policyData.getSpecification();
PreparedStatement statement = connection.prepareStatement(SQLConstants.OperationPolicyConstants.UPDATE_OPERATION_POLICY_CONTENT);
statement.setString(1, policySpecification.getName());
statement.setString(2, policySpecification.getDisplayName());
statement.setString(3, policySpecification.getDescription());
statement.setString(4, policySpecification.getApplicableFlows().toString());
statement.setString(5, policySpecification.getSupportedGateways().toString());
statement.setString(6, policySpecification.getSupportedApiTypes().toString());
statement.setBinaryStream(7, new ByteArrayInputStream(APIUtil.getPolicyAttributesAsString(policySpecification).getBytes()));
statement.setString(8, policyData.getOrganization());
statement.setString(9, policySpecification.getCategory().toString());
statement.setBoolean(10, policySpecification.isMultipleAllowed());
statement.setString(11, policyData.getMd5Hash());
statement.setString(12, policyId);
statement.executeUpdate();
statement.close();
if (policyData.getSynapsePolicyDefinition() != null) {
updateOperationPolicyDefinition(connection, policyId, policyData.getSynapsePolicyDefinition());
}
if (policyData.getCcPolicyDefinition() != null) {
updateOperationPolicyDefinition(connection, policyId, policyData.getCcPolicyDefinition());
}
}
Aggregations