//check to see if user has permission to delete group (admin)
//set up retrieval tools
ObjectRetrievalTools<UserRoleGroup> objTool = new ObjectRetrievalTools<UserRoleGroup>();
//return the UserRoleGroup
UserRoleGroup urg = (UserRoleGroup)objTool.getObject(Table.UserRoleGroup, "userId", userId, "groupId", groupId);
//get role id
int admin = urg.getRoleId();
//check for admin
if (admin == 0) {
throw new Exception ("User does not have admin privledges");
}
//admin confirmed
else {
boolean answer;
//first check to see if group has any questions first
//if there are questions, there will be answers as well
if (answer = myTools.dataSearch("Question", "groupId", groupId)){
//get all the questions associated with the group id
ObjectRetrievalTools<Question> objTool2 = new ObjectRetrievalTools<Question>();
List<Question> questionList = objTool2.getObjectList(Table.Question, "groupId", groupId);
//delete the questions from the db
for (Iterator<Question> questIterator = questionList.iterator(); questIterator.hasNext();) {
Question questionDelete = questIterator.next();
//get questionId for answer deletion
int questionId = questionDelete.getId();
myTools.dataRemoval(questionDelete);
//get all the answers associated with the question id
ObjectRetrievalTools<Answer> objTool3 = new ObjectRetrievalTools<Answer>();
List<Answer> answerList = objTool3.getObjectList(Table.Answer, "questionId", questionId);
//delete all the answers from the db
for (Iterator<Answer> ansIterator = answerList.iterator(); ansIterator.hasNext();) {
Answer answerDelete = ansIterator.next();
myTools.dataRemoval(answerDelete);
}
}
}
//group has no questions/answers
else {}
//get all the UserRoleGroup associated with the group id
//there should be at least 1 for the group creator
ObjectRetrievalTools<UserRoleGroup> objTool4 = new ObjectRetrievalTools<UserRoleGroup>();
List<UserRoleGroup> urgList = objTool4.getObjectList(Table.UserRoleGroup, "groupId", groupId);
//delete all the UserRoleGroup from db
for (Iterator<UserRoleGroup> iterator = urgList.iterator(); iterator.hasNext();) {
UserRoleGroup urgDelete = iterator.next();
myTools.dataRemoval(urgDelete);
}
//lastly, retrieve the actual group for deletion
ObjectRetrievalTools<Group> objTool5 = new ObjectRetrievalTools<Group>();