Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jabref.model.groups.AutomaticGroup;
import org.jabref.model.groups.AutomaticKeywordGroup;
import org.jabref.model.groups.AutomaticPersonsGroup;
import org.jabref.model.groups.DateGroup;
import org.jabref.model.groups.ExplicitGroup;
import org.jabref.model.groups.GroupEntryChanger;
import org.jabref.model.groups.GroupTreeNode;
Expand Down Expand Up @@ -464,6 +465,8 @@ public boolean canAddEntriesIn() {
return false;
} else if (group instanceof AutomaticDateGroup) {
return false;
} else if (group instanceof DateGroup) {
return false;
} else {
throw new UnsupportedOperationException("canAddEntriesIn method not yet implemented in group: " + group.getClass().getName());
}
Expand Down Expand Up @@ -508,6 +511,7 @@ public boolean canAddGroupsIn() {
case AutomaticKeywordGroup _,
AutomaticPersonsGroup _,
AutomaticDateGroup _,
DateGroup _,
SmartGroup _ ->
false;
case KeywordGroup _ ->
Expand All @@ -534,6 +538,7 @@ public boolean canRemove() {
AutomaticKeywordGroup _,
AutomaticPersonsGroup _,
AutomaticDateGroup _,
DateGroup _,
TexGroup _ ->
true;
case KeywordGroup _ ->
Expand All @@ -553,6 +558,7 @@ public boolean isEditable() {
AbstractGroup group = groupNode.getGroup();
return switch (group) {
case AllEntriesGroup _,
DateGroup _,
SmartGroup _ ->
false;
case ExplicitGroup _,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ public static Set<Field> getPersonNameFields() {
return getFieldsFiltered(field -> field.getProperties().contains(FieldProperty.PERSON_NAMES));
}

/// Gets all fields with [FieldProperty#DATE].
/// Also includes [StandardField#YEAR].
///
/// @return Set of fields
public static Set<Field> getDateFields() {
return getFieldsFiltered(field -> field.getProperties().contains(FieldProperty.DATE));
return getFieldsFiltered(field -> field.getProperties().contains(FieldProperty.DATE) || field == StandardField.YEAR);
}

private static Set<Field> getFieldsFiltered(Predicate<Field> selector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ public DateGranularity getGranularity() {
public Set<GroupTreeNode> createSubgroups(BibEntry entry) {
var out = new LinkedHashSet<GroupTreeNode>();

DateGroup.extractDate(field, entry).ifPresent(d -> {
DateGroup.extractDate(field, entry).ifPresent(date -> {
switch (granularity) {
case YEAR -> {
DateGroup.extractYear(field, entry).ifPresent(y -> {
String key = "%04d".formatted(y);
date.getYear().ifPresent(year -> {
String key = "%04d".formatted(year);
out.add(new GroupTreeNode(new DateGroup(key, GroupHierarchyType.INDEPENDENT, field, key)));
});
}
case MONTH ->
DateGroup.getDateKey(d, "YYYY-MM").ifPresent(key -> {
DateGroup.getDateKey(date, "YYYY-MM").ifPresent(key -> {
out.add(new GroupTreeNode(new DateGroup(key, GroupHierarchyType.INDEPENDENT, field, key)));
});
case FULL_DATE ->
DateGroup.getDateKey(d, "YYYY-MM-DD").ifPresent(key -> {
DateGroup.getDateKey(date, "YYYY-MM-DD").ifPresent(key -> {
out.add(new GroupTreeNode(new DateGroup(key, GroupHierarchyType.INDEPENDENT, field, key)));
});
}
Expand Down
8 changes: 1 addition & 7 deletions jablib/src/main/java/org/jabref/model/groups/DateGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public DateGroup(String groupName, GroupHierarchyType context, Field searchField
this.date = date;
}

static Optional<Integer> extractYear(Field field, BibEntry bibEntry) {
return bibEntry.getField(field)
.flatMap(Date::parse)
.flatMap(Date::getYear);
}

static Optional<Date> extractDate(Field field, BibEntry entry) {
boolean isCore =
(field == StandardField.DATE)
Expand Down Expand Up @@ -58,7 +52,7 @@ static Optional<String> getDateKey(Date d, String dateKeyFormat) {
Optional<Integer> y = d.getYear();
return switch (numOfdashes) {
case 0 ->
y.map(val -> "%04d".formatted(val)); // "YYYY"
y.map("%04d"::formatted); // "YYYY"
case 1 -> { // "YYYY-MM"
if (d.getYear().isPresent() && d.getMonth().isPresent()) {
String out = "%04d-%02d".formatted(d.getYear().get(), d.getMonth().get().getNumber());
Expand Down