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();
}
}
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);
}
}
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()));
}
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));
}
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));
}
Aggregations