use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateRating.
@Override
public void updateRating(String apiId, String ratingId, Rating rating) throws APIMgtDAOException {
final String updateRatingQuery = "UPDATE AM_API_RATINGS SET RATING = ? , UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE API_ID = ? AND UUID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(updateRatingQuery)) {
try {
connection.setAutoCommit(false);
statement.setInt(1, rating.getRating());
statement.setString(2, rating.getUsername());
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(4, apiId);
statement.setString(5, ratingId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "updating Rating for API: " + apiId + ", Rating: " + rating.getUuid();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "updating Rating for API: " + apiId + ", Rating: " + rating.getUuid();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @param updatedBy user who performs the action
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateApiDefinition.
@Override
public void updateApiDefinition(String apiID, String apiDefinition, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
updateAPIDefinition(connection, apiID, apiDefinition, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API definition of API: " + apiID, e);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiDAOImpl method getResourcesOfApi.
/**
* @see org.wso2.carbon.apimgt.core.dao.ApiDAO#getResourcesOfApi(String, String)
*/
@Override
public List<UriTemplate> getResourcesOfApi(String apiContext, String apiVersion) throws APIMgtDAOException {
final String query = "SELECT operationMapping.OPERATION_ID AS OPERATION_ID,operationMapping.HTTP_METHOD AS " + "HTTP_METHOD,operationMapping.URL_PATTERN AS URL_PATTERN,operationMapping.AUTH_SCHEME AS AUTH_SCHEME," + "operationMapping.API_POLICY_ID AS API_POLICY_ID FROM AM_API_OPERATION_MAPPING operationMapping," + "AM_API api WHERE operationMapping.API_ID = api.UUID AND api.CONTEXT = ? AND api.VERSION = ?";
List<UriTemplate> uriTemplates = new ArrayList<>();
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, apiContext);
preparedStatement.setString(2, apiVersion);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
UriTemplate uriTemplate = new UriTemplate.UriTemplateBuilder().uriTemplate(resultSet.getString("URL_PATTERN")).authType(resultSet.getString("AUTH_SCHEME")).httpVerb(resultSet.getString("HTTP_METHOD")).policy(new APIPolicy(resultSet.getString("API_POLICY_ID"), "")).templateId(resultSet.getString("OPERATION_ID")).build();
uriTemplates.add(uriTemplate);
}
}
} catch (SQLException e) {
String msg = "getting API resources for Context: " + apiContext + ", Version: " + apiVersion;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
return uriTemplates;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method updateAPI.
/**
* @see ApiDAO#updateAPI(String apiID, API substituteAPI)
*/
@Override
public void updateAPI(String apiID, API substituteAPI) throws APIMgtDAOException {
API oldAPI = getAPI(apiID);
if (oldAPI == null) {
String errorMsg = "Error while updating API. Unable to find API with Id: " + apiID;
log.error(errorMsg);
throw new APIMgtDAOException(errorMsg, ExceptionCodes.API_NOT_FOUND);
}
// set immutable properties from old API
API updatedAPI = new API.APIBuilder(substituteAPI).id(apiID).provider(oldAPI.getProvider()).name(oldAPI.getName()).version(oldAPI.getVersion()).context(oldAPI.getContext()).createdTime(oldAPI.getCreatedTime()).createdBy(oldAPI.getCreatedBy()).lifecycleInstanceId(oldAPI.getLifecycleInstanceId()).lifeCycleStatus(oldAPI.getLifeCycleStatus()).copiedFromApiId(oldAPI.getCopiedFromApiId()).build();
// Adding the API override the existing files.
addAPI(updatedAPI);
}
Aggregations