Search in sources :

Example 1 with ApiVersionBean

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

the class RestHelper method hideSensitiveDataFromApiVersionBean.

/**
 * This method will hide sensitive data, such as created by, from the result
 *
 * @param apiVersionBean the apiVersionBean
 * @return the apiVersionBean without sensitive data
 */
public static ApiVersionBean hideSensitiveDataFromApiVersionBean(ApiVersionBean apiVersionBean) {
    ApiBean api = new ApiBean();
    api.setId(apiVersionBean.getApi().getId());
    api.setName(apiVersionBean.getApi().getName());
    api.setDescription(apiVersionBean.getApi().getDescription());
    OrganizationBean org = new OrganizationBean();
    org.setId(apiVersionBean.getApi().getOrganization().getId());
    org.setName(apiVersionBean.getApi().getOrganization().getName());
    org.setDescription(apiVersionBean.getApi().getOrganization().getDescription());
    api.setOrganization(org);
    ApiVersionBean apiVersion = new ApiVersionBean();
    apiVersion.setApi(api);
    apiVersion.setStatus(apiVersionBean.getStatus());
    apiVersion.setEndpointType(apiVersionBean.getEndpointType());
    apiVersion.setEndpointContentType(apiVersionBean.getEndpointContentType());
    apiVersion.setGateways(apiVersionBean.getGateways());
    apiVersion.setPublicAPI(apiVersionBean.isPublicAPI());
    apiVersion.setPlans(apiVersionBean.getPlans());
    apiVersion.setVersion(apiVersionBean.getVersion());
    apiVersion.setDefinitionType(apiVersionBean.getDefinitionType());
    return apiVersion;
}
Also used : ApiBean(io.apiman.manager.api.beans.apis.ApiBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean)

Example 2 with ApiVersionBean

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

the class EsStorage method getApiVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#getApiVersion(java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public ApiVersionBean getApiVersion(String organizationId, String apiId, String version) throws StorageException {
    Map<String, Object> source = getEntity(INDEX_MANAGER_POSTFIX_API_VERSION, id(organizationId, apiId, version));
    if (source == null) {
        return null;
    }
    ApiVersionBean bean = EsMarshalling.unmarshallApiVersion(source);
    bean.setApi(getApi(organizationId, apiId));
    return bean;
}
Also used : ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean)

Example 3 with ApiVersionBean

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

the class EsStorage method getAllApiVersions.

/**
 * @see io.apiman.manager.api.core.IStorage#getAllApiVersions(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Iterator<ApiVersionBean> getAllApiVersions(String organizationId, String apiId) throws StorageException {
    BoolQueryBuilder qb = QueryBuilders.boolQuery();
    List<QueryBuilder> filter = qb.filter();
    filter.add(QueryBuilders.termQuery("organizationId", organizationId));
    filter.add(QueryBuilders.termQuery("apiId", apiId));
    return getAll(INDEX_MANAGER_POSTFIX_API_VERSION, new // $NON-NLS-1$
    IUnmarshaller<ApiVersionBean>() {

        @Override
        public ApiVersionBean unmarshal(Map<String, Object> source) {
            return EsMarshalling.unmarshallApiVersion(source);
        }
    }, qb);
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean)

Example 4 with ApiVersionBean

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

the class EsMarshallingTest method testMarshallApiVersionBean.

/**
 * Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.apis.ApiVersionBean)}.
 */
@Test
public void testMarshallApiVersionBean() throws Exception {
    ApiVersionBean bean = createBean(ApiVersionBean.class);
    XContentBuilder builder = EsMarshalling.marshall(bean);
    Assert.assertEquals("{\"organizationId\":\"ID\",\"organizationName\":\"NAME\",\"apiId\":\"ID\",\"apiName\":\"NAME\",\"apiDescription\":\"DESCRIPTION\",\"version\":\"VERSION\",\"status\":\"Created\",\"createdBy\":\"CREATEDBY\",\"createdOn\":1,\"modifiedBy\":\"MODIFIEDBY\",\"modifiedOn\":1,\"publishedOn\":1,\"retiredOn\":1,\"publicAPI\":true,\"endpoint\":\"ENDPOINT\",\"endpointType\":\"rest\",\"endpointContentType\":\"json\",\"parsePayload\":true,\"disableKeysStrip\":true,\"definitionType\":\"None\",\"definitionUrl\":\"DEFINITIONURL\",\"gateways\":[{\"gatewayId\":\"GATEWAYID\"}],\"plans\":[{\"planId\":\"PLANID\",\"version\":\"VERSION\"}],\"endpointProperties\":{\"KEY-1\":\"VALUE-1\",\"KEY-2\":\"VALUE-2\"}}", Strings.toString(builder));
}
Also used : ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 5 with ApiVersionBean

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

the class OrganizationResourceImpl method deleteApi.

/**
 * @see IOrganizationResource#deleteApi(java.lang.String, java.lang.String)
 */
@Override
public void deleteApi(@PathParam("organizationId") String organizationId, @PathParam("apiId") String apiId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
    securityContext.checkPermissions(PermissionType.apiAdmin, organizationId);
    try {
        storage.beginTx();
        ApiBean api = getApiFromStorage(organizationId, apiId);
        Iterator<ApiVersionBean> apiVersions = storage.getAllApiVersions(organizationId, apiId);
        Iterable<ApiVersionBean> iterable = () -> apiVersions;
        List<ApiVersionBean> apiVersionBeans = StreamSupport.stream(iterable.spliterator(), false).collect(toList());
        List<ApiVersionBean> registeredElems = apiVersionBeans.stream().filter(clientVersion -> clientVersion.getStatus() == ApiStatus.Published).limit(5).collect(toList());
        if (!registeredElems.isEmpty()) {
            throw ExceptionFactory.entityStillActiveExceptionApiVersions(registeredElems);
        }
        for (ApiVersionBean apiVersion : apiVersionBeans) {
            // add apiBean to apiVersionBean, otherwise deleteApiDefinition fails for EsStorage
            apiVersion.setApi(api);
            if (apiVersionHasApiDefinition(apiVersion)) {
                storage.deleteApiDefinition(apiVersion);
            }
        }
        storage.deleteApi(api);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug("Deleted API: " + api.getName());
    } 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) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) 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

ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)68 StorageException (io.apiman.manager.api.core.exceptions.StorageException)34 Date (java.util.Date)29 NewApiVersionBean (io.apiman.manager.api.beans.apis.NewApiVersionBean)28 UpdateApiVersionBean (io.apiman.manager.api.beans.apis.UpdateApiVersionBean)28 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)25 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)25 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)25 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)23 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)22 PlanVersionNotFoundException (io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException)22 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)20 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)20 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)19 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)18 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)17 IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)16 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)16 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)16 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)16