Skip to content

Commit

Permalink
Add type definition causing issues to log
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Apr 2, 2024
1 parent d69e9dc commit 71f7904
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public static Optional<BibEntryType> parseCustomEntryType(String comment) {
// Important fields are optional fields, but displayed first. Thus, they do not need to be separated by "/".
// See org.jabref.model.entry.field.FieldPriority for details on important optional fields.
.withImportantFields(FieldFactory.parseFieldList(optFields));
if (entryTypeBuilder.hasWarnings()) {
LOGGER.warn("Following custom entry type definition has duplicate fields: {}", comment);
return Optional.empty();
}
return Optional.of(entryTypeBuilder.build());
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/model/entry/BibEntryTypeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class BibEntryTypeBuilder {
private final Set<Field> seenFields = new HashSet<>();
private SequencedSet<BibField> optionalFields = new LinkedHashSet<>();
private EntryType type = StandardEntryType.Misc;
private boolean hasWarnings = false;

public BibEntryTypeBuilder withType(EntryType type) {
this.type = type;
Expand All @@ -38,6 +39,7 @@ public BibEntryTypeBuilder withImportantFields(SequencedSet<Field> newFields) {
List<Field> containedFields = containedInSeenFields(newFields);
if (!containedFields.isEmpty()) {
LOGGER.warn("Fields {} already added to type {}.", containedFields, type.getDisplayName());
hasWarnings = true;
}
this.seenFields.addAll(newFields);
this.optionalFields = Streams.concat(optionalFields.stream(), newFields.stream().map(field -> new BibField(field, FieldPriority.IMPORTANT)))
Expand All @@ -53,6 +55,7 @@ public BibEntryTypeBuilder withDetailFields(SequencedCollection<Field> newFields
List<Field> containedFields = containedInSeenFields(newFields);
if (!containedFields.isEmpty()) {
LOGGER.warn("Fields {} already added to type {}.", containedFields, type.getDisplayName());
hasWarnings = true;
}
this.seenFields.addAll(newFields);
this.optionalFields = Streams.concat(optionalFields.stream(), newFields.stream().map(field -> new BibField(field, FieldPriority.DETAIL)))
Expand All @@ -73,6 +76,7 @@ public BibEntryTypeBuilder addRequiredFields(SequencedSet<OrFields> requiredFiel
List<Field> containedFields = containedInSeenFields(fieldsToAdd);
if (!containedFields.isEmpty()) {
LOGGER.warn("Fields {} already added to type {}.", containedFields, type.getDisplayName());
hasWarnings = true;
}
this.seenFields.addAll(fieldsToAdd);
this.requiredFields.addAll(requiredFields);
Expand Down Expand Up @@ -109,6 +113,10 @@ public BibEntryType build() {
return new BibEntryType(type, allFields, requiredFields);
}

public boolean hasWarnings() {
return hasWarnings;
}

private List<Field> containedInSeenFields(Collection<Field> fields) {
return fields.stream().filter(seenFields::contains).toList();
}
Expand Down

0 comments on commit 71f7904

Please sign in to comment.