/**
   * Verifies what we were doing to the current bundle, it was received for this server?, or this
   * server is trying to send it...., we don't want to retry bundles we received.
   *
   * @param request
   * @param config
   * @return
   */
  private Boolean sendingBundle(
      HttpServletRequest request, PushPublisherConfig config, String bundleId)
      throws DotDataException {

    // Get the local address
    String remoteIP = request.getRemoteHost();
    int port = request.getLocalPort();
    if (!UtilMethods.isSet(remoteIP)) {
      remoteIP = request.getRemoteAddr();
    }

    /*
    Getting the bundle end points in order to compare if this current server it is an end point or not.
    If it is is because we received this bundle as we were a targeted end point server.
    */

    List<Environment> environments =
        APILocator.getEnvironmentAPI().findEnvironmentsByBundleId(bundleId);

    for (Environment environment : environments) {

      List<PublishingEndPoint> endPoints =
          APILocator.getPublisherEndPointAPI()
              .findSendingEndPointsByEnvironment(environment.getId());
      for (PublishingEndPoint endPoint : endPoints) {

        // Getting the end point details
        String endPointAddress = endPoint.getAddress();
        String endPointPort = endPoint.getPort();

        if (endPointAddress.equals(remoteIP) && endPointPort.equals(String.valueOf(port))) {
          return false;
        }
      }
    }

    return true;
  }
  /** Returns the list of ids the user is trying to remote publish. */
  private List<String> getIdsToPush(
      List<String> assetIds, String _contentFilterDate, SimpleDateFormat dateFormat)
      throws ParseException, DotDataException {

    List<String> ids = new ArrayList<String>();

    for (String _assetId : assetIds) {

      if (_assetId != null && !_assetId.trim().isEmpty()) {

        if (ids.contains(_assetId)) {
          continue;
        }

        // check for the categories
        if (_assetId.contains("user_") || _assetId.contains("users_")) { // Trying to publish users
          // If we are trying to push users a filter date must be available
          if (_assetId.contains("users_")) {
            Date filteringDate = dateFormat.parse(_contentFilterDate);
            // Get users where createdate >= ?
            List<String> usersIds =
                APILocator.getUserAPI().getUsersIdsByCreationDate(filteringDate, 0, -1);
            if (usersIds != null) {
              for (String id : usersIds) {
                ids.add("user_" + id);
              }
            }
          } else {
            ids.add(_assetId);
          }
        } else if (_assetId.equals("CAT")) {
          ids.add(_assetId);
        } else if (_assetId.contains(".jar")) { // Check for OSGI jar bundles
          ids.add(_assetId);
        } else {
          // if the asset is a folder put the inode instead of the identifier
          try {
            Folder folder = null;
            try {
              folder = APILocator.getFolderAPI().find(_assetId, getUser(), false);
            } catch (DotSecurityException e) {
              Logger.error(
                  getClass(),
                  "User: "******" does not have permission to access folder. Folder identifier: "
                      + _assetId);
            } catch (DotDataException e) {
              Logger.info(getClass(), "FolderAPI.find(): Identifier is null");
            }

            if (folder != null && UtilMethods.isSet(folder.getInode())) {
              ids.add(_assetId);
            } else {
              // if the asset is not a folder and has identifier, put it, if not, put the inode
              Identifier iden = APILocator.getIdentifierAPI().findFromInode(_assetId);
              if (!ids.contains(iden.getId())) { // Multiples languages have the same identifier
                ids.add(iden.getId());
              }
            }

          } catch (DotStateException e) {
            ids.add(_assetId);
          }
        }
      }
    }

    return ids;
  }