Search in sources :

Example 1 with NewApiBean

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

the class ApiService method createApi.

public ApiBeanDto createApi(String organizationId, NewApiBean bean) throws OrganizationNotFoundException, ApiAlreadyExistsException, NotAuthorizedException, InvalidNameException {
    FieldValidator.validateName(bean.getName());
    ApiBean newApi = new ApiBean();
    newApi.setName(bean.getName());
    newApi.setDescription(bean.getDescription());
    newApi.setId(BeanUtils.idFromName(bean.getName()));
    newApi.setCreatedOn(new Date());
    newApi.setCreatedBy(securityContext.getCurrentUser());
    newApi.setImage(bean.getImage());
    newApi.setTags(tagMapper.toEntity(bean.getTags()));
    return tryAction(() -> {
        GatewaySummaryBean gateway = getSingularGateway();
        OrganizationBean orgBean = organizationService.getOrg(organizationId);
        if (storage.getApi(orgBean.getId(), newApi.getId()) != null) {
            throw ExceptionFactory.apiAlreadyExistsException(bean.getName());
        }
        newApi.setOrganization(orgBean);
        // Store/persist the new API
        storage.createApi(newApi);
        storage.createAuditEntry(AuditUtils.apiCreated(newApi, securityContext));
        if (bean.getInitialVersion() != null) {
            NewApiVersionBean newApiVersion = new NewApiVersionBean();
            newApiVersion.setEndpoint(bean.getEndpoint());
            newApiVersion.setEndpointType(bean.getEndpointType());
            newApiVersion.setEndpointContentType(bean.getEndpointContentType());
            newApiVersion.setPlans(bean.getPlans());
            newApiVersion.setPublicAPI(bean.getPublicAPI());
            newApiVersion.setParsePayload(bean.getParsePayload());
            newApiVersion.setDisableKeysStrip(bean.getDisableKeysStrip());
            newApiVersion.setVersion(bean.getInitialVersion());
            newApiVersion.setDefinitionUrl(bean.getDefinitionUrl());
            newApiVersion.setDefinitionType(bean.getDefinitionType());
            newApiVersion.setExtendedDescription(bean.getExtendedDescription());
            createApiVersionInternal(newApiVersion, newApi, gateway);
        }
        return apiMapper.toDto(newApi);
    });
}
Also used : UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) Date(java.util.Date) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean)

Example 2 with NewApiBean

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

the class OrganizationResourceImpl method createApi.

/**
 * @see IOrganizationResource#createApi(java.lang.String, io.apiman.manager.api.beans.apis.NewApiBean)
 */
@Override
public ApiBean createApi(String organizationId, NewApiBean bean) throws OrganizationNotFoundException, ApiAlreadyExistsException, NotAuthorizedException, InvalidNameException {
    securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
    FieldValidator.validateName(bean.getName());
    ApiBean newApi = new ApiBean();
    newApi.setName(bean.getName());
    newApi.setDescription(bean.getDescription());
    newApi.setId(BeanUtils.idFromName(bean.getName()));
    newApi.setCreatedOn(new Date());
    newApi.setCreatedBy(securityContext.getCurrentUser());
    try {
        GatewaySummaryBean gateway = getSingularGateway();
        storage.beginTx();
        OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
        if (storage.getApi(orgBean.getId(), newApi.getId()) != null) {
            throw ExceptionFactory.apiAlreadyExistsException(bean.getName());
        }
        newApi.setOrganization(orgBean);
        // Store/persist the new API
        storage.createApi(newApi);
        storage.createAuditEntry(AuditUtils.apiCreated(newApi, securityContext));
        if (bean.getInitialVersion() != null) {
            NewApiVersionBean newApiVersion = new NewApiVersionBean();
            newApiVersion.setEndpoint(bean.getEndpoint());
            newApiVersion.setEndpointType(bean.getEndpointType());
            newApiVersion.setEndpointContentType(bean.getEndpointContentType());
            newApiVersion.setPlans(bean.getPlans());
            newApiVersion.setPublicAPI(bean.getPublicAPI());
            newApiVersion.setParsePayload(bean.getParsePayload());
            newApiVersion.setDisableKeysStrip(bean.getDisableKeysStrip());
            newApiVersion.setVersion(bean.getInitialVersion());
            newApiVersion.setDefinitionUrl(bean.getDefinitionUrl());
            newApiVersion.setDefinitionType(bean.getDefinitionType());
            createApiVersionInternal(newApiVersion, newApi, gateway);
        }
        storage.commitTx();
        return newApi;
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) ClientUsagePerApiBean(io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) Date(java.util.Date) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)

Aggregations

ApiBean (io.apiman.manager.api.beans.apis.ApiBean)2 NewApiBean (io.apiman.manager.api.beans.apis.NewApiBean)2 NewApiVersionBean (io.apiman.manager.api.beans.apis.NewApiVersionBean)2 UpdateApiBean (io.apiman.manager.api.beans.apis.UpdateApiBean)2 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)2 GatewaySummaryBean (io.apiman.manager.api.beans.summary.GatewaySummaryBean)2 ClientUsagePerApiBean (io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean)1 NewOrganizationBean (io.apiman.manager.api.beans.orgs.NewOrganizationBean)1 UpdateOrganizationBean (io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)1 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)1 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)1 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)1 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)1 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)1 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)1 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)1 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)1