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

WIP Restapi #628

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b29aaea
Add jaxrs copy over code
Siedlerchr Sep 21, 2022
c951839
try with jetty
Siedlerchr Sep 21, 2022
96d917a
fcking inject (
Siedlerchr Sep 21, 2022
4b38bd1
Update afterburner to jakarta
Siedlerchr Sep 21, 2022
8f8dff9
Merge remote-tracking branch 'upstream/afterburner' into restApi
Siedlerchr Sep 21, 2022
03bcdd3
add another fcking injection stuff
Siedlerchr Sep 21, 2022
7ce929b
test again
Siedlerchr Sep 22, 2022
809a579
fix afterburner
Siedlerchr Sep 22, 2022
607cb2a
Merge remote-tracking branch 'upstream/main' into restapi
Siedlerchr Oct 13, 2022
9293da1
Fix conflicts
Siedlerchr Oct 13, 2022
698e88f
cleanup
Siedlerchr Oct 14, 2022
4638d77
Merge remote-tracking branch 'upstream/main' into restapi
Siedlerchr Jan 5, 2023
bcca5cc
fix compile errors
Siedlerchr Jan 5, 2023
dd77dce
Switch to JBOSS RestEasy (and Jackson instead of Glassfish)
koppor Jan 5, 2023
4640087
Switch back to Glassfish for JAXB (instead of Jackson)
koppor Jan 6, 2023
a6ee546
Switch from Glassfish to Jackson2 for JSON (but keep it for XML)
koppor Jan 6, 2023
1b4c30d
Remove one dependency
koppor Jan 6, 2023
67280b0
Merge remote-tracking branch 'origin/main' into restapi
koppor Mar 17, 2023
1bbb1db
Remove two "nice-to-have" Markdown plugins (strikethrough, tasklist)
koppor Mar 17, 2023
5c448de
Fix checkstyle
koppor Mar 17, 2023
6095223
Remove duoble dependency entry
koppor Mar 17, 2023
82492fd
Really remove Markdown extension
koppor Mar 17, 2023
bf659ea
Endless startup...
koppor Mar 17, 2023
636873d
Get server to run
koppor Mar 17, 2023
2f8302b
Make use of JabRefDesktop for default directory
koppor Mar 17, 2023
1b1fa9d
Streamline code of ServerPropertyService
koppor Mar 17, 2023
cf14659
Fix checkstyle
koppor Mar 18, 2023
ba80857
Merge remote-tracking branch 'upstream/main' into restapi
Siedlerchr Mar 18, 2023
0c2c30c
fix starting error
Siedlerchr Mar 18, 2023
306d731
fix jlink dupliate module
Siedlerchr Mar 18, 2023
a0799b0
run in background thread
Siedlerchr Mar 18, 2023
21b20f1
Merge remote-tracking branch 'upstream/main' into restapi
Siedlerchr Mar 20, 2023
3b14255
remove tika
Siedlerchr Mar 20, 2023
e734892
Fix checkstyle
koppor Mar 20, 2023
1aacc96
Merge branch 'main' into restapi
koppor Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ dependencies {
implementation "org.tinylog:tinylog-api:2.5.0"
implementation "org.tinylog:slf4j-tinylog:2.5.0"
implementation "org.tinylog:tinylog-impl:2.5.0"

implementation 'de.undercouch:citeproc-java:3.0.0-alpha.6'

// jakarta.activation is already dependency of glassfish
implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '3.0.1'
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '3.0.2'
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.0.0'

implementation ('com.github.tomtung:latex2unicode_2.13:0.3.2') {
exclude module: 'fastparse_2.13'
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
requires net.harawata.appdirs;

requires org.eclipse.jgit;
requires jakarta.ws.rs;
uses org.eclipse.jgit.transport.SshSessionFactory;
uses org.eclipse.jgit.lib.GpgSigner;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.jabref.logic.pdf.search.indexing;

import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;

/**
* Wrapper around {@link PdfIndexer} to execute all operations in the background.
*/
public class IndexingTaskManager extends BackgroundTask<Void> {

private final Queue<Runnable> taskQueue = new ConcurrentLinkedQueue<>();
private TaskExecutor taskExecutor;
private int numOfIndexedFiles = 0;

private final Object lock = new Object();
private boolean isRunning = false;
private boolean isBlockingNewTasks = false;

public IndexingTaskManager(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
showToUser(true);
willBeRecoveredAutomatically(true);
DefaultTaskExecutor.runInJavaFXThread(() -> {
this.updateProgress(1, 1);
this.titleProperty().set(Localization.lang("Indexing pdf files"));
});
}

@Override
protected Void call() throws Exception {
synchronized (lock) {
isRunning = true;
}
updateProgress();
while (!taskQueue.isEmpty() && !isCanceled()) {
taskQueue.poll().run();
numOfIndexedFiles++;
updateProgress();
}
synchronized (lock) {
isRunning = false;
}
return null;
}

private void updateProgress() {
DefaultTaskExecutor.runInJavaFXThread(() -> {
updateMessage(Localization.lang("%0 of %1 linked files added to the index", numOfIndexedFiles, numOfIndexedFiles + taskQueue.size()));
updateProgress(numOfIndexedFiles, numOfIndexedFiles + taskQueue.size());
});
}

private void enqueueTask(Runnable indexingTask) {
if (!isBlockingNewTasks) {
taskQueue.add(indexingTask);
// What if already running?
synchronized (lock) {
if (!isRunning) {
isRunning = true;
this.executeWith(taskExecutor);
showToUser(false);
}
}
}
}

public AutoCloseable blockNewTasks() {
synchronized (lock) {
isBlockingNewTasks = true;
}
return () -> {
synchronized (lock) {
isBlockingNewTasks = false;
}
};
}

public void createIndex(PdfIndexer indexer) {
enqueueTask(() -> indexer.createIndex());
}

public void updateIndex(PdfIndexer indexer, BibDatabaseContext databaseContext) {
Set<String> pathsToRemove = indexer.getListOfFilePaths();
for (BibEntry entry : databaseContext.getEntries()) {
for (LinkedFile file : entry.getFiles()) {
System.out.println("Adding file " + file.getLink());
enqueueTask(() -> indexer.addToIndex(entry, file, databaseContext));
pathsToRemove.remove(file.getLink());
}
}
for (String pathToRemove : pathsToRemove) {
<<<<<<< HEAD
=======
System.out.println("Removing file " + pathToRemove);
>>>>>>> 972bac7252 (Cleanup index when opening a library)
koppor marked this conversation as resolved.
Show resolved Hide resolved
enqueueTask(() -> indexer.removeFromIndex(pathToRemove));
}
}

public void addToIndex(PdfIndexer indexer, BibEntry entry, BibDatabaseContext databaseContext) {
enqueueTask(() -> addToIndex(indexer, entry, entry.getFiles(), databaseContext));
}

public void addToIndex(PdfIndexer indexer, BibEntry entry, List<LinkedFile> linkedFiles, BibDatabaseContext databaseContext) {
for (LinkedFile file : linkedFiles) {
enqueueTask(() -> indexer.addToIndex(entry, file, databaseContext));
}
}

public void removeFromIndex(PdfIndexer indexer, BibEntry entry, List<LinkedFile> linkedFiles) {
for (LinkedFile file : linkedFiles) {
enqueueTask(() -> indexer.removeFromIndex(file.getLink()));
}
}

public void removeFromIndex(PdfIndexer indexer, BibEntry entry) {
enqueueTask(() -> removeFromIndex(indexer, entry, entry.getFiles()));
}

public void updateDatabaseName(String name) {
DefaultTaskExecutor.runInJavaFXThread(() -> this.titleProperty().set(Localization.lang("Indexing for %0", name)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.jabref.logic.shared.restserver.core.properties;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerPropertyService {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerPropertyService.class);
private static ServerPropertyService instance;
private final Properties serverProperties;

private ServerPropertyService() {
serverProperties = loadProperties();
}

public static ServerPropertyService getInstance() {
if (instance == null) {
instance = new ServerPropertyService();
}
return instance;
}

/**
* Tries to determine the working directory of the library.
* Uses the first path it finds when resolving in this order:
* 1. Environment variable LIBRARY_WORKSPACE
* 2. Default User home with a new directory for the library
*/
private Properties loadProperties() {
Properties properties = new Properties();
if (!((System.getenv("LIBRARY_WORKSPACE") == null) || System.getenv("LIBRARY_WORKSPACE").isBlank())) {
LOGGER.info("Environment Variable found, using defined directory: {}", System.getenv("LIBRARY_WORKSPACE"));
properties.setProperty("workingDirectory", System.getenv("LIBRARY_WORKSPACE"));
} else {
LOGGER.info("Working directory was not found in either the properties or the environment variables, falling back to default location: {}", System.getProperty("user.home") + "/planqk-library");
properties.setProperty("workingDirectory", System.getProperty("user.home") + "/planqk-library");
}
return properties;
}

public Path getWorkingDirectory() {
return Paths.get(serverProperties.getProperty("workingDirectory"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jabref.logic.shared.restserver.core.repository;

import java.io.IOException;

import org.jabref.logic.crawler.Crawler;
import org.jabref.logic.exporter.SaveException;

import org.eclipse.jgit.api.errors.GitAPIException;

public class CrawlTask implements Runnable {
private final Crawler crawler;
private TaskStatus status;

public CrawlTask(Crawler crawler) {
this.crawler = crawler;
}

public TaskStatus getStatus() {
return status;
}

@Override
public void run() {
status = TaskStatus.RUNNING;
try {
crawler.performCrawl();
} catch (IOException | GitAPIException | SaveException e) {
status = TaskStatus.FAILED;
throw new RuntimeException(e);
}
status = TaskStatus.DONE;
}
}