| 1 |
|
package be.dvw.administration.mvc.actions; |
| 2 |
|
|
| 3 |
|
import be.dvw.administration.Constants; |
| 4 |
|
import be.dvw.administration.model.Instrument; |
| 5 |
|
import be.dvw.administration.services.instruments.InstrumentService; |
| 6 |
|
import be.dvw.administration.services.instruments.InstrumentServiceCastorImpl; |
| 7 |
|
import org.apache.commons.logging.Log; |
| 8 |
|
import org.apache.commons.logging.LogFactory; |
| 9 |
|
import org.apache.struts.action.ActionForm; |
| 10 |
|
import org.apache.struts.action.ActionForward; |
| 11 |
|
import org.apache.struts.action.ActionMapping; |
| 12 |
|
import org.apache.struts.action.DynaActionForm; |
| 13 |
|
import org.apache.struts.actions.MappingDispatchAction; |
| 14 |
|
|
| 15 |
|
import javax.servlet.http.HttpServletRequest; |
| 16 |
|
import javax.servlet.http.HttpServletResponse; |
| 17 |
|
import java.util.List; |
| 18 |
|
import java.util.Calendar; |
| 19 |
|
|
| 20 |
|
|
| 21 |
0 |
public final class InstrumentAction extends MappingDispatchAction { |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
0 |
private static Log LOG = LogFactory.getLog(InstrumentAction.class); |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
0 |
private InstrumentService instrumentService = new InstrumentServiceCastorImpl(); |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
public ActionForward create(ActionMapping mapping, |
| 45 |
|
ActionForm form, |
| 46 |
|
HttpServletRequest request, |
| 47 |
|
HttpServletResponse response) |
| 48 |
|
throws Exception { |
| 49 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "create"); |
| 50 |
0 |
request.getSession().setAttribute(Constants.ACTION, "create"); |
| 51 |
0 |
return mapping.findForward("success"); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
public ActionForward edit(ActionMapping mapping, |
| 65 |
|
ActionForm form, |
| 66 |
|
HttpServletRequest request, |
| 67 |
|
HttpServletResponse response) |
| 68 |
|
throws Exception { |
| 69 |
|
|
| 70 |
|
try |
| 71 |
|
{ |
| 72 |
|
|
| 73 |
0 |
if (request.getParameter("id") == null || "".equals( request.getParameter("id" ))) |
| 74 |
|
{ |
| 75 |
0 |
request.setAttribute("error","error-noselection"); |
| 76 |
0 |
List list = instrumentService.getAll(); |
| 77 |
0 |
request.setAttribute("list", list); |
| 78 |
0 |
return mapping.findForward("error-noselection"); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
Instrument i; |
| 83 |
0 |
i = instrumentService.load(Integer.parseInt(request.getParameter("id"))); |
| 84 |
0 |
DynaActionForm dynForm = (DynaActionForm) form; |
| 85 |
|
|
| 86 |
0 |
dynForm.set("id", Integer.toString( i.getId()) ) ; |
| 87 |
0 |
dynForm.set("brand", i.getBrand() ); |
| 88 |
0 |
dynForm.set("type", i.getType() ); |
| 89 |
0 |
dynForm.set("serialNumber", i.getSerialNumber()); |
| 90 |
0 |
dynForm.set("instrumentGroup", i.getInstrumentGroup() ); |
| 91 |
0 |
dynForm.set("purchaseDate", i.getPurchaseDate().toString() ); |
| 92 |
0 |
dynForm.set("purchasePrice", Float.toString(i.getPurchasePrice()) ) ; |
| 93 |
0 |
dynForm.set("purchasedFrom", i.getPurchasedFrom()); |
| 94 |
0 |
dynForm.set("purchasedNew", Boolean.toString(i.isPurchasedNew()) ); |
| 95 |
0 |
dynForm.set("description", i.getDescription() ); |
| 96 |
|
|
| 97 |
|
|
| 98 |
0 |
request.getSession().setAttribute(Constants.ACTION, "edit"); |
| 99 |
|
|
| 100 |
0 |
return mapping.findForward("success"); |
| 101 |
|
} |
| 102 |
0 |
catch (Exception e) |
| 103 |
|
{ |
| 104 |
0 |
LOG.error("Edit form failed to load ", e); |
| 105 |
0 |
return mapping.findForward("error-partituur"); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
public ActionForward save(ActionMapping mapping, |
| 121 |
|
ActionForm form, |
| 122 |
|
HttpServletRequest request, |
| 123 |
|
HttpServletResponse response) |
| 124 |
|
throws Exception { |
| 125 |
|
|
| 126 |
0 |
Instrument i = new Instrument(); |
| 127 |
0 |
boolean newInstrument = true; |
| 128 |
|
|
| 129 |
0 |
DynaActionForm dynForm = (DynaActionForm) form; |
| 130 |
|
|
| 131 |
0 |
if ( dynForm.get("id") != null && |
| 132 |
|
!"".equals( dynForm.get("id") ) && |
| 133 |
|
!"0".equals( (String) dynForm.get("id") ) ) |
| 134 |
|
{ |
| 135 |
0 |
i.setId( Integer.parseInt((String) dynForm.get( "id")) ); |
| 136 |
0 |
newInstrument = false; |
| 137 |
|
} |
| 138 |
|
|
| 139 |
0 |
i.setBrand( (String)dynForm.get("brand") ); |
| 140 |
0 |
i.setType( (String)dynForm.get( "type") ); |
| 141 |
0 |
i.setSerialNumber( (String)dynForm.get( "serialNumber") ); |
| 142 |
0 |
i.setInstrumentGroup( (String)dynForm.get( "instrumentGroup") ); |
| 143 |
0 |
i.setPurchaseDate( (String) dynForm.get("purchaseDate") ); ; |
| 144 |
0 |
i.setPurchasePrice( Float.parseFloat ( (String) dynForm.get( "purchasePrice") ) ); |
| 145 |
0 |
i.setPurchasedFrom( (String)dynForm.get( "purchasedFrom") ); |
| 146 |
0 |
i.setPurchasedNew( new Boolean( (String) dynForm.get( "purchasedNew")).booleanValue() ); |
| 147 |
0 |
i.setDescription( (String) dynForm.get( "description") ); |
| 148 |
|
|
| 149 |
0 |
i = instrumentService.save(i, newInstrument); |
| 150 |
|
|
| 151 |
0 |
request.setAttribute( Constants.INSTRUMENT_CURRENT, i); |
| 152 |
0 |
return mapping.findForward("success"); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
public ActionForward delete(ActionMapping mapping, |
| 156 |
|
ActionForm form, |
| 157 |
|
HttpServletRequest request, |
| 158 |
|
HttpServletResponse response) |
| 159 |
|
throws Exception { |
| 160 |
|
|
| 161 |
0 |
instrumentService.delete( Integer.parseInt(request.getParameter("id")) ); |
| 162 |
0 |
request.getSession().setAttribute(Constants.ACTION, "delete"); |
| 163 |
0 |
return mapping.findForward("success"); |
| 164 |
|
|
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
public ActionForward inventory(ActionMapping mapping, |
| 179 |
|
ActionForm form, |
| 180 |
|
HttpServletRequest request, |
| 181 |
|
HttpServletResponse response) |
| 182 |
|
throws Exception { |
| 183 |
|
|
| 184 |
0 |
List list = instrumentService.getAll(); |
| 185 |
0 |
request.setAttribute("list", list); |
| 186 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "inventory"); |
| 187 |
0 |
request.getSession().setAttribute(Constants.ACTION, "inventory"); |
| 188 |
0 |
return mapping.findForward("success"); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
public ActionForward search (ActionMapping mapping, |
| 203 |
|
ActionForm form, |
| 204 |
|
HttpServletRequest request, |
| 205 |
|
HttpServletResponse response) |
| 206 |
|
throws Exception |
| 207 |
|
{ |
| 208 |
|
|
| 209 |
0 |
List list = instrumentService.search(""); |
| 210 |
0 |
request.setAttribute("list", list); |
| 211 |
0 |
return mapping.findForward("success"); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
public ActionForward searchForm (ActionMapping mapping, |
| 225 |
|
ActionForm form, |
| 226 |
|
HttpServletRequest request, |
| 227 |
|
HttpServletResponse response) |
| 228 |
|
throws Exception |
| 229 |
|
{ |
| 230 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "search"); |
| 231 |
0 |
request.getSession().setAttribute(Constants.ACTION, "search"); |
| 232 |
0 |
return mapping.findForward("success"); |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
public ActionForward details (ActionMapping mapping, |
| 236 |
|
ActionForm form, |
| 237 |
|
HttpServletRequest request, |
| 238 |
|
HttpServletResponse response) |
| 239 |
|
throws Exception |
| 240 |
|
{ |
| 241 |
|
try |
| 242 |
|
{ |
| 243 |
|
|
| 244 |
0 |
if (request.getParameter("id") == null || "".equals( request.getParameter("id" ))) |
| 245 |
|
{ |
| 246 |
0 |
request.setAttribute("error","error-noselection"); |
| 247 |
0 |
List list = instrumentService.getAll(); |
| 248 |
0 |
request.setAttribute("list", list); |
| 249 |
0 |
return mapping.findForward("error-noselection"); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
0 |
Instrument i = instrumentService.load(Integer.parseInt( request.getParameter("id") )); |
| 253 |
0 |
request.setAttribute( Constants.INSTRUMENT_CURRENT, i); |
| 254 |
0 |
request.getSession().setAttribute(Constants.ACTION, "details"); |
| 255 |
0 |
return mapping.findForward("success"); |
| 256 |
|
} |
| 257 |
0 |
catch (Exception e) |
| 258 |
|
{ |
| 259 |
0 |
LOG.error("Instrument failed to load ", e); |
| 260 |
0 |
return mapping.findForward("error-instrument"); |
| 261 |
|
} |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
} |