tabulapdf / tabula-web-java

Tabula is a tool for liberating data tables trapped inside PDF files
http://tabula.technology
MIT License
11 stars 7 forks source link

Pdf file upload redirection not working #3

Open dharm18990 opened 6 years ago

dharm18990 commented 6 years ago

when I try to upload the pdf file the pdf file is uploaded successfully to the system folder. but the upload progress is showing in the waiting stage so the redirection from progress bar to view pdf file not working.

package technology.tabula.tabula_web.routes;

import spark.Request; import spark.Response; import spark.Route; import spark.RouteGroup; import technology.tabula.tabula_web.JsonTransformer; import technology.tabula.tabula_web.background.JobExecutor; import technology.tabula.tabula_web.background.job.DetectTables; import technology.tabula.tabula_web.background.job.GenerateDocumentData; import technology.tabula.tabula_web.background.job.Job;

import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream;

import static spark.Spark.get;

public class JobProgressRouteGroup implements RouteGroup {

static class JobProgress {
    public String upload_id;
    public String file_id;
    public String status;
    public String message;
    public String error_type;
    public int pct_complete;

    public JobProgress(String status, String message, String error_type, int pct_complete) {
        this.status = status;
        this.message = message;
        this.error_type = error_type;
        this.pct_complete = pct_complete;
    }

    public JobProgress(String status, String message, String error_type, int pct_complete, String file_id, String upload_id) {
        this(status, message, error_type, pct_complete);
        this.file_id = file_id;
        this.upload_id = upload_id;
    }
}

class JobStatusJson implements Route {

    @Override
    public Object handle(Request request, Response response) throws Exception {

        String batchId = request.params(":upload_id");
        List<Job> jobs = JobExecutor.getInstance().getByBatch(batchId);

        if (jobs.isEmpty()) {
            response.status(404);
            return new JobProgress("error", "No such job", "no-such-job", 0);
        } else if (jobs.stream().anyMatch(j -> j.isFailed() && (j instanceof GenerateDocumentData))) {
            return new JobProgress("error", "Fatal Error: No text data is contained in this PDF file. Tabula can't process it.",
                    "no-text", 99);
        } else if (jobs.stream().anyMatch(Job::isFailed)) {
            return new JobProgress("error", "Sorry, your file upload could not be processed. Please double-check that the file you uploaded is a valid PDF file and try again.",
                    "unknown", 99);
        } else {
            List<Job> batch = jobs.stream().filter(j -> !((j instanceof DetectTables) && j.isWorking())).collect(Collectors.toList());
            batch.sort((j1, j2) -> Integer.compare(j1.percentComplete(), j2.percentComplete()));

            Job firstWorkingJob = batch.stream().filter(Job::isWorking).findFirst().get();

            int pctComplete = batch.stream().map(Job::percentComplete).reduce(0, (sum, pct) -> sum + pct) / batch.size();

            // TODO finish this branch
            return new JobProgress(firstWorkingJob != null ? "working" : "completed",
                    "Dummy message",
                    "",
                    pctComplete,
                    request.params(":file_id"),
                    batchId);
        }
    }
}

@Override
public void addRoutes() {
    get(":upload_id/json", new JobStatusJson(), new JsonTransformer());
    get(":upload_id", (req, rsp) -> {
        return "";
    }); // TODO: implement
}

}


return new JobProgress(firstWorkingJob != null ? "working" : "completed", "Dummy message", "", pctComplete, request.params(":file_id"), batchId);

firstWorkingJob= value is never getting null so jobProgress never completed

unable to identify how to complete the job progress

I have checked the same scenario in the ruby project that's working fine. tabula-error

jazzido commented 6 years ago

Hi @dharm18990,

Yes, I never got around to finishing that part. This project (tabula-web-java) is a proof of concept, meant to evaluate whether we should move to Java in our web app.

Of course, we will gladly accept a PR that implements that (it pretty much needs to replicate the JRuby version's behavior).

nirukk52 commented 4 years ago

HI @dharm18990

Did you solve this issue?

I am stuck at this part.

ClementNerma commented 3 years ago

I have the same issue, no error on the server whatsoever.

jazzido commented 3 years ago

Hi @ClementNerma, my previous answer: https://github.com/tabulapdf/tabula-web-java/issues/3#issuecomment-346371888

ClementNerma commented 3 years ago

Hi @ClementNerma, my previous answer: #3 (comment)

I saw your answer, I just added an answer to indicate the problem was still there, I don't know if there has been any update on this / opened PR on this topic?

jazzido commented 3 years ago

No updates, unfortunately. At the moment, all of the projects under the tabulapdf organization are dormant.