Skip to content

Commit

Permalink
SAK-49206 Lessons deleting question should delete responses (sakaipro…
Browse files Browse the repository at this point in the history
…ject#12186)

Co-authored-by: Earle Nietzel <[email protected]>
  • Loading branch information
jkjanetschek and ern authored Mar 5, 2024
1 parent 2084e79 commit b0c5448
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,7 @@ public class PageData {
public List<SimplePageItem> getOrderedTopLevelPageItems(String siteId);

public void deleteLogForLessonsItem(SimplePageItem item);

public void deleteQuestionResponsesForItem(SimplePageItem item);

}
Original file line number Diff line number Diff line change
Expand Up @@ -1982,4 +1982,17 @@ public void deleteLogForLessonsItem(SimplePageItem item) {
log.warn("Failed to delete lessons log for item {}", item.getId());
}
}

public void deleteQuestionResponsesForItem(SimplePageItem item) {
try {
DetachedCriteria d = DetachedCriteria.forClass(SimplePageQuestionResponse.class).add(Restrictions.eq("questionId",item.getId()));
DetachedCriteria d2 = DetachedCriteria.forClass(SimplePageQuestionResponseTotals.class).add(Restrictions.eq("questionId",item.getId()));
getHibernateTemplate().deleteAll(getHibernateTemplate().findByCriteria(d));
getHibernateTemplate().deleteAll(getHibernateTemplate().findByCriteria(d2));
} catch (DataAccessException e) {
log.error("Failed to delete SimplePageQuestion responses for item {}: {}", item.getId(), e.toString());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,11 @@ public String deleteItem(SimplePageItem item, boolean updateSequence) {
simplePageToolDao.deleteAllSavedStatusesForChecklist(item);
}

//delete corresponding response entries for question item
if(item.getType() == SimplePageItem.QUESTION) {
simplePageToolDao.deleteQuestionResponsesForItem(item);
}

// delete lessonsItem log
simplePageToolDao.deleteLogForLessonsItem(item);

Expand Down

0 comments on commit b0c5448

Please sign in to comment.