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();
}
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();
}
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;
}
Aggregations