docs: protected ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version,
              boolean hasPermission) throws ClientNotFoundException, NotAuthorizedException {
          // Try to get the client first - will throw a ClientNotFoundException if not found.
          ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version, hasPermission);
  
          Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
          Map<String, GatewayBean> gateways = new HashMap<>();
          boolean txStarted = false;
          try {
              ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
  
              // Hide some stuff if the user doesn't have the clientView permission
              if (hasPermission) {
                  apiRegistry.setApiKey(clientVersion.getApikey());
              }
  
              List<ApiEntryBean> apis = apiRegistry.getApis();
  
              storage.beginTx();
              txStarted = true;
              for (ApiEntryBean api : apis) {
                  String gatewayId = api.getGatewayId();
                  // Don't return the gateway id.
                  api.setGatewayId(null);
                  GatewayBean gateway = gateways.get(gatewayId);
                  if (gateway == null) {
                      gateway = storage.getGateway(gatewayId);
                      gateways.put(gatewayId, gateway);
                  }
                  IGatewayLink link = gatewayLinks.get(gatewayId);
                  if (link == null) {
                      link = gatewayLinkFactory.create(gateway);
                      gatewayLinks.put(gatewayId, link);
                  }
  
                  ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
                  String apiEndpoint = se.getEndpoint();
                  api.setHttpEndpoint(apiEndpoint);
              }
  
              return apiRegistry;
          } catch (StorageException|GatewayAuthenticationException e) {
              throw new SystemErrorException(e);
          } finally {
              if (txStarted) {
                  storage.rollbackTx();
              }
              for (IGatewayLink link : gatewayLinks.values()) {
                  link.close();
              }
          }
      }