Search in sources :

Example 16 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method toAPIInfo.

/**
 * Converts {@link API} List to an {@link APIInfoDTO} List.
 *
 * @param apiSummaryList List of APIs
 * @return List of APIInfoDTO
 */
private static List<APIInfoDTO> toAPIInfo(List<API> apiSummaryList) {
    List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
    for (API apiSummary : apiSummaryList) {
        APIInfoDTO apiInfo = new APIInfoDTO();
        apiInfo.setId(apiSummary.getId());
        apiInfo.setContext(apiSummary.getContext());
        apiInfo.setDescription(apiSummary.getDescription());
        apiInfo.setName(apiSummary.getName());
        apiInfo.setProvider(apiSummary.getProvider());
        apiInfo.setLifeCycleStatus(apiSummary.getLifeCycleStatus());
        apiInfo.setVersion(apiSummary.getVersion());
        apiInfoList.add(apiInfo);
    }
    return apiInfoList;
}
Also used : ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIInfoDTO)

Example 17 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromAPIInfoToDTO.

private static APIInfoDTO fromAPIInfoToDTO(APIInfo apiInfo, ZoneId zoneId) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setId(apiInfo.getId());
    apiInfoDTO.setName(apiInfo.getName());
    apiInfoDTO.setVersion(apiInfo.getVersion());
    apiInfoDTO.setContext(apiInfo.getContext());
    apiInfoDTO.setDescription(apiInfo.getDescription());
    apiInfoDTO.setLifeCycleStatus(apiInfo.getLifeCycleStatus());
    apiInfoDTO.setProvider(apiInfo.getProvider());
    apiInfoDTO.setWorkflowStatus(apiInfo.getWorkflowStatus());
    apiInfoDTO.setTime(epochToISO8601DateTime(apiInfo.getCreatedTime(), zoneId));
    return apiInfoDTO;
}
Also used : APIInfoDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoDTO)

Example 18 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO 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 19 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO 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)

Example 20 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIInfoMappingUtil method fromAPIInfoToDTO.

/**
 * Converts a APIIdentifier object into APIInfoDTO
 *
 * @param apiId APIIdentifier object
 * @return APIInfoDTO corresponds to APIIdentifier object
 */
private static APIInfoDTO fromAPIInfoToDTO(APIIdentifier apiId) throws UnsupportedEncodingException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    APIIdentifier apiIdEmailReplacedBack = new APIIdentifier(APIUtil.replaceEmailDomainBack(apiId.getProviderName()).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), URLEncoder.encode(apiId.getApiName(), RestApiConstants.CHARSET).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), apiId.getVersion().replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER));
    apiInfoDTO.setName(apiIdEmailReplacedBack.getApiName());
    apiInfoDTO.setVersion(apiIdEmailReplacedBack.getVersion());
    apiInfoDTO.setProvider(apiIdEmailReplacedBack.getProviderName());
    return apiInfoDTO;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)11 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)7 Tier (org.wso2.carbon.apimgt.api.model.Tier)7 APIInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)7 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)5 API (org.wso2.carbon.apimgt.api.model.API)4 APIInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIInfoDTO)4 JSONObject (org.json.simple.JSONObject)3 API (org.wso2.carbon.apimgt.core.models.API)3 ResourceInfoDTO (org.wso2.carbon.apimgt.impl.dto.ResourceInfoDTO)3 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)3 APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 Application (org.wso2.carbon.apimgt.api.model.Application)2