Search in sources :

Example 1 with APIExternalStoreListDTO

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

the class ApisApiServiceImpl method publishAPIToExternalStores.

/**
 * Publish API to given external stores.
 *
 * @param apiId API Id
 * @param externalStoreIds  External Store Ids
 * @param ifMatch   If-match header value
 * @param messageContext CXF Message Context
 * @return Response of published external store list
 */
@Override
public Response publishAPIToExternalStores(String apiId, String externalStoreIds, String ifMatch, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    API api = null;
    List<String> externalStoreIdList = Arrays.asList(externalStoreIds.split("\\s*,\\s*"));
    try {
        APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
        if (apiIdentifier == null) {
            throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
        }
        api = apiProvider.getAPIbyUUID(apiId, organization);
        api.setOrganization(organization);
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else {
            String errorMessage = "Error while getting API: " + apiId;
            log.error(errorMessage, e);
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    if (apiProvider.publishToExternalAPIStores(api, externalStoreIdList)) {
        Set<APIStore> publishedStores = apiProvider.getPublishedExternalAPIStores(api.getUuid());
        APIExternalStoreListDTO apiExternalStoreListDTO = ExternalStoreMappingUtil.fromAPIExternalStoreCollectionToDTO(publishedStores);
        return Response.ok().entity(apiExternalStoreListDTO).build();
    }
    return Response.serverError().build();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) APIExternalStoreListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreListDTO) APIStore(org.wso2.carbon.apimgt.api.model.APIStore)

Example 2 with APIExternalStoreListDTO

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

the class ApisApiServiceImpl method getAllPublishedExternalStoresByAPI.

/**
 * Get external store list which the given API is already published to.
 * @param apiId API Identifier
 * @param ifNoneMatch If-None-Match header value
 * @param messageContext CXF Message Context
 * @return External Store list of published API
 */
@Override
public Response getAllPublishedExternalStoresByAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    Set<APIStore> publishedStores = apiProvider.getPublishedExternalAPIStores(apiId);
    APIExternalStoreListDTO apiExternalStoreListDTO = ExternalStoreMappingUtil.fromAPIExternalStoreCollectionToDTO(publishedStores);
    return Response.ok().entity(apiExternalStoreListDTO).build();
}
Also used : APIProvider(org.wso2.carbon.apimgt.api.APIProvider) APIExternalStoreListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreListDTO) APIStore(org.wso2.carbon.apimgt.api.model.APIStore)

Example 3 with APIExternalStoreListDTO

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

the class ExternalStoreMappingUtil method fromAPIExternalStoreCollectionToDTO.

/**
 * Converts list of APIStore object into APIExternalStoreListDTO object.
 *
 * @param externalStoreCollection a collection of APIStore objects
 * @return APIExternalStoreListDTO object containing APIExternalStoreDTOs
 */
public static APIExternalStoreListDTO fromAPIExternalStoreCollectionToDTO(Collection<APIStore> externalStoreCollection) {
    APIExternalStoreListDTO apiExternalStoreListDTO = new APIExternalStoreListDTO();
    List<APIExternalStoreDTO> apiExternalStoreDTOS = apiExternalStoreListDTO.getList();
    if (externalStoreCollection == null) {
        externalStoreCollection = new HashSet<>();
    }
    for (APIStore externalStore : externalStoreCollection) {
        apiExternalStoreDTOS.add(fromAPIExternalStoreToDTO(externalStore));
    }
    apiExternalStoreListDTO.setList(apiExternalStoreDTOS);
    apiExternalStoreListDTO.setCount(apiExternalStoreDTOS.size());
    return apiExternalStoreListDTO;
}
Also used : APIExternalStoreListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreListDTO) APIExternalStoreDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreDTO) APIStore(org.wso2.carbon.apimgt.api.model.APIStore)

Aggregations

APIStore (org.wso2.carbon.apimgt.api.model.APIStore)3 APIExternalStoreListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreListDTO)3 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)1 APIExternalStoreDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIExternalStoreDTO)1