Skip to content

Commit

Permalink
Merge branch 'main' into postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
LoayGhreeb committed Oct 11, 2024
2 parents a7ca4d3 + 3805661 commit d4c0123
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 48 deletions.
40 changes: 23 additions & 17 deletions docs/code-howtos/http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@ parent: Code Howtos
---
# HTTP Server

## Get SSL Working

(Based on <https://stackoverflow.com/a/57511038/873282>)

Howto for Windows - other operating systems work similar:

1. As admin `choco install mkcert`
2. As admin: `mkcert -install`
3. `cd %APPDATA%\..\local\org.jabref\jabref\ssl`
4. `mkcert -pkcs12 jabref.desktop jabref localhost 127.0.0.1 ::1`
5. Rename the file to `server.p12`

Note: If you do not do this, you get following error message:

```text
Could not find server key store C:\Users\USERNAME\AppData\Local\org.jabref\jabref\ssl\server.p12.
```
JabRef has a build in http server.
For example, the resource for a library is implemented at [`org.jabref.http.server.LibraryResource`](https://github.com/JabRef/jabref/blob/main/src/main/java/org/jabref/http/server/LibraryResource.java).

## Start http server

Expand Down Expand Up @@ -69,3 +54,24 @@ DEBUG: Server started.

IntelliJ Ultimate offers a Markdown-based http-client. One has to open the file `src/test/java/org/jabref/testutils/interactive/http/rest-api.http`.
Then, there are play buttons appearing for interacting with the server.

## Get SSL Working

When interacting with the [Microsoft Word AddIn](https://github.com/JabRef/JabRef-Word-Addin), a SSL-based connection is required.
[The Word-AddIn is currentely under development](https://github.com/JabRef/JabRef-Word-Addin/pull/568).

(Based on <https://stackoverflow.com/a/57511038/873282>)

Howto for Windows - other operating systems work similar:

1. As admin `choco install mkcert`
2. As admin: `mkcert -install`
3. `cd %APPDATA%\..\local\org.jabref\jabref\ssl`
4. `mkcert -pkcs12 jabref.desktop jabref localhost 127.0.0.1 ::1`
5. Rename the file to `server.p12`

Note: If you do not do this, you get following error message:

```text
Could not find server key store C:\Users\USERNAME\AppData\Local\org.jabref\jabref\ssl\server.p12.
```
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.jabref.logic.importer.fileformat.PdfContentImporter;
import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibTextImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibtexImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
Expand Down Expand Up @@ -460,7 +460,7 @@ public void parsePdfMetadataAndShowMergeDialog() {
MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor);
dialog.setTitle(Localization.lang("Merge PDF metadata"));
dialog.addSource(Localization.lang("Entry"), entry);
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibtexImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath));
if (preferences.getGrobidPreferences().isGrobidEnabled()) {
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportFormatPreferences()), filePath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter;
import org.jabref.logic.importer.fileformat.PdfGrobidImporter;
import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibTextImporter;
import org.jabref.logic.importer.fileformat.PdfVerbatimBibtexImporter;
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.importer.fileformat.RepecNepImporter;
import org.jabref.logic.importer.fileformat.RisImporter;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void reset() {
formats.add(new MsBibImporter());
formats.add(new OvidImporter());
formats.add(new PdfMergeMetadataImporter(importFormatPreferences));
formats.add(new PdfVerbatimBibTextImporter(importFormatPreferences));
formats.add(new PdfVerbatimBibtexImporter(importFormatPreferences));
formats.add(new PdfContentImporter());
formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.os.OS;
Expand All @@ -38,8 +37,10 @@
* <p>
* In case one wants to have a list of {@link BibEntry} matching the bibliography of a PDF,
* please see {@link BibliographyFromPdfImporter}.
* <p>
* If several PDF importers should be tried, use {@link PdfMergeMetadataImporter}.
*/
public class PdfContentImporter extends Importer {
public class PdfContentImporter extends PdfImporter {

private static final Pattern YEAR_EXTRACT_PATTERN = Pattern.compile("\\d{4}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Objects;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
Expand All @@ -32,7 +31,7 @@
/**
* PdfEmbeddedBibFileImporter imports an embedded Bib-File from the PDF.
*/
public class PdfEmbeddedBibFileImporter extends Importer {
public class PdfEmbeddedBibFileImporter extends PdfImporter {

private final BibtexParser bibtexParser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Optional;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.util.GrobidService;
import org.jabref.logic.l10n.Localization;
Expand All @@ -20,7 +19,7 @@
/**
* Wraps the GrobidService function to be used as an Importer.
*/
public class PdfGrobidImporter extends Importer {
public class PdfGrobidImporter extends PdfImporter {

private final GrobidService grobidService;
private final ImportFormatPreferences importFormatPreferences;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jabref.logic.importer.fileformat;

import org.jabref.logic.importer.Importer;

/**
* Intermediate class to bundle all PdfImporters
*/
public abstract class PdfImporter extends Importer {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.importer.fetcher.isbntobibtex.IsbnFetcher;
Expand All @@ -32,23 +31,23 @@
import org.slf4j.LoggerFactory;

/**
* Tries to import BibTeX data trying multiple PDF content importers and merging the results.
* Tries to import BibTeX data trying multiple {@Link PdfImporter}s and merging the results.
* See {@Link org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter#metadataImporters} for the list of importers used.
*
* After all importers are applied, this importer tries to fetch additional metadata for the entry using the DOI and ISBN.
*/
public class PdfMergeMetadataImporter extends Importer {
public class PdfMergeMetadataImporter extends PdfImporter {

private static final Logger LOGGER = LoggerFactory.getLogger(PdfMergeMetadataImporter.class);

private final ImportFormatPreferences importFormatPreferences;
private final List<Importer> metadataImporters;
private final List<PdfImporter> metadataImporters;

public PdfMergeMetadataImporter(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;

this.metadataImporters = new ArrayList<>(5);
this.metadataImporters.add(new PdfVerbatimBibTextImporter(importFormatPreferences));
this.metadataImporters.add(new PdfVerbatimBibtexImporter(importFormatPreferences));
this.metadataImporters.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) {
this.metadataImporters.add(new PdfGrobidImporter(importFormatPreferences));
Expand Down Expand Up @@ -80,7 +79,7 @@ public ParserResult importDatabase(String data) throws IOException {
public ParserResult importDatabase(Path filePath) throws IOException {
List<BibEntry> candidates = new ArrayList<>();

for (Importer metadataImporter : metadataImporters) {
for (PdfImporter metadataImporter : metadataImporters) {
List<BibEntry> extractedEntries = metadataImporter.importDatabase(filePath).getDatabase().getEntries();
if (extractedEntries.isEmpty()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Objects;

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
Expand All @@ -24,11 +23,11 @@
/**
* This importer imports a verbatim BibTeX entry from the first page of the PDF.
*/
public class PdfVerbatimBibTextImporter extends Importer {
public class PdfVerbatimBibtexImporter extends PdfImporter {

private final ImportFormatPreferences importFormatPreferences;

public PdfVerbatimBibTextImporter(ImportFormatPreferences importFormatPreferences) {
public PdfVerbatimBibtexImporter(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Path;
import java.util.Objects;

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
Expand All @@ -16,7 +15,7 @@
/**
* Wraps the XMPUtility function to be used as an Importer.
*/
public class PdfXmpImporter extends Importer {
public class PdfXmpImporter extends PdfImporter {

private final XmpPreferences xmpPreferences;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.logic.quality.consistency;

import java.nio.file.Path;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
Expand All @@ -11,9 +10,7 @@
import java.util.SequencedCollection;
import java.util.Set;

import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.types.EntryType;

Expand All @@ -32,9 +29,9 @@ public record EntryTypeResult(Collection<Field> fields, SequencedCollection<BibE
* Computes the fields set in all entries. In case entries of the same type has more fields defined, it is output.
* <p>
* This class <em>does not</em> check whether all required fields are present or if the fields are valid for the entry type.
* That result can a) be retrieved by using the JabRef UI and b) by checking the CSV output of {@link BibliographyConsistencyCheckResultCsvWriter#writeFindingsAsCsv(Result, Path, BibEntryTypesManager, BibDatabaseMode)}
* That result can a) be retrieved by using the JabRef UI and b) by checking the CSV output of {@link BibliographyConsistencyCheckResultCsvWriter#writeFindings}
*
* @implNote This class does not implement {@link org.jabref.logic.integrity.DatabaseChecker}, because it returns a list of {@link org.jabref.logic.integrity.IntegrityMessage}, which are too fine grained.
* @implNote This class does not implement {@link org.jabref.logic.integrity.DatabaseChecker}, because it returns a list of {@link org.jabref.logic.integrity.IntegrityMessage}, which are too fine-grained.
*/
public Result check(List<BibEntry> entries) {
// collects fields existing in any entry, scoped by entry type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class PdfVerbatimBibTextImporterTest {
class PdfVerbatimBibtexImporterTest {

private PdfVerbatimBibTextImporter importer;
private PdfVerbatimBibtexImporter importer;

@BeforeEach
void setUp() {
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
when(importFormatPreferences.fieldPreferences().getNonWrappableFields()).thenReturn(FXCollections.emptyObservableList());
importer = new PdfVerbatimBibTextImporter(importFormatPreferences);
importer = new PdfVerbatimBibtexImporter(importFormatPreferences);
}

@Test
void doesNotHandleEncryptedPdfs() throws Exception {
Path file = Path.of(PdfVerbatimBibTextImporter.class.getResource("/pdfs/encrypted.pdf").toURI());
Path file = Path.of(PdfVerbatimBibtexImporter.class.getResource("/pdfs/encrypted.pdf").toURI());
List<BibEntry> result = importer.importDatabase(file).getDatabase().getEntries();
assertEquals(Collections.emptyList(), result);
}

@Test
void importTwiceWorksAsExpected() throws Exception {
Path file = Path.of(PdfVerbatimBibTextImporterTest.class.getResource("mixedMetadata.pdf").toURI());
Path file = Path.of(PdfVerbatimBibtexImporterTest.class.getResource("mixedMetadata.pdf").toURI());
List<BibEntry> result = importer.importDatabase(file).getDatabase().getEntries();

BibEntry expected = new BibEntry(StandardEntryType.Article);
Expand Down

0 comments on commit d4c0123

Please sign in to comment.