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