use of org.wso2.carbon.apimgt.api.model.API in project product-apim by wso2.
the class ApiClient method setApiKey.
/**
* Helper method to configure the first api key found
*
* @param apiKey API key
*/
public void setApiKey(String apiKey) {
for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof ApiKeyAuth) {
ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
keyAuth.setApiKey(apiKey);
return;
}
}
throw new RuntimeException("No API key authentication configured!");
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method getUserRatingForApiFromUser.
@Override
public Rating getUserRatingForApiFromUser(String apiId, String userId) throws APIMgtDAOException {
final String query = "SELECT UUID, API_ID, RATING, USER_IDENTIFIER, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME " + "FROM AM_API_RATINGS WHERE USER_IDENTIFIER = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, userId);
statement.setString(2, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return constructRatingFromResultSet(rs);
}
}
} catch (SQLException e) {
String errorMessage = "getting User Rating for API: " + apiId + ", User: " + userId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
} catch (SQLException e) {
String errorMessage = "getting User Rating for API: " + apiId + ", User: " + userId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateAPIWorkflowStatus.
/**
* Update an existing API workflow state
*
* @param apiID The {@link String} of the API that needs to be updated
* @param workflowStatus workflow status
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateAPIWorkflowStatus(String apiID, APILCWorkflowStatus workflowStatus) throws APIMgtDAOException {
final String query = "UPDATE AM_API SET LAST_UPDATED_TIME = ?, LC_WORKFLOW_STATUS=? WHERE UUID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
connection.setAutoCommit(false);
statement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(2, workflowStatus.toString());
statement.setString(3, apiID);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateAPI.
/**
* Update an existing API
*
* @param apiID The {@link String} of the API that needs to be updated
* @param substituteAPI Substitute {@link API} object that will replace the existing API
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateAPI(String apiID, API substituteAPI) throws APIMgtDAOException {
final String query = "UPDATE AM_API SET CONTEXT = ?, IS_DEFAULT_VERSION = ?, DESCRIPTION = ?, VISIBILITY = ?, " + "IS_RESPONSE_CACHED = ?, CACHE_TIMEOUT = ?, TECHNICAL_OWNER = ?, TECHNICAL_EMAIL = ?, " + "BUSINESS_OWNER = ?, BUSINESS_EMAIL = ?, CORS_ENABLED = ?, CORS_ALLOW_ORIGINS = ?, " + "CORS_ALLOW_CREDENTIALS = ?, CORS_ALLOW_HEADERS = ?, CORS_ALLOW_METHODS = ?, LAST_UPDATED_TIME = ?," + "UPDATED_BY = ?, LC_WORKFLOW_STATUS = ?, SECURITY_SCHEME = ? WHERE UUID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
connection.setAutoCommit(false);
statement.setString(1, substituteAPI.getContext());
statement.setBoolean(2, substituteAPI.isDefaultVersion());
statement.setString(3, substituteAPI.getDescription());
statement.setString(4, substituteAPI.getVisibility().toString());
statement.setBoolean(5, substituteAPI.isResponseCachingEnabled());
statement.setInt(6, substituteAPI.getCacheTimeout());
BusinessInformation businessInformation = substituteAPI.getBusinessInformation();
statement.setString(7, businessInformation.getTechnicalOwner());
statement.setString(8, businessInformation.getTechnicalOwnerEmail());
statement.setString(9, businessInformation.getBusinessOwner());
statement.setString(10, businessInformation.getBusinessOwnerEmail());
CorsConfiguration corsConfiguration = substituteAPI.getCorsConfiguration();
statement.setBoolean(11, corsConfiguration.isEnabled());
statement.setString(12, String.join(",", corsConfiguration.getAllowOrigins()));
statement.setBoolean(13, corsConfiguration.isAllowCredentials());
statement.setString(14, String.join(",", corsConfiguration.getAllowHeaders()));
statement.setString(15, String.join(",", corsConfiguration.getAllowMethods()));
statement.setTimestamp(16, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(17, substituteAPI.getUpdatedBy());
statement.setString(18, substituteAPI.getWorkflowStatus());
statement.setInt(19, substituteAPI.getSecurityScheme());
statement.setString(20, apiID);
statement.execute();
// Delete current visible roles if they exist
deleteVisibleRoles(connection, apiID);
if (API.Visibility.RESTRICTED == substituteAPI.getVisibility()) {
addVisibleRole(connection, apiID, substituteAPI.getVisibleRoles());
}
deleteAPIPermission(connection, apiID);
updateApiPermission(connection, substituteAPI.getPermissionMap(), apiID);
deleteTransports(connection, apiID);
addTransports(connection, apiID, substituteAPI.getTransport());
deleteThreatProtectionPolicies(connection, apiID);
if (substituteAPI.getThreatProtectionPolicies() != null) {
addThreatProtectionPolicies(connection, apiID, substituteAPI.getThreatProtectionPolicies());
}
// Delete current tag mappings if they exist
deleteTagsMapping(connection, apiID);
addTagsMapping(connection, apiID, substituteAPI.getTags());
deleteLabelsMapping(connection, apiID);
addLabelMapping(connection, apiID, substituteAPI.getLabels());
deleteSubscriptionPolicies(connection, apiID);
addSubscriptionPolicies(connection, substituteAPI.getPolicies(), apiID);
deleteEndPointsForApi(connection, apiID);
addEndPointsForApi(connection, apiID, substituteAPI.getEndpoint());
deleteEndPointsForOperation(connection, apiID);
deleteUrlMappings(connection, apiID);
addUrlMappings(connection, substituteAPI.getUriTemplates().values(), apiID);
deleteApiPolicy(connection, apiID);
if (substituteAPI.getApiPolicy() != null) {
addApiPolicy(connection, substituteAPI.getApiPolicy().getUuid(), apiID);
}
connection.commit();
} catch (SQLException | IOException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API: " + substituteAPI.getProvider() + " - " + substituteAPI.getName() + " - " + substituteAPI.getVersion(), e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API: " + substituteAPI.getProvider() + " - " + substituteAPI.getName() + " - " + substituteAPI.getVersion(), e);
}
}
use of org.wso2.carbon.apimgt.api.model.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructAPISummaryList.
private List<API> constructAPISummaryList(Connection connection, PreparedStatement statement) throws SQLException {
List<API> apiList = new ArrayList<>();
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String apiPrimaryKey = rs.getString("UUID");
API apiSummary = new API.APIBuilder(rs.getString("PROVIDER"), rs.getString("NAME"), rs.getString("VERSION")).id(apiPrimaryKey).context(rs.getString("CONTEXT")).description(rs.getString("DESCRIPTION")).lifeCycleStatus(rs.getString("CURRENT_LC_STATUS")).lifecycleInstanceId(rs.getString("LIFECYCLE_INSTANCE_ID")).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).securityScheme(rs.getInt("SECURITY_SCHEME")).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
apiList.add(apiSummary);
}
}
return apiList;
}
Aggregations