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;
}
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);
}
Aggregations