@Override
    public List<PolicySummaryBean> getPolicies(String organizationId, String entityId, String version,
            PolicyType type) throws StorageException {
        beginTx();
        try {
            EntityManager entityManager = getActiveEntityManager();
            String jpql =
                      "SELECT p from PolicyBean p "
                    + " WHERE p.organizationId = :orgId "
                    + "   AND p.entityId = :entityId "
                    + "   AND p.entityVersion = :entityVersion "
                    + "   AND p.type = :type"
                    + " ORDER BY p.orderIndex ASC";
            Query query = entityManager.createQuery(jpql);
            query.setParameter("orgId", organizationId);
            query.setParameter("entityId", entityId);
            query.setParameter("entityVersion", version);
            query.setParameter("type", type);

            List<PolicyBean> policyBeans = query.getResultList();
            List<PolicySummaryBean> rval = new ArrayList<>(policyBeans.size());
            for (PolicyBean policyBean : policyBeans) {
                PolicyTemplateUtil.generatePolicyDescription(policyBean);
                PolicySummaryBean psb = new PolicySummaryBean();
                psb.setId(policyBean.getId());
                psb.setName(policyBean.getName());
                psb.setDescription(policyBean.getDescription());
                psb.setPolicyDefinitionId(policyBean.getDefinition().getId());
                psb.setIcon(policyBean.getDefinition().getIcon());
                psb.setCreatedBy(policyBean.getCreatedBy());
                psb.setCreatedOn(policyBean.getCreatedOn());
                rval.add(psb);
            }
            return rval;
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
            throw new StorageException(t);
        } finally {
            rollbackTx();
        }
    }
@ Override public List < PolicySummaryBean > getPolicies ( String organizationId , String entityId , String version , PolicyType type ) throws StorageException { beginTx ( ) ; try { EntityManager entityManager = getActiveEntityManager ( ) ; String jpql = "SELECT p from PolicyBean p " + " WHERE p.organizationId = :orgId " + "   AND p.entityId = :entityId " + "   AND p.entityVersion = :entityVersion " + "   AND p.type = :type" + " ORDER BY p.orderIndex ASC" ; Query query = entityManager . createQuery ( jpql ) ; query . setParameter ( "orgId" , organizationId ) ; query . setParameter ( "entityId" , entityId ) ; query . setParameter ( "entityVersion" , version ) ; query . setParameter ( "type" , type ) ; List < PolicyBean > policyBeans = query . getResultList ( ) ; List < PolicySummaryBean > rval = new ArrayList < > ( policyBeans . size ( ) ) ; for ( PolicyBean policyBean : policyBeans ) { PolicyTemplateUtil . generatePolicyDescription ( policyBean ) ; PolicySummaryBean psb = new PolicySummaryBean ( ) ; psb . setId ( policyBean . getId ( ) ) ; psb . setName ( policyBean . getName ( ) ) ; psb . setDescription ( policyBean . getDescription ( ) ) ; psb . setPolicyDefinitionId ( policyBean . getDefinition ( ) . getId ( ) ) ; psb . setIcon ( policyBean . getDefinition ( ) . getIcon ( ) ) ; psb . setCreatedBy ( policyBean . getCreatedBy ( ) ) ; psb . setCreatedOn ( policyBean . getCreatedOn ( ) ) ; rval . add ( psb ) ; } return rval ; } catch ( Throwable t ) { logger . error ( t . getMessage ( ) , t ) ; throw new StorageException ( t ) ; } finally { rollbackTx ( ) ; } }
@see io.apiman.manager.api.core.IStorageQuery#getPolicies(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.PolicyType)