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

Pdf file upload redirection not working #3

Open
dharm18990 opened this issue Nov 22, 2017 · 6 comments
Open

Pdf file upload redirection not working #3

dharm18990 opened this issue Nov 22, 2017 · 6 comments

Comments

@dharm18990
Copy link

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
Copy link
Contributor

jazzido commented Nov 22, 2017

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
Copy link

HI @dharm18990

Did you solve this issue?

I am stuck at this part.

@ClementNerma
Copy link

ClementNerma commented Feb 1, 2021

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

@jazzido
Copy link
Contributor

jazzido commented Feb 9, 2021

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

@ClementNerma
Copy link

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
Copy link
Contributor

jazzido commented Feb 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants