Search in sources :

Example 1 with ApiDefinitionType

use of io.apiman.manager.api.beans.apis.ApiDefinitionType in project apiman by apiman.

the class OrganizationResourceImpl method updateApiDefinition.

@Override
public void updateApiDefinition(String organizationId, String apiId, String version) throws ApiVersionNotFoundException, NotAuthorizedException, InvalidApiStatusException {
    securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
    String contentType = request.getContentType();
    InputStream data;
    try {
        data = request.getInputStream();
    } catch (IOException e) {
        throw new SystemErrorException(e);
    }
    try {
        ApiDefinitionType newDefinitionType;
        if (contentType.toLowerCase().contains("application/json")) {
            // $NON-NLS-1$
            newDefinitionType = ApiDefinitionType.SwaggerJSON;
        } else if (contentType.toLowerCase().contains("application/x-yaml")) {
            // $NON-NLS-1$
            newDefinitionType = ApiDefinitionType.SwaggerYAML;
        } else if (contentType.toLowerCase().contains("application/wsdl+xml")) {
            // $NON-NLS-1$
            newDefinitionType = ApiDefinitionType.WSDL;
        } else {
            // $NON-NLS-1$
            throw new SystemErrorException(Messages.i18n.format("InvalidApiDefinitionContentType", contentType));
        }
        apiService.setApiDefinition(organizationId, apiId, version, newDefinitionType, data);
        // $NON-NLS-1$
        LOGGER.debug("Updated API definition for {0}", apiId);
    } finally {
        IOUtils.closeQuietly(data);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) InputStream(java.io.InputStream) IOException(java.io.IOException) ApiDefinitionType(io.apiman.manager.api.beans.apis.ApiDefinitionType)

Aggregations

ApiDefinitionType (io.apiman.manager.api.beans.apis.ApiDefinitionType)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1