Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically created groups with Field to group by as entrytype (#4539) #4555

Merged
merged 4 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We updated updated the Related Articles tab to accept JSON from the new version of the Mr. DLib service
- We added an option in the preference dialog box that allows user to choose behavior after dragging and dropping files in Entry Editor. [#4356](https://github.com/JabRef/jabref/issues/4356)
- We added the ability to have an export preference where previously "File"-->"Export"/"Export selected entries" would not save the user's preference[#4495](https://github.com/JabRef/jabref/issues/4495)

- For automatically created groups, added ability to filter groups by entry type. [#4539](https://github.com/JabRef/jabref/issues/4539)



Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ private void invalidateFieldCache(String fieldName) {
}

public Optional<String> getLatexFreeField(String name) {
if (!hasField(name)) {
if (!hasField(name) && !TYPE_HEADER.equals(name)) {
return Optional.empty();
} else if (latexFreeFields.containsKey(name)) {
return Optional.ofNullable(latexFreeFields.get(toLowerCase(name)));
Expand All @@ -812,6 +812,15 @@ public Optional<String> getLatexFreeField(String name) {
Optional<String> citeKey = getCiteKeyOptional();
latexFreeFields.put(name, citeKey.get());
return citeKey;
} else if (TYPE_HEADER.equals(name)) {
Optional<EntryType> entryType = EntryTypes.getType(getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent()) {
String entryName = entryType.get().getName();
latexFreeFields.put(name, entryName);
return Optional.of(entryName);
} else {
return Optional.empty();
shubhamatlani marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
String latexFreeField = LatexToUnicodeAdapter.format(getField(name).get()).intern();
latexFreeFields.put(name, latexFreeField);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/model/groups/WordKeywordGroup.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.jabref.model.groups;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.jabref.model.EntryTypes;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryType;
import org.jabref.model.entry.KeywordList;
import org.jabref.model.strings.StringUtil;

Expand Down Expand Up @@ -113,6 +118,14 @@ public boolean contains(BibEntry entry) {

private Set<String> getFieldContentAsWords(BibEntry entry) {
if (onlySplitWordsAtSeparator) {
if (BibEntry.TYPE_HEADER.equals(searchField)) {
for (String searchWord : searchWords) {
Optional<EntryType> entryType = EntryTypes.getType(entry.getType(), BibDatabaseMode.BIBLATEX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can move the EntryType.get... Before the loop

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you could implement the for loop as stream with filter and in the end you can use map / and collectors.toSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have a question - While fetching entryType, how do I decide which BibDatabaseMode to pass? BIBTEX or BIBLATEX? In both the committed files I have used BIBLATEX. Is that correct?

if (entryType.isPresent() && entryType.get().getName().equals(searchWord)) {
return new HashSet<>(Arrays.asList(searchWord));
}
}
}
return entry.getField(searchField)
.map(content -> KeywordList.parse(content, keywordSeparator).toStringList())
.orElse(Collections.emptySet());
Expand Down