Search in sources :

Example 26 with APIInfoDTO

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

the class ServicesApiServiceImpl method getServiceUsage.

@Override
public Response getServiceUsage(String serviceId, MessageContext messageContext) {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        List<API> apiList = serviceCatalog.getServiceUsage(serviceId, tenantId);
        if (apiList != null) {
            APIListDTO apiListDTO = new APIListDTO();
            List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
            for (API api : apiList) {
                apiInfoDTOList.add(ServiceEntryMappingUtil.fromAPIToAPIInfoDTO(api));
            }
            apiListDTO.setList(apiInfoDTOList);
            apiListDTO.setCount(apiList.size());
            return Response.ok().entity(apiListDTO).build();
        } else {
            RestApiUtil.handleResourceNotFoundError("Service", serviceId, log);
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API usage of service";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIInfoDTO)

Example 27 with APIInfoDTO

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

the class ServiceEntryMappingUtil method fromAPIToAPIInfoDTO.

public static APIInfoDTO fromAPIToAPIInfoDTO(API api) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setName(api.getId().getApiName());
    apiInfoDTO.setVersion(api.getId().getVersion());
    apiInfoDTO.setContext(api.getContext());
    apiInfoDTO.setId(api.getUuid());
    apiInfoDTO.setProvider(api.getId().getProviderName());
    return apiInfoDTO;
}
Also used : APIInfoDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIInfoDTO)

Example 28 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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.admin.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