Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."));
}
}
}

Expand Down