Search in sources :

Example 21 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class OrganizationPurgeDAO method getAPIIdList.

/**
 * Get API data for given organization
 *
 * @param orgId organization Id
 * @return ArrayList<APIIdentifier>
 * @throws APIManagementException
 */
public ArrayList<APIIdentifier> getAPIIdList(String orgId) throws APIManagementException {
    ArrayList<APIIdentifier> apiList = new ArrayList<>();
    try (Connection conn = APIMgtDBUtil.getConnection();
        PreparedStatement ps = conn.prepareStatement(OrganizationPurgeConstants.GET_API_LIST_SQL_BY_ORG_SQL)) {
        ps.setString(1, orgId);
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                int apiId = rs.getInt("API_ID");
                String apiUuid = rs.getString("API_UUID");
                String apiName = rs.getString("API_Name");
                String apiProvider = rs.getString("API_Provider");
                String apiVersion = rs.getString("API_Version");
                APIIdentifier apiIdentifier = new APIIdentifier(apiProvider, apiName, apiVersion, apiUuid);
                apiIdentifier.setId(apiId);
                apiList.add(apiIdentifier);
            }
        }
    } catch (SQLException e) {
        log.error("Error while getting apiUuid list of organization" + orgId, e);
        handleException("Failed to get API apiUuid list of organization " + orgId, e);
    }
    return apiList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) PreparedStatement(java.sql.PreparedStatement)

Example 22 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class APIConsumerImpl method searchPaginatedAPIs.

@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end, String sortBy, String sortOrder) throws APIManagementException {
    Map<String, Object> result = new HashMap<String, Object>();
    if (log.isDebugEnabled()) {
        log.debug("Original search query received : " + searchQuery);
    }
    Organization org = new Organization(organization);
    String userName = (userNameWithoutChange != null) ? userNameWithoutChange : username;
    String[] roles = APIUtil.getListOfRoles(userName);
    Map<String, Object> properties = APIUtil.getUserProperties(userName);
    UserContext userCtx = new UserContext(userNameWithoutChange, org, properties, roles);
    try {
        DevPortalAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForDevPortal(org, searchQuery, start, end, userCtx);
        if (log.isDebugEnabled()) {
            log.debug("searched Devportal APIs for query : " + searchQuery + " :-->: " + searchAPIs.toString());
        }
        SortedSet<Object> apiSet = new TreeSet<>(new APIAPIProductNameComparator());
        if (searchAPIs != null) {
            List<DevPortalAPIInfo> list = searchAPIs.getDevPortalAPIInfoList();
            List<Object> apiList = new ArrayList<>();
            for (DevPortalAPIInfo devPortalAPIInfo : list) {
                API mappedAPI = APIMapper.INSTANCE.toApi(devPortalAPIInfo);
                mappedAPI.setRating(APIUtil.getAverageRating(mappedAPI.getUuid()));
                apiList.add(mappedAPI);
            }
            apiSet.addAll(apiList);
            result.put("apis", apiSet);
            result.put("length", searchAPIs.getTotalAPIsCount());
            result.put("isMore", true);
        } else {
            result.put("apis", apiSet);
            result.put("length", 0);
            result.put("isMore", false);
        }
    } catch (APIPersistenceException e) {
        throw new APIManagementException("Error while searching the api ", e);
    }
    return result;
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) DevPortalAPIInfo(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPIInfo) ArrayList(java.util.ArrayList) DevPortalAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPISearchResult) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) TreeSet(java.util.TreeSet) JSONObject(org.json.simple.JSONObject) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) APIAPIProductNameComparator(org.wso2.carbon.apimgt.impl.utils.APIAPIProductNameComparator)

Example 23 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIListToInfoDTO.

/**
 * Converts a List object of APIs into Info DTO List.
 *
 * @param apiList List of APIs
 * @return APIListDTO object containing APIDTOs
 */
public static APIListDTO fromAPIListToInfoDTO(List<API> apiList) throws APIManagementException {
    APIListDTO apiListDTO = new APIListDTO();
    List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
    for (API api : apiList) {
        apiInfoDTOs.add(fromAPIToInfoDTO(api));
    }
    apiListDTO.setCount(apiInfoDTOs.size());
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO)

Example 24 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisGet.

public Response apisGet(String context, String version, String tenantDomain, MessageContext messageContext) {
    tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
    SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    if (subscriptionDataStore == null) {
        log.warn("Subscription data store is not initialized for " + tenantDomain);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
        API api = subscriptionDataStore.getApiByContextAndVersion(context, version);
        if (api == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(Collections.singletonList(api));
        return Response.ok().entity(apiListDTO).build();
    } else if ((StringUtils.isEmpty(context) && StringUtils.isNotEmpty(version)) || (StringUtils.isNotEmpty(context) && StringUtils.isEmpty(version))) {
        return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
    } else {
        List<API> apiList = subscriptionDataStore.getAPIs();
        APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(apiList);
        return Response.status(Response.Status.OK).entity(apiListDTO).build();
    }
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO) APIListDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.APIListDTO) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) List(java.util.List) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 25 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIListToDTO.

/**
 * Converts a List object of APIs into a DTO
 *
 * @param apiList List of APIs
 * @return APIListDTO object containing APIDTOs
 * @throws APIManagementException
 */
public static APIListDTO fromAPIListToDTO(List<Object> apiList, String organization) throws APIManagementException {
    APIListDTO apiListDTO = new APIListDTO();
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
    Map<String, Tier> tierMap = APIUtil.getTiers(organization);
    List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
    if (apiList != null) {
        for (Object api : apiList) {
            APIInfoDTO apiInfoDTO = null;
            if (api instanceof API) {
                API api1 = (API) api;
                apiInfoDTO = fromAPIToInfoDTO((API) api);
                setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
            } else if (api instanceof APIProduct) {
                APIProduct api1 = (APIProduct) api;
                apiInfoDTO = fromAPIToInfoDTO((API) api);
                setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
            }
            apiInfoDTOs.add(apiInfoDTO);
        }
    }
    apiListDTO.setCount(apiInfoDTOs.size());
    return apiListDTO;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) Tier(org.wso2.carbon.apimgt.api.model.Tier) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIListDTO) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject) API(org.wso2.carbon.apimgt.api.model.API) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)33 API (org.wso2.carbon.apimgt.core.models.API)21 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)15 API (org.wso2.carbon.apimgt.api.model.API)14 Test (org.testng.annotations.Test)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)12 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)12 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 JSONObject (org.json.simple.JSONObject)9 APIComparator (org.wso2.carbon.apimgt.core.util.APIComparator)8 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)7 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)6 TreeSet (java.util.TreeSet)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)5 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 List (java.util.List)4