use of io.apiman.manager.api.beans.apis.ApiDefinitionBean in project apiman by apiman.
the class JpaStorage method getApiDefinition.
/**
* {@inheritDoc}
*/
@Override
public InputStream getApiDefinition(String apiOrgId, String apiId, String apiVersion) throws StorageException {
try {
EntityManager entityManager = getActiveEntityManager();
String jpql = "SELECT v from ApiDefinitionBean v " + "JOIN v.apiVersion av " + "JOIN av.api api " + "JOIN api.organization org " + "WHERE org.id = :apiOrgId " + "AND api.id = :apiId " + "AND av.version = :apiVersion ";
TypedQuery<ApiDefinitionBean> query = entityManager.createQuery(jpql, ApiDefinitionBean.class).setParameter("apiOrgId", apiOrgId).setParameter("apiId", apiId).setParameter("apiVersion", apiVersion);
ApiDefinitionBean apiDef = query.getSingleResult();
return new ByteArrayInputStream(apiDef.getData());
} catch (NoResultException e) {
return null;
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
throw new StorageException(t);
}
}
use of io.apiman.manager.api.beans.apis.ApiDefinitionBean in project apiman by apiman.
the class JpaStorage method updateApiDefinition.
/**
* {@inheritDoc}
*/
@Override
public void updateApiDefinition(ApiVersionBean version, InputStream definitionStream) throws StorageException {
try {
ApiDefinitionBean bean = super.get(version.getId(), ApiDefinitionBean.class);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(definitionStream, baos);
byte[] data = baos.toByteArray();
if (bean != null) {
bean.setData(data);
super.update(bean);
} else {
bean = new ApiDefinitionBean();
bean.setId(version.getId());
bean.setData(data);
bean.setApiVersion(version);
super.create(bean);
}
} catch (IOException e) {
throw new StorageException(e);
}
}
Aggregations