Search in sources :

Example 1 with ConnectedApps

use of org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getConnectedApplications.

/**
 * Get list of applications that are connected to the identity provider from DB.
 *
 * @param resourceId IDP resource ID.
 * @param limit      Limit parameter for pagination.
 * @param offset     Offset parameter for pagination.
 * @return ConnectedAppsResult.
 * @throws IdentityProviderManagementException
 */
public ConnectedAppsResult getConnectedApplications(String resourceId, int limit, int offset) throws IdentityProviderManagementException {
    ConnectedAppsResult connectedAppsResult = new ConnectedAppsResult();
    List<String> connectedApps = new ArrayList<>();
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (PreparedStatement prepStmt = createConnectedAppsSqlStatement(connection, resourceId, limit, offset)) {
            try (ResultSet resultSet = prepStmt.executeQuery()) {
                while (resultSet.next()) {
                    connectedApps.add(resultSet.getString("UUID"));
                }
            }
        }
        String sqlQuery = IdPManagementConstants.SQLQueries.CONNECTED_APPS_TOTAL_COUNT_SQL;
        try (PreparedStatement prepStmt = connection.prepareStatement(sqlQuery)) {
            prepStmt.setString(1, resourceId);
            prepStmt.setString(2, resourceId);
            try (ResultSet resultSet = prepStmt.executeQuery()) {
                if (resultSet.next()) {
                    connectedAppsResult.setTotalAppCount(resultSet.getInt(1));
                }
            }
        }
    } catch (SQLException e) {
        log.error("Error occurred during retrieving connected applications of IDP: " + resourceId, e);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_IDP_CONNECTED_APPS, resourceId);
    }
    connectedAppsResult.setApps(connectedApps);
    connectedAppsResult.setLimit(limit);
    connectedAppsResult.setOffSet(offset);
    return connectedAppsResult;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ConnectedApps

use of org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps in project identity-api-server by wso2.

the class ServerIdpManagementService method createConnectedAppsResponse.

private ConnectedApps createConnectedAppsResponse(String resourceId, ConnectedAppsResult connectedAppsResult) {
    ConnectedApps connectedAppsResponse = new ConnectedApps();
    if (connectedAppsResult == null) {
        return connectedAppsResponse;
    }
    List<ConnectedApp> connectedAppList = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(connectedAppsResult.getApps())) {
        for (String app : connectedAppsResult.getApps()) {
            ConnectedApp listItem = new ConnectedApp();
            listItem.setAppId(app);
            listItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + "/applications/%s", app)).toString());
            connectedAppList.add(listItem);
        }
        connectedAppsResponse.setConnectedApps(connectedAppList);
        connectedAppsResponse.setCount(connectedAppList.size());
    } else {
        connectedAppsResponse.setCount(0);
    }
    connectedAppsResponse.setTotalResults(connectedAppsResult.getTotalAppCount());
    connectedAppsResponse.setStartIndex(connectedAppsResult.getOffSet() + 1);
    connectedAppsResponse.setLinks(createLinks(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + Constants.PATH_SEPERATOR + resourceId + "/connected-apps", connectedAppsResult.getLimit(), connectedAppsResult.getOffSet(), connectedAppsResult.getTotalAppCount(), null));
    return connectedAppsResponse;
}
Also used : ConnectedApp(org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApp) ArrayList(java.util.ArrayList) ConnectedApps(org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps)

Aggregations

ArrayList (java.util.ArrayList)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ConnectedApp (org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApp)1 ConnectedApps (org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps)1 ConnectedAppsResult (org.wso2.carbon.idp.mgt.model.ConnectedAppsResult)1