1 package org.nextime.ion.admin.action.publi; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.struts.action.Action; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nextime.ion.admin.form.PubliForm; 15 import org.nextime.ion.framework.business.Category; 16 import org.nextime.ion.framework.business.Publication; 17 import org.nextime.ion.framework.business.Section; 18 import org.nextime.ion.framework.business.TypePublication; 19 import org.nextime.ion.framework.business.User; 20 import org.nextime.ion.framework.business.impl.PublicationImpl; 21 import org.nextime.ion.framework.mapping.Mapping; 22 import org.nextime.ion.framework.workflow.Workflow; 23 import org.nextime.ion.framework.workflow.WorkflowStep; 24 25 public class EditPubliAction extends Action { 26 27 public ActionForward perform( 28 ActionMapping mapping, 29 ActionForm form, 30 HttpServletRequest request, 31 HttpServletResponse response) 32 throws IOException , ServletException { 33 34 request.setAttribute("view", "publi"); 36 37 if (request.getParameter("id") != null) 38 request.setAttribute("id", request.getParameter("id")); 39 String id = request.getAttribute("id") + ""; 40 int version = 1; 41 if( request.getParameter("version") != null ) { 42 version = Integer.parseInt(request.getParameter("version")); 43 } 44 request.setAttribute("version",version+""); 45 46 try { 47 48 Mapping.begin(); 50 request.setAttribute("sectionList", Section.listAll()); 51 request.setAttribute("categoryList", Category.listAll()); 52 request.setAttribute("userList", User.listAll()); 53 request.setAttribute("typeList", TypePublication.listAll()); 54 request.setAttribute("workflowList", Workflow.listTypes()); 55 request.setAttribute("versions", Publication.getInstance(id).getVersions()); 56 Mapping.rollback(); 57 58 if (request.getParameter("editSubmit") == null || "changeVersion".equals(request.getParameter("editSubmit"))) { 59 Mapping.begin(); 60 61 Publication u = Publication.getInstance(id); 63 PubliForm f = (PubliForm) form; 64 f.setVersion(version+""); 65 f.setId(u.getId()); 66 if (u.getVersion(version).getAuthor() != null) { 67 f.setAuthor(u.getVersion(version).getAuthor().getLogin()); 68 } 69 f.setType(u.getType().getId()); 70 f.setSections(u.getSectionsIds()); 71 f.setCategories(u.getCategoriesIds()); 72 request.setAttribute( 73 "metaData", 74 ((PublicationImpl) u).getMetaData()); 75 request.setAttribute("data", ((PublicationImpl) u).getVersion(version).getDataAsString()); 76 String workflowUser = ((User)User.listAll().firstElement()).getLogin(); 78 f.setWorkflowUser(workflowUser); 79 f.setWorkflow(u.getVersion(version).getWorkflow(User.getInstance(workflowUser)).getId()+" ("+u.getVersion(version).getWorkflow(User.getInstance(workflowUser)).getWorkflowType()+")"); 80 request.setAttribute("actions", u.getVersion(version).getWorkflow(User.getInstance(workflowUser)).getAvailableActions()); 81 request.setAttribute("permissions", u.getVersion(version).getWorkflow(User.getInstance(workflowUser)).getPermissions()); 82 request.setAttribute("steps", u.getVersion(version).getWorkflow(User.getInstance(workflowUser)).getCurrentSteps() ); 83 84 try { 85 System.out.println(((WorkflowStep)u.getVersion(version).getWorkflow(User.getInstance(f.getWorkflowUser())).getCurrentSteps().firstElement()).getName()); 86 } catch( Exception e ) { 87 e.printStackTrace(); 88 } 89 90 Mapping.commit(); 91 return new ActionForward(mapping.getInput()); 92 } 93 94 Mapping.begin(); 96 PubliForm f = (PubliForm) form; 97 version = Integer.parseInt(f.getVersion()); 98 Publication u = Publication.getInstance(id); 99 if (!f.getType().equals(u.getType().getId())) { 105 u.getVersion(version).resetData(); 106 } 107 u.changeType(TypePublication.getInstance(f.getType())); 108 String [] g = f.getSections(); 109 u.resetSections(); 110 if (g != null) { 111 for (int i = 0; i < g.length; i++) { 112 u.addSection(Section.getInstance(g[i])); 113 } 114 } 115 g = f.getCategories(); 116 if (g != null) { 117 for (int i = 0; i < g.length; i++) { 118 u.addCategory(Category.getInstance(g[i])); 119 } 120 } 121 if( !request.getParameter("workflowAction").equals("NULL") ) { 123 u.getVersion(version).getWorkflow(User.getInstance(f.getWorkflowUser())).getAction(Integer.parseInt(request.getParameter("workflowAction"))).execute(); 124 } 125 request.setAttribute("actions", u.getVersion(version).getWorkflow(User.getInstance(f.getWorkflowUser())).getAvailableActions()); 126 request.setAttribute("permissions", u.getVersion(version).getWorkflow(User.getInstance(f.getWorkflowUser())).getPermissions()); 127 request.setAttribute("steps", u.getVersion(version).getWorkflow(User.getInstance(f.getWorkflowUser())).getCurrentSteps() ); 128 129 130 133 String data = request.getParameter("data"); 134 u.getVersion(version).setDataAsString(data); 135 136 request.setAttribute("data", ((PublicationImpl) u).getVersion(version).getDataAsString()); 137 138 140 150 Enumeration ps = request.getParameterNames(); 152 while (ps.hasMoreElements()) { 153 String name = ps.nextElement() + ""; 154 if (name.startsWith("META_")) { 155 name = name.substring(5); 156 u.setMetaData(name, request.getParameter("META_" + name)); 157 } 158 } 159 String mtd = request.getParameter("metaToDelete"); 161 if ((mtd + "").trim().equals("")) 162 mtd = null; 163 if (mtd != null) { 164 u.removeMetaData(mtd); 165 request.setAttribute( 166 "metaData", 167 ((PublicationImpl) u).getMetaData()); 168 } 169 String mtd2 = request.getParameter("newMETA"); 171 if ((mtd2 + "").trim().equals("")) 172 mtd2 = null; 173 if (mtd2 != null) { 174 u.setMetaData(mtd2, ""); 175 request.setAttribute( 176 "metaData", 177 ((PublicationImpl) u).getMetaData()); 178 } 179 Mapping.commit(); 180 181 if (mtd != null || mtd2 != null) { 183 return new ActionForward(mapping.getInput()); 184 } 185 186 if (request.getParameter("editSubmit").equals("temp")) { 188 return new ActionForward(mapping.getInput()); 189 } 190 191 193 } catch (Exception e) { 194 Mapping.rollback(); 195 request.setAttribute("error", e.getMessage()); 196 return new ActionForward(mapping.getInput()); 197 } 198 199 return mapping.findForward("success"); 200 } 201 202 } | Popular Tags |