Search in sources :

Example 1 with SharedScopeUsageDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO in project carbon-apimgt by wso2.

the class ScopesApiServiceImpl method getSharedScopeUsages.

@Override
public Response getSharedScopeUsages(String scopeId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
    if (StringUtils.isEmpty(scopeId)) {
        throw new APIManagementException("Scope Id cannot be null or empty", ExceptionCodes.SHARED_SCOPE_ID_NOT_SPECIFIED);
    }
    SharedScopeUsage sharedScopeUsage = apiProvider.getSharedScopeUsage(scopeId, tenantId);
    SharedScopeUsageDTO sharedScopeUsageDTO = SharedScopeMappingUtil.fromSharedScopeUsageToDTO(sharedScopeUsage);
    return Response.ok().entity(sharedScopeUsageDTO).build();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SharedScopeUsageDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) SharedScopeUsage(org.wso2.carbon.apimgt.api.model.SharedScopeUsage)

Example 2 with SharedScopeUsageDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO in project carbon-apimgt by wso2.

the class SharedScopeMappingUtil method fromSharedScopeUsageToDTO.

/**
 * Converts SharedScopeUsage object into SharedScopeUsageDTO object.
 *
 * @param sharedScopeUsage SharedScopeUsage object
 * @return SharedScopeUsageDTO object
 */
public static SharedScopeUsageDTO fromSharedScopeUsageToDTO(SharedScopeUsage sharedScopeUsage) {
    SharedScopeUsageDTO sharedScopeUsageDTO = new SharedScopeUsageDTO();
    sharedScopeUsageDTO.setId(sharedScopeUsage.getId());
    sharedScopeUsageDTO.setName(sharedScopeUsage.getName());
    List<SharedScopeUsedAPIInfoDTO> usedAPIInfoDTOList = new ArrayList<>();
    for (API api : sharedScopeUsage.getApis()) {
        APIIdentifier apiIdentifier = api.getId();
        SharedScopeUsedAPIInfoDTO usedAPIInfoDTO = new SharedScopeUsedAPIInfoDTO();
        usedAPIInfoDTO.setName(apiIdentifier.getName());
        usedAPIInfoDTO.setVersion(apiIdentifier.getVersion());
        usedAPIInfoDTO.setProvider(apiIdentifier.getProviderName());
        usedAPIInfoDTO.setContext(api.getContext());
        List<SharedScopeUsedAPIResourceInfoDTO> usedAPIResourceInfoDTOList = new ArrayList<>();
        for (URITemplate uriTemplate : api.getUriTemplates()) {
            SharedScopeUsedAPIResourceInfoDTO usedAPIResourceInfoDTO = new SharedScopeUsedAPIResourceInfoDTO();
            usedAPIResourceInfoDTO.setTarget(uriTemplate.getUriTemplate());
            usedAPIResourceInfoDTO.setVerb(uriTemplate.getHTTPVerb());
            usedAPIResourceInfoDTOList.add(usedAPIResourceInfoDTO);
        }
        usedAPIInfoDTO.setUsedResourceList(usedAPIResourceInfoDTOList);
        usedAPIInfoDTOList.add(usedAPIInfoDTO);
    }
    sharedScopeUsageDTO.setUsedApiList(usedAPIInfoDTOList);
    return sharedScopeUsageDTO;
}
Also used : SharedScopeUsedAPIResourceInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIResourceInfoDTO) ArrayList(java.util.ArrayList) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SharedScopeUsageDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO) SharedScopeUsedAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIInfoDTO)

Aggregations

SharedScopeUsageDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO)2 ArrayList (java.util.ArrayList)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 SharedScopeUsage (org.wso2.carbon.apimgt.api.model.SharedScopeUsage)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 SharedScopeUsedAPIInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIInfoDTO)1 SharedScopeUsedAPIResourceInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIResourceInfoDTO)1