Search in sources :

Example 41 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.

@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
    Swagger swagger = new Swagger();
    Info info = new Info();
    info.setTitle(api.getName());
    info.setDescription(api.getDescription());
    info.setVersion(api.getVersion());
    swagger.setInfo(info);
    Map<String, Path> stringPathMap = new HashMap();
    for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
        String uriTemplateString = uriTemplate.getUriTemplate();
        List<Parameter> parameterList = getParameters(uriTemplateString);
        if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
            parameterList.add(getDefaultBodyParameter());
        }
        Operation operation = new Operation();
        operation.setParameters(parameterList);
        operation.setOperationId(uriTemplate.getTemplateId());
        operation.addResponse("200", getDefaultResponse());
        if (stringPathMap.containsKey(uriTemplateString)) {
            Path path = stringPathMap.get(uriTemplateString);
            path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
        } else {
            Path path = new Path();
            path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
            stringPathMap.put(uriTemplateString, path);
        }
    }
    swagger.setPaths(stringPathMap);
    swagger.setPaths(stringPathMap);
    return Json.pretty(swagger);
}
Also used : Path(io.swagger.models.Path) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

Example 42 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addCompositeAPI.

/**
 * @see APIGateway#addCompositeAPI(CompositeAPI api)
 */
@Override
public void addCompositeAPI(CompositeAPI api) throws GatewayException {
    // build the message to send
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
    gatewayDTO.setLabels(api.getLabels());
    APISummary apiSummary = new APISummary();
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    gatewayDTO.setApiSummary(apiSummary);
    publishToPublisherTopic(gatewayDTO);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 43 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addAPI.

@Override
public void addAPI(API api) throws GatewayException {
    // build the message to send
    APIEvent apiCreateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
    apiCreateEvent.setLabels(api.getLabels());
    apiCreateEvent.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(apiCreateEvent);
    if (log.isDebugEnabled()) {
        log.debug("API : " + api.getName() + " created event has been successfully published to broker");
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 44 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method toAPISummary.

/**
 * Convert API definition into APISummary
 *
 * @param api API definition
 * @return The summary of the API
 */
private APISummary toAPISummary(API api) {
    APISummary apiSummary = new APISummary();
    apiSummary.setId(api.getId());
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setLifeCycleStatus(api.getLifeCycleStatus());
    apiSummary.setLifeCycleStatus(api.getLifeCycleStatus());
    apiSummary.setCreatedTime(api.getCreatedTime());
    apiSummary.setLastUpdatedTime(api.getLastUpdatedTime());
    apiSummary.setSecurityScheme(api.getSecurityScheme());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    return apiSummary;
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary)

Example 45 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteCompositeAPI.

@Override
public void deleteCompositeAPI(CompositeAPI api) throws GatewayException {
    // build the message to send
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
    gatewayDTO.setLabels(api.getLabels());
    APISummary apiSummary = new APISummary();
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    gatewayDTO.setApiSummary(apiSummary);
    publishToPublisherTopic(gatewayDTO);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)320 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)132 HashMap (java.util.HashMap)129 ArrayList (java.util.ArrayList)112 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)106 Test (org.junit.Test)83 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)83 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)82 SQLException (java.sql.SQLException)75 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)70 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)61 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)60 Connection (java.sql.Connection)58 Response (javax.ws.rs.core.Response)58