docs: protected PolicyBean doCreatePolicy(String organizationId, String entityId, String entityVersion,
              NewPolicyBean bean, PolicyType type) throws PolicyDefinitionNotFoundException {
          if (bean.getDefinitionId() == null) {
              throw ExceptionFactory.policyDefNotFoundException("null"); //$NON-NLS-1$
          }
          PolicyDefinitionBean def;
          try {
              storage.beginTx();
              def = storage.getPolicyDefinition(bean.getDefinitionId());
              if (def == null) {
                  throw ExceptionFactory.policyDefNotFoundException(bean.getDefinitionId());
              }
              storage.rollbackTx();
          } catch (AbstractRestException e) {
              throw e;
          } catch (Exception e) {
              throw new SystemErrorException(e);
          }
  
          int newIdx;
          try {
              newIdx = query.getMaxPolicyOrderIndex(organizationId, entityId, entityVersion, type) + 1;
          } catch (StorageException e) {
              throw new SystemErrorException(e);
          }
  
          try {
              PolicyBean policy = new PolicyBean();
              policy.setId(null);
              policy.setDefinition(def);
              policy.setName(def.getName());
              policy.setConfiguration(bean.getConfiguration());
              policy.setCreatedBy(securityContext.getCurrentUser());
              policy.setCreatedOn(new Date());
              policy.setModifiedBy(securityContext.getCurrentUser());
              policy.setModifiedOn(new Date());
              policy.setOrganizationId(organizationId);
              policy.setEntityId(entityId);
              policy.setEntityVersion(entityVersion);
              policy.setType(type);
              policy.setOrderIndex(newIdx);
  
              storage.beginTx();
  
              if (type == PolicyType.Client) {
                  ClientVersionBean cvb = storage.getClientVersion(organizationId, entityId, entityVersion);
                  cvb.setModifiedBy(securityContext.getCurrentUser());
                  cvb.setModifiedOn(new Date());
                  storage.updateClientVersion(cvb);
              } else if (type == PolicyType.Api) {
                  ApiVersionBean avb = storage.getApiVersion(organizationId, entityId, entityVersion);
                  avb.setModifiedBy(securityContext.getCurrentUser());
                  avb.setModifiedOn(new Date());
                  storage.updateApiVersion(avb);
              } else if (type == PolicyType.Plan) {
                  PlanVersionBean pvb = storage.getPlanVersion(organizationId, entityId, entityVersion);
                  pvb.setModifiedBy(securityContext.getCurrentUser());
                  pvb.setModifiedOn(new Date());
                  storage.updatePlanVersion(pvb);
              }
  
              storage.createPolicy(policy);
              storage.createAuditEntry(AuditUtils.policyAdded(policy, type, securityContext));
              storage.commitTx();
  
              PolicyTemplateUtil.generatePolicyDescription(policy);
  
              log.debug(String.format("Created client policy: %s", policy)); //$NON-NLS-1$
              return policy;
          } catch (AbstractRestException e) {
              storage.rollbackTx();
              throw e;
          } catch (Exception e) {
              storage.rollbackTx();
              throw new SystemErrorException(e);
          }
      }