private PersonFavourite addFavouriteSite(String userName, NodeRef nodeRef) {
    PersonFavourite favourite = null;

    SiteInfo siteInfo = siteService.getSite(nodeRef);
    if (siteInfo != null) {
      favourite = getFavouriteSite(userName, siteInfo);
      if (favourite == null) {
        Map<String, Serializable> preferences = new HashMap<String, Serializable>(1);

        String siteFavouritedKey = siteFavouritedKey(siteInfo);
        preferences.put(siteFavouritedKey, Boolean.TRUE);

        // ISO8601 string format: PreferenceService works with strings only for dates it seems
        String siteCreatedAtKey = siteCreatedAtKey(siteInfo);
        Date createdAt = new Date();
        String createdAtStr = ISO8601DateFormat.format(createdAt);
        preferences.put(siteCreatedAtKey, createdAtStr);

        preferenceService.setPreferences(userName, preferences);

        favourite =
            new PersonFavourite(
                userName, siteInfo.getNodeRef(), Type.SITE, siteInfo.getTitle(), createdAt);

        QName nodeClass = nodeService.getType(nodeRef);
        OnAddFavouritePolicy policy = onAddFavouriteDelegate.get(nodeRef, nodeClass);
        policy.onAddFavourite(userName, nodeRef);
      }
    } else {
      // shouldn't happen, getType recognizes it as a site or subtype
      logger.warn("Unable to get site for " + nodeRef);
    }

    return favourite;
  }
  private PersonFavourite getFavouriteSite(String userName, SiteInfo siteInfo) {
    PersonFavourite favourite = null;

    String siteFavouritedKey = siteFavouritedKey(siteInfo);
    String siteCreatedAtKey = siteCreatedAtKey(siteInfo);

    Boolean isFavourited = false;
    Serializable s = preferenceService.getPreference(userName, siteFavouritedKey);
    if (s != null) {
      if (s instanceof String) {
        isFavourited = Boolean.valueOf((String) s);
      } else if (s instanceof Boolean) {
        isFavourited = (Boolean) s;
      } else {
        throw new AlfrescoRuntimeException("Unexpected favourites preference value");
      }
    }

    if (isFavourited) {
      String createdAtStr = (String) preferenceService.getPreference(userName, siteCreatedAtKey);
      Date createdAt = (createdAtStr == null ? null : ISO8601DateFormat.parse(createdAtStr));

      favourite =
          new PersonFavourite(
              userName, siteInfo.getNodeRef(), Type.SITE, siteInfo.getTitle(), createdAt);
    }

    return favourite;
  }
Exemple #3
0
  @Override
  protected void tearDown() throws Exception {
    super.tearDown();

    // admin user required to delete user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_WIKI);
    if (siteInfo != null) {
      // delete the site
      siteService.deleteSite(SITE_SHORT_NAME_WIKI);
      nodeArchiveService.purgeArchivedNode(
          nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
    }

    // delete the users
    if (personService.personExists(USER_ONE)) {
      personService.deletePerson(USER_ONE);
    }
    if (this.authenticationService.authenticationExists(USER_ONE)) {
      this.authenticationService.deleteAuthentication(USER_ONE);
    }

    if (personService.personExists(USER_TWO)) {
      personService.deletePerson(USER_TWO);
    }
    if (this.authenticationService.authenticationExists(USER_TWO)) {
      this.authenticationService.deleteAuthentication(USER_TWO);
    }
  }
  private void extractFavouriteSite(
      String userName,
      Type type,
      Map<PersonFavouriteKey, PersonFavourite> sortedFavouriteNodes,
      Map<String, Serializable> preferences,
      String key) {
    // preference value indicates whether the site has been favourited
    Serializable pref = preferences.get(key);
    Boolean isFavourite = (Boolean) pref;
    if (isFavourite) {
      PrefKeys sitePrefKeys = getPrefKeys(Type.SITE);
      int length = sitePrefKeys.getSharePrefKey().length();
      String siteId = key.substring(length);

      try {
        SiteInfo siteInfo = siteService.getSite(siteId);
        if (siteInfo != null) {
          StringBuilder builder = new StringBuilder(sitePrefKeys.getAlfrescoPrefKey());
          builder.append(siteId);
          builder.append(".createdAt");
          String createdAtPrefKey = builder.toString();
          String createdAtStr = (String) preferences.get(createdAtPrefKey);
          Date createdAt = null;
          if (createdAtStr != null) {
            createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr) : null);
          }
          PersonFavourite personFavourite =
              new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteId, createdAt);
          sortedFavouriteNodes.put(personFavourite.getKey(), personFavourite);
        }
      } catch (AccessDeniedException ex) {
        // the user no longer has access to this site, skip over the favourite
        // TODO remove the favourite preference
        return;
      }
    }
  }