Search in sources :

Example 1 with APIKeyInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO in project carbon-apimgt by wso2.

the class ApiMgtDAO method getSubscribedUsersForAPI.

/**
 * Get API key information for given API
 *
 * @param apiInfoDTO API info
 * @return APIKeyInfoDTO[]
 * @throws APIManagementException if failed to get key info for given API
 */
public APIKeyInfoDTO[] getSubscribedUsersForAPI(APIInfoDTO apiInfoDTO) throws APIManagementException {
    APIKeyInfoDTO[] apiKeyInfoDTOs = null;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    List<APIKeyInfoDTO> apiKeyInfoList = new ArrayList<APIKeyInfoDTO>();
    String sqlQuery = SQLConstants.GET_SUBSCRIBED_USERS_FOR_API_SQL;
    try {
        conn = APIMgtDBUtil.getConnection();
        ps = conn.prepareStatement(sqlQuery);
        ps.setString(1, APIUtil.replaceEmailDomainBack(apiInfoDTO.getProviderId()));
        ps.setString(2, apiInfoDTO.getApiName());
        ps.setString(3, apiInfoDTO.getVersion());
        rs = ps.executeQuery();
        while (rs.next()) {
            String userId = rs.getString(APIConstants.SUBSCRIBER_FIELD_USER_ID);
            APIKeyInfoDTO apiKeyInfoDTO = new APIKeyInfoDTO();
            apiKeyInfoDTO.setUserId(userId);
            apiKeyInfoList.add(apiKeyInfoDTO);
        }
        apiKeyInfoDTOs = apiKeyInfoList.toArray(new APIKeyInfoDTO[apiKeyInfoList.size()]);
    } catch (SQLException e) {
        handleException("Error while executing SQL", e);
    } finally {
        APIMgtDBUtil.closeAllConnections(ps, conn, rs);
    }
    return apiKeyInfoDTOs;
}
Also used : APIKeyInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 2 with APIKeyInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO in project carbon-apimgt by wso2.

the class APIMgtDAOTest method testGetSubscribedUsersForAPI.

@Test
public void testGetSubscribedUsersForAPI() throws Exception {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setApiName("API1");
    apiInfoDTO.setProviderId("SUMEDHA");
    apiInfoDTO.setVersion("V1.0.0");
    APIKeyInfoDTO[] apiKeyInfoDTO = apiMgtDAO.getInstance().getSubscribedUsersForAPI(apiInfoDTO);
    assertNotNull(apiKeyInfoDTO);
    assertTrue(apiKeyInfoDTO.length > 1);
}
Also used : APIKeyInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIInfoDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

APIKeyInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIKeyInfoDTO)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIInfoDTO)1