| 1 | package edu.ucsb.cs156.courses.services; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
| 4 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
| 5 | import java.util.Optional; | |
| 6 | import org.springframework.stereotype.Service; | |
| 7 | ||
| 8 | @Service | |
| 9 | public class ConvertedSectionUpsertService { | |
| 10 | ||
| 11 | private final ConvertedSectionCollection collection; | |
| 12 | ||
| 13 | public ConvertedSectionUpsertService(ConvertedSectionCollection collection) { | |
| 14 | this.collection = collection; | |
| 15 | } | |
| 16 | ||
| 17 | public void upsert(ConvertedSection incoming) { | |
| 18 | String quarter = incoming.getCourseInfo().getQuarter(); | |
| 19 | String enrollCode = incoming.getSection().getEnrollCode(); | |
| 20 | ||
| 21 | Optional<ConvertedSection> existing = | |
| 22 | collection.findOneByQuarterAndEnrollCode(quarter, enrollCode); | |
| 23 | ||
| 24 |
1
1. upsert : negated conditional → KILLED |
if (existing.isPresent()) { |
| 25 | ConvertedSection stored = existing.get(); | |
| 26 |
1
1. upsert : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED |
stored.setCourseInfo(incoming.getCourseInfo()); |
| 27 |
1
1. upsert : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED |
stored.setSection(incoming.getSection()); |
| 28 | collection.save(stored); | |
| 29 | } else { | |
| 30 | collection.save(incoming); | |
| 31 | } | |
| 32 | } | |
| 33 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 26 |
1.1 |
|
| 27 |
1.1 |