Skip to content

Commit a42bdd1

Browse files
authored
Merge pull request #2 from XDZhelheim/CS304_ProgressReport
Cs304 progress report
2 parents 422f025 + 9c5f705 commit a42bdd1

File tree

15 files changed

+542
-35
lines changed

15 files changed

+542
-35
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
3737

3838
### Fixed
3939

40+
- We fixed an issue where searching for bibliographies and importing them triggers uncaught java.lang.IndexOutOfBoundsException [#7606](https://github.com/JabRef/jabref/issues/7606)
4041
- We fixed an issue where the table column sort order was not properly stored and resulted in unsorted eports [#7524](https://github.com/JabRef/jabref/issues/7524)
4142
- We fixed an issue where the value of the field `school` or `institution` would be printed twice in the HTML Export [forum#2634](https://discourse.jabref.org/t/problem-with-exporting-techreport-phdthesis-mastersthesis-to-html/2634)
4243
- We fixed an issue preventing to connect to a shared database. [#7570](https://github.com/JabRef/jabref/pull/7570)
@@ -78,6 +79,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
7879
- We fixed an issue with very large page numbers [#7590](https://github.com/JabRef/jabref/issues/7590)
7980
- We fixed an issue where journal abbreviations in UTF-8 were not recognized [#5850](https://github.com/JabRef/jabref/issues/5850)
8081
- We fixed an issue where the article title with curly brackets fails to download the arXiv link (pdf file). [#7633](https://github.com/JabRef/jabref/issues/7633)
82+
- We fixed an issue with the default path of external application. [#7641](https://github.com/JabRef/jabref/issues/7641)
83+
- We fixed an issue where urls must be embedded in a style tag when importing EndNote style Xml files. Now it can parse url with or without a style tag. [#6199](https://github.com/JabRef/jabref/issues/6199)
8184

8285
### Removed
8386

src/main/java/org/jabref/gui/desktop/os/Windows.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.nio.file.Files;
56
import java.nio.file.Path;
67
import java.util.Optional;
78

@@ -24,16 +25,50 @@ public void openFile(String filePath, String fileType) throws IOException {
2425
}
2526
}
2627

28+
/**
29+
* CS304 Issue link: https://github.com/EvoSuite/evosuite/issues/7641
30+
* Detect the path of program under ProgramFiles or ProgramFiles(x86), return empty string if nothing found.
31+
* @param programName Name of program (for example, texstudio)
32+
* @param directoryName Name of the directory that contains program (for example, TeXstudio)
33+
*/
2734
@Override
2835
public String detectProgramPath(String programName, String directoryName) {
2936
String progFiles = System.getenv("ProgramFiles(x86)");
30-
if (progFiles == null) {
31-
progFiles = System.getenv("ProgramFiles");
37+
String programPath;
38+
if (progFiles != null) {
39+
programPath = getProgramPath(programName, directoryName, progFiles);
40+
if (programPath != null) {
41+
return programPath;
42+
}
3243
}
44+
45+
progFiles = System.getenv("ProgramFiles");
46+
programPath = getProgramPath(programName, directoryName, progFiles);
47+
if (programPath != null) {
48+
return programPath;
49+
}
50+
51+
return "";
52+
}
53+
54+
/**
55+
* CS304 Issue link: https://github.com/EvoSuite/evosuite/issues/7641
56+
* Find the path of program under ProgramFiles or ProgramFiles(x86), return null if program not exists.
57+
* @param programName Name of program (for example, texstudio)
58+
* @param directoryName Name of the directory that contains program (for example, TeXstudio)
59+
* @param progFiles Path of windows system directory (for example, C:/Program Files or C:/Program Files(x86))
60+
*/
61+
private String getProgramPath(String programName, String directoryName, String progFiles) {
62+
Path programPath;
3363
if ((directoryName != null) && !directoryName.isEmpty()) {
34-
return Path.of(progFiles, directoryName, programName + DEFAULT_EXECUTABLE_EXTENSION).toString();
64+
programPath = Path.of(progFiles, directoryName, programName + DEFAULT_EXECUTABLE_EXTENSION);
65+
} else {
66+
programPath = Path.of(progFiles, programName + DEFAULT_EXECUTABLE_EXTENSION);
67+
}
68+
if (Files.exists(programPath)) {
69+
return programPath.toString();
3570
}
36-
return Path.of(progFiles, programName + DEFAULT_EXECUTABLE_EXTENSION).toString();
71+
return null;
3772
}
3873

3974
@Override

src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,15 @@ private Optional<ArXivEntry> searchForEntryById(String id) throws FetcherExcepti
115115
}
116116
}
117117

118-
// CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
119-
// Ignore the curly brackets in the title before it serves as a parameter to search arXiv entry and before the comparison with arXiv title
118+
/**
119+
* CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
120+
*
121+
* Ignore the curly brackets in the title before it serves as a parameter to search arXiv entry and before the comparison with arXiv title
122+
*
123+
* @param entry the BibEntry variable saving the elements of the .bib file
124+
* @return if do not found the pdf file, return empty, else, it will return the pdf file
125+
* @throws FetcherException fail to request arXiv eprint API
126+
*/
120127
private List<ArXivEntry> searchForEntries(BibEntry entry) throws FetcherException {
121128
// 1. Eprint
122129
Optional<String> identifier = entry.getField(StandardField.EPRINT);
@@ -256,6 +263,10 @@ public Optional<HelpFile> getHelpPage() {
256263
/**
257264
* Constructs a complex query string using the field prefixes specified at https://arxiv.org/help/api/user-manual
258265
*
266+
* CS304 Issue Link: https://github.com/JabRef/jabref/issues/7606
267+
*
268+
* Set the onPerformSucceed to true after performedPage
269+
*
259270
* @param luceneQuery the root node of the lucene query
260271
* @return A list of entries matching the complex query
261272
*/
@@ -266,8 +277,10 @@ public Page<BibEntry> performSearchPaged(QueryNode luceneQuery, int pageNumber)
266277
List<BibEntry> searchResult = searchForEntries(transformedQuery, pageNumber).stream()
267278
.map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()))
268279
.collect(Collectors.toList());
280+
CompositeSearchBasedFetcher.PerformSucceed();
269281
return new Page<>(transformedQuery, pageNumber, filterYears(searchResult, transformer));
270282
}
283+
// when perform pages set onPerformSearch to true
271284

272285
private List<BibEntry> filterYears(List<BibEntry> searchResult, ArXivQueryTransformer transformer) {
273286
return searchResult.stream()

src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.slf4j.LoggerFactory;
1919

2020
public class CompositeSearchBasedFetcher implements SearchBasedFetcher {
21+
public static volatile Boolean onPerformSucceed = false;
2122

2223
private static final Logger LOGGER = LoggerFactory.getLogger(CompositeSearchBasedFetcher.class);
2324

@@ -36,6 +37,15 @@ public CompositeSearchBasedFetcher(Set<SearchBasedFetcher> searchBasedFetchers,
3637
this.maximumNumberOfReturnedResults = maximumNumberOfReturnedResults;
3738
}
3839

40+
/**
41+
* CS304 Issue Link: https://github.com/JabRef/jabref/issues/7606
42+
* Set onPerformSucceed to true at performSearchPaged method in ArXiv
43+
*/
44+
public static void PerformSucceed() {
45+
onPerformSucceed = true;
46+
}
47+
48+
// keep a status of perform search to make sure the execute order
3949
@Override
4050
public String getName() {
4151
return "SearchAll";
@@ -46,21 +56,37 @@ public Optional<HelpFile> getHelpPage() {
4656
return Optional.empty();
4757
}
4858

59+
/**
60+
* CS304 Issue Link: https://github.com/JabRef/jabref/issues/7606
61+
*
62+
* @param luceneQuery the root node of the lucene query
63+
*
64+
* @return return the fetchers stream
65+
*
66+
* @throws FetcherException when API request failed at searchBasedFetcher.getName()
67+
*/
4968
@Override
5069
public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherException {
5170
ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX);
5271
// All entries have to be converted into one format, this is necessary for the format conversion
53-
return fetchers.parallelStream()
72+
return fetchers.stream()
5473
.flatMap(searchBasedFetcher -> {
5574
try {
75+
onPerformSucceed = false;
5676
return searchBasedFetcher.performSearch(luceneQuery).stream();
5777
} catch (FetcherException e) {
5878
LOGGER.warn(String.format("%s API request failed", searchBasedFetcher.getName()), e);
5979
return Stream.empty();
6080
}
6181
})
6282
.limit(maximumNumberOfReturnedResults)
63-
.map(cleanup::doPostCleanup)
83+
.map(x-> {
84+
while (!onPerformSucceed) {
85+
Thread.onSpinWait();
86+
}
87+
return cleanup.doPostCleanup(x);
88+
})
6489
.collect(Collectors.toList());
6590
}
6691
}
92+
// clear only after the perform search

src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,39 @@ private Optional<String> getUrl(Record record) {
259259
.findFirst();
260260
}
261261

262+
/**
263+
* Extracts url address of Class Url generated from a user-imported .xml file.
264+
* More specifically, this method will check whether text of url is wrapped in a style tag.
265+
* If it is, extract from inner text; otherwise, use vanilla text outside.
266+
*
267+
* @param url a Url class object containing info from .xml file imported by user.
268+
* @return entity url address of given class url
269+
*/
262270
private Optional<String> getUrlValue(Url url) {
263-
return Optional.ofNullable(url)
264-
.map(Url::getStyle)
265-
.map(Style::getContent)
266-
.map(this::clean);
271+
Optional<List<Object>> urlContent = Optional.ofNullable(url).map(Url::getContent);
272+
List<Object> list = urlContent.orElse(null);
273+
Optional<String> ret;
274+
if (list == null || list.size() == 0) {
275+
return Optional.empty();
276+
} else {
277+
boolean isStyleExist = false;
278+
int style_index = -1;
279+
for (int i = 0; i < list.size(); i++) {
280+
if (list.get(i) instanceof Style) {
281+
isStyleExist = true;
282+
style_index = i;
283+
}
284+
}
285+
if (!isStyleExist) {
286+
ret = Optional.ofNullable((String) list.get(0))
287+
.map(this::clean);
288+
} else {
289+
ret = Optional.ofNullable((Style) list.get(style_index))
290+
.map(Style::getContent)
291+
.map(this::clean);
292+
}
293+
}
294+
return ret;
267295
}
268296

269297
private List<String> getKeywords(Record record) {

src/main/java/org/jabref/model/strings/StringUtil.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,15 @@ public static boolean containsIgnoreCase(String text, String searchString) {
735735
public static String substringBetween(String str, String open, String close) {
736736
return StringUtils.substringBetween(str, open, close);
737737
}
738-
739-
// CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
740-
// ingore the curly brackets in the title if the title is not blank
738+
739+
/**
740+
* CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
741+
*
742+
* Ignore the curly brackets in the String
743+
*
744+
* @param title the title of the article saved in .bib file
745+
* @return the fixed title without the curly brackets
746+
*/
741747
public static String ignoreCurlyBracket(String title) {
742748
return isNotBlank(title) ? title.replace("{", "").replace("}", "") : title;
743749
}

src/main/resources/xjc/endnote/endnote.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@
668668
</xs:complexType>
669669
</xs:element>
670670
<xs:element name="url">
671-
<xs:complexType>
671+
<xs:complexType mixed="true">
672672
<xs:sequence>
673673
<xs:element minOccurs="0" ref="style"/>
674674
</xs:sequence>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.jabref.gui.desktop.os;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class WindowsTest {
8+
9+
Windows windows = new Windows();
10+
11+
// CS304 Issue Link: https://github.com/JabRef/jabref/issues/7641
12+
@Test
13+
void detectProgramPathUnderProgramFileTest() {
14+
assertEquals("C:\\Program Files\\TeXstudio\\texstudio.exe", windows.detectProgramPath("texstudio", "TeXstudio"));
15+
}
16+
17+
// CS304 Issue Link: https://github.com/JabRef/jabref/issues/7641
18+
@Test
19+
void detectProgramPathNotUnderProgramFileTest() {
20+
assertEquals("C:\\Program Files\\TeXstudio\\texstudio.exe", windows.detectProgramPath("texstudio", "teXstudio"));
21+
}
22+
}

src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ void findFullTextByTitle() throws IOException {
9595
assertEquals(Optional.of(new URL("http://arxiv.org/pdf/cond-mat/0406246v1")), fetcher.findFullText(entry));
9696
}
9797

98-
// CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
99-
// Test method: ArXiv.searchForEntries
100-
@Test
101-
void findFullTextByTitleWithCurlyBracket() throws IOException {
102-
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");
103-
104-
assertEquals(Optional.of(new URL("https://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry));
105-
}
106-
98+
/**
99+
* CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
100+
*
101+
* Test method: ArXiv.searchForEntries, erase the curly brackets in the title
102+
*
103+
* @throws IOException if there is something wrong with read or write data
104+
*/
107105
@Test
108106
void findFullTextByTitleWithCurlyBracket() throws IOException {
109107
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");
@@ -119,16 +117,13 @@ void findFullTextByTitleAndPartOfAuthor() throws IOException {
119117
assertEquals(Optional.of(new URL("http://arxiv.org/pdf/cond-mat/0406246v1")), fetcher.findFullText(entry));
120118
}
121119

122-
// CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
123-
// Test method: ArXiv.searchForEntries
124-
@Test
125-
void findFullTextByTitleWithCurlyBracketAndPartOfAuthor() throws IOException {
126-
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");
127-
entry.setField(StandardField.AUTHOR, "Zhang, Ruohan and Guo");
128-
129-
assertEquals(Optional.of(new URL("https://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry));
130-
}
131-
120+
/**
121+
* CS304 Issue link: https://github.com/JabRef/jabref/issues/7633
122+
*
123+
* Test method: ArXiv.searchForEntries, erase the curly brackets in the title
124+
*
125+
* @throws IOException if there is somethinf wrong with read or write data
126+
*/
132127
@Test
133128
void findFullTextByTitleWithCurlyBracketAndPartOfAuthor() throws IOException {
134129
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");

src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public void createCompositeFetcherWithNullSet() {
4040
() -> new CompositeSearchBasedFetcher(null, 0));
4141
}
4242

43+
@Test
44+
public void setPerformSucceed() {
45+
CompositeSearchBasedFetcher.PerformSucceed();
46+
Assertions.assertEquals(true, CompositeSearchBasedFetcher.onPerformSucceed);
47+
}
48+
4349
@Test
4450
public void performSearchWithoutFetchers() throws Exception {
4551
Set<SearchBasedFetcher> empty = new HashSet<>();

0 commit comments

Comments
 (0)