use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class AsyncApiParser method buildURITemplate.
private URITemplate buildURITemplate(String target, String verb, Aai20Operation operation, Set<Scope> scopes, Aai20ChannelItem channel) throws APIManagementException {
URITemplate template = new URITemplate();
template.setHTTPVerb(verb);
template.setHttpVerbs(verb);
template.setUriTemplate(target);
Extension authTypeExtension = channel.getExtension(APIConstants.SWAGGER_X_AUTH_TYPE);
if (authTypeExtension != null && authTypeExtension.value instanceof String) {
template.setAuthType(authTypeExtension.value.toString());
}
List<String> opScopes = getScopeOfOperations(operation);
if (!opScopes.isEmpty()) {
if (opScopes.size() == 1) {
String firstScope = opScopes.get(0);
Scope scope = APIUtil.findScopeByKey(scopes, firstScope);
if (scope == null) {
throw new APIManagementException("Scope '" + firstScope + "' not found.");
}
template.setScope(scope);
template.setScopes(scope);
} else {
for (String scopeName : opScopes) {
Scope scope = APIUtil.findScopeByKey(scopes, scopeName);
if (scope == null) {
throw new APIManagementException("Resource Scope '" + scopeName + "' not found.");
}
template.setScopes(scope);
}
}
}
return template;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class ApiMgtDAO method getOperationPoliciesOfURITemplate.
/**
* Get operation polycies attached to the resource identified by the url mapping ID
*
* @param urlMappingId URL Mapping ID of the resource
* @return
* @throws SQLException
* @throws APIManagementException
*/
private List<OperationPolicy> getOperationPoliciesOfURITemplate(int urlMappingId) throws SQLException, APIManagementException {
List<OperationPolicy> operationPolicies = new ArrayList<>();
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(SQLConstants.OperationPolicyConstants.GET_OPERATION_POLICIES_BY_URI_TEMPLATE_ID)) {
ps.setInt(1, urlMappingId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
OperationPolicy policy = populateOperationPolicyWithRS(rs);
operationPolicies.add(policy);
}
}
}
return operationPolicies;
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class ApiMgtDAO method cloneOperationPolicy.
/**
* Clone an operation policy to the API. This method is used to clone policy to a newly created api version.
* Cloning a common policy to API.
* Cloning a dependent policy of a product
* Each of these scenarios, original APIs' policy ID will be recorded as the cloned policy ID.
*
* @param apiUUID UUID of the API
* @param operationPolicyData
* @return cloned policyID
* @throws APIManagementException
*/
public String cloneOperationPolicy(String apiUUID, OperationPolicyData operationPolicyData) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
String policyId = addAPISpecificOperationPolicy(connection, apiUUID, null, operationPolicyData, operationPolicyData.getClonedCommonPolicyId());
connection.commit();
return policyId;
} catch (SQLException e) {
connection.rollback();
throw e;
}
} catch (SQLException e) {
throw new APIManagementException("Error while cloning Operation policies", e);
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class ApiMgtDAO method addOperationPolicyMapping.
public void addOperationPolicyMapping(Set<URITemplate> uriTemplates) throws APIManagementException {
if (uriTemplates != null && !uriTemplates.isEmpty()) {
try (Connection connection = APIMgtDBUtil.getConnection()) {
connection.setAutoCommit(false);
try (PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.OperationPolicyConstants.ADD_API_OPERATION_POLICY_MAPPING)) {
for (URITemplate uriTemplate : uriTemplates) {
List<OperationPolicy> operationPolicies = uriTemplate.getOperationPolicies();
if (operationPolicies != null && !operationPolicies.isEmpty()) {
for (OperationPolicy operationPolicy : operationPolicies) {
Gson gson = new Gson();
String paramJSON = gson.toJson(operationPolicy.getParameters());
preparedStatement.setInt(1, uriTemplate.getId());
preparedStatement.setString(2, operationPolicy.getPolicyId());
preparedStatement.setString(3, operationPolicy.getDirection());
preparedStatement.setString(4, paramJSON);
preparedStatement.setInt(5, operationPolicy.getOrder());
preparedStatement.addBatch();
}
}
}
preparedStatement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw e;
}
} catch (SQLException e) {
throw new APIManagementException("Error while updating operation Policy mapping for API", e);
}
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Operation in project carbon-apimgt by wso2.
the class ApiMgtDAO method deleteAPIProductRevision.
/**
* Delete API Product revision database records
*
* @param apiRevision content of the revision
* @throws APIManagementException if an error occurs when restoring an API revision
*/
public void deleteAPIProductRevision(APIRevision apiRevision) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
// Retrieve API ID
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiRevision.getApiUUID());
int apiId = getAPIID(apiRevision.getApiUUID(), connection);
int tenantId = APIUtil.getTenantId(APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()));
// Removing related revision entries from AM_REVISION table
PreparedStatement removeAMRevisionStatement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.DELETE_API_REVISION);
removeAMRevisionStatement.setString(1, apiRevision.getRevisionUUID());
removeAMRevisionStatement.executeUpdate();
// Removing related revision entries from AM_API_PRODUCT_MAPPING table
PreparedStatement removeProductMappingsStatement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_REVISION_ENTRIES_IN_AM_API_PRODUCT_MAPPING_BY_REVISION_UUID);
removeProductMappingsStatement.setInt(1, apiId);
removeProductMappingsStatement.setString(2, apiRevision.getRevisionUUID());
removeProductMappingsStatement.executeUpdate();
// Removing related revision entries from AM_API_URL_MAPPING table
PreparedStatement removeURLMappingsStatement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_PRODUCT_REVISION_ENTRIES_IN_AM_API_URL_MAPPING_BY_REVISION_UUID);
removeURLMappingsStatement.setString(1, apiRevision.getRevisionUUID());
removeURLMappingsStatement.executeUpdate();
// Removing related revision entries from AM_API_CLIENT_CERTIFICATE table
PreparedStatement removeClientCertificatesStatement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_REVISION_ENTRIES_IN_AM_API_CLIENT_CERTIFICATE_BY_REVISION_UUID);
removeClientCertificatesStatement.setInt(1, apiId);
removeClientCertificatesStatement.setString(2, apiRevision.getRevisionUUID());
removeClientCertificatesStatement.executeUpdate();
// Removing related revision entries from AM_GRAPHQL_COMPLEXITY table
PreparedStatement removeGraphQLComplexityStatement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.REMOVE_REVISION_ENTRIES_IN_AM_GRAPHQL_COMPLEXITY_BY_REVISION_UUID);
removeGraphQLComplexityStatement.setInt(1, apiId);
removeGraphQLComplexityStatement.setString(2, apiRevision.getRevisionUUID());
removeGraphQLComplexityStatement.executeUpdate();
// Removing related revision entries for operation policies
deleteAllAPISpecificOperationPoliciesByAPIUUID(connection, apiRevision.getApiUUID(), apiRevision.getRevisionUUID());
connection.commit();
} catch (SQLException e) {
connection.rollback();
handleException("Failed to delete API Revision entry of API Product UUID " + apiRevision.getApiUUID(), e);
}
} catch (SQLException e) {
handleException("Failed to delete API Revision entry of API Product UUID " + apiRevision.getApiUUID(), e);
}
}
Aggregations