Package org.wso2.carbon.rest.api.service

## Class RestApiAdmin

- java.lang.Object
- - org.wso2.carbon.core.AbstractAdmin
  - - org.wso2.carbon.mediation.initializer.AbstractServiceBusAdmin
    - - org.wso2.carbon.rest.api.service.RestApiAdmin

-     public class RestApiAdmin
      extends org.wso2.carbon.mediation.initializer.AbstractServiceBusAdmin

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `SYNAPSE_CONFIGURATION` |

    - ### Fields inherited from class org.wso2.carbon.core.AbstractAdmin

      `axisConfig, configurationContext`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RestApiAdmin()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `addApi​(APIData apiData)` |
    `boolean` | `addApiForTenant​(String apiData, String tenantDomain)` | Set the tenant domain when a publisher publishes his API in MT mode.
    `boolean` | `addApiFromString​(String apiData)` |
    `void` | `addSwaggerDocument​(String apiName, String swaggerJsonString, int tenantId)` | Replace the swagger document in the registry with the given swagger json string
    `void` | `deleteAllApi()` | Delete All API in the synapse configuration
    `boolean` | `deleteApi​(String apiName)` |
    `boolean` | `deleteApiForTenant​(String apiName, String tenantDomain)` | Set the tenant domain when a publisher deletes his API in MT mode.
    `void` | `deleteSelectedApi​(String[] apiNames)` | Delete Selected API
    `String` | `disableStatistics​(String apiName)` |
    `String` | `disableTracing​(String apiName)` |
    `String` | `enableStatistics​(String apiName)` |
    `String` | `enableTracing​(String apiName)` |
    `String` | `generateAPIFromSwagger​(String swaggerJsonString)` | Function to generate API from swagger definition (from JSON representation)
    `String` | `generateAPIFromSwaggerByFormat​(String swaggerString, boolean isJSON)` | Function to generate API from swagger definition (from JSON representation)
    `String` | `generateSwaggerFromSynapseAPI​(org.apache.synapse.api.API api)` | Function to generate API from swagger definition (from Synapse API)
    `String` | `generateSwaggerFromSynapseAPIByFormat​(org.apache.synapse.api.API api, boolean isJSON)` | Function to generate API from swagger definition (from Synapse API).
    `String` | `generateUpdatedAPIFromSwagger​(String swaggerJsonString, String existingApiName)` | Function to generate updated existing API by referring to swagger definition (from JSON representation)
    `String` | `generateUpdatedAPIFromSwaggerByFormat​(String swaggerJsonString, boolean isJSON, org.apache.synapse.api.API existingApi)` | Function to generate updated existing API by referring to swagger definition.
    `String` | `generateUpdatedAPIFromSwaggerForAPI​(String swaggerJsonString, org.apache.synapse.api.API existingApi)` | Function to generate updated existing API by referring to swagger definition (from JSON representation)
    `String` | `generateUpdatedSwaggerFromAPI​(String existingSwagger, boolean isJSONIn, boolean isJSONOut, org.apache.synapse.api.API api)` | Generate updated OpenApi definition using an updated API.
    `APIData` | `getApiByName​(String apiName)` |
    `org.apache.axiom.om.OMElement` | `getAPIContent​(String apiName, String tenantDomain)` |
    `int` | `getAPICount()` |
    `APIData` | `getApiForTenant​(String apiName, String tenantDomain)` | Set the tenant domain when a publisher tries to retrieve API his API in MT mode.
    `String[]` | `getApiNames()` |
    `APIData[]` | `getAPIsForListing​(int pageNumber, int itemsPerPage)` |
    `String` | `getApiSource​(APIData apiData)` |
    `protected org.apache.axis2.engine.AxisConfiguration` | `getAxisConfig()` | Override the AbstarctAdmin.java's getAxisConfig() to create the CarbonContext from ThreadLoaclContext.
    `protected org.apache.axis2.context.ConfigurationContext` | `getConfigContext()` |
    `String` | `getResourceSource​(ResourceData resourceData)` |
    `String[]` | `getSequences()` |
    `String` | `getServerContext()` |
    `String` | `getSwaggerDocument​(String apiName, int tenantId)` | Return the registry resource for the provided location
    `protected org.apache.synapse.api.API` | `getSynapseAPIByName​(String apiName)` | Function to retrieve synapse API object for given API name
    `protected org.apache.synapse.config.SynapseConfiguration` | `getSynapseConfiguration()` | Override the parent's getSynapseconfig() method to retrieve the Synapse configuration from the relevant axis configuration
    `boolean` | `updateApi​(String apiName, APIData apiData)` |
    `boolean` | `updateApiForTenant​(String apiName, String apiData, String tenantDomain)` | Set the tenant domain when a publisher updates his API in MT mode.
    `boolean` | `updateApiFromString​(String apiName, String apiData)` |
    `String` | `updateNameInSwagger​(String newName, String swagger)` | Update the title of a given swagger document.
    `void` | `updateSwaggerDocument​(String apiName, String swaggerJsonString, int tenantId)` | Create a registry resource for the swagger document and update the registry resource with the default swagger

    - ### Methods inherited from class org.wso2.carbon.mediation.initializer.AbstractServiceBusAdmin

      `getLock, getMediationPersistenceManager, getServerConfigurationInformation, getServerContextInformation, getSynapseEnvironment, getSynapseEnvironment, lockSynapseConfiguration, unlockSynapseConfiguration`

    - ### Methods inherited from class org.wso2.carbon.core.AbstractAdmin

      `getConfigSystemRegistry, getConfigUserRegistry, getGovernanceRegistry, getGovernanceSystemRegistry, getGovernanceUserRegistry, getHttpSession, getLocalRepo, getRegistry, getTenantDomain, getUserId, getUsername, getUserRealm, setConfigurationContext, setPermissionUpdateTimestamp`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SYNAPSE_CONFIGURATION

          public static final String SYNAPSE_CONFIGURATION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### RestApiAdmin

          public RestApiAdmin()

  - ### Method Detail

    - #### addApi

          public boolean addApi​(APIData apiData)
                         throws APIException

      Throws:
        `APIException`

    - #### addApiFromString

          public boolean addApiFromString​(String apiData)
                                   throws APIException

      Throws:
        `APIException`

    - #### addApiForTenant

          public boolean addApiForTenant​(String apiData,
                                         String tenantDomain)
                                  throws APIException

      Set the tenant domain when a publisher publishes his API in MT mode. When publisher publishes the API, we login the gateway as supretenant. But we need to publish the API in the particular tenant domain.
      Parameters:
        `apiData` -
        `tenantDomain` -
      Returns:
      Throws:
        `APIException`

    - #### updateApi

          public boolean updateApi​(String apiName,
                                   APIData apiData)
                            throws APIException

      Throws:
        `APIException`

    - #### updateApiFromString

          public boolean updateApiFromString​(String apiName,
                                             String apiData)
                                      throws APIException

      Throws:
        `APIException`

    - #### updateApiForTenant

          public boolean updateApiForTenant​(String apiName,
                                            String apiData,
                                            String tenantDomain)
                                     throws APIException

      Set the tenant domain when a publisher updates his API in MT mode. When publisher updates the API, we login the gateway as supretenant. But we need to update the API,which is in the particular tenant domain.
      Parameters:
        `apiName` -
        `apiData` -
      Returns:
      Throws:
        `APIException`

    - #### deleteApi

          public boolean deleteApi​(String apiName)
                            throws APIException

      Throws:
        `APIException`

    - #### deleteSelectedApi

          public void deleteSelectedApi​(String[] apiNames)
                                 throws APIException

      Delete Selected API
      Parameters:
        `apiNames` -
      Throws:
        `APIException`

    - #### deleteAllApi

          public void deleteAllApi()
                            throws APIException

      Delete All API in the synapse configuration
      Throws:
        `APIException`

    - #### deleteApiForTenant

          public boolean deleteApiForTenant​(String apiName,
                                            String tenantDomain)
                                     throws APIException

      Set the tenant domain when a publisher deletes his API in MT mode. When publisher deletes the API, we login the gateway as supretenant. But we need to delete the API,which is in the particular tenant domain.
      Parameters:
        `apiName` -
        `tenantDomain` -
      Returns:
      Throws:
        `APIException`

    - #### getAPIsForListing

          public APIData[] getAPIsForListing​(int pageNumber,
                                             int itemsPerPage)

    - #### getAPICount

          public int getAPICount()

    - #### getServerContext

          public String getServerContext()
                                  throws APIException

      Throws:
        `APIException`

    - #### getApiNames

          public String[] getApiNames()

    - #### getApiByName

          public APIData getApiByName​(String apiName)

    - #### getSynapseAPIByName

          protected org.apache.synapse.api.API getSynapseAPIByName​(String apiName)

      Function to retrieve synapse API object for given API name
      Parameters:
        `apiName` - API name
      Returns:
        API object if exists, null otherwise

    - #### getApiForTenant

          public APIData getApiForTenant​(String apiName,
                                         String tenantDomain)
                                  throws APIException

      Set the tenant domain when a publisher tries to retrieve API his API in MT mode. When publisher gets the API, we login the gateway as supretenant. But we need to get the API,which is in the particular tenant domain.
      Parameters:
        `apiName` -
        `tenantDomain` -
      Returns:
      Throws:
        `APIException`

    - #### getSequences

          public String[] getSequences()

    - #### enableStatistics

          public String enableStatistics​(String apiName)
                                  throws APIException

      Throws:
        `APIException`

    - #### disableStatistics

          public String disableStatistics​(String apiName)
                                   throws APIException

      Throws:
        `APIException`

    - #### enableTracing

          public String enableTracing​(String apiName)
                               throws APIException

      Throws:
        `APIException`

    - #### disableTracing

          public String disableTracing​(String apiName)
                                throws APIException

      Throws:
        `APIException`

    - #### getApiSource

          public String getApiSource​(APIData apiData)

    - #### getResourceSource

          public String getResourceSource​(ResourceData resourceData)

    - #### getSynapseConfiguration

          protected org.apache.synapse.config.SynapseConfiguration getSynapseConfiguration()

      Override the parent's getSynapseconfig() method to retrieve the Synapse configuration from the relevant axis configuration
      Overrides:
        `getSynapseConfiguration` in class `org.wso2.carbon.mediation.initializer.AbstractServiceBusAdmin`
      Returns:
        extracted SynapseConfiguration from the relevant AxisConfiguration

    - #### getAxisConfig

          protected org.apache.axis2.engine.AxisConfiguration getAxisConfig()

      Override the AbstarctAdmin.java's getAxisConfig() to create the CarbonContext from ThreadLoaclContext. We do this to support, publishing APIs as a supertenant but want to deploy that in tenant space. (This model is needed for APIManager)
      Overrides:
        `getAxisConfig` in class `org.wso2.carbon.core.AbstractAdmin`

    - #### getConfigContext

          protected org.apache.axis2.context.ConfigurationContext getConfigContext()

      Overrides:
        `getConfigContext` in class `org.wso2.carbon.core.AbstractAdmin`

    - #### addSwaggerDocument

          public void addSwaggerDocument​(String apiName,
                                         String swaggerJsonString,
                                         int tenantId)
                                  throws APIException

      Replace the swagger document in the registry with the given swagger json string
      Parameters:
        `apiName` -
        `swaggerJsonString` -
        `tenantId` -
      Throws:
        `APIException`

    - #### updateSwaggerDocument

          public void updateSwaggerDocument​(String apiName,
                                            String swaggerJsonString,
                                            int tenantId)
                                     throws APIException

      Create a registry resource for the swagger document and update the registry resource with the default swagger
      Parameters:
        `apiName` - Name of the API
        `swaggerJsonString` -
        `tenantId` -
      Throws:
        `APIException`

    - #### getSwaggerDocument

          public String getSwaggerDocument​(String apiName,
                                           int tenantId)
                                    throws APIException

      Return the registry resource for the provided location
      Parameters:
        `apiName` -
        `tenantId` -
      Returns:
      Throws:
        `APIException`

    - #### generateSwaggerFromSynapseAPIByFormat

          public String generateSwaggerFromSynapseAPIByFormat​(org.apache.synapse.api.API api,
                                                              boolean isJSON)
                                                       throws APIException

      Function to generate API from swagger definition (from Synapse API).
      Parameters:
        `api` - api existing synapse API
        `isJSON` - generate Swagger in YAML / JSON format.
      Returns:
        generated swagger.
      Throws:
        `APIException` - error occurred while retrieving host details.

    - #### generateSwaggerFromSynapseAPI

          public String generateSwaggerFromSynapseAPI​(org.apache.synapse.api.API api)
                                               throws APIException

      Function to generate API from swagger definition (from Synapse API)
      Parameters:
        `api` - existing synapse API
      Returns:
        generated swagger
      Throws:
        `APIException`

    - #### generateAPIFromSwagger

          public String generateAPIFromSwagger​(String swaggerJsonString)
                                        throws APIException

      Function to generate API from swagger definition (from JSON representation)
      Parameters:
        `swaggerJsonString` - swagger definition
      Returns:
        generated synapse API
      Throws:
        `APIException` - error occurred while retrieving host details.

    - #### generateAPIFromSwaggerByFormat

          public String generateAPIFromSwaggerByFormat​(String swaggerString,
                                                       boolean isJSON)
                                                throws APIException

      Function to generate API from swagger definition (from JSON representation)
      Parameters:
        `swaggerString` - swagger definition
        `isJSON` - input in YAML / JSON format.
      Returns:
        generated synapse API.
      Throws:
        `APIException` - error occurred while retrieving host details.

    - #### generateUpdatedAPIFromSwagger

          public String generateUpdatedAPIFromSwagger​(String swaggerJsonString,
                                                      String existingApiName)
                                               throws APIException

      Function to generate updated existing API by referring to swagger definition (from JSON representation)
      Parameters:
        `swaggerJsonString` - swagger definition
        `existingApiName` - name of the existing API
      Returns:
        generated synapse API
      Throws:
        `APIException`

    - #### generateUpdatedAPIFromSwaggerByFormat

          public String generateUpdatedAPIFromSwaggerByFormat​(String swaggerJsonString,
                                                              boolean isJSON,
                                                              org.apache.synapse.api.API existingApi)
                                                       throws APIException

      Function to generate updated existing API by referring to swagger definition.
      Parameters:
        `swaggerJsonString` - swagger definition.
        `isJSON` - input in YAML / JSON format.
        `existingApi` - existing synapse API.
      Returns:
        generated synapse API.
      Throws:
        `APIException` - error occurred while retrieving host details.

    - #### generateUpdatedAPIFromSwaggerForAPI

          public String generateUpdatedAPIFromSwaggerForAPI​(String swaggerJsonString,
                                                            org.apache.synapse.api.API existingApi)
                                                     throws APIException

      Function to generate updated existing API by referring to swagger definition (from JSON representation)
      Parameters:
        `swaggerJsonString` - swagger definition
        `existingApi` - existing synapse API
      Returns:
        generated synapse API
      Throws:
        `APIException`

    - #### generateUpdatedSwaggerFromAPI

          public String generateUpdatedSwaggerFromAPI​(String existingSwagger,
                                                      boolean isJSONIn,
                                                      boolean isJSONOut,
                                                      org.apache.synapse.api.API api)
                                               throws org.wso2.carbon.mediation.commons.rest.api.swagger.APIGenException

      Generate updated OpenApi definition using an updated API.
      Parameters:
        `existingSwagger` - existing OpenApi definition of the API.
        `isJSONIn` - input data-type JSON / YAML.
        `isJSONOut` - output required in JSON / YAML.
        `api` - updated synapse API.
      Returns:
        OpenApi definition of the updated API.
      Throws:
        `org.wso2.carbon.mediation.commons.rest.api.swagger.APIGenException` - Error occurred while generating the updated definition.

    - #### updateNameInSwagger

          public String updateNameInSwagger​(String newName,
                                            String swagger)
                                     throws APIException

      Update the title of a given swagger document.
      Parameters:
        `newName` - new title which should be added.
        `swagger` - swagger document.
      Returns:
        updated swagger.
      Throws:
        `APIException` - Error occurred while updating the title of the swagger.

    - #### getAPIContent

          public org.apache.axiom.om.OMElement getAPIContent​(String apiName,
                                                             String tenantDomain)