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();
}
}
Aggregations