// Get Information for Person requesting the new source
PersonPojo p = SocialUtils.getPerson(source.getOwnerId().toString());
// Get the root URL to prepend to the approve/reject link below
PropertiesManager propManager = new PropertiesManager();
String rootUrl = propManager.getUrlRoot();
// Subject Line
String subject = "Approve/Reject New Source: " + source.getTitle();
// Get array of community IDs and get corresponding CommunityPojo objects
ArrayList<CommunityPojo> communities = SocialUtils.getCommunities(source.getCommunityIds());
// Iterate over the communities and send an email to each set of owner/moderators requesting
// that the approve or reject the source
for (CommunityPojo c : communities)
{
// Email address or addresses to send to
// Extract email addresses for owners and moderators from list of community members
StringBuffer sendTo = new StringBuffer();
Set<CommunityMemberPojo> members = c.getMembers();
CommunityMemberPojo owner = null;
for (CommunityMemberPojo member : members)
{
if (member.getUserType().equalsIgnoreCase("owner") || member.getUserType().equalsIgnoreCase("moderator"))
{
owner = member;
if (sendTo.length() > 0) sendTo.append(";");
sendTo.append(member.getEmail());
}
}
if (0 == sendTo.length()) {
throw new RuntimeException("community " + c.getName() + " / " + c.getId() + " has no owner/moderator");
}
//create a community request and post to db
CommunityApprovePojo cap = new CommunityApprovePojo();
cap.set_id(new ObjectId());
cap.setCommunityId( c.getId().toString() );
cap.setIssueDate(new Date());
cap.setPersonId(owner.get_id().toString());
cap.setRequesterId(p.get_id().toString());
cap.setType("source");
cap.setSourceId(source.getId().toString());
DbManager.getSocial().getCommunityApprove().insert(cap.toDb());
// Message Body
String body = "<p>" + p.getDisplayName() + " has requested that the following source be " +
"added to the " + c.getName() + " community:</p>" +
"<p>" +
"Title: " + source.getTitle() + "<br/>" +
"Description: " + source.getDescription() + "<br/>" +
"URL (eg): " + source.getRepresentativeUrl() + "<br/>" +
"</p>" +
"<p>Please click on the Approve or Reject links below to complete the approval process: </p>" +
"<li><a href=\"" + rootUrl + "social/community/requestresponse/" + cap.get_id().toString() + "/true\">Approve new Source</a></li>" +
"<li><a href=\"" + rootUrl + "social/community/requestresponse/" + cap.get_id().toString() + "/false\">Reject new Source</a></li>";
// Send
new SendMail(new PropertiesManager().getAdminEmailAddress(), sendTo.toString(), subject, body).send("text/html");
}
return true;
}