use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method getApplicationByName.
/**
* Retrieve a given instance of an Application
*
* @param appName Name of the Application
* @param ownerId ID of the application owner.
* @return valid {@link Application} object or null
* @throws APIMgtDAOException If failed to retrieve application.
*/
@Override
public Application getApplicationByName(String appName, String ownerId) throws APIMgtDAOException {
final String completeGetAppQuery = GET_APPS_WITH_POLICY_QUERY + "AND APPLICATION.NAME = ? AND APPLICATION" + ".CREATED_BY = ?";
Application application;
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(completeGetAppQuery)) {
ps.setString(1, appName);
ps.setString(2, ownerId);
try (ResultSet rs = ps.executeQuery()) {
application = this.createApplicationFromResultSet(rs);
}
if (application == null) {
throw new APIMgtDAOException("Application is not available in the system.", ExceptionCodes.APPLICATION_NOT_FOUND);
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting application(name: " + appName + ", " + "ownerId: " + ownerId + ")", ex);
}
return application;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method getAllApplications.
@Override
public List<Application> getAllApplications() throws APIMgtDAOException {
List<Application> applicationList = new ArrayList<>();
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(GET_APPS_QUERY)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String createdUser = rs.getString("CREATED_BY");
Application application = new Application(rs.getString("NAME"), createdUser);
application.setId(rs.getString("UUID"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setPolicy(new ApplicationPolicy(rs.getString("APPLICATION_POLICY_ID"), ""));
applicationList.add(application);
}
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting all applications", ex);
}
return applicationList;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method createApplicationFromResultSet.
private Application createApplicationFromResultSet(ResultSet rs) throws APIMgtDAOException, SQLException {
Application application = null;
if (rs.next()) {
String createdUser = rs.getString("CREATED_BY");
application = new Application(rs.getString("NAME"), createdUser);
application.setId(rs.getString("UUID"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setCreatedTime(rs.getTimestamp("CREATED_TIME").toLocalDateTime());
application.setUpdatedUser(rs.getString("UPDATED_BY"));
application.setUpdatedTime(rs.getTimestamp("LAST_UPDATED_TIME").toLocalDateTime());
application.setPolicy(new ApplicationPolicy(rs.getString("APPLICATION_POLICY_NAME")));
}
return application;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.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.identity.oauth.dcr.bean.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);
}
}
Aggregations