{
// Group's can not have blank names.
result.setContinue(false);
result.addError("group_name");
result.setOutcome(false);
result.setMessage(new Message("default","The group name may not be blank."));
return result;
}
// Create a new group, check if the newName is already in use.
Group potentialDuplicate = Group.findByName(context,newName);
if (potentialDuplicate == null)
{
// All good, create the new group.
group = Group.create(context);
group.setName(newName);
}
else
{
// The name is already in use, return an error.
result.setContinue(false);
result.addError("group_name");
result.addError("group_name_duplicate");
result.setOutcome(false);
result.setMessage(new Message("default","The group name is already in use"));
return result;
}
}
else
{
group = Group.find(context,groupID);
String name = group.getName();
// Only update the name if there has been a change.
if (newName != null && newName.length() > 0 && !name.equals(newName))
{
// The group name is to be updated, check if the newName is already in use.
Group potentialDuplicate = Group.findByName(context,newName);
if (potentialDuplicate == null)
{
// All good, update the name
group.setName(newName);
}
else
{
// The name is already in use, return an error.
result.setContinue(false);
result.addError("group_name");
result.addError("group_name_duplicate");
result.setOutcome(false);
result.setMessage(new Message("default","The group name is already in use"));
return result;
}
}
}