Mapping.rollback();
}
// get the form
CreatePublicationForm sform = (CreatePublicationForm) form;
ActionErrors errors = sform.myValidate(request);
// user need cancel
if (request.getParameter("cancel") != null) {
// Forward to the next page
return (mapping.findForward("cancel"));
}
// retrieve section id
String id = request.getParameter("id").toString();
// fill data | first time
if (sform.getName() == null) {
try {
Mapping.begin();
Section section = Section.getInstance(id);
String template = section.getMetaData("template")+"";
TypeBean type = SectionTypes.getSectionBean(servlet,template);
request.setAttribute("types",type.getPublicationTypes());
request.setAttribute("workflows",Workflow.listTypes());
Mapping.rollback();
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the view page
return (mapping.findForward("view"));
}
// fill data | errors
if (errors.size() > 0) {
try {
Mapping.begin();
Section section = Section.getInstance(id);
String template = section.getMetaData("template")+"";
TypeBean type = SectionTypes.getSectionBean(servlet,template);
request.setAttribute("types",type.getPublicationTypes());
request.setAttribute(ERROR_KEY,errors);
Mapping.rollback();
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the view page
return (mapping.findForward("view"));
}
// all it's ok : create publication
try {
Mapping.begin();
Section section = Section.getInstance(id);
String newId = IdGenerator.nextPublicationId();
TypePublication type = TypePublication.getInstance(sform.getType());
Publication publi = Publication.create(User.getInstance(request.getSession().getAttribute("userLogin")+""),newId,type, section.getMetaData("workflow")+"");
section.addPublication(publi);
publi.setMetaData("name", sform.getName());
request.setAttribute("id", newId);
Mapping.commit();
} catch (Exception e) {
Mapping.rollback();