Skip to content

Commit

Permalink
ESURVEY-8629 DeleteSurveyUpdater: OptimisticLockException
Browse files Browse the repository at this point in the history
  • Loading branch information
clam2310 committed Jan 17, 2025
1 parent fd7f74a commit 3965e6a
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/main/java/com/ec/survey/service/SurveyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,7 @@ public void deleteNoTransaction(int id, boolean deleteLogs, boolean deleteFileMa
Session session = sessionFactory.getCurrentSession();

Survey s = this.getSurvey(id, false, false, false, false);
String uid = s.getUniqueId();

List<Integer> surveyIDs = surveyService.getAllSurveyVersions(s.getShortname(), s.getUniqueId());
fileService.deleteFilesForSurveys(s.getUniqueId());
Expand All @@ -2314,10 +2315,8 @@ public void deleteNoTransaction(int id, boolean deleteLogs, boolean deleteFileMa
// delete draft
Map<String, Integer> referencedFiles = s.getReferencedFileUIDs(contextpath);
deleteSurveyData(id, true, true, s.getUniqueId(), deleteLogs);
session.flush();
session.delete(s);
session.flush();


for (Entry<String, Integer> entry : referencedFiles.entrySet()) {
if (entry.getValue() == null) {
// delete files belonging to images and background documents
Expand All @@ -2326,21 +2325,16 @@ public void deleteNoTransaction(int id, boolean deleteLogs, boolean deleteFileMa
}

// delete published versions
Survey published = getSurveyByUniqueId(s.getUniqueId(), false, false);
if (published != null) {
surveyIDs = this.getAllSurveyVersions(published.getId());
for (Integer sid : surveyIDs) {
s = this.getSurvey(sid, false, false, false, false);
referencedFiles = s.getReferencedFileUIDs(contextpath);
deleteSurveyData(s.getId(), true, true, s.getUniqueId(), deleteLogs);
session.flush();
session.delete(s);
session.flush();
for (Entry<String, Integer> entry : referencedFiles.entrySet()) {
if (entry.getValue() == null) {
// delete files belonging to images and background documents
fileService.deleteIfNotReferenced(entry.getKey(), s.getUniqueId());
}
surveyIDs = this.getAllPublishedSurveyVersions(uid);
for (Integer sid : surveyIDs) {
s = this.getSurvey(sid, false, false, false, false);
referencedFiles = s.getReferencedFileUIDs(contextpath);
deleteSurveyData(s.getId(), true, true, s.getUniqueId(), deleteLogs);
session.delete(s);
for (Entry<String, Integer> entry : referencedFiles.entrySet()) {
if (entry.getValue() == null) {
// delete files belonging to images and background documents
fileService.deleteIfNotReferenced(entry.getKey(), s.getUniqueId());
}
}
}
Expand Down

0 comments on commit 3965e6a

Please sign in to comment.