Search in sources :

Example 1 with TopicListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method updateTopics.

@Override
public Response updateTopics(String apiId, TopicListDTO topicListDTO, String ifMatch, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    // validate if api exists
    validateAPIExistence(apiId);
    API existingAPI = apiProvider.getAPIbyUUID(apiId, organization);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(existingAPI.getStatus());
    Set<URITemplate> uriTemplates = existingAPI.getUriTemplates();
    uriTemplates.clear();
    for (TopicDTO topicDTO : topicListDTO.getList()) {
        URITemplate uriTemplate = new URITemplate();
        uriTemplate.setUriTemplate(topicDTO.getName());
        uriTemplate.setHTTPVerb(topicDTO.getMode().toUpperCase());
        // TODO: Get these from proper locations
        uriTemplate.setAuthType(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN);
        uriTemplate.setThrottlingTier(APIConstants.UNLIMITED_TIER);
        uriTemplates.add(uriTemplate);
    }
    existingAPI.setUriTemplates(uriTemplates);
    // TODO: Add scopes
    existingAPI.setOrganization(organization);
    try {
        apiProvider.updateAPI(existingAPI);
    } catch (FaultGatewaysException e) {
        String errorMessage = "Error while updating API : " + apiId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return Response.ok().build();
}
Also used : URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) TopicDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.TopicDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 2 with TopicListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.

the class AsyncAPIMappingUtil method fromTopicListToDTO.

/**
 * Converts Set of Topic objects to DTO.
 *
 * @param topics set of Topic objects
 * @return TopicListDTO containing TopicDTOs
 */
public static TopicListDTO fromTopicListToDTO(Set<Topic> topics) {
    TopicListDTO topicListDTO = new TopicListDTO();
    List<TopicDTO> topicDTOs = topicListDTO.getList();
    topicListDTO.setCount(topics.size());
    if (topicDTOs == null) {
        topicDTOs = new ArrayList<>();
        topicListDTO.setList(topicDTOs);
    }
    for (Topic topic : topics) {
        topicDTOs.add(fromTopicToDTO(topic));
    }
    return topicListDTO;
}
Also used : TopicListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO) TopicDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicDTO) Topic(org.wso2.carbon.apimgt.api.model.webhooks.Topic)

Example 3 with TopicListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdTopicsGet.

@Override
public Response apisApiIdTopicsGet(String apiId, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
    if (org.apache.commons.lang.StringUtils.isNotEmpty(apiId)) {
        String username = RestApiCommonUtil.getLoggedInUsername();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        Set<Topic> topics;
        try {
            APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
            ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
            TopicListDTO topicListDTO;
            if (apiTypeWrapper.isAPIProduct()) {
                topics = apiConsumer.getTopics(apiTypeWrapper.getApiProduct().getUuid());
            } else {
                topics = apiConsumer.getTopics(apiTypeWrapper.getApi().getUuid());
            }
            topicListDTO = AsyncAPIMappingUtil.fromTopicListToDTO(topics);
            return Response.ok().entity(topicListDTO).build();
        } catch (APIManagementException e) {
            if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
                RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
            } else {
                RestApiUtil.handleInternalServerError("Failed to get topics of Async API " + apiId, e, log);
            }
        }
    } else {
        RestApiUtil.handleBadRequest("API Id is missing in request", log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Topic(org.wso2.carbon.apimgt.api.model.webhooks.Topic)

Aggregations

Topic (org.wso2.carbon.apimgt.api.model.webhooks.Topic)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)1 API (org.wso2.carbon.apimgt.api.model.API)1 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)1 TopicDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.TopicDTO)1 TopicDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicDTO)1 TopicListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO)1