Search in sources :

Example 1 with PlanVersionSummaryBean

use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.

the class EsMarshalling method unmarshallPlanVersionSummary.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the plan version summary
 */
public static PlanVersionSummaryBean unmarshallPlanVersionSummary(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    PlanVersionSummaryBean bean = new PlanVersionSummaryBean();
    bean.setDescription(asString(source.get("planDescription")));
    bean.setId(asString(source.get("planId")));
    bean.setName(asString(source.get("planName")));
    bean.setOrganizationId(asString(source.get("organizationId")));
    bean.setOrganizationName(asString(source.get("organizationName")));
    bean.setStatus(asEnum(source.get("status"), PlanStatus.class));
    bean.setVersion(asString(source.get("version")));
    postMarshall(bean);
    return bean;
}
Also used : PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus)

Example 2 with PlanVersionSummaryBean

use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.

the class OrganizationResourceImpl method deletePlan.

@Override
public void deletePlan(@PathParam("organizationId") String organizationId, @PathParam("planId") String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
    securityContext.checkPermissions(PermissionType.planAdmin, organizationId);
    List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
    if (!lockedPlans.isEmpty())
        throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
    try {
        storage.beginTx();
        PlanBean plan = storage.getPlan(organizationId, planId);
        storage.deletePlan(plan);
        storage.commitTx();
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean) MemberBean(io.apiman.manager.api.beans.members.MemberBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ISecurityContext(io.apiman.manager.api.security.ISecurityContext) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) StringUtils(org.apache.commons.lang3.StringUtils) UserBean(io.apiman.manager.api.beans.idm.UserBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) ApiVersionEndpointSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionEndpointSummaryBean) MediaType(javax.ws.rs.core.MediaType) DownloadType(io.apiman.manager.api.beans.download.DownloadType) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) ApiManagerConfig(io.apiman.manager.api.core.config.ApiManagerConfig) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) NewApiDefinitionBean(io.apiman.manager.api.beans.apis.NewApiDefinitionBean) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) IApiValidator(io.apiman.manager.api.core.IApiValidator) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) ApiVersionStatusBean(io.apiman.manager.api.beans.apis.ApiVersionStatusBean) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) IOUtils(org.apache.commons.io.IOUtils) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) UsageHistogramBean(io.apiman.manager.api.beans.metrics.UsageHistogramBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) IMetricsAccessor(io.apiman.manager.api.core.IMetricsAccessor) UpdateClientBean(io.apiman.manager.api.beans.clients.UpdateClientBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) ResponseStatsHistogramBean(io.apiman.manager.api.beans.metrics.ResponseStatsHistogramBean) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) IOrganizationResource(io.apiman.manager.api.rest.IOrganizationResource) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) UsagePerClientBean(io.apiman.manager.api.beans.metrics.UsagePerClientBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) StreamSupport(java.util.stream.StreamSupport) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UsagePerPlanBean(io.apiman.manager.api.beans.metrics.UsagePerPlanBean) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) GrantRolesBean(io.apiman.manager.api.beans.idm.GrantRolesBean) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) BeanUtils(io.apiman.manager.api.beans.BeanUtils) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) TreeMap(java.util.TreeMap) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) Messages(io.apiman.manager.api.rest.exceptions.i18n.Messages) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ExceptionFactory(io.apiman.manager.api.rest.exceptions.util.ExceptionFactory) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) URL(java.net.URL) Date(java.util.Date) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) HistogramIntervalType(io.apiman.manager.api.beans.metrics.HistogramIntervalType) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) IGatewayLinkFactory(io.apiman.manager.api.gateway.IGatewayLinkFactory) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiDefinitionType(io.apiman.manager.api.beans.apis.ApiDefinitionType) IDownloadManager(io.apiman.manager.api.core.IDownloadManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) IClientValidator(io.apiman.manager.api.core.IClientValidator) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) Context(javax.ws.rs.core.Context) ClientUsagePerApiBean(io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IRoleResource(io.apiman.manager.api.rest.IRoleResource) List(java.util.List) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) IUserResource(io.apiman.manager.api.rest.IUserResource) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) PathParam(javax.ws.rs.PathParam) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) HashMap(java.util.HashMap) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) AuditUtils(io.apiman.manager.api.rest.impl.audit.AuditUtils) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) ResponseStatsSummaryBean(io.apiman.manager.api.beans.metrics.ResponseStatsSummaryBean) FieldValidator(io.apiman.manager.api.rest.impl.util.FieldValidator) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IApiKeyGenerator(io.apiman.manager.api.core.IApiKeyGenerator) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) SwaggerWsdlHelper(io.apiman.manager.api.rest.impl.util.SwaggerWsdlHelper) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) MembershipData(io.apiman.manager.api.beans.audit.data.MembershipData) Iterator(java.util.Iterator) EntityType(io.apiman.common.util.crypt.DataEncryptionContext.EntityType) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) MalformedURLException(java.net.MalformedURLException) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) DateTime(org.joda.time.DateTime) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) Collectors.toList(java.util.stream.Collectors.toList) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) RequestScoped(javax.enterprise.context.RequestScoped) NewClientBean(io.apiman.manager.api.beans.clients.NewClientBean) ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean) RestHelper(io.apiman.manager.api.rest.impl.util.RestHelper) InputStream(java.io.InputStream) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UsagePerPlanBean(io.apiman.manager.api.beans.metrics.UsagePerPlanBean) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) 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)

Example 3 with PlanVersionSummaryBean

use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.

the class PlanService method deletePlan.

public void deletePlan(String organizationId, String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
    List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
    if (!lockedPlans.isEmpty())
        throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
    tryAction(() -> {
        PlanBean plan = storage.getPlan(organizationId, planId);
        storage.deletePlan(plan);
    });
}
Also used : NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean) Date(java.util.Date) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ISecurityContext(io.apiman.manager.api.security.ISecurityContext) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) PagingBean(io.apiman.manager.api.beans.search.PagingBean) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) Transactional(javax.transaction.Transactional) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) List(java.util.List) IApimanLogger(io.apiman.common.logging.IApimanLogger) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) AuditUtils(io.apiman.manager.api.rest.impl.audit.AuditUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) FieldValidator(io.apiman.manager.api.rest.impl.util.FieldValidator) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) DataAccessUtilMixin(io.apiman.manager.api.rest.impl.util.DataAccessUtilMixin) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) IStorage(io.apiman.manager.api.core.IStorage) BeanUtils(io.apiman.manager.api.beans.BeanUtils) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) Collectors.toList(java.util.stream.Collectors.toList) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ExceptionFactory(io.apiman.manager.api.rest.exceptions.util.ExceptionFactory) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean)

Example 4 with PlanVersionSummaryBean

use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.

the class JpaStorage method getPlanVersions.

/**
 * {@inheritDoc}
 */
@Override
public List<PlanVersionSummaryBean> getPlanVersions(String orgId, String planId) throws StorageException {
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT v from PlanVersionBean v" + "  JOIN v.plan p" + "  JOIN p.organization o" + " WHERE o.id = :orgId" + "   AND p.id = :planId" + " ORDER BY v.createdOn DESC";
        TypedQuery<PlanVersionBean> query = entityManager.createQuery(jpql, PlanVersionBean.class).setMaxResults(500).setParameter("orgId", orgId).setParameter("planId", planId);
        List<PlanVersionBean> planVersions = query.getResultList();
        List<PlanVersionSummaryBean> rval = new ArrayList<>(planVersions.size());
        for (PlanVersionBean planVersion : planVersions) {
            PlanVersionSummaryBean pvsb = new PlanVersionSummaryBean();
            pvsb.setOrganizationId(planVersion.getPlan().getOrganization().getId());
            pvsb.setOrganizationName(planVersion.getPlan().getOrganization().getName());
            pvsb.setId(planVersion.getPlan().getId());
            pvsb.setName(planVersion.getPlan().getName());
            pvsb.setDescription(planVersion.getPlan().getDescription());
            pvsb.setVersion(planVersion.getVersion());
            pvsb.setStatus(planVersion.getStatus());
            rval.add(pvsb);
        }
        return rval;
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 5 with PlanVersionSummaryBean

use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.

the class EsStorage method getPlanVersions.

/**
 * @see io.apiman.manager.api.core.IStorageQuery#getPlanVersions(java.lang.String, java.lang.String)
 */
@Override
public List<PlanVersionSummaryBean> getPlanVersions(String organizationId, String planId) throws StorageException {
    @SuppressWarnings("nls") BoolQueryBuilder query = QueryBuilders.boolQuery();
    List<QueryBuilder> filter = query.filter();
    filter.add(QueryBuilders.termQuery("organizationId", organizationId));
    filter.add(QueryBuilders.termQuery("planId", planId));
    @SuppressWarnings("nls") SearchSourceBuilder builder = new SearchSourceBuilder().sort(// $NON-NLS-1$
    new FieldSortBuilder("createdOn").order(SortOrder.DESC)).query(query).size(500);
    // $NON-NLS-1$
    List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_PLAN_VERSION, builder);
    List<PlanVersionSummaryBean> rval = new ArrayList<>(hits.size());
    for (SearchHit hit : hits) {
        PlanVersionSummaryBean bean = EsMarshalling.unmarshallPlanVersionSummary(hit.getSourceAsMap());
        rval.add(bean);
    }
    return rval;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

PlanVersionSummaryBean (io.apiman.manager.api.beans.summary.PlanVersionSummaryBean)5 PlanStatus (io.apiman.manager.api.beans.plans.PlanStatus)3 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)3 StorageException (io.apiman.manager.api.core.exceptions.StorageException)3 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)2 IApimanLogger (io.apiman.common.logging.IApimanLogger)2 BeanUtils (io.apiman.manager.api.beans.BeanUtils)2 AuditEntryBean (io.apiman.manager.api.beans.audit.AuditEntryBean)2 EntityUpdatedData (io.apiman.manager.api.beans.audit.data.EntityUpdatedData)2 PermissionType (io.apiman.manager.api.beans.idm.PermissionType)2 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)2 NewPlanBean (io.apiman.manager.api.beans.plans.NewPlanBean)2 NewPlanVersionBean (io.apiman.manager.api.beans.plans.NewPlanVersionBean)2 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)2 UpdatePlanBean (io.apiman.manager.api.beans.plans.UpdatePlanBean)2 NewPolicyBean (io.apiman.manager.api.beans.policies.NewPolicyBean)2 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)2 PolicyChainBean (io.apiman.manager.api.beans.policies.PolicyChainBean)2 PolicyType (io.apiman.manager.api.beans.policies.PolicyType)2 UpdatePolicyBean (io.apiman.manager.api.beans.policies.UpdatePolicyBean)2