Search in sources :

Example 1 with TopicDTO

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

the class AsyncAPIMappingUtil method fromTopicToDTO.

/**
 * Converts Topic object to DTO.
 *
 * @param topic Topic object
 * @return TopicDTO
 */
public static TopicDTO fromTopicToDTO(Topic topic) {
    TopicDTO topicDTO = new TopicDTO();
    topicDTO.setApiId(topic.getApiId());
    topicDTO.setName(topic.getName());
    topicDTO.setType(topic.getType());
    return topicDTO;
}
Also used : TopicDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicDTO)

Example 2 with TopicDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.TopicDTO 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 3 with TopicDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.TopicDTO 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)

Aggregations

TopicDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicDTO)2 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 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 Topic (org.wso2.carbon.apimgt.api.model.webhooks.Topic)1 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)1 TopicDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.TopicDTO)1 TopicListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.TopicListDTO)1