@Override protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; List<IResultUpdate> updaters = ValidationUpdateRegister.getRegisteredUpdaters(); boolean areListeners = updaters != null && !updaters.isEmpty(); request.getSession().setAttribute(SAVE_DISABLED, "true"); BaseActionForm dynaForm = (BaseActionForm) form; ResultValidationPaging paging = new ResultValidationPaging(); paging.updatePagedResults(request, dynaForm); List<AnalysisItem> resultItemList = paging.getResults(request); String testSectionName = (String) dynaForm.get("testSection"); String testName = (String) dynaForm.get("testName"); setRequestType(testSectionName); ActionMessages errors = validateModifiedItems(resultItemList); if (errors.size() > 0) { saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); return mapping.findForward(FWD_VALIDATION_ERROR); } createSystemUser(); setSampleFinishedStatuses(); noteUpdateList = new ArrayList<Note>(); resultUpdateList = new ArrayList<Result>(); analysisUpdateList = new ArrayList<Analysis>(); modifiedResultSet = new ArrayList<ResultSet>(); newResultSet = new ArrayList<ResultSet>(); deletableList = new ArrayList<Result>(); if (testSectionName.equals("serology")) { createUpdateElisaList(resultItemList); } else { createUpdateList(resultItemList, areListeners); } Transaction tx = HibernateUtil.getSession().beginTransaction(); try { ResultSaveService.removeDeletedResultsInTransaction(deletableList, currentUserId); // update analysis for (Analysis analysis : analysisUpdateList) { analysisDAO.updateData(analysis); } for (Result result : resultUpdateList) { if (result.getId() != null) { resultDAO.updateData(result); } else { resultDAO.insertData(result); } } checkIfSamplesFinished(resultItemList); // update finished samples for (Sample sample : sampleUpdateList) { sampleDAO.updateData(sample); } // create or update notes for (Note note : noteUpdateList) { if (note != null) { if (note.getId() == null) { noteDAO.insertData(note); } else { noteDAO.updateData(note); } } } for (IResultUpdate updater : updaters) { updater.transactionalUpdate(this); } tx.commit(); } catch (LIMSRuntimeException lre) { tx.rollback(); } for (IResultUpdate updater : updaters) { updater.postTransactionalCommitUpdate(this); } if (isBlankOrNull(testSectionName)) { return mapping.findForward(forward); } else { Map<String, String> params = new HashMap<String, String>(); params.put("type", testSectionName); params.put("test", testName); params.put("forward", forward); return getForwardWithParameters(mapping.findForward(forward), params); } }
protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Scriptlet. // If there is a parameter present, we should bring up an existing // Scriptlet to edit. String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "false"); request.setAttribute(NEXT_DISABLED, "false"); String id = request.getParameter(ID); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true; } else { isNew = false; } BaseActionForm dynaForm = (BaseActionForm) form; // server-side validation (validation.xml) ActionMessages errors = dynaForm.validate(mapping, request); if (errors != null && errors.size() > 0) { saveErrors(request, errors); // since we forward to jsp - not Action we don't need to repopulate // the lists here return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); Scriptlet scriptlet = new Scriptlet(); // get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); scriptlet.setSysUserId(sysUserId); // populate valueholder from form PropertyUtils.copyProperties(scriptlet, dynaForm); try { ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); if (!isNew) { // UPDATE scriptletDAO.updateData(scriptlet); } else { // INSERT scriptletDAO.insertData(scriptlet); } } catch (LIMSRuntimeException lre) { // bugzilla 2154 LogEvent.logError("ScriptletUpdateAction", "performAction()", lre.toString()); request.setAttribute(IActionConstants.REQUEST_FAILED, true); errors = new ActionMessages(); java.util.Locale locale = (java.util.Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE"); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { // how can I get popup instead of struts error at the top of // page? // ActionMessages errors = dynaForm.validate(mapping, request); error = new ActionError("errors.OptimisticLockException", null, null); } else { // bugzilla 1482 if (lre.getException() instanceof LIMSDuplicateRecordException) { String messageKey = "scriptlet.scriptletName"; String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey); error = new ActionError("errors.DuplicateRecord", msg, null); } else { error = new ActionError("errors.UpdateException", null, null); } } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); // bugzilla 1485: allow change and try updating again (enable save button) // request.setAttribute(IActionConstants.ALLOW_EDITS_KEY, "false"); // disable previous and next request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); forward = FWD_FAIL; } if (forward.equals(FWD_FAIL)) return mapping.findForward(forward); // initialize the form dynaForm.initialize(mapping); // repopulate the form from valueholder PropertyUtils.copyProperties(dynaForm, scriptlet); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (scriptlet.getId() != null && !scriptlet.getId().equals("0")) { request.setAttribute(ID, scriptlet.getId()); } // bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; // bugzilla 1467 added direction for redirect to NextPreviousAction return getForward(mapping.findForward(forward), scriptlet.getId(), start, direction); }
public String validateAndUpdateAnalyzerTestName( ActionMapping mapping, HttpServletRequest request, BaseActionForm dynaForm) { String forward = FWD_SUCCESS_INSERT; String analyzerId = dynaForm.getString("analyzerId"); String testId = dynaForm.getString("testId"); String analyzerTestName = dynaForm.getString("analyzerTestName"); boolean newMapping = "0".equals(request.getParameter("ID")); ActionMessages errors = new ActionMessages(); AnalyzerTestMapping analyzerTestNameMapping = validateAnalyzerAndTestName(analyzerId, analyzerTestName, testId, errors, newMapping); if (errors.size() > 0) { saveErrors(request, errors); return FWD_FAIL; } if (newMapping) { analyzerTestNameMapping = new AnalyzerTestMapping(); analyzerTestNameMapping.setAnalyzerId(analyzerId); analyzerTestNameMapping.setAnalyzerTestName(analyzerTestName); analyzerTestNameMapping.setTestId(testId); } AnalyzerTestMappingDAO mappingDAO = new AnalyzerTestMappingDAOImpl(); Transaction tx = HibernateUtil.getSession().beginTransaction(); try { if (newMapping) { mappingDAO.insertData(analyzerTestNameMapping, currentUserId); } else { mappingDAO.updateMapping(analyzerTestNameMapping, currentUserId); } } catch (LIMSRuntimeException lre) { tx.rollback(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { error = new ActionError("errors.UpdateException", null, null); } persisteError(request, error); disableNavigationButtons(request); forward = FWD_FAIL; } finally { if (!tx.wasRolledBack()) { tx.commit(); } HibernateUtil.closeSession(); } AnalyzerTestNameCache.instance().reloadCache(); return forward; }
protected ActionForward performAction( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new Sample. // If there is a parameter present, we should bring up an existing // Sample to edit. String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); String id = request.getParameter(ID); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true; } else { isNew = false; } BaseActionForm dynaForm = (BaseActionForm) form; // first get the accessionNumber and whether we are on blank page or not String accessionNumber = (String) dynaForm.get("accessionNumber"); // bugzilla 2154 LogEvent.logDebug( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "accessionNumber coming in: " + accessionNumber); String start = (String) request.getParameter("startingRecNo"); String typeOfSample = (String) dynaForm.get("typeOfSampleDesc"); String sourceOfSample = (String) dynaForm.get("sourceOfSampleDesc"); List typeOfSamples = new ArrayList(); List sourceOfSamples = new ArrayList(); if (dynaForm.get("typeOfSamples") != null) { typeOfSamples = (List) dynaForm.get("typeOfSamples"); } else { TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl(); typeOfSamples = typeOfSampleDAO.getAllTypeOfSamples(); } if (dynaForm.get("sourceOfSamples") != null) { sourceOfSamples = (List) dynaForm.get("sourceOfSamples"); } else { SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl(); sourceOfSamples = sourceOfSampleDAO.getAllSourceOfSamples(); } HashMap humanSampleOneMap = new HashMap(); if (dynaForm.get("humanSampleOneMap") != null) { humanSampleOneMap = (HashMap) dynaForm.get("humanSampleOneMap"); } String projectIdOrName = (String) dynaForm.get("projectIdOrName"); String project2IdOrName = (String) dynaForm.get("project2IdOrName"); String projectNameOrId = (String) dynaForm.get("projectNameOrId"); String project2NameOrId = (String) dynaForm.get("project2NameOrId"); String projectId = null; String project2Id = null; if (projectIdOrName != null && projectNameOrId != null) { try { Integer i = Integer.valueOf(projectIdOrName); projectId = projectIdOrName; } catch (NumberFormatException nfe) { // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", nfe.toString()); projectId = projectNameOrId; } } if (project2IdOrName != null && project2NameOrId != null) { try { Integer i = Integer.valueOf(project2IdOrName); project2Id = project2IdOrName; } catch (NumberFormatException nfe) { // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", nfe.toString()); project2Id = project2NameOrId; } } // bugzilla 2154 LogEvent.logDebug( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "ProjectId is: " + projectId + " Project2Id is: " + project2Id); // set current date for validation of dates Date today = Calendar.getInstance().getTime(); Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE"); String dateAsText = DateUtil.formatDateAsText(today, locale); Patient patient = new Patient(); Person person = new Person(); Provider provider = new Provider(); Person providerPerson = new Person(); Sample sample = new Sample(); SampleHuman sampleHuman = new SampleHuman(); SampleOrganization sampleOrganization = new SampleOrganization(); List sampleProjects = new ArrayList(); List updatedSampleProjects = new ArrayList(); SampleItem sampleItem = new SampleItem(); // TODO need to populate this with tests entered in HSE I List analyses = new ArrayList(); // tests are not handled in HSE II /* * String stringOfTestIds = (String) dynaForm.get("selectedTestIds"); * * String[] listOfTestIds = stringOfTestIds.split(SystemConfiguration * .getInstance().getDefaultIdSeparator(), -1); * * List analyses = new ArrayList(); for (int i = 0; i < * listOfTestIds.length; i++) { if * (!StringUtil.isNullorNill(listOfTestIds[i])) { Analysis analysis = * new Analysis(); analysis.setTestId(listOfTestIds[i]); // TODO: need * to populate this with actual data!!! * analysis.setAnalysisType("TEST"); analyses.add(analysis); } } */ ActionMessages errors = null; // validate on server-side sample accession number try { errors = new ActionMessages(); errors = validateAccessionNumber(request, errors, dynaForm); // System.out.println("Just validated accessionNumber"); } catch (Exception e) { // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", e.toString()); ActionError error = new ActionError("errors.ValidationException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } // System.out.println("This is errors after validation of accn Number " // + errors); if (errors != null && errors.size() > 0) { saveErrors(request, errors); // initialize the form but retain the invalid accessionNumber dynaForm.initialize(mapping); dynaForm.set("accessionNumber", accessionNumber); // repopulate lists PropertyUtils.setProperty(dynaForm, "typeOfSamples", typeOfSamples); PropertyUtils.setProperty(dynaForm, "sourceOfSamples", sourceOfSamples); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } // System.out.println("Now try to get data for accession number "); try { PatientDAO patientDAO = new PatientDAOImpl(); PersonDAO personDAO = new PersonDAOImpl(); ProviderDAO providerDAO = new ProviderDAOImpl(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl(); SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { sampleHuman.setSampleId(sample.getId()); sampleHumanDAO.getDataBySample(sampleHuman); sampleOrganization.setSampleId(sample.getId()); sampleOrganizationDAO.getDataBySample(sampleOrganization); // bugzilla 1773 need to store sample not sampleId for use in // sorting sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); patient.setId(sampleHuman.getPatientId()); patientDAO.getData(patient); person = patient.getPerson(); personDAO.getData(person); provider.setId(sampleHuman.getProviderId()); providerDAO.getData(provider); providerPerson = provider.getPerson(); personDAO.getData(providerPerson); // bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); humanSampleOneMap = populateHumanSampleOneMap( patient, person, provider, providerPerson, sample, sampleHuman, sampleOrganization, sampleItem, analyses); } } catch (LIMSRuntimeException lre) { // if error then forward to fail and don't update to blank page // = false // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", lre.toString()); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { // how can I get popup instead of struts error at the top of // page? // ActionMessages errors = dynaForm.validate(mapping, // request); error = new ActionError("errors.OptimisticLockException", null, null); // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "errors.OptimisticLockException"); } else { error = new ActionError("errors.GetException", null, null); // bugzilla 2154 LogEvent.logError( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "errors.GetException"); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } // initialize the form dynaForm.initialize(mapping); // set lastupdated fields dynaForm.set("lastupdated", sample.getLastupdated()); dynaForm.set("personLastupdated", person.getLastupdated()); dynaForm.set("patientLastupdated", patient.getLastupdated()); dynaForm.set("providerPersonLastupdated", providerPerson.getLastupdated()); dynaForm.set("providerLastupdated", provider.getLastupdated()); dynaForm.set("sampleItemLastupdated", sampleItem.getLastupdated()); dynaForm.set("sampleHumanLastupdated", sampleHuman.getLastupdated()); dynaForm.set("sampleOrganizationLastupdated", sampleOrganization.getLastupdated()); if (updatedSampleProjects != null && updatedSampleProjects.size() > 0) { if (updatedSampleProjects.size() == 1) { SampleProject sp = (SampleProject) updatedSampleProjects.get(0); dynaForm.set("sampleProject1Lastupdated", sp.getLastupdated()); // bugzilla 1857 deprecated stuff // System.out.println("This is sp ts " // + StringUtil.formatDateAsText(sp.getLastupdated(), // SystemConfiguration.getInstance() // .getDefaultLocale())); } if (updatedSampleProjects.size() == 2) { SampleProject sp2 = (SampleProject) updatedSampleProjects.get(1); dynaForm.set("sampleProject2Lastupdated", sp2.getLastupdated()); // bugzilla 1857 deprecated stuff // System.out.println("This is sp2 ts " // + StringUtil.formatDateAsText(sp2.getLastupdated(), // SystemConfiguration.getInstance() // .getDefaultLocale())); } } if (dynaForm.get("sampleProject1Lastupdated") == null) { PropertyUtils.setProperty( form, "sampleProject1Lastupdated", new Timestamp(System.currentTimeMillis())); } if (dynaForm.get("sampleProject2Lastupdated") == null) { PropertyUtils.setProperty( form, "sampleProject2Lastupdated", new Timestamp(System.currentTimeMillis())); } PropertyUtils.setProperty(dynaForm, "currentDate", dateAsText); PropertyUtils.setProperty(dynaForm, "accessionNumber", sample.getAccessionNumber()); // set receivedDate PropertyUtils.setProperty( dynaForm, "receivedDateForDisplay", (String) sample.getReceivedDateForDisplay()); PropertyUtils.setProperty(dynaForm, "typeOfSamples", typeOfSamples); PropertyUtils.setProperty(dynaForm, "sourceOfSamples", sourceOfSamples); PropertyUtils.setProperty(dynaForm, "humanSampleOneMap", humanSampleOneMap); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (sample.getId() != null && !sample.getId().equals("0")) { request.setAttribute(ID, sample.getId()); } if (forward.equals(FWD_SUCCESS)) { request.setAttribute("menuDefinition", "default"); } // bugzilla 2154 LogEvent.logDebug( "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "forwarding to: " + forward); // pdf - get accession number List if (SystemConfiguration.getInstance().getEnabledSamplePdf().equals(YES)) { String status = SystemConfiguration.getInstance().getSampleStatusEntry1Complete(); // status = 2 String humanDomain = SystemConfiguration.getInstance().getHumanDomain(); UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); List accessionNumberListTwo = userTestSectionDAO.getSamplePdfList(request, locale, status, humanDomain); PropertyUtils.setProperty(form, "accessionNumberListTwo", accessionNumberListTwo); } // return getForward(mapping.findForward(forward), id, start); return mapping.findForward(forward); }
/** * @param errors * @param request * @return * @throws Exception */ public int validarNumOrden(ActionMessages errors, HttpServletRequest request) throws Exception { ActionErrors errorsTemp = null; PropertyValidator validar = null; ArrayList estadosDetallesPedido = null; boolean[] autorizacionesIncorrectas = null; if (this.botonGuardarOrdenesCompra != null) { validar = new PropertyValidatorImpl(); autorizacionesIncorrectas = new boolean[this.numerosAutorizaciones.length]; LogSISPE.getLog().info("Valores arreglo boolean"); for (boolean a : autorizacionesIncorrectas) { LogSISPE.getLog().info("a1: {}", a); } for (int i = 0; i < this.numerosAutorizaciones.length; i++) { if (this.numerosAutorizaciones[i].equals("") && this.observacionesNumerosAutorizaciones[i].equals("") == false) { errors.add( "numerosAutorizaciones", new ActionMessage("errors.numeroAutorizacionOrdenCompraObligatorio")); autorizacionesIncorrectas[i] = true; } else if (this.numerosAutorizaciones[i].equals("") == false && this.observacionesNumerosAutorizaciones[i].equals("")) { errors.add( "observacionesNumerosAutorizaciones", new ActionMessage("errors.observacionAutorizacionOrdenCompraObligatorio")); autorizacionesIncorrectas[i] = true; } else { errorsTemp = new ActionErrors(); validar.validateFormato( errorsTemp, "numerosAutorizaciones", this.numerosAutorizaciones[i], false, "^(\\d)*$", "errors.formato.numeroAutorizacionOrdenCompra", "errors.requerido", "N\u00FAmero de autorizaci\u00F3n de orden de compra"); validar.validateFormato( errorsTemp, "observacionesNumerosAutorizaciones", this.observacionesNumerosAutorizaciones[i], false, "^(.){1,500}$", "errors.formato.observacionNumeroAutorizacionOrdenCompra", "errors.requerido", "Observación del abono"); if (errorsTemp.size() > 0) { autorizacionesIncorrectas[i] = true; for (Iterator j = errorsTemp.get(); j.hasNext(); ) { // LogSISPE.getLog().info("ClaseErrorsRegistroOrdenCompra: " + j.next().getClass()); errors.add("observacionesNumerosAutorizaciones", (ActionMessage) j.next()); } } } } if (errors.size() > 0) { if (request.getSession().getAttribute("ec.com.smx.sic.sispe.ordenCompra.detallesPedido") != null) { estadosDetallesPedido = (ArrayList) request .getSession() .getAttribute("ec.com.smx.sic.sispe.ordenCompra.detallesPedido"); for (int i = 0; i < this.getNumerosAutorizaciones().length; i++) { if (this.getNumerosAutorizaciones()[i].equals("") == false) { EstadoDetallePedidoDTO estadoDetallePedidoActual = (EstadoDetallePedidoDTO) estadosDetallesPedido.get(i); estadoDetallePedidoActual.setNumeroAutorizacionOrdenCompra( this.getNumerosAutorizaciones()[i]); estadoDetallePedidoActual.setObservacionAutorizacionOrdenCompra( this.getObservacionesNumerosAutorizaciones()[i]); estadoDetallePedidoActual.setNpNumeroAutorizacionOrdenCompraInCorrecto( autorizacionesIncorrectas[i]); } } } } } LogSISPE.getLog().info("numero de errores:{}", errors.size()); return errors.size(); }
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { SolverParamDefForm myForm = (SolverParamDefForm) form; // Check Access sessionContext.checkPermission(Right.SolverParameters); // Read operation to be performed String op = (myForm.getOp() != null ? myForm.getOp() : request.getParameter("op")); if (request.getParameter("op2") != null && request.getParameter("op2").length() > 0) op = request.getParameter("op2"); if (op == null) { myForm.reset(mapping, request); myForm.setVisible(Boolean.TRUE); } // Reset Form if ("Back".equals(op)) { if (myForm.getUniqueId() != null) request.setAttribute("hash", myForm.getUniqueId()); myForm.reset(mapping, request); myForm.setVisible(Boolean.TRUE); } if ("Add Solver Parameter".equals(op)) { myForm.reset(mapping, request); myForm.setVisible(Boolean.TRUE); myForm.setOp("Save"); myForm.setGroup(request.getParameter("group")); } // Add / Update if ("Update".equals(op) || "Save".equals(op)) { // Validate input ActionMessages errors = myForm.validate(mapping, request); if (errors.size() > 0) { saveErrors(request, errors); } else { Transaction tx = null; try { SolverParameterDefDAO dao = new SolverParameterDefDAO(); org.hibernate.Session hibSession = dao.getSession(); if (hibSession.getTransaction() == null || !hibSession.getTransaction().isActive()) tx = hibSession.beginTransaction(); SolverParameterDef def = null; if (op.equals("Save")) def = new SolverParameterDef(); else def = dao.get(myForm.getUniqueId(), hibSession); def.setName(myForm.getName()); def.setDescription(myForm.getDescription()); def.setDefault(myForm.getDefault()); def.setType(myForm.getType()); def.setVisible(myForm.getVisible()); SolverParameterGroup group = null; List groups = hibSession .createCriteria(SolverParameterGroup.class) .add(Restrictions.eq("name", myForm.getGroup())) .list(); if (!groups.isEmpty()) group = (SolverParameterGroup) groups.get(0); if (def.getGroup() != null && !def.getGroup().equals(group)) { List list = hibSession .createCriteria(SolverParameterDef.class) .add(Restrictions.eq("group", def.getGroup())) .add(Restrictions.gt("order", def.getOrder())) .list(); for (Iterator i = list.iterator(); i.hasNext(); ) { SolverParameterDef d = (SolverParameterDef) i.next(); d.setOrder(new Integer(d.getOrder().intValue() - 1)); dao.save(d, hibSession); } myForm.setOrder(-1); } if (myForm.getOrder() < 0) { def.setOrder(new Integer(group == null ? 0 : group.getParameters().size())); } def.setGroup(group); dao.saveOrUpdate(def, hibSession); if (tx != null) tx.commit(); hibSession.refresh(def); request.setAttribute("hash", def.getUniqueId().toString()); } catch (Exception e) { if (tx != null) tx.rollback(); Debug.error(e); } myForm.reset(mapping, request); myForm.setVisible(Boolean.TRUE); } } // Edit if (op.equals("Edit")) { String id = request.getParameter("id"); ActionMessages errors = new ActionMessages(); if (id == null || id.trim().length() == 0) { errors.add("key", new ActionMessage("errors.invalid", "Unique Id : " + id)); saveErrors(request, errors); } else { SolverParameterDefDAO dao = new SolverParameterDefDAO(); SolverParameterDef def = dao.get(new Long(id)); if (def == null) { errors.add("name", new ActionMessage("errors.invalid", "Unique Id : " + id)); saveErrors(request, errors); } else { myForm.setUniqueId(def.getUniqueId()); myForm.setName(def.getName()); myForm.setOrder(def.getOrder().intValue()); myForm.setDescription(def.getDescription()); myForm.setGroup(def.getGroup().getName()); myForm.setType(def.getType()); myForm.setDefault(def.getDefault()); myForm.setVisible(def.isVisible()); myForm.setOp("Update"); } } } // Delete if ("Delete".equals(op)) { Transaction tx = null; try { SolverParameterDefDAO dao = new SolverParameterDefDAO(); org.hibernate.Session hibSession = dao.getSession(); if (hibSession.getTransaction() == null || !hibSession.getTransaction().isActive()) tx = hibSession.beginTransaction(); SolverParameterDef def = dao.get(myForm.getUniqueId(), hibSession); List list = hibSession .createCriteria(SolverParameterDef.class) .add(Restrictions.eq("group", def.getGroup())) .add(Restrictions.gt("order", def.getOrder())) .list(); for (Iterator i = list.iterator(); i.hasNext(); ) { SolverParameterDef d = (SolverParameterDef) i.next(); d.setOrder(new Integer(d.getOrder().intValue() - 1)); dao.save(d, hibSession); } dao.delete(def, hibSession); if (tx != null) tx.commit(); } catch (Exception e) { if (tx != null) tx.rollback(); Debug.error(e); } if (myForm.getGroup() != null) request.setAttribute("hash", myForm.getGroup()); myForm.reset(mapping, request); myForm.setVisible(Boolean.TRUE); } // Move Up or Down if ("Move Up".equals(op) || "Move Down".equals(op)) { Transaction tx = null; try { SolverParameterDefDAO dao = new SolverParameterDefDAO(); org.hibernate.Session hibSession = dao.getSession(); if (hibSession.getTransaction() == null || !hibSession.getTransaction().isActive()) tx = hibSession.beginTransaction(); SolverParameterDef def = dao.get(myForm.getUniqueId(), hibSession); if ("Move Up".equals(op)) { List list = hibSession .createCriteria(SolverParameterDef.class) .add(Restrictions.eq("group", def.getGroup())) .add(Restrictions.eq("order", new Integer(def.getOrder().intValue() - 1))) .list(); if (!list.isEmpty()) { SolverParameterDef prior = (SolverParameterDef) list.get(0); prior.setOrder(new Integer(prior.getOrder().intValue() + 1)); dao.save(prior, hibSession); def.setOrder(new Integer(def.getOrder().intValue() - 1)); dao.save(def, hibSession); } } else { List list = hibSession .createCriteria(SolverParameterDef.class) .add(Restrictions.eq("group", def.getGroup())) .add(Restrictions.eq("order", new Integer(def.getOrder().intValue() + 1))) .list(); if (!list.isEmpty()) { SolverParameterDef next = (SolverParameterDef) list.get(0); next.setOrder(new Integer(next.getOrder().intValue() - 1)); dao.save(next, hibSession); def.setOrder(new Integer(def.getOrder().intValue() + 1)); dao.save(def, hibSession); } } myForm.setOrder(def.getOrder().intValue()); if (myForm.getUniqueId() != null) request.setAttribute("hash", myForm.getUniqueId()); if (tx != null) tx.commit(); } catch (Exception e) { if (tx != null) tx.rollback(); Debug.error(e); } } if ("List".equals(myForm.getOp())) { // Read all existing settings and store in request getSolverParameterDefs(request, myForm.getUniqueId()); return mapping.findForward("list"); } return mapping.findForward("Save".equals(myForm.getOp()) ? "add" : "edit"); }