Skip to content

Commit

Permalink
Fix exception when parsing groups which contain a top level group (#2611
Browse files Browse the repository at this point in the history
)

* Fix exception when getParent is null

* Changelog

* Add test for importing subGroups
  • Loading branch information
Siedlerchr authored Mar 4, 2017
1 parent 79ff330 commit 961ce30
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Sciencedirect/Elsevier fetcher is now able to scrape new HTML structure [#2576](https://github.com/JabRef/jabref/issues/2576)
- Fixed the synchronization logic of keywords and special fields and vice versa [#2580](https://github.com/JabRef/jabref/issues/2580)
- Fixed a display issue when removing a group with a long name [#1407](https://github.com/JabRef/jabref/issues/1407)

- The group selection is no longer lost when switching tabs [#1104](https://github.com/JabRef/jabref/issues/1104)

- We fixed an issue where the "find unlinked files" functionality threw an error when only one PDF was imported but not assigned to an entry [#2577](https://github.com/JabRef/jabref/issues/2577)
- We fixed issue where escaped braces were incorrectly counted when calculating brace balance in a field [#2561](https://github.com/JabRef/jabref/issues/2561)
- We fixed an issue introduced with Version 3.8.2 where executing the `Rename PDFs`-cleanup operation moved the files to the file directory. [#2526](https://github.com/JabRef/jabref/issues/2526)
- We fixed an issue where the `Move linked files to default file directory`- cleanup operation did not move the files to the location of the bib-file. [#2454](https://github.com/JabRef/jabref/issues/2454)
- We fixed an issue where executing `Move file` on a selected file in the `general`-tab could overwrite an existing file. [#2385](https://github.com/JabRef/jabref/issues/2358)
- We fixed an issue with importing groups and subgroups [#2600](https://github.com/JabRef/jabref/issues/2600)
### Removed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static GroupTreeNode importGroups(List<String> orderedData, Character key
root = cursor;
} else {
// insert at desired location
while (level <= cursor.getLevel()) {
while ((level <= cursor.getLevel()) && (cursor.getParent().isPresent())) {
cursor = cursor.getParent().get();
}
cursor.addChild(newNode);
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/jabref/logic/importer/util/GroupsParserTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.jabref.logic.importer.util;

import java.util.Arrays;
import java.util.List;

import org.jabref.logic.importer.ParseException;
import org.jabref.model.groups.AbstractGroup;
import org.jabref.model.groups.ExplicitGroup;
import org.jabref.model.groups.GroupHierarchyType;
import org.jabref.model.groups.GroupTreeNode;

import org.junit.Test;

Expand All @@ -24,4 +28,33 @@ public void fromStringParsesExplicitGroupWithEscapedCharacterInName() throws Exc
public void fromStringThrowsParseExceptionForNotEscapedGroupName() throws Exception {
GroupsParser.fromString("ExplicitGroup:slit\\\\;0\\;mertsch_slit2_2007\\;;", ',');
}

@Test
public void testImportSubGroups() throws ParseException {

List<String> orderedData = Arrays.asList("0 AllEntriesGroup:", "1 ExplicitGroup:1;0;",
"2 ExplicitGroup:2;0;;", "0 ExplicitGroup:3;0;;");
//Create group hierarchy:
// Level 0 Name: All entries
// Level 1 Name: 1
// Level 2 Name: 2
// Level 1 Name: 3

GroupTreeNode rootNode = new GroupTreeNode(
new ExplicitGroup("All entries", GroupHierarchyType.INDEPENDENT, ','));

AbstractGroup firstSubGrpLvl1 = new ExplicitGroup("1", GroupHierarchyType.INDEPENDENT, ',');
rootNode.addSubgroup(firstSubGrpLvl1);

AbstractGroup subLvl2 = new ExplicitGroup("2", GroupHierarchyType.INDEPENDENT, ',');
rootNode.getFirstChild().ifPresent(c -> c.addSubgroup(subLvl2));

AbstractGroup thirdSubGrpLvl1 = new ExplicitGroup("3", GroupHierarchyType.INDEPENDENT, ',');
rootNode.addSubgroup(thirdSubGrpLvl1);

GroupTreeNode parsedNode = GroupsParser.importGroups(orderedData, ',');
assertEquals(rootNode.getChildren(), parsedNode.getChildren());

}

}

0 comments on commit 961ce30

Please sign in to comment.