use of io.apiman.manager.api.core.exceptions.StorageException in project apiman by apiman.
the class EsMarshalling method marshall.
/**
* Marshals the given bean into the given map.
* @param bean the bean
* @return the content builder
* @throws StorageException when a storage problem occurs while storing a bean
*/
public static XContentBuilder marshall(ApiDefinitionBean bean) throws StorageException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
preMarshall(bean);
builder.startObject().field("data", bean.getData()).endObject();
postMarshall(bean);
return builder;
} catch (IOException e) {
throw new StorageException(e);
}
}
use of io.apiman.manager.api.core.exceptions.StorageException in project apiman by apiman.
the class EsMarshalling method marshall.
/**
* Marshals the given bean into the given map.
* @param bean the bean
* @return the content builder
* @throws StorageException when a storage problem occurs while storing a bean
*/
public static XContentBuilder marshall(PlanBean bean) throws StorageException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
preMarshall(bean);
builder.startObject().field("organizationId", bean.getOrganization().getId()).field("organizationName", bean.getOrganization().getName()).field("id", bean.getId()).field("name", bean.getName()).field("description", bean.getDescription()).field("createdBy", bean.getCreatedBy()).field("createdOn", bean.getCreatedOn().getTime()).endObject();
postMarshall(bean);
return builder;
} catch (IOException e) {
throw new StorageException(e);
}
}
use of io.apiman.manager.api.core.exceptions.StorageException in project apiman by apiman.
the class JpaStorage method getUserMemberships.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getUserMemberships(java.lang.String)
*/
@Override
public Set<RoleMembershipBean> getUserMemberships(String userId) throws StorageException {
Set<RoleMembershipBean> memberships = new HashSet<>();
beginTx();
try {
EntityManager entityManager = getActiveEntityManager();
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<RoleMembershipBean> criteriaQuery = builder.createQuery(RoleMembershipBean.class);
Root<RoleMembershipBean> from = criteriaQuery.from(RoleMembershipBean.class);
criteriaQuery.where(builder.equal(from.get("userId"), userId));
TypedQuery<RoleMembershipBean> typedQuery = entityManager.createQuery(criteriaQuery);
List<RoleMembershipBean> resultList = typedQuery.getResultList();
memberships.addAll(resultList);
return memberships;
} catch (Throwable t) {
logger.error(t.getMessage(), t);
throw new StorageException(t);
} finally {
rollbackTx();
}
}
use of io.apiman.manager.api.core.exceptions.StorageException 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();
}
}
use of io.apiman.manager.api.core.exceptions.StorageException 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();
}
}
Aggregations