Пример #1
0
  /**
   * Method to remove the user profile from cache.
   *
   * @param userId
   */
  protected void removeProfileDataFromCache(String userId) throws ProfileServiceException {
    if (logger.isLoggable(Level.FINEST)) {
      logger.entering(sourceClass, "removeProfileDataFromCache", userId);
    }
    if (isEmail(userId)) {
      String key;
      Set<String> keys = lruCache.getKeySet();
      Iterator<String> itr = keys.iterator();
      while (itr.hasNext()) {
        key = itr.next();
        Document data = lruCache.get(key);
        // check if email in profile object is same as input userId
        String email = "";
        try {
          email = DOMUtil.value(data, Profile.xpathMap.get("email"));
        } catch (XMLException e) {
          continue;
        }

        // cache hit
        if (StringUtil.equalsIgnoreCase(email, userId)) {
          lruCache.remove(key);
        }
      }
      // Cache miss

    } else {
      lruCache.remove(userId);
    }
    if (logger.isLoggable(Level.FINEST)) {
      logger.exiting(sourceClass, "removeProfileDataFromCache");
    }
  }
Пример #2
0
 /*
  * Method to search the cache
  *
  * @param userId
  * @return Document
  */
 private Document findInCache(String userId) {
   String key;
   Set<String> keys = lruCache.getKeySet();
   Iterator<String> itr = keys.iterator();
   while (itr.hasNext()) {
     key = itr.next();
     Document data = lruCache.get(key);
     // check if email in profile object is same as input userId
     String email = "";
     try {
       email = DOMUtil.value(data, Profile.xpathMap.get("email"), Profile.nameSpaceCtx);
     } catch (XMLException e) {
       continue;
     }
     // cache hit
     if (StringUtil.equalsIgnoreCase(email, userId)) {
       return data;
     }
   }
   // Cache miss
   return null;
 }
Пример #3
0
  /**
   * This method returns a array of profiles.
   *
   * @param Data
   * @param ProfileService
   * @return Profile[]
   */
  public static Profile[] convertToProfiles(ProfileService ps, Document data) {
    if (logger.isLoggable(Level.FINEST)) {
      logger.entering(sourceClass, "returnProfiles");
    }

    Profile[] profile = null;

    if (data != null) {
      NodeList profileEntries = data.getElementsByTagName("entry");
      profile = new Profile[profileEntries.getLength()];
      if (profileEntries != null && profileEntries.getLength() > 0) {
        for (int i = 0; i < profileEntries.getLength(); i++) {
          Node entry = profileEntries.item(i);
          Document doc;
          try {
            doc = DOMUtil.createDocument();
            Node dup = doc.importNode(entry, true);
            Element root = doc.createElement("feed");
            root.appendChild(dup);
            doc.appendChild(root);
            profile[i] = new Profile(ps, DOMUtil.value(entry, "contributor/snx:userid"));
            profile[i].setData(doc);
          } catch (XMLException e) {
            if (logger.isLoggable(Level.SEVERE)) {
              logger.log(
                  Level.SEVERE,
                  "Error encountered while converting data into contacts profiles",
                  e);
            }
          }
        }
      }
    }
    if (logger.isLoggable(Level.FINEST)) {
      logger.exiting(sourceClass, "returnProfiles");
    }
    return profile;
  }