Search in sources :

Example 1 with ClientBean

use of io.apiman.manager.api.beans.clients.ClientBean 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 2 with ClientBean

use of io.apiman.manager.api.beans.clients.ClientBean 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 3 with ClientBean

use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.

the class EsStorage method deleteClientVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#deleteClientVersion(io.apiman.manager.api.beans.clients.ClientVersionBean)
 */
@Override
public void deleteClientVersion(ClientVersionBean version) throws StorageException {
    ClientBean client = version.getClient();
    deleteEntity(INDEX_MANAGER_POSTFIX_CLIENT_VERSION, id(client.getOrganization().getId(), client.getId(), version.getVersion()));
}
Also used : ClientBean(io.apiman.manager.api.beans.clients.ClientBean)

Example 4 with ClientBean

use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.

the class EsStorage method createClientVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#createClientVersion(io.apiman.manager.api.beans.clients.ClientVersionBean)
 */
@Override
public void createClientVersion(ClientVersionBean version) throws StorageException {
    ClientBean client = version.getClient();
    String id = id(client.getOrganization().getId(), client.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_VERSION, id, EsMarshalling.marshall(version));
    PoliciesBean policies = PoliciesBean.from(PolicyType.Client, client.getOrganization().getId(), client.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_POLICIES, id, EsMarshalling.marshall(policies));
}
Also used : ClientBean(io.apiman.manager.api.beans.clients.ClientBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean)

Example 5 with ClientBean

use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.

the class EsStorage method updateClientVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#updateClientVersion(io.apiman.manager.api.beans.clients.ClientVersionBean)
 */
@Override
public void updateClientVersion(ClientVersionBean version) throws StorageException {
    ClientBean client = version.getClient();
    updateEntity(INDEX_MANAGER_POSTFIX_CLIENT_VERSION, id(client.getOrganization().getId(), client.getId(), version.getVersion()), EsMarshalling.marshall(version));
}
Also used : ClientBean(io.apiman.manager.api.beans.clients.ClientBean)

Aggregations

ClientBean (io.apiman.manager.api.beans.clients.ClientBean)27 NewClientBean (io.apiman.manager.api.beans.clients.NewClientBean)11 UpdateClientBean (io.apiman.manager.api.beans.clients.UpdateClientBean)11 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)10 StorageException (io.apiman.manager.api.core.exceptions.StorageException)10 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)7 NewClientVersionBean (io.apiman.manager.api.beans.clients.NewClientVersionBean)6 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)6 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)6 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)6 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)6 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)6 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)6 InvalidClientStatusException (io.apiman.manager.api.rest.exceptions.InvalidClientStatusException)6 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)6 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)6 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)6 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)6 IOException (java.io.IOException)6 ResponseStatsPerClientBean (io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean)5