Exemplo n.º 1
0
  /**
   * Permanently removes locally stored message history for the metacontact, remove any recent
   * contacts if any.
   */
  public void eraseLocallyStoredHistory(MetaContact contact) throws IOException {
    List<ComparableEvtObj> toRemove = null;
    synchronized (recentMessages) {
      toRemove = new ArrayList<ComparableEvtObj>();
      Iterator<Contact> iter = contact.getContacts();
      while (iter.hasNext()) {
        Contact item = iter.next();
        String id = item.getAddress();
        ProtocolProviderService provider = item.getProtocolProvider();

        for (ComparableEvtObj msc : recentMessages) {
          if (msc.getProtocolProviderService().equals(provider)
              && msc.getContactAddress().equals(id)) {
            toRemove.add(msc);
          }
        }
      }

      recentMessages.removeAll(toRemove);
    }
    if (recentQuery != null) {
      for (ComparableEvtObj msc : toRemove) {
        recentQuery.fireContactRemoved(msc);
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Searches for contact ids in history of recent messages.
   *
   * @param provider
   * @param after
   * @return
   */
  List<String> getRecentContactIDs(String provider, Date after) {
    List<String> res = new ArrayList<String>();

    try {
      History history = getHistory();

      if (history != null) {
        Iterator<HistoryRecord> recs = history.getReader().findLast(NUMBER_OF_MSGS_IN_HISTORY);
        SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);

        while (recs.hasNext()) {
          HistoryRecord hr = recs.next();

          String contact = null;
          String recordProvider = null;
          Date timestamp = null;

          for (int i = 0; i < hr.getPropertyNames().length; i++) {
            String propName = hr.getPropertyNames()[i];

            if (propName.equals(STRUCTURE_NAMES[0])) recordProvider = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[1])) contact = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[2])) {
              try {
                timestamp = sdf.parse(hr.getPropertyValues()[i]);
              } catch (ParseException e) {
                timestamp = new Date(Long.parseLong(hr.getPropertyValues()[i]));
              }
            }
          }

          if (recordProvider == null || contact == null) continue;

          if (after != null && timestamp != null && timestamp.before(after)) continue;

          if (recordProvider.equals(provider)) res.add(contact);
        }
      }
    } catch (IOException ex) {
      logger.error("cannot create recent_messages history", ex);
    }

    return res;
  }
Exemplo n.º 3
0
  public void testCreateDB() {
    ArrayList<String> al = new ArrayList<String>();

    Iterator<HistoryID> i = this.historyService.getExistingIDs();
    while (i.hasNext()) {
      HistoryID id = i.next();
      String[] components = id.getID();

      if (components.length == 2 && "test".equals(components[0])) {
        al.add(components[1]);
      }
    }

    int count = al.size();
    boolean unique = false;
    String lastComp = null;
    while (!unique) {
      lastComp = Integer.toHexString(random.nextInt());
      for (int j = 0; j < count; j++) {
        if (lastComp.equals(al.get(j))) {
          continue;
        }
      }
      unique = true;
    }

    HistoryID id = HistoryID.createFromRawID(new String[] {"test", lastComp});

    try {
      this.historyService.createHistory(id, recordStructure);
    } catch (Exception e) {
      fail("Could not create database with id " + id + " with error " + e);
    }

    try {
      // after creating, remove it - do not leave content
      this.historyService.purgeLocallyStoredHistory(id);
    } catch (Exception ex) {
      fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
    }
  }