Search in sources :

Example 1 with JobPanel

use of eu.esdihumboldt.hale.server.webapp.components.JobPanel in project hale by halestudio.

the class StatusPage method addControls.

@Override
protected void addControls(boolean loggedIn) {
    super.addControls(loggedIn);
    final String workspaceId = getPageParameters().get(PARAMETER_WORKSPACE).toOptionalString();
    if (workspaceId == null || workspaceId.isEmpty()) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace ID not specified.");
    }
    try {
        workspaces.getWorkspaceFolder(workspaceId);
    } catch (FileNotFoundException e) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace does not exist.");
    }
    final IModel<TransformationWorkspace> workspace = new LoadableDetachableModel<TransformationWorkspace>() {

        private static final long serialVersionUID = 2600444242247550094L;

        @Override
        protected TransformationWorkspace load() {
            return new TransformationWorkspace(workspaceId);
        }
    };
    // job panel
    final Serializable family = AbstractTransformationJob.createFamily(workspaceId);
    final JobPanel jobs = new JobPanel("jobs", family, true);
    add(jobs);
    // status
    final Label status = new Label("status", new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = -4351763182104835300L;

        @Override
        protected String load() {
            if (workspace.getObject().isTransformationFinished()) {
                if (workspace.getObject().isTransformationSuccessful()) {
                    return "Transformation completed.";
                } else {
                    return "Transformation failed.";
                }
            } else {
                if (Job.getJobManager().find(family).length > 0) {
                    return "Transformation is running:";
                } else {
                    return "No transformation running.";
                }
            }
        }
    });
    status.setOutputMarkupId(true);
    add(status);
    // result
    final WebMarkupContainer result = new WebMarkupContainer("result");
    result.setOutputMarkupId(true);
    add(result);
    final WebMarkupContainer update = new WebMarkupContainer("update") {

        private static final long serialVersionUID = -2591480922683644827L;

        @Override
        public boolean isVisible() {
            return workspace.getObject().isTransformationFinished();
        }
    };
    result.add(update);
    // result : report
    File reportFile = workspace.getObject().getReportFile();
    DownloadLink report = new DownloadLink("log", reportFile, reportFile.getName());
    update.add(report);
    // result : file list
    IModel<? extends List<File>> resultFilesModel = new LoadableDetachableModel<List<File>>() {

        private static final long serialVersionUID = -7971872898614031331L;

        @Override
        protected List<File> load() {
            return Arrays.asList(workspace.getObject().getTargetFolder().listFiles());
        }
    };
    final ListView<File> fileList = new ListView<File>("file", resultFilesModel) {

        private static final long serialVersionUID = -8045643864251639540L;

        @Override
        protected void populateItem(ListItem<File> item) {
            // download link
            DownloadLink download = new DownloadLink("download", item.getModelObject(), item.getModelObject().getName());
            item.add(download);
            // file name
            download.add(new Label("name", item.getModelObject().getName()));
        }
    };
    update.add(fileList);
    // leaseEnd
    String leaseEnd;
    try {
        leaseEnd = workspaces.getLeaseEnd(workspaceId).toString(DateTimeFormat.mediumDateTime());
    } catch (IOException e) {
        leaseEnd = "unknown";
    }
    add(new Label("leaseEnd", leaseEnd));
    boolean transformationFinished = workspace.getObject().isTransformationFinished();
    if (transformationFinished) {
        // disable job timer
        jobs.getTimer().stopOnNextUpdate();
    } else {
        // timer
        add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1500)) {

            private static final long serialVersionUID = -3726349470723024150L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                if (workspace.getObject().isTransformationFinished()) {
                    // update status and result
                    target.add(status);
                    target.add(result);
                    // stop timers
                    stop(target);
                    jobs.getTimer().stopOnNextUpdate();
                }
            }
        });
    }
}
Also used : TransformationWorkspace(eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace) DownloadLink(org.apache.wicket.markup.html.link.DownloadLink) Serializable(java.io.Serializable) AbortWithHttpErrorCodeException(org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException) FileNotFoundException(java.io.FileNotFoundException) Label(org.apache.wicket.markup.html.basic.Label) IOException(java.io.IOException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) AbstractAjaxTimerBehavior(org.apache.wicket.ajax.AbstractAjaxTimerBehavior) ListItem(org.apache.wicket.markup.html.list.ListItem) JobPanel(eu.esdihumboldt.hale.server.webapp.components.JobPanel) File(java.io.File)

Aggregations

TransformationWorkspace (eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace)1 JobPanel (eu.esdihumboldt.hale.server.webapp.components.JobPanel)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 AbstractAjaxTimerBehavior (org.apache.wicket.ajax.AbstractAjaxTimerBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 DownloadLink (org.apache.wicket.markup.html.link.DownloadLink)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1 LoadableDetachableModel (org.apache.wicket.model.LoadableDetachableModel)1 AbortWithHttpErrorCodeException (org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException)1