Search in sources :

Example 1 with NewTemplatePage

use of eu.esdihumboldt.hale.server.templates.war.pages.NewTemplatePage in project hale by halestudio.

the class TemplateUploadForm method onUploadSuccess.

/**
 * Called after a successful upload.
 *
 * @param form the form
 * @param templateId the template identifier
 * @param projectInfo the project info
 * @param updateInfo if for an updated template, the template information
 *            should be updated from the project
 */
protected void onUploadSuccess(Form<?> form, String templateId, ProjectInfo projectInfo, boolean updateInfo) {
    boolean newTemplate = TemplateUploadForm.this.templateId == null;
    OrientGraph graph = DatabaseHelper.getGraph();
    try {
        Template template = Template.getByTemplateId(graph, templateId);
        if (template == null) {
            form.error("Template could not be created");
            return;
        }
        if (newTemplate) {
            // created template was a new template
            // associate user as owner to template
            String login = UserUtil.getLogin();
            if (login != null) {
                User user = User.getByLogin(graph, login);
                graph.addEdge(null, template.getV(), user.getV(), "owner");
            }
            // forward to page to fill in template information
            setResponsePage(new NewTemplatePage(templateId));
        } else {
            // created template already existed
            // set last updated
            template.setLastUpdate(new Date());
            // update template info from project info
            if (updateInfo) {
                template.setName(projectInfo.getName());
                template.setAuthor(projectInfo.getAuthor());
                template.setDescription(projectInfo.getDescription());
            }
            // forward to template page
            setResponsePage(TemplatePage.class, new PageParameters().set(0, templateId));
        }
    } catch (NonUniqueResultException e) {
        form.error("Internal error");
        log.error("Duplicate template or user");
    } finally {
        graph.shutdown();
    }
}
Also used : NonUniqueResultException(eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException) User(eu.esdihumboldt.hale.server.model.User) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) NewTemplatePage(eu.esdihumboldt.hale.server.templates.war.pages.NewTemplatePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Date(java.util.Date) Template(eu.esdihumboldt.hale.server.model.Template)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 Template (eu.esdihumboldt.hale.server.model.Template)1 User (eu.esdihumboldt.hale.server.model.User)1 NewTemplatePage (eu.esdihumboldt.hale.server.templates.war.pages.NewTemplatePage)1 NonUniqueResultException (eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException)1 Date (java.util.Date)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1