use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class SystemApplicationDaoImpl method getConsumerKeyForApplication.
@Override
public String getConsumerKeyForApplication(String appName) throws APIMgtDAOException {
final String query = "SELECT CONSUMER_KEY FROM AM_SYSTEM_APPS WHERE NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, appName);
log.debug("Executing query: {} ", query);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
return resultSet.getString("CONSUMER_KEY");
} else {
throw new APIMgtDAOException("System Application with " + appName + " does not exist", ExceptionCodes.SYSTEM_APP_NOT_FOUND);
}
}
} catch (SQLException e) {
String errorMsg = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class SystemApplicationDaoImpl method isConsumerKeyExistForApplication.
@Override
public boolean isConsumerKeyExistForApplication(String appName) throws APIMgtDAOException {
final String query = "SELECT CONSUMER_KEY FROM AM_SYSTEM_APPS WHERE NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, appName);
log.debug("Executing query: {} ", query);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
return true;
} else {
return false;
}
}
} catch (SQLException e) {
String errorMsg = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class SystemApplicationDaoImpl method addApplicationKey.
@Override
public void addApplicationKey(String appName, String consumerKey) throws APIMgtDAOException {
final String query = "INSERT INTO AM_SYSTEM_APPS (NAME,CONSUMER_KEY,CREATED_TIME) VALUES (?,?,?)";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
connection.setAutoCommit(false);
try {
statement.setString(1, appName);
statement.setString(2, consumerKey);
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()), Calendar.getInstance(TimeZone.getTimeZone("UTC")));
log.debug("Executing query: {} ", query);
statement.execute();
connection.commit();
} catch (SQLException ex) {
connection.rollback();
throw new APIMgtDAOException("Couldn't Create System Application", ex);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMsg = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class PolicyDAOImpl method addApplicationPolicy.
@Override
public void addApplicationPolicy(ApplicationPolicy policy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
addApplicationPolicy(policy, connection);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "Error in adding Application policy, policy name: " + policy.getPolicyName();
log.error(errorMessage, e);
throw new APIMgtDAOException(errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMsg = "Error in obtaining DB connection";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class APIPublisherImpl method removePendingLifecycleWorkflowTaskForAPI.
/**
* {@inheritDoc}
*/
@Override
public void removePendingLifecycleWorkflowTaskForAPI(String apiId) throws APIManagementException {
try {
API api = getApiDAO().getAPI(apiId);
if (APILCWorkflowStatus.PENDING.toString().equals(api.getWorkflowStatus())) {
// change the state back
getApiDAO().updateAPIWorkflowStatus(apiId, APILCWorkflowStatus.APPROVED);
// call executor's cleanup task
cleanupPendingTaskForAPIStateChange(apiId);
} else {
String msg = "API does not have a pending lifecycle state change.";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.WORKFLOW_NO_PENDING_TASK);
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while changing api lifecycle workflow status";
log.error(msg, e);
throw new APIManagementException(msg, e.getErrorHandler());
}
}
Aggregations