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; }
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 String getSiteName(Map<String, String> properties) { String siteFullName = properties.get(wfVarResourceName); SiteInfo site = siteService.getSite(siteFullName); if (site == null) throw new InvitationException("The site " + siteFullName + " could not be found."); String siteName = site.getShortName(); String siteTitle = site.getTitle(); if (siteTitle != null && siteTitle.length() > 0) { siteName = siteTitle; } return siteName; }