Search in sources :

Example 1 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method getOrgs.

/**
 * @see io.apiman.manager.api.core.IStorageQuery#getOrgs(java.util.Set)
 */
@Override
public List<OrganizationSummaryBean> getOrgs(Set<String> orgIds) throws StorageException {
    List<OrganizationSummaryBean> orgs = new ArrayList<>();
    if (orgIds == null || orgIds.isEmpty()) {
        return orgs;
    }
    beginTx();
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT o from OrganizationBean o WHERE o.id IN :orgs ORDER BY o.id ASC";
        Query query = entityManager.createQuery(jpql);
        query.setParameter("orgs", orgIds);
        List<OrganizationBean> qr = query.getResultList();
        for (OrganizationBean bean : qr) {
            OrganizationSummaryBean summary = new OrganizationSummaryBean();
            summary.setId(bean.getId());
            summary.setName(bean.getName());
            summary.setDescription(bean.getDescription());
            orgs.add(summary);
        }
        return orgs;
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        throw new StorageException(t);
    } finally {
        rollbackTx();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 2 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method findPlans.

/**
 * @see io.apiman.manager.api.core.IStorageQuery#findPlans(java.lang.String, io.apiman.manager.api.beans.search.SearchCriteriaBean)
 */
@Override
public SearchResultsBean<PlanSummaryBean> findPlans(String organizationId, SearchCriteriaBean criteria) throws StorageException {
    criteria.addFilter("organization.id", organizationId, SearchCriteriaFilterOperator.eq);
    SearchResultsBean<PlanBean> result = find(criteria, PlanBean.class);
    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 : SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean)

Example 3 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method getClientsInOrgs.

/**
 * @see io.apiman.manager.api.core.IStorageQuery#getClientsInOrgs(java.util.Set)
 */
@Override
public List<ClientSummaryBean> getClientsInOrgs(Set<String> orgIds) throws StorageException {
    List<ClientSummaryBean> rval = new ArrayList<>();
    if (orgIds == null || orgIds.isEmpty()) {
        return rval;
    }
    beginTx();
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT a FROM ClientBean a JOIN a.organization o WHERE o.id IN :orgs ORDER BY a.id ASC";
        Query query = entityManager.createQuery(jpql);
        query.setParameter("orgs", orgIds);
        List<ClientBean> qr = query.getResultList();
        for (ClientBean bean : qr) {
            ClientSummaryBean summary = new ClientSummaryBean();
            summary.setId(bean.getId());
            summary.setName(bean.getName());
            summary.setDescription(bean.getDescription());
            // TODO find the number of contracts - probably need a native SQL query to pull that together
            summary.setNumContracts(0);
            OrganizationBean org = bean.getOrganization();
            summary.setOrganizationId(org.getId());
            summary.setOrganizationName(org.getName());
            rval.add(summary);
        }
        return rval;
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        throw new StorageException(t);
    } finally {
        rollbackTx();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 4 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class OrganizationResourceImpl method createClient.

/**
 * @see IOrganizationResource#createClient(java.lang.String, io.apiman.manager.api.beans.clients.NewClientBean)
 */
@Override
public ClientBean createClient(String organizationId, NewClientBean bean) throws OrganizationNotFoundException, ClientAlreadyExistsException, NotAuthorizedException, InvalidNameException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    FieldValidator.validateName(bean.getName());
    ClientBean newClient = new ClientBean();
    newClient.setId(BeanUtils.idFromName(bean.getName()));
    newClient.setName(bean.getName());
    newClient.setDescription(bean.getDescription());
    newClient.setCreatedBy(securityContext.getCurrentUser());
    newClient.setCreatedOn(new Date());
    try {
        // Store/persist the new client
        storage.beginTx();
        OrganizationBean org = getOrganizationFromStorage(organizationId);
        newClient.setOrganization(org);
        if (storage.getClient(org.getId(), newClient.getId()) != null) {
            throw ExceptionFactory.clientAlreadyExistsException(bean.getName());
        }
        storage.createClient(newClient);
        storage.createAuditEntry(AuditUtils.clientCreated(newClient, securityContext));
        if (bean.getInitialVersion() != null) {
            NewClientVersionBean newClientVersion = new NewClientVersionBean();
            newClientVersion.setVersion(bean.getInitialVersion());
            createClientVersionInternal(newClientVersion, newClient);
        }
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Created client %s: %s", newClient.getName(), newClient));
        return newClient;
    } 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) UpdateClientBean(io.apiman.manager.api.beans.clients.UpdateClientBean) UsagePerClientBean(io.apiman.manager.api.beans.metrics.UsagePerClientBean) ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) NewClientBean(io.apiman.manager.api.beans.clients.NewClientBean) NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) 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) 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 5 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean 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)

Aggregations

OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)49 StorageException (io.apiman.manager.api.core.exceptions.StorageException)20 ContractBean (io.apiman.manager.api.beans.contracts.ContractBean)14 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)13 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)13 NewOrganizationBean (io.apiman.manager.api.beans.orgs.NewOrganizationBean)13 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)13 IOException (java.io.IOException)13 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)12 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)12 UpdateOrganizationBean (io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)12 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)10 Date (java.util.Date)10 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)9 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)9 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)8 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)8 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)8 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)8 EntityManager (javax.persistence.EntityManager)8