Skip to content

Commit

Permalink
Add logging to findOrCreate (#341)
Browse files Browse the repository at this point in the history
- We think this method is suspect for session splitting; let's add some
logging.

Co-Authored-By: Sree Prasad <sprasad@codeforamerica.org>
Co-Authored-By: Cypress Borg <cborg@codeforamerica.org>
Co-Authored-By: Ana Medrano Fernandez <amedrano@codeforamerica.org>
Co-authored-by: Tom Dooner <tdooner@codeforamerica.org>
  • Loading branch information
4 people committed Aug 1, 2023
1 parent e0cfb61 commit 3880385
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -13,6 +15,7 @@
*/
@Service
@Transactional
@Slf4j
public class SubmissionRepositoryService {

SubmissionRepository repository;
Expand All @@ -31,7 +34,11 @@ public SubmissionRepositoryService(SubmissionRepository repository, SubmissionEn
* @return UUID of the saved submission
*/
public UUID save(Submission submission) {
var newRecord = submission.getId() == null;
UUID id = repository.save(encryptionService.encrypt(submission)).getId();
if (newRecord) {
log.info("created submission id: " + id);
}
submission.setId(id);
return id;
}
Expand Down Expand Up @@ -85,9 +92,18 @@ public Submission findOrCreate(HttpSession httpSession) {
var id = (UUID) httpSession.getAttribute("id");
if (id != null) {
Optional<Submission> submissionOptional = findById(id);
return submissionOptional.orElseGet(Submission::new);
if (submissionOptional.isEmpty()) {
log.error("findOrCreate could not find submission: " + id);
Submission newSubmission = new Submission();
log.info("findOrCreate created new submission: " + newSubmission.getId());
return newSubmission;
} else {
return submissionOptional.get();
}
} else {
return new Submission();
Submission newSubmission = new Submission();
log.info("findOrCreate got no submission id from session, so created new submission: " + newSubmission.getId());
return newSubmission;
}
}
}

0 comments on commit 3880385

Please sign in to comment.