use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method addApplicationKeys.
@Override
public void addApplicationKeys(String appId, String keyType, String consumerKey) throws APIMgtDAOException {
final String addApplicationKeysQuery = "INSERT INTO AM_APP_KEY_MAPPING (APPLICATION_ID, CLIENT_ID, KEY_TYPE) " + "VALUES (?, ?, ?)";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(addApplicationKeysQuery)) {
ps.setString(1, appId);
ps.setString(2, consumerKey);
ps.setString(3, keyType);
ps.executeUpdate();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application keys(appId: " + appId + ")", ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application keys(appId: " + appId + ")", ex);
}
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method updateApplicationState.
@Override
public void updateApplicationState(String appID, String state) throws APIMgtDAOException {
final String updateAppQuery = "UPDATE AM_APPLICATION SET APPLICATION_STATUS=?, LAST_UPDATED_TIME=? " + "WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(updateAppQuery)) {
ps.setString(1, state);
ps.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now()));
ps.setString(3, appID);
ps.executeUpdate();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application state(appId: " + appID + ", state: " + state + ")", ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application state(appId: " + appID + ", state: " + state + ")", ex);
}
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method updateApplication.
/**
* Update an existing Application
*
* @param appID The UUID of the Application that needs to be updated
* @param updatedApp Substitute {@link Application} object that will replace the existing Application
* @throws APIMgtDAOException If failed to update applications.
*/
@Override
public void updateApplication(String appID, Application updatedApp) throws APIMgtDAOException {
final String updateAppQuery = "UPDATE AM_APPLICATION SET NAME=?, APPLICATION_POLICY_ID=" + "?, DESCRIPTION=?, APPLICATION_STATUS=?, UPDATED_BY=?, LAST_UPDATED_TIME=? WHERE UUID=?";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(updateAppQuery)) {
ps.setString(1, updatedApp.getName());
ps.setString(2, updatedApp.getPolicy().getUuid());
ps.setString(3, updatedApp.getDescription());
ps.setString(4, updatedApp.getStatus());
ps.setString(5, updatedApp.getUpdatedUser());
ps.setTimestamp(6, Timestamp.valueOf(updatedApp.getUpdatedTime()));
ps.setString(7, appID);
ps.executeUpdate();
updateApplicationPermission(conn, updatedApp.getPermissionMap(), updatedApp.getId());
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application: " + appID, ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application: " + appID, ex);
}
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method deleteApplication.
/**
* Remove an existing Application
*
* @param appID The UUID of the Application that needs to be deleted
* @throws APIMgtDAOException If failed to delete application.
*/
@Override
public void deleteApplication(String appID) throws APIMgtDAOException {
final String appDeleteQuery = "DELETE FROM AM_APPLICATION WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection()) {
boolean originalAutoCommitState = conn.getAutoCommit();
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(appDeleteQuery)) {
ps.setString(1, appID);
ps.execute();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting application: " + appID, ex);
} finally {
conn.setAutoCommit(originalAutoCommitState);
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting application: " + appID, ex);
}
}
use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.
the class PolicyDAOImpl method isValidApplication.
/**
* validate the blocking application.
*
* @param appName name of the application
* @param uuid uuid of the application
* @return return true/false depends of the success
* @throws APIMgtDAOException if failed validating application
*/
private boolean isValidApplication(String appName, String uuid) throws APIMgtDAOException {
String query = "SELECT 1 FROM AM_APPLICATION WHERE UUID = ? AND NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
connection.setAutoCommit(false);
statement.setString(1, uuid);
statement.setString(2, appName);
try (ResultSet resultSet = statement.executeQuery()) {
return resultSet.next();
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "checking if Block condition with Application Name " + appName + " , Application ID = " + uuid + " exists", e);
}
}
Aggregations