diff --git a/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java b/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java index a06d3ce8c3..acd2116f3f 100644 --- a/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java +++ b/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java @@ -61,6 +61,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -251,7 +252,7 @@ private synchronized void buildGitContentIndex(final String sha, // add children (and parent) from flattened Set to // cache if they have ids - for (Content flattenedContent : this.flattenContentObjects(content)) { + for (Content flattenedContent : flattenContentObjects(content)) { if (flattenedContent.getId() == null) { continue; } @@ -386,6 +387,12 @@ private Content augmentChildContent(final Content content, final String canonica log.debug("Found question without id '{}' in {}", content.getTitle(), canonicalSourceFile); } + // Give title-less questions unique titles so they remain distinct in Set-based flattening, even if they have + // the same id. + if (content instanceof Question && content.getTitle() == null) { + content.setTitle("untitled-question-" + UUID.randomUUID()); + } + // Try to figure out the parent ids. String newParentId; if (null == parentId && content.getId() != null) { @@ -1073,8 +1080,13 @@ && flattenContentObjects(content).stream() } // Verify that significant figure bounds are correct if (!q.getDisregardSignificantFigures()) { - if (null == q.getSignificantFiguresMin() ^ null == q.getSignificantFiguresMax()) { - // Both bounds need to be present, or both not present + // If not 'exact answers only', s.f. bounds should be set + if (null == q.getSignificantFiguresMin() && null == q.getSignificantFiguresMax()) { + this.registerContentProblem(content, "Numeric Question: " + q.getId() + " has no " + + "significant figure bounds set. If this question does not use significant figures then " + + "'exact answers only' should be set.", indexProblemCache); + } else if (null == q.getSignificantFiguresMin() || null == q.getSignificantFiguresMax()) { + // Both bounds need to be present this.registerContentProblem(content, "Numeric Question: " + q.getId() + " has only one " + "significant figure bound, and may be unanswerable as a result. Please add both upper " + "and lower significant figure bounds, or omit both.", indexProblemCache); diff --git a/src/test/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexerTest.java b/src/test/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexerTest.java index 8f53b11002..b359f26bf5 100644 --- a/src/test/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexerTest.java +++ b/src/test/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexerTest.java @@ -204,7 +204,7 @@ public void flattenContentObjects_flattenMultiTierObject_checkCorrectObjectRetur } /** - * Test that recordContentTypeSpecificError does not add an error message to indexProblemCache when neither + * Test that recordContentTypeSpecificError adds an error message to indexProblemCache when neither * significant figure is set whilst disregardSignificantFigures is not set. */ @Test @@ -221,7 +221,9 @@ public void recordContentTypeSpecificError_noSigFigSet_checkNoError() { // ASSERT for (Content key : indexProblemCache.keySet()) { - assertTrue(indexProblemCache.get(key).isEmpty()); + for (String problem : indexProblemCache.get(key)) { + assertTrue(problem.contains("has no significant figure bounds set.")); + } } }