Skip to content

Commit e05f8b0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fileDescr
* upstream/master: Add tests for removal changes Improve telemetry (#3218) Real test linking real other entry (#3214) Check for explicit group at different location Update java-string-similarity from 0.24 -> 1.0.0 Only remove ExplicitGroups from entries, but not keyword-based groups Remove unused import in GroupTreeNode Move getEntriesInGroup to GroupTreeNode Inline Consumer updateViewModel Undo IntelliJ autoformat of FXML annotations Remove unused import Rewrite selection logic to avoid NPEs Clear group selection when a group is removed Also remove a group from entries when you remove it
2 parents 3197713 + be41624 commit e05f8b0

File tree

12 files changed

+148
-23
lines changed

12 files changed

+148
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
3939
- We fixed an issue where the arrow keys in the search bar did not work as expected [#3081](https://github.com/JabRef/jabref/issues/3081)
4040
- We fixed wrong hotkey being displayed at "automatically file links" in the entry editor
4141
- We fixed an issue where metadata syncing with local and shared database were unstable. It will also fix syncing groups and sub-groups in database. [#2284](https://github.com/JabRef/jabref/issues/2284)
42+
- We fixed an issue where the "Remove group and subgroups" operation did not remove group information from entries in the group [#3190](https://github.com/JabRef/jabref/issues/3190)
4243
- We fixed an issue where it was possible to leave the entry editor with an imbalance of braces. [#3167](https://github.com/JabRef/jabref/issues/3167)
4344
- Renaming files now truncates the filename to not exceed the limit of 255 chars [#2622](https://github.com/JabRef/jabref/issues/2622)
4445
- We improved the handling of hyphens in names. [#2775](https://github.com/JabRef/jabref/issues/2775)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dependencies {
8282
compile 'org.openoffice:unoil:4.1.2'
8383

8484
compile 'com.github.bkromhout:java-diff-utils:2.1.1'
85-
compile 'info.debatty:java-string-similarity:0.24'
85+
compile 'info.debatty:java-string-similarity:1.0.0'
8686

8787
antlr3 'org.antlr:antlr:3.5.2'
8888
compile 'org.antlr:antlr-runtime:3.5.2'
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package org.jabref;
22

3-
import org.apache.logging.log4j.LogManager;
4-
import org.apache.logging.log4j.Logger;
5-
import org.apache.logging.log4j.Marker;
6-
import org.apache.logging.log4j.MarkerManager;
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
75

86
/**
97
* Catch and log any unhandled exceptions.
108
*/
119
public class FallbackExceptionHandler implements Thread.UncaughtExceptionHandler {
1210

13-
private static final Marker UncaughtException_MARKER = MarkerManager.getMarker("UncaughtException");
11+
private static final Log LOGGER = LogFactory.getLog(FallbackExceptionHandler.class);
1412

1513
public static void installExceptionHandler() {
1614
Thread.setDefaultUncaughtExceptionHandler(new FallbackExceptionHandler());
1715
}
1816

1917
@Override
2018
public void uncaughtException(Thread thread, Throwable exception) {
21-
Logger logger = LogManager.getLogger(FallbackExceptionHandler.class);
22-
logger.error(UncaughtException_MARKER, "Uncaught exception Occurred in " + thread, exception);
19+
LOGGER.error("Uncaught exception occurred in " + thread, exception);
2320
}
2421
}

src/main/java/org/jabref/gui/actions/NewEntryAction.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.jabref.gui.actions;
22

33
import java.awt.event.ActionEvent;
4+
import java.util.HashMap;
5+
import java.util.Map;
46

57
import javax.swing.Action;
68
import javax.swing.KeyStroke;
79

10+
import org.jabref.Globals;
811
import org.jabref.gui.EntryTypeDialog;
912
import org.jabref.gui.IconTheme;
1013
import org.jabref.gui.JabRefFrame;
@@ -58,6 +61,8 @@ public void actionPerformed(ActionEvent e) {
5861
return;
5962
}
6063
thisType = tp.getName();
64+
65+
trackNewEntry(tp);
6166
}
6267

6368
if (jabRefFrame.getBasePanelCount() > 0) {
@@ -68,4 +73,12 @@ public void actionPerformed(ActionEvent e) {
6873
LOGGER.info("Action 'New entry' must be disabled when no database is open.");
6974
}
7075
}
76+
77+
private void trackNewEntry(EntryType type) {
78+
Map<String, String> properties = new HashMap<>();
79+
properties.put("EntryType", type.getName());
80+
Map<String, Double> measurements = new HashMap<>();
81+
82+
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("NewEntry", properties, measurements));
83+
}
7184
}

src/main/java/org/jabref/gui/groups/GroupTreeController.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import java.lang.reflect.InvocationTargetException;
44
import java.lang.reflect.Method;
5+
import java.util.ArrayList;
56
import java.util.List;
67
import java.util.Optional;
78
import java.util.function.Consumer;
8-
import java.util.stream.Collectors;
99

1010
import javax.inject.Inject;
1111

@@ -79,19 +79,12 @@ public void initialize() {
7979
// Set-up bindings
8080
Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups =
8181
(newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);
82-
Consumer<List<TreeItem<GroupNodeViewModel>>> updateViewModel =
83-
(newSelectedGroups) -> {
84-
if (newSelectedGroups == null) {
85-
viewModel.selectedGroupsProperty().clear();
86-
} else {
87-
viewModel.selectedGroupsProperty().setAll(newSelectedGroups.stream().map(TreeItem::getValue).collect(Collectors.toList()));
88-
}
89-
};
82+
9083
BindingsHelper.bindContentBidirectional(
9184
groupTree.getSelectionModel().getSelectedItems(),
9285
viewModel.selectedGroupsProperty(),
9386
updateSelectedGroups,
94-
updateViewModel
87+
this::updateSelection
9588
);
9689

9790
viewModel.filterTextProperty().bind(searchField.textProperty());
@@ -247,6 +240,20 @@ public void initialize() {
247240
setupClearButtonField(searchField);
248241
}
249242

243+
private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroups) {
244+
if (newSelectedGroups == null) {
245+
viewModel.selectedGroupsProperty().clear();
246+
} else {
247+
List<GroupNodeViewModel> list = new ArrayList<>();
248+
for (TreeItem<GroupNodeViewModel> model : newSelectedGroups) {
249+
if (model != null && model.getValue() != null) {
250+
list.add(model.getValue());
251+
}
252+
}
253+
viewModel.selectedGroupsProperty().setAll(list);
254+
}
255+
}
256+
250257
private void selectNode(GroupNodeViewModel value) {
251258
getTreeItemByValue(value)
252259
.ifPresent(treeItem -> groupTree.getSelectionModel().select(treeItem));
@@ -257,7 +264,7 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(GroupNodeViewM
257264
}
258265

259266
private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<GroupNodeViewModel> root,
260-
GroupNodeViewModel value) {
267+
GroupNodeViewModel value) {
261268
if (root.getValue().equals(value)) {
262269
return Optional.of(root);
263270
}

src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.jabref.logic.l10n.Localization;
2828
import org.jabref.model.FieldChange;
2929
import org.jabref.model.database.BibDatabaseContext;
30+
import org.jabref.model.entry.BibEntry;
3031
import org.jabref.model.groups.AbstractGroup;
3132
import org.jabref.model.groups.ExplicitGroup;
3233
import org.jabref.model.groups.GroupTreeNode;
@@ -248,13 +249,27 @@ public void removeGroupAndSubgroups(GroupNodeViewModel group) {
248249
//final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_AND_CHILDREN);
249250
//panel.getUndoManager().addEdit(undo);
250251

252+
removeGroupsAndSubGroupsFromEntries(group);
253+
251254
group.getGroupNode().removeFromParent();
252255

253256
dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName()));
254257
writeGroupChangesToMetaData();
255258
}
256259
}
257260

261+
void removeGroupsAndSubGroupsFromEntries(GroupNodeViewModel group) {
262+
for (GroupNodeViewModel child: group.getChildren()) {
263+
removeGroupsAndSubGroupsFromEntries(child);
264+
}
265+
266+
// only remove explicit groups from the entries, keyword groups should not be deleted
267+
if (group.getGroupNode().getGroup() instanceof ExplicitGroup) {
268+
List<BibEntry> entriesInGroup = group.getGroupNode().getEntriesInGroup(this.currentDatabase.get().getEntries());
269+
group.getGroupNode().removeEntriesFromGroup(entriesInGroup);
270+
}
271+
}
272+
258273
public void addSelectedEntries(GroupNodeViewModel group) {
259274
// TODO: Warn
260275
// if (!WarnAssignmentSideEffects.warnAssignmentSideEffects(node.getNode().getGroup(), panel.frame())) {

src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void append(LogEvent rawEvent) {
3939
Telemetry telemetry;
4040
if (event.isException()) {
4141
ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(event.getException());
42+
exceptionTelemetry.getProperties().put("Message", rawEvent.getMessage().getFormattedMessage());
4243
exceptionTelemetry.setSeverityLevel(event.getNormalizedSeverityLevel());
4344
telemetry = exceptionTelemetry;
4445
} else {

src/main/java/org/jabref/model/database/BibDatabase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,5 @@ public String generateSharedDatabaseID() {
613613
public DuplicationChecker getDuplicationChecker() {
614614
return duplicationChecker;
615615
}
616+
616617
}

src/main/java/org/jabref/model/groups/GroupTreeNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ public List<GroupTreeNode> getMatchingGroups(List<BibEntry> entries) {
181181
return groups;
182182
}
183183

184+
public List<BibEntry> getEntriesInGroup(List<BibEntry> entries) {
185+
List<BibEntry> result = new ArrayList<>();
186+
for (BibEntry entry: entries) {
187+
if (this.group.contains(entry)) {
188+
result.add(entry);
189+
}
190+
}
191+
return result;
192+
}
193+
184194
public String getName() {
185195
return group.getName();
186196
}

src/test/java/org/jabref/gui/groups/GroupNodeViewModelTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import org.jabref.gui.util.TaskExecutor;
1111
import org.jabref.model.database.BibDatabaseContext;
1212
import org.jabref.model.entry.BibEntry;
13+
import org.jabref.model.entry.FieldName;
1314
import org.jabref.model.groups.AbstractGroup;
1415
import org.jabref.model.groups.AutomaticKeywordGroup;
16+
import org.jabref.model.groups.ExplicitGroup;
1517
import org.jabref.model.groups.GroupHierarchyType;
1618
import org.jabref.model.groups.GroupTreeNode;
1719
import org.jabref.model.groups.WordKeywordGroup;
@@ -149,6 +151,20 @@ public void draggedOnTopOfGroupAddsBeforeItWhenSourceGroupWasBefore() throws Exc
149151
assertEquals(Arrays.asList(groupBViewModel, groupAViewModel, groupCViewModel), rootViewModel.getChildren());
150152
}
151153

154+
@Test
155+
public void entriesAreAddedCorrectly() {;
156+
String groupName = "group";
157+
ExplicitGroup group = new ExplicitGroup(groupName, GroupHierarchyType.INDEPENDENT,',');
158+
BibEntry entry = new BibEntry();
159+
databaseContext.getDatabase().insertEntry(entry);
160+
161+
GroupNodeViewModel model = new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, group);
162+
model.addEntriesToGroup(databaseContext.getEntries());
163+
164+
assertEquals(databaseContext.getEntries(), model.getGroupNode().getEntriesInGroup(databaseContext.getEntries()));
165+
assertEquals(groupName, entry.getField(FieldName.GROUPS).get());
166+
}
167+
152168
private GroupNodeViewModel getViewModelForGroup(AbstractGroup group) {
153169
return new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, group);
154170
}

0 commit comments

Comments
 (0)