{
throw new AuthorizeException(
"Only administrators can create communities");
}
TableRow row = DatabaseManager.create(context, "community");
Community c = new Community(context, row);
c.handle = HandleManager.createHandle(context, c);
// create the default authorization policy for communities
// of 'anonymous' READ
Group anonymousGroup = Group.find(context, 0);
ResourcePolicy myPolicy = ResourcePolicy.create(context);
myPolicy.setResource(c);
myPolicy.setAction(Constants.READ);
myPolicy.setGroup(anonymousGroup);
myPolicy.update();
context.addEvent(new Event(Event.CREATE, Constants.COMMUNITY, c.getID(), c.handle));
// if creating a top-level Community, simulate an ADD event at the Site.
if (parent == null)
context.addEvent(new Event(Event.ADD, Constants.SITE, Site.SITE_ID, Constants.COMMUNITY, c.getID(), c.handle));
log.info(LogManager.getHeader(context, "create_community",
"community_id=" + row.getIntColumn("community_id"))
+ ",handle=" + c.handle);
return c;
}