@Context HttpHeaders headers, @Context HttpServletRequest request) throws WebApplicationException
{
log.info("Creating community at top level.");
org.dspace.core.Context context = null;
Community retCommunity = null;
try
{
context = createContext(getUser(headers));
if (!AuthorizeManager.isAdmin(context))
{
context.abort();
String user = "anonymous";
if (context.getCurrentUser() != null)
{
user = context.getCurrentUser().getEmail();
}
log.error("User(" + user + ") has not permission to create community!");
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
org.dspace.content.Community dspaceCommunity = org.dspace.content.Community.create(null, context);
writeStats(dspaceCommunity, UsageEvent.Action.CREATE, user_ip, user_agent, xforwarderfor,
headers, request, context);
dspaceCommunity.setMetadata("name", community.getName());
dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
dspaceCommunity.update();
retCommunity = new Community(dspaceCommunity, "", context);
context.complete();
}
catch (SQLException e)
{
processException("Could not create new top community, SQLException. Message: " + e, context);
}
catch (ContextException e)
{
processException("Could not create new top community, ContextException. Message: " + e.getMessage(), context);
}
catch (AuthorizeException e)
{
processException("Could not create new top community, AuthorizeException. Message: " + e.getMessage(), context);
}
finally
{
processFinally(context);
}
log.info("Community at top level has been successfully created. Handle:" + retCommunity.getHandle());
return retCommunity;
}