use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class ClientAppService method deleteClient.
public void deleteClient(String organizationId, String clientId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
tryAction(() -> {
ClientBean client = getClientFromStorage(organizationId, clientId);
Iterator<ClientVersionBean> clientVersions = storage.getAllClientVersions(organizationId, clientId);
Iterable<ClientVersionBean> iterable = () -> clientVersions;
List<ClientVersionBean> registeredElems = StreamSupport.stream(iterable.spliterator(), false).filter(clientVersion -> clientVersion.getStatus() == ClientStatus.Registered).limit(5).collect(toList());
if (!registeredElems.isEmpty()) {
throw ExceptionFactory.entityStillActiveExceptionClientVersions(registeredElems);
}
storage.deleteClient(client);
if (client.getImage() != null) {
blobstore.remove(client.getImage());
}
// $NON-NLS-1$
LOGGER.debug("Deleted ClientApp: {0}", client.getName());
});
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class ClientAppService method fireClientStatusChangeEvent.
// TODO: make private at some point
public void fireClientStatusChangeEvent(ClientVersionBean cvb, ClientStatus oldStatus) {
if (oldStatus == cvb.getStatus()) {
LOGGER.debug("Old status and new status same {0} => {1}", cvb.getId(), cvb.getStatus());
return;
}
ClientBean cb = cvb.getClient();
ApimanEventHeaders headers = ApimanEventHeaders.builder().setId(UUID.randomUUID().toString().substring(8)).setSource(URI.create("/apiman/events/clients")).setSubject("status.change").build();
var event = ClientVersionStatusEvent.builder().setHeaders(headers).setClientOrgId(cb.getOrganization().getId()).setClientId(cvb.getClient().getId()).setClientVersion(cvb.getVersion()).setPreviousStatus(oldStatus).setNewStatus(cvb.getStatus()).build();
eventService.fireEvent(event);
LOGGER.debug("Sending client status change event: {0}");
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class JpaStorage method getContracts.
/**
* {@inheritDoc}
*/
@Override
public List<ContractSummaryBean> getContracts(String organizationId, String apiId, String version, int page, int pageSize) throws StorageException {
int start = (page - 1) * pageSize;
try {
EntityManager entityManager = getActiveEntityManager();
String jpql = "SELECT c from ContractBean c " + " JOIN c.api apiv " + " JOIN apiv.api api " + " JOIN c.client clientv " + " JOIN clientv.client client " + " JOIN api.organization sorg" + " JOIN client.organization aorg" + " WHERE api.id = :apiId " + " AND sorg.id = :orgId " + " AND apiv.version = :version " + " ORDER BY sorg.id, api.id ASC";
Query query = entityManager.createQuery(jpql);
query.setParameter("orgId", organizationId);
query.setParameter("apiId", apiId);
query.setParameter("version", version);
query.setFirstResult(start);
query.setMaxResults(pageSize);
List<ContractBean> contracts = query.getResultList();
List<ContractSummaryBean> rval = new ArrayList<>(contracts.size());
for (ContractBean contractBean : contracts) {
ClientBean client = contractBean.getClient().getClient();
ApiBean api = contractBean.getApi().getApi();
PlanBean plan = contractBean.getPlan().getPlan();
OrganizationBean clientOrg = entityManager.find(OrganizationBean.class, client.getOrganization().getId());
OrganizationBean apiOrg = entityManager.find(OrganizationBean.class, api.getOrganization().getId());
ContractSummaryBean csb = new ContractSummaryBean();
csb.setStatus(contractBean.getStatus());
csb.setClientId(client.getId());
csb.setClientOrganizationId(client.getOrganization().getId());
csb.setClientOrganizationName(clientOrg.getName());
csb.setClientName(client.getName());
csb.setClientVersion(contractBean.getClient().getVersion());
csb.setContractId(contractBean.getId());
csb.setCreatedOn(contractBean.getCreatedOn());
csb.setPlanId(plan.getId());
csb.setPlanName(plan.getName());
csb.setPlanVersion(contractBean.getPlan().getVersion());
csb.setApiDescription(api.getDescription());
csb.setApiId(api.getId());
csb.setApiName(api.getName());
csb.setApiOrganizationId(apiOrg.getId());
csb.setApiOrganizationName(apiOrg.getName());
csb.setApiVersion(contractBean.getApi().getVersion());
rval.add(csb);
}
return rval;
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
throw new StorageException(t);
}
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class JpaStorage method findClients.
/**
* {@inheritDoc}
*/
@Override
public SearchResultsBean<ClientSummaryBean> findClients(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
// If unconstrained, do nothing.
Consumer<CriteriaBuilder<ClientBean>> constraintFunc = builder -> {
};
if (permissionConstraint.isConstrained()) {
constraintFunc = (builder) -> builder.where("organization.id").in(permissionConstraint.getPermittedOrgs());
}
SearchResultsBean<ClientBean> result = find(criteria, List.of(new OrderByBean(true, ClientBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, ClientBean.class, "client", true);
SearchResultsBean<ClientSummaryBean> rval = new SearchResultsBean<>();
rval.setTotalSize(result.getTotalSize());
List<ClientBean> beans = result.getBeans();
rval.setBeans(new ArrayList<>(beans.size()));
for (ClientBean client : beans) {
ClientSummaryBean summary = new ClientSummaryBean();
OrganizationBean organization = client.getOrganization();
summary.setId(client.getId());
summary.setName(client.getName());
summary.setDescription(client.getDescription());
summary.setImage(client.getImage());
// TODO find the number of contracts - probably need native SQL for that
summary.setNumContracts(0);
summary.setOrganizationId(client.getOrganization().getId());
summary.setOrganizationName(organization.getName());
rval.getBeans().add(summary);
}
return rval;
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class StorageImportDispatcher method clientContract.
/**
* @see io.apiman.manager.api.exportimport.read.IImportReaderDispatcher#clientContract(io.apiman.manager.api.beans.contracts.ContractBean)
*/
@Override
public void clientContract(ContractBean contract) {
ClientVersionBean clientVersion = new ClientVersionBean();
clientVersion.setClient(new ClientBean());
clientVersion.getClient().setOrganization(new OrganizationBean());
clientVersion.getClient().setId(currentClient.getId());
clientVersion.getClient().getOrganization().setId(currentOrg.getId());
clientVersion.setVersion(currentClientVersion.getVersion());
contract.setClient(clientVersion);
contracts.add(contract);
}
Aggregations