Search in sources :

Example 1 with SearchCriteriaBean

use of io.apiman.manager.api.beans.search.SearchCriteriaBean in project apiman by apiman.

the class OrganizationResourceImpl method create.

/**
 * @see IOrganizationResource#create(io.apiman.manager.api.beans.orgs.NewOrganizationBean)
 */
@Override
public OrganizationBean create(NewOrganizationBean bean) throws OrganizationAlreadyExistsException, InvalidNameException {
    if (config.isAdminOnlyOrgCreationEnabled()) {
        securityContext.checkAdminPermissions();
    }
    FieldValidator.validateName(bean.getName());
    List<RoleBean> autoGrantedRoles;
    SearchCriteriaBean criteria = new SearchCriteriaBean();
    criteria.setPage(1);
    criteria.setPageSize(100);
    // $NON-NLS-1$ //$NON-NLS-2$
    criteria.addFilter("autoGrant", "true", SearchCriteriaFilterOperator.bool_eq);
    try {
        autoGrantedRoles = query.findRoles(criteria).getBeans();
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
    if ("true".equals(System.getProperty("apiman.manager.require-auto-granted-org", "true"))) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (autoGrantedRoles.isEmpty()) {
            // $NON-NLS-1$
            throw new SystemErrorException(Messages.i18n.format("OrganizationResourceImpl.NoAutoGrantRoleAvailable"));
        }
    }
    OrganizationBean orgBean = new OrganizationBean();
    orgBean.setName(bean.getName());
    orgBean.setDescription(bean.getDescription());
    orgBean.setId(BeanUtils.idFromName(bean.getName()));
    orgBean.setCreatedOn(new Date());
    orgBean.setCreatedBy(securityContext.getCurrentUser());
    orgBean.setModifiedOn(new Date());
    orgBean.setModifiedBy(securityContext.getCurrentUser());
    try {
        // Store/persist the new organization
        storage.beginTx();
        if (storage.getOrganization(orgBean.getId()) != null) {
            throw ExceptionFactory.organizationAlreadyExistsException(bean.getName());
        }
        storage.createOrganization(orgBean);
        storage.createAuditEntry(AuditUtils.organizationCreated(orgBean, securityContext));
        // Auto-grant memberships in roles to the creator of the organization
        for (RoleBean roleBean : autoGrantedRoles) {
            String currentUser = securityContext.getCurrentUser();
            String orgId = orgBean.getId();
            RoleMembershipBean membership = RoleMembershipBean.create(currentUser, roleBean.getId(), orgId);
            membership.setCreatedOn(new Date());
            storage.createMembership(membership);
        }
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Created organization %s: %s", orgBean.getName(), orgBean));
        return orgBean;
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) 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) StorageException(io.apiman.manager.api.core.exceptions.StorageException) Date(java.util.Date) 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 2 with SearchCriteriaBean

use of io.apiman.manager.api.beans.search.SearchCriteriaBean in project apiman by apiman.

the class RoleResourceImpl method list.

/**
 * @see IRoleResource#list()
 */
@Override
public List<RoleBean> list() {
    // No permission check needed
    try {
        SearchCriteriaBean criteria = new SearchCriteriaBean();
        // $NON-NLS-1$
        criteria.setOrder("name", true);
        // Hide sensitive data and set only needed data for the UI
        if (securityContext.isAdmin()) {
            return query.findRoles(criteria).getBeans();
        } else {
            List<RoleBean> roles = new ArrayList<>();
            for (RoleBean role : query.findRoles(criteria).getBeans()) {
                roles.add(RestHelper.hideSensitiveDataFromRoleBean(securityContext, role));
            }
            return roles;
        }
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) NewRoleBean(io.apiman.manager.api.beans.idm.NewRoleBean) UpdateRoleBean(io.apiman.manager.api.beans.idm.UpdateRoleBean) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) ArrayList(java.util.ArrayList) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 3 with SearchCriteriaBean

use of io.apiman.manager.api.beans.search.SearchCriteriaBean in project apiman by apiman.

the class JpaStorage method findOrganizations.

/**
 * {@inheritDoc}
 */
@Override
public SearchResultsBean<OrganizationSummaryBean> findOrganizations(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
    Consumer<CriteriaBuilder<OrganizationBean>> constraintFunc = builder -> {
    };
    if (permissionConstraint.isConstrained()) {
        // With constraint, first allow the user's explicitly permitted orgs, plus orgs with discoverable APIs.
        constraintFunc = (builder) -> builder.whereOr().where(OrganizationBean_.ID).in(permissionConstraint.getPermittedOrgs()).where("org.id").in().from(DiscoverabilityEntity.class, "d").select("d.orgId").where("d.discoverability").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
    }
    SearchResultsBean<OrganizationBean> orgs = find(criteria, List.of(new OrderByBean(true, OrganizationBean_.ID)), constraintFunc, OrganizationBean.class, "org", true);
    SearchResultsBean<OrganizationSummaryBean> rval = new SearchResultsBean<>();
    rval.setTotalSize(orgs.getTotalSize());
    List<OrganizationBean> beans = orgs.getBeans();
    for (OrganizationBean bean : beans) {
        OrganizationSummaryBean osb = new OrganizationSummaryBean();
        osb.setId(bean.getId());
        osb.setName(bean.getName());
        osb.setDescription(bean.getDescription());
        rval.getBeans().add(osb);
    }
    return rval;
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) RoleBean_(io.apiman.manager.api.beans.idm.RoleBean_) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) NoResultException(javax.persistence.NoResultException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) ApiDefinitionBean(io.apiman.manager.api.beans.apis.ApiDefinitionBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) DeveloperBean(io.apiman.manager.api.beans.developers.DeveloperBean) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) DiscoverabilityEntity(io.apiman.manager.api.beans.idm.DiscoverabilityEntity) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) GatewayType(io.apiman.manager.api.beans.gateways.GatewayType) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) Transactional(javax.transaction.Transactional) Set(java.util.Set) UserBean_(io.apiman.manager.api.beans.idm.UserBean_) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) PluginSummaryBean(io.apiman.manager.api.beans.summary.PluginSummaryBean) Collectors(java.util.stream.Collectors) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Query(javax.persistence.Query) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) OrganizationBean_(io.apiman.manager.api.beans.orgs.OrganizationBean_) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PostConstruct(javax.annotation.PostConstruct) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClientBean_(io.apiman.manager.api.beans.clients.ClientBean_) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Alternative(javax.enterprise.inject.Alternative) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) TypedQuery(javax.persistence.TypedQuery) AuditEntryBean_(io.apiman.manager.api.beans.audit.AuditEntryBean_) ArrayList(java.util.ArrayList) AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanBean_(io.apiman.manager.api.beans.plans.PlanBean_) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) MetadataBean(io.apiman.manager.api.beans.system.MetadataBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) Iterator(java.util.Iterator) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) ApiMapper(io.apiman.manager.api.beans.summary.mappers.ApiMapper) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) PolicyBean_(io.apiman.manager.api.beans.policies.PolicyBean_) Consumer(java.util.function.Consumer) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) Collections(java.util.Collections) InputStream(java.io.InputStream) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean)

Example 4 with SearchCriteriaBean

use of io.apiman.manager.api.beans.search.SearchCriteriaBean in project apiman by apiman.

the class JpaStorage method findPlans.

/**
 * {@inheritDoc}
 */
@Override
public SearchResultsBean<PlanSummaryBean> findPlans(String organizationId, SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
    Consumer<CriteriaBuilder<PlanBean>> constraintFunc = builder -> {
    };
    if (permissionConstraint.isConstrained()) {
        constraintFunc = builder -> builder.whereOr().where("plan.organization.id").in(permissionConstraint.getPermittedOrgs()).where("plan.id").in().from(DiscoverabilityEntity.class, "d").select("d.planId").where("d.orgId").eq(organizationId).where("d.planId").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
    }
    SearchResultsBean<PlanBean> result = find(criteria, List.of(new OrderByBean(true, PlanBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, PlanBean.class, "plan", true);
    // TODO(msavy): replace with projection or mapping
    SearchResultsBean<PlanSummaryBean> rval = new SearchResultsBean<>();
    rval.setTotalSize(result.getTotalSize());
    List<PlanBean> plans = result.getBeans();
    rval.setBeans(new ArrayList<>(plans.size()));
    for (PlanBean plan : plans) {
        PlanSummaryBean summary = new PlanSummaryBean();
        OrganizationBean organization = plan.getOrganization();
        summary.setId(plan.getId());
        summary.setName(plan.getName());
        summary.setDescription(plan.getDescription());
        summary.setOrganizationId(plan.getOrganization().getId());
        summary.setOrganizationName(organization.getName());
        rval.getBeans().add(summary);
    }
    return rval;
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) RoleBean_(io.apiman.manager.api.beans.idm.RoleBean_) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) NoResultException(javax.persistence.NoResultException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) ApiDefinitionBean(io.apiman.manager.api.beans.apis.ApiDefinitionBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) DeveloperBean(io.apiman.manager.api.beans.developers.DeveloperBean) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) DiscoverabilityEntity(io.apiman.manager.api.beans.idm.DiscoverabilityEntity) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) GatewayType(io.apiman.manager.api.beans.gateways.GatewayType) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) Transactional(javax.transaction.Transactional) Set(java.util.Set) UserBean_(io.apiman.manager.api.beans.idm.UserBean_) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) PluginSummaryBean(io.apiman.manager.api.beans.summary.PluginSummaryBean) Collectors(java.util.stream.Collectors) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Query(javax.persistence.Query) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) OrganizationBean_(io.apiman.manager.api.beans.orgs.OrganizationBean_) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PostConstruct(javax.annotation.PostConstruct) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClientBean_(io.apiman.manager.api.beans.clients.ClientBean_) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Alternative(javax.enterprise.inject.Alternative) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) TypedQuery(javax.persistence.TypedQuery) AuditEntryBean_(io.apiman.manager.api.beans.audit.AuditEntryBean_) ArrayList(java.util.ArrayList) AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanBean_(io.apiman.manager.api.beans.plans.PlanBean_) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) MetadataBean(io.apiman.manager.api.beans.system.MetadataBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) Iterator(java.util.Iterator) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) ApiMapper(io.apiman.manager.api.beans.summary.mappers.ApiMapper) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) PolicyBean_(io.apiman.manager.api.beans.policies.PolicyBean_) Consumer(java.util.function.Consumer) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) Collections(java.util.Collections) InputStream(java.io.InputStream) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean)

Example 5 with SearchCriteriaBean

use of io.apiman.manager.api.beans.search.SearchCriteriaBean in project apiman by apiman.

the class JpaStorage method auditEntity.

/**
 * {@inheritDoc}
 */
@Override
public <T> SearchResultsBean<AuditEntryBean> auditEntity(String organizationId, String entityId, String entityVersion, Class<T> type, PagingBean paging) throws StorageException {
    SearchCriteriaBean criteria = new SearchCriteriaBean();
    if (paging != null) {
        criteria.setPaging(paging);
    } else {
        criteria.setPage(1);
        criteria.setPageSize(20);
    }
    criteria.setOrder("id", false);
    if (organizationId != null) {
        criteria.addFilter("organizationId", organizationId, SearchCriteriaFilterOperator.eq);
    }
    if (entityId != null) {
        criteria.addFilter("entityId", entityId, SearchCriteriaFilterOperator.eq);
    }
    if (entityVersion != null) {
        criteria.addFilter("entityVersion", entityVersion, SearchCriteriaFilterOperator.eq);
    }
    if (type != null) {
        AuditEntityType entityType = null;
        if (type == OrganizationBean.class) {
            entityType = AuditEntityType.Organization;
        } else if (type == ClientBean.class) {
            entityType = AuditEntityType.Client;
        } else if (type == ApiBean.class) {
            entityType = AuditEntityType.Api;
        } else if (type == PlanBean.class) {
            entityType = AuditEntityType.Plan;
        }
        if (entityType != null) {
            criteria.addFilter("entityType", entityType.name(), SearchCriteriaFilterOperator.eq);
        }
    }
    return find(criteria, List.of(new OrderByBean(true, AuditEntryBean_.ID)), AuditEntryBean.class, true);
}
Also used : AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean)

Aggregations

SearchCriteriaBean (io.apiman.manager.api.beans.search.SearchCriteriaBean)12 OrderByBean (io.apiman.manager.api.beans.search.OrderByBean)7 RoleBean (io.apiman.manager.api.beans.idm.RoleBean)6 StorageException (io.apiman.manager.api.core.exceptions.StorageException)6 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)5 AuditEntityType (io.apiman.manager.api.beans.audit.AuditEntityType)5 AuditEntryBean (io.apiman.manager.api.beans.audit.AuditEntryBean)5 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)5 RoleMembershipBean (io.apiman.manager.api.beans.idm.RoleMembershipBean)5 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)5 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)3 DeleteCriteriaBuilder (com.blazebit.persistence.DeleteCriteriaBuilder)3 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)3 IApimanLogger (io.apiman.common.logging.IApimanLogger)3 DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)3 IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)3 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)3