List of usage examples for java.util ArrayList set
public E set(int index, E element)
From source file:com.mimp.hibernate.HiberNna.java
public ArrayList<Nna> ListaNnaPrioritarios(String clasificacion) { Session session = sessionFactory.getCurrentSession(); final String clasif = clasificacion; final ArrayList<Nna> allNna = new ArrayList(); final ArrayList<Nna> allNnaAux = new ArrayList(); final ArrayList<Nna> allNnaFinal = new ArrayList(); Work work = new Work() { @Override/*w w w . j av a 2 s. co m*/ public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; Nna tempnna; Designacion desig; EstudioCaso est; String hql = "{call HN_GET_NNA_PRIO(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp = (ResultSet) statement.getObject(1); while (temp.next()) { tempnna = new Nna(); tempnna.setIdnna(temp.getLong(1)); tempnna.setNombre(temp.getString(2)); tempnna.setApellidoP(temp.getString(3)); tempnna.setApellidoM(temp.getString(4)); tempnna.setSexo(temp.getString(5)); tempnna.setFechaNacimiento(temp.getDate(6)); tempnna.setEdadAnhos(temp.getShort(7)); tempnna.setEdadMeses(temp.getShort(8)); tempnna.setActaNacimiento(temp.getShort(9)); tempnna.setCondicionSalud(temp.getString(10)); tempnna.setDepartamentoNacimiento(temp.getString(11)); tempnna.setProvinciaNacimiento(temp.getString(12)); tempnna.setDistritoNacimiento(temp.getString(13)); tempnna.setPaisNacimiento(temp.getString(14)); tempnna.setLugarNac(temp.getString(15)); tempnna.setFechaResolAbandono(temp.getDate(16)); tempnna.setFechaResolConsentida(temp.getDate(17)); tempnna.setClasificacion(temp.getString(18)); tempnna.setIncesto(temp.getShort(19)); tempnna.setMental(temp.getShort(20)); tempnna.setEpilepsia(temp.getShort(21)); tempnna.setAbuso(temp.getShort(22)); tempnna.setSifilis(temp.getShort(23)); tempnna.setSeguiMedico(temp.getShort(24)); tempnna.setOperacion(temp.getShort(25)); tempnna.setHiperactivo(temp.getShort(26)); tempnna.setEspecial(temp.getShort(27)); tempnna.setEnfermo(temp.getShort(28)); tempnna.setMayor(temp.getShort(29)); tempnna.setAdolescente(temp.getShort(30)); tempnna.setHermano(temp.getShort(31)); tempnna.setNn(temp.getShort(32)); tempnna.setObservaciones(temp.getString(33)); tempnna.setNResolAband(temp.getString(34)); tempnna.setNResolCons(temp.getString(35)); try { expnna = getExpNna(temp.getLong(1)); if (expnna.getIdexpedienteNna() != 0) { Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>(); listexp.add(expnna); tempnna.setExpedienteNnas(listexp); } } catch (Exception e) { } allNnaAux.add(tempnna); } statement.close(); temp.close(); //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO for (Nna auxnna : allNnaAux) { Set<Designacion> listDesig = new HashSet<Designacion>(); String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, auxnna.getIdnna()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { desig = new Designacion(); desig.setIddesignacion(rs2.getLong(1)); desig.setNDesignacion(rs2.getString(5)); desig.setPrioridad(rs2.getLong(6)); desig.setFechaPropuesta(rs2.getDate(7)); desig.setFechaConsejo(rs2.getDate(8)); desig.setAceptacionConsejo(rs2.getShort(9)); desig.setTipoPropuesta(rs2.getString(10)); desig.setObs(rs2.getString(11)); listDesig.add(desig); } auxnna.setDesignacions(listDesig); allNna.add(auxnna); statement2.close(); rs2.close(); } for (Nna auxnna : allNna) { if (auxnna.getClasificacion().equals("prioritario")) { Set<EstudioCaso> listEst = new HashSet<EstudioCaso>(); String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, auxnna.getIdnna()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); while (rs3.next()) { est = new EstudioCaso(); est.setIdestudioCaso(rs3.getLong(1)); est.setOrden(rs3.getString(4)); est.setFechaEstudio(rs3.getDate(5)); est.setFechaSolAdop(rs3.getDate(6)); est.setResultado(rs3.getString(7)); est.setPrioridad(rs3.getLong(8)); est.setNSolicitud(rs3.getLong(9)); listEst.add(est); } auxnna.setEstudioCasos(listEst); statement3.close(); rs3.close(); } allNnaFinal.add(auxnna); } //METODO BUBBLESORT PARA ORDENAR POR CODIGO if (clasif.equals("prioritario")) { Nna auxnna2; int n = allNnaFinal.size(); for (int i = 0; i < n - 1; i++) { for (int j = i; j < n - 1; j++) { if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) { if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } else { String apellidoPrev = ""; String apellidoNext = ""; try { apellidoPrev = allNnaFinal.get(i).getApellidoP(); if (apellidoPrev == null) { apellidoPrev = ""; } } catch (Exception ex) { apellidoPrev = ""; } try { apellidoNext = allNnaFinal.get(j + 1).getApellidoP(); if (apellidoNext == null) { apellidoNext = ""; } } catch (Exception ex) { apellidoNext = ""; } if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } } } else { Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas(); Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas(); if (!listExp2.isEmpty()) { for (ExpedienteNna exp1 : listExp1) { for (ExpedienteNna exp2 : listExp2) { String codant = exp1.getCodigoReferencia(); String codpost = exp2.getCodigoReferencia(); if (codant == null) { codant = ""; } if (codpost == null) { codpost = ""; } if (codant.compareToIgnoreCase(codpost) > 0) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } } } } } } } } } }; session.doWork(work); return allNnaFinal; }
From source file:com.mimp.hibernate.HiberNna.java
public ArrayList<Nna> ListaNna(String clasificacion) { Session session = sessionFactory.getCurrentSession(); final String clasif = clasificacion; final ArrayList<Nna> allNna = new ArrayList(); final ArrayList<Nna> allNnaAux = new ArrayList(); final ArrayList<Nna> allNnaFinal = new ArrayList(); Work work = new Work() { @Override//from w w w. j a v a 2 s . c o m public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; Nna tempnna; Designacion desig; EstudioCaso est; String hql = "{call HN_GET_NNA_CLAS(?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setString(1, clasif); statement.registerOutParameter(2, OracleTypes.CURSOR); statement.execute(); temp = (ResultSet) statement.getObject(2); while (temp.next()) { tempnna = new Nna(); tempnna.setIdnna(temp.getLong(1)); tempnna.setNombre(temp.getString(2)); tempnna.setApellidoP(temp.getString(3)); tempnna.setApellidoM(temp.getString(4)); tempnna.setSexo(temp.getString(5)); tempnna.setFechaNacimiento(temp.getDate(6)); tempnna.setEdadAnhos(temp.getShort(7)); tempnna.setEdadMeses(temp.getShort(8)); tempnna.setActaNacimiento(temp.getShort(9)); tempnna.setCondicionSalud(temp.getString(10)); tempnna.setDepartamentoNacimiento(temp.getString(11)); tempnna.setProvinciaNacimiento(temp.getString(12)); tempnna.setDistritoNacimiento(temp.getString(13)); tempnna.setPaisNacimiento(temp.getString(14)); tempnna.setLugarNac(temp.getString(15)); tempnna.setFechaResolAbandono(temp.getDate(16)); tempnna.setFechaResolConsentida(temp.getDate(17)); tempnna.setClasificacion(temp.getString(18)); tempnna.setIncesto(temp.getShort(19)); tempnna.setMental(temp.getShort(20)); tempnna.setEpilepsia(temp.getShort(21)); tempnna.setAbuso(temp.getShort(22)); tempnna.setSifilis(temp.getShort(23)); tempnna.setSeguiMedico(temp.getShort(24)); tempnna.setOperacion(temp.getShort(25)); tempnna.setHiperactivo(temp.getShort(26)); tempnna.setEspecial(temp.getShort(27)); tempnna.setEnfermo(temp.getShort(28)); tempnna.setMayor(temp.getShort(29)); tempnna.setAdolescente(temp.getShort(30)); tempnna.setHermano(temp.getShort(31)); tempnna.setNn(temp.getShort(32)); tempnna.setObservaciones(temp.getString(33)); tempnna.setNResolAband(temp.getString(34)); tempnna.setNResolCons(temp.getString(35)); try { expnna = getExpNna(temp.getLong(1)); if (expnna.getIdexpedienteNna() != 0) { Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>(); listexp.add(expnna); tempnna.setExpedienteNnas(listexp); } } catch (Exception e) { } allNnaAux.add(tempnna); } statement.close(); temp.close(); //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO for (Nna auxnna : allNnaAux) { Set<Designacion> listDesig = new HashSet<Designacion>(); String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, auxnna.getIdnna()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { desig = new Designacion(); desig.setIddesignacion(rs2.getLong(1)); desig.setNDesignacion(rs2.getString(5)); desig.setPrioridad(rs2.getLong(6)); desig.setFechaPropuesta(rs2.getDate(7)); desig.setFechaConsejo(rs2.getDate(8)); desig.setAceptacionConsejo(rs2.getShort(9)); desig.setTipoPropuesta(rs2.getString(10)); desig.setObs(rs2.getString(11)); listDesig.add(desig); } auxnna.setDesignacions(listDesig); allNna.add(auxnna); statement2.close(); rs2.close(); } for (Nna auxnna : allNna) { if (auxnna.getClasificacion().equals("prioritario")) { Set<EstudioCaso> listEst = new HashSet<EstudioCaso>(); String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, auxnna.getIdnna()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); while (rs3.next()) { est = new EstudioCaso(); est.setIdestudioCaso(rs3.getLong(1)); est.setOrden(rs3.getString(4)); est.setFechaEstudio(rs3.getDate(5)); est.setFechaSolAdop(rs3.getDate(6)); est.setResultado(rs3.getString(7)); est.setPrioridad(rs3.getLong(8)); est.setNSolicitud(rs3.getLong(9)); listEst.add(est); } auxnna.setEstudioCasos(listEst); statement3.close(); rs3.close(); } allNnaFinal.add(auxnna); } //METODO BUBBLESORT PARA ORDENAR POR CODIGO if (clasif.equals("prioritario")) { Nna auxnna2; int n = allNnaFinal.size(); for (int i = 0; i < n - 1; i++) { for (int j = i; j < n - 1; j++) { if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) { if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } else { String apellidoPrev = ""; String apellidoNext = ""; try { apellidoPrev = allNnaFinal.get(i).getApellidoP(); if (apellidoPrev == null) { apellidoPrev = ""; } } catch (Exception ex) { apellidoPrev = ""; } try { apellidoNext = allNnaFinal.get(j + 1).getApellidoP(); if (apellidoNext == null) { apellidoNext = ""; } } catch (Exception ex) { apellidoNext = ""; } if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } } } else { Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas(); Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas(); if (!listExp2.isEmpty()) { for (ExpedienteNna exp1 : listExp1) { for (ExpedienteNna exp2 : listExp2) { String codant = exp1.getCodigoReferencia(); String codpost = exp2.getCodigoReferencia(); if (codant == null) { codant = ""; } if (codpost == null) { codpost = ""; } if (codant.compareToIgnoreCase(codpost) > 0) { auxnna2 = allNnaFinal.get(i); allNnaFinal.set(i, allNnaFinal.get(j + 1)); allNnaFinal.set(j + 1, auxnna2); } } } } } } } } } }; session.doWork(work); return allNnaFinal; }
From source file:org.akaza.openclinica.control.submit.DataEntryServlet.java
@Override protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { //JN:The following were the the global variables, moved as local. locale = LocaleResolver.getLocale(request); EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF); SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN); ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale); HttpSession session = request.getSession(); StudyBean currentStudy = (StudyBean) session.getAttribute("study"); StudyUserRoleBean currentRole = (StudyUserRoleBean) session.getAttribute("userRole"); SectionDAO sdao = new SectionDAO(getDataSource()); /**/*ww w . j a v a 2 s . c om*/ * Determines whether the form was submitted. Calculated once in processRequest. The reason we don't use the normal means to determine if the form was * submitted (ie FormProcessor.isSubmitted) is because when we use forwardPage, Java confuses the inputs from the just-processed form with the inputs for * the forwarded-to page. This is a problem since frequently we're forwarding from one (submitted) section to the next (unsubmitted) section. If we use the * normal means, Java will always think that the unsubmitted section is, in fact, submitted. This member is guaranteed to be calculated before * shouldLoadDBValues() is called. */ boolean isSubmitted = false; boolean hasGroup = false; EventCRFDAO ecdao = null; FormProcessor fp = new FormProcessor(request); logMe("Enterting DataEntry Servlet" + System.currentTimeMillis()); EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource()); FormDiscrepancyNotes discNotes; panel.setStudyInfoShown(false); String age = ""; UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME); String instantAtt = CV_INSTANT_META + ecb.getCRFVersionId(); //for 11958: repeating groups rows appear if validation returns to the same section int isFirstTimeOnSection = fp.getInt("isFirstTimeOnSection"); request.setAttribute("isFirstTimeOnSection", isFirstTimeOnSection + ""); if (fp.getString(GO_EXIT).equals("") && !isSubmitted && fp.getString("tabId").equals("") && fp.getString("sectionId").equals("")) { //HashMap unavailableCRF = getUnavailableCRFList(); if (getCrfLocker().isLocked(ecb.getId())) { int userId = getCrfLocker().getLockOwner(ecb.getId()); UserAccountDAO udao = new UserAccountDAO(getDataSource()); UserAccountBean ubean = (UserAccountBean) udao.findByPK(userId); addPageMessage(resword.getString("CRF_unavailable") + " " + ubean.getName() + " " + resword.getString("Currently_entering_data") + " " + resword.getString("Leave_the_CRF"), request); forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response); } else { getCrfLocker().lock(ecb.getId(), ub.getId()); } } if (!ecb.isActive()) { throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("event_not_exists")); } logMe("Enterting DataEntry Get the status/number of item discrepancy notes" + System.currentTimeMillis()); // Get the status/number of item discrepancy notes DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource()); ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>(); List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>(); List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>(); // BWP: this try block is not necessary try { dndao = new DiscrepancyNoteDAO(getDataSource()); allNotes = dndao.findAllTopNotesByEventCRF(ecb.getId()); eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb); if (!eventCrfNotes.isEmpty()) { allNotes.addAll(eventCrfNotes); } logMe("Entering DataEntry Create disc note threads out of the various notes" + System.currentTimeMillis()); // Create disc note threads out of the various notes DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil(); noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true); // variables that provide values for the CRF discrepancy note header int updatedNum = 0; int openNum = 0; int closedNum = 0; int resolvedNum = 0; int notAppNum = 0; DiscrepancyNoteBean tempBean; for (DiscrepancyNoteThread dnThread : noteThreads) { /* * 3014: do not count parent beans, only the last child disc note of the thread. */ tempBean = dnThread.getLinkedNoteList().getLast(); if (tempBean != null) { if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) { updatedNum++; } else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) { openNum++; } else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) { // if (dn.getParentDnId() > 0){ closedNum++; // } } else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) { // if (dn.getParentDnId() > 0){ resolvedNum++; // } } else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) { notAppNum++; } } } logMe("Entering DataEntry Create disc note threads out of the various notes DONE" + System.currentTimeMillis()); request.setAttribute("updatedNum", updatedNum + ""); request.setAttribute("openNum", openNum + ""); request.setAttribute("closedNum", closedNum + ""); request.setAttribute("resolvedNum", resolvedNum + ""); request.setAttribute("notAppNum", notAppNum + ""); String fromViewNotes = fp.getString("fromViewNotes"); if (fromViewNotes != null && "1".equals(fromViewNotes)) { request.setAttribute("fromViewNotes", fromViewNotes); } logMe("Entering Create studySubjDao.. ++++stuff" + System.currentTimeMillis()); StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource()); StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId()); // YW 11-07-2007, data entry could not be performed if its study subject // has been removed. // Notice: ViewSectionDataEntryServelet, ViewSectionDataEntryPreview, // PrintCRFServlet and PrintDataEntryServlet, have theirs own // processRequest Status s = ssb.getStatus(); if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) { addPageMessage(respage.getString("you_may_not_perform_data_entry_on_a_CRF") + respage.getString("study_subject_has_been_deleted"), request); request.setAttribute("id", new Integer(ecb.getStudySubjectId()).toString()); session.removeAttribute(instantAtt); forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response); } // YW >> HashMap<String, String> newUploadedFiles = (HashMap<String, String>) session .getAttribute("newUploadedFiles"); if (newUploadedFiles == null) { newUploadedFiles = new HashMap<String, String>(); } request.setAttribute("newUploadedFiles", newUploadedFiles); if (!fp.getString("exitTo").equals("")) { request.setAttribute("exitTo", fp.getString("exitTo")); } //some EVENT CRF CHECK logMe("Entering some EVENT CRF CHECK" + System.currentTimeMillis()); if (!fp.getString(GO_EXIT).equals("")) { session.removeAttribute(GROUP_HAS_DATA); session.removeAttribute("to_create_crf"); session.removeAttribute("mayProcessUploading"); //Removing the user and EventCRF from the locked CRF List getCrfLocker().unlock(ecb.getId()); if (newUploadedFiles.size() > 0) { if (this.unloadFiles(newUploadedFiles)) { } else { String missed = ""; Iterator iter = newUploadedFiles.keySet().iterator(); while (iter.hasNext()) { missed += " " + newUploadedFiles.get(iter.next()); } addPageMessage(respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request); } } session.removeAttribute("newUploadedFiles"); addPageMessage(respage.getString("exit_without_saving"), request); // addPageMessage("You chose to exit the data entry page."); // changed bu jxu 03/06/2007- we should use redirection to go to // another servlet if (fromViewNotes != null && "1".equals(fromViewNotes)) { String viewNotesURL = (String) session.getAttribute("viewNotesURL"); if (viewNotesURL != null && viewNotesURL.length() > 0) { response.sendRedirect(response.encodeRedirectURL(viewNotesURL)); } return; } String fromResolvingNotes = fp.getString("fromResolvingNotes", true); String winLocation = (String) session.getAttribute(ViewNotesServlet.WIN_LOCATION); session.removeAttribute(instantAtt); if (!StringUtil.isBlank(fromResolvingNotes) && !StringUtil.isBlank(winLocation)) { response.sendRedirect(response.encodeRedirectURL(winLocation)); } else { if (!fp.getString("exitTo").equals("")) { response.sendRedirect(response.encodeRedirectURL(fp.getString("exitTo"))); } else response.sendRedirect(response.encodeRedirectURL("ListStudySubjects")); } // forwardPage(Page.SUBMIT_DATA_SERVLET); return; } logMe("Entering some EVENT CRF CHECK DONE" + System.currentTimeMillis()); // checks if the section has items in item group // for repeating items // hasGroup = getInputBeans(); hasGroup = checkGroups(fp, ecb); Boolean b = (Boolean) request.getAttribute(INPUT_IGNORE_PARAMETERS); isSubmitted = fp.isSubmitted() && b == null; // variable is used for fetching any null values like "not applicable" int eventDefinitionCRFId = 0; if (fp != null) { eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId"); } StudyBean study = (StudyBean) session.getAttribute("study"); // constructs the list of items used on UI // tbh>> // logger.trace("trying event def crf id: "+eventDefinitionCRFId); logMe("Entering some EVENT DEF CRF CHECK " + System.currentTimeMillis()); if (eventDefinitionCRFId <= 0) { // TODO we have to get that id before we can continue EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId()); eventDefinitionCRFId = edcBean.getId(); } logMe("Entering some EVENT DEF CRF CHECK DONE " + System.currentTimeMillis()); logMe("Entering some Study EVENT DEF CRF CHECK " + System.currentTimeMillis()); StudyEventDAO seDao = new StudyEventDAO(getDataSource()); EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcdao.findByPK(eventDefinitionCRFId); EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) edcdao.findByPK(eventDefinitionCRFId); request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);//JN:Putting the event_def_crf_bean in the request attribute. StudyEventBean studyEventBean = (StudyEventBean) seDao.findByPK(ecb.getStudyEventId()); edcBean.setId(eventDefinitionCRFId); StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource()); StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) seddao .findByPK(edcBean.getStudyEventDefinitionId()); CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource()); CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId()); Phase phase2 = Phase.INITIAL_DATA_ENTRY; if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) { phase2 = Phase.DOUBLE_DATA_ENTRY; } else if (getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET)) { phase2 = Phase.ADMIN_EDITING; } logMe("Entering ruleSets::: CreateAndInitializeRuleSet:::" + Thread.currentThread()); logMe("Entering ruleSets::: CreateAndInitializeRuleSet:::" + Thread.currentThread() + "currentStudy?" + currentStudy + "studyEventDefinition" + studyEventDefinition + "crfVersionBean" + crfVersionBean + "studyEventBean" + studyEventBean + "ecb" + ecb); // List<RuleSetBean> ruleSets = createAndInitializeRuleSet(currentStudy, studyEventDefinition, crfVersionBean, studyEventBean, ecb, true, request, response); // boolean shouldRunRules = getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets, phase2); logMe("Entering getDisplayBean:::::Thread::::" + Thread.currentThread()); DisplaySectionBean section = getDisplayBean(hasGroup, false, request, isSubmitted); //hasSCDItem has been initialized in getDisplayBean() which is online above VariableSubstitutionHelper.replaceVariables(section, study, ssb, studyEventDefinition, studyEventBean, dataSource); if (section.getSection().hasSCDItem()) { SimpleConditionalDisplayService cds0 = (SimpleConditionalDisplayService) SpringServletAccess .getApplicationContext(getServletContext()).getBean("simpleConditionalDisplayService"); section = cds0.initConditionalDisplays(section); } logMe("Entering Find out the id of the section's first field " + System.currentTimeMillis()); // 2790: Find out the id of the section's first field String firstFieldId = getSectionFirstFieldId(section.getSection().getId()); request.setAttribute("formFirstField", firstFieldId); // logger.trace("now trying event def crf id: "+eventDefinitionCRFId); // above is necessary to give us null values during DDE // ironically, this only covers vertical null value result sets // horizontal ones are covered in FormBeanUtil, tbh 112007 logMe("Entering displayItemWithGroups " + System.currentTimeMillis()); //@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method createItemWithGroups List<DisplayItemWithGroupBean> displayItemWithGroups = createItemWithGroups(section, hasGroup, eventDefinitionCRFId, request, isSubmitted); logMe("Entering displayItemWithGroups end " + System.currentTimeMillis()); this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups, section.getSection().getId(), ecb); section.setDisplayItemGroups(displayItemWithGroups); DisplayTableOfContentsBean toc = TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY), (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()) .getBean("dynamicsMetadataService")); request.setAttribute(TOC_DISPLAY, toc); LinkedList<Integer> sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc); // why do we get previousSec and nextSec here, rather than in // getDisplayBeans? // so that we can use them in forwarding the user to the previous/next // section // if the validation was successful logMe("Entering displayItemWithGroups sdao.findPrevious " + System.currentTimeMillis()); int sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc); SectionBean previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex); logMe("Entering displayItemWithGroups sdao.findPrevious end " + System.currentTimeMillis()); SectionBean nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex); section.setFirstSection(!previousSec.isActive()); section.setLastSection(!nextSec.isActive()); // this is for generating side info panel // and the information panel under the Title SubjectDAO subjectDao = new SubjectDAO(getDataSource()); StudyDAO studydao = new StudyDAO(getDataSource()); SubjectBean subject = (SubjectBean) subjectDao.findByPK(ssb.getSubjectId()); // Get the study then the parent study logMe("Entering Get the study then the parent study " + System.currentTimeMillis()); if (study.getParentStudyId() > 0) { // this is a site,find parent StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId()); request.setAttribute("studyTitle", parentStudy.getName()); request.setAttribute("siteTitle", study.getName()); } else { request.setAttribute("studyTitle", study.getName()); } logMe("Entering Get the study then the parent study end " + System.currentTimeMillis()); // Let us process the age if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) { // YW 11-16-2007 erollment-date is used for calculating age. Date enrollmentDate = ssb.getEnrollmentDate(); age = Utils.getInstacne().processAge(enrollmentDate, subject.getDateOfBirth()); } //ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(ssb, getDataSource(), ub, currentRole); request.setAttribute("studySubject", ssb); request.setAttribute("subject", subject); //request.setAttribute("beans", beans); request.setAttribute("eventCRF", ecb); request.setAttribute("age", age); request.setAttribute("decryptedPassword", ((SecurityManager) SpringServletAccess.getApplicationContext(getServletContext()) .getBean("securityManager")).encrytPassword("root", getUserDetails())); // set up interviewer name and date fp.addPresetValue(INPUT_INTERVIEWER, ecb.getInterviewerName()); if (ecb.getDateInterviewed() != null) { DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale()); String idateFormatted = local_df.format(ecb.getDateInterviewed()); fp.addPresetValue(INPUT_INTERVIEW_DATE, idateFormatted); } else { fp.addPresetValue(INPUT_INTERVIEW_DATE, ""); } setPresetValues(fp.getPresetValues(), request); logMe("Entering Checks !submitted " + System.currentTimeMillis()); if (!isSubmitted) { // TODO: prevent data enterer from seeing results of first round of // data // entry, if this is second round // FLAG--SLOW HERE WHEN LOADING logMe("Entering Checks !submitted entered " + System.currentTimeMillis()); long t = System.currentTimeMillis(); request.setAttribute(BEAN_DISPLAY, section); request.setAttribute(BEAN_ANNOTATIONS, getEventCRFAnnotations(request)); session.setAttribute("shouldRunValidation", null); session.setAttribute("rulesErrors", null); session.setAttribute(DataEntryServlet.NOTE_SUBMITTED, null); discNotes = new FormDiscrepancyNotes(); // discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME); // if (discNotes == null) { // discNotes = new FormDiscrepancyNotes(); // } // << tbh 01/2010 section = populateNotesWithDBNoteCounts(discNotes, section, request); populateInstantOnChange(request.getSession(), ecb, section); LOGGER.debug( "+++ just ran populateNotes, printing field notes: " + discNotes.getFieldNotes().toString()); LOGGER.debug("found disc notes: " + discNotes.getNumExistingFieldNotes().toString()); session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes); if (section.getSection().hasSCDItem()) { section = SCDItemDisplayInfo.generateSCDDisplayInfo(section, this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request)); } int keyId = ecb.getId(); session.removeAttribute(DoubleDataEntryServlet.COUNT_VALIDATE + keyId); setUpPanel(section); if (newUploadedFiles.size() > 0) { if (this.unloadFiles(newUploadedFiles)) { } else { String missed = ""; Iterator iter = newUploadedFiles.keySet().iterator(); while (iter.hasNext()) { missed += " " + newUploadedFiles.get(iter.next()); } addPageMessage(respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request); } } logMe("Entering Checks !submitted entered end forwarding page " + System.currentTimeMillis()); logMe("Time Took for this block" + (System.currentTimeMillis() - t)); forwardPage(getJSPPage(), request, response); return; } else { logMe("Entering Checks !submitted not entered " + System.currentTimeMillis()); // // VALIDATION / LOADING DATA // // If validation is required for this round, we will go through // each item and add an appropriate validation to the Validator // // Otherwise, we will just load the data into the DisplayItemBean // so that we can write to the database later. // // Validation is required if two conditions are met: // 1. The user clicked a "Save" button, not a "Confirm" button // 2. In this type of data entry servlet, when the user clicks // a Save button, the inputs are validated // boolean validate = fp.getBoolean(INPUT_CHECK_INPUTS) && validateInputOnFirstRound(); // did the user click a "Save" button? // is validation required in this type of servlet when the user // clicks // "Save"? // We can conclude that the user is trying to save data; therefore, // set a request // attribute indicating that default values for items shouldn't be // displayed // in the application UI that will subsequently be displayed // TODO: find a better, less random place for this // session.setAttribute(HAS_DATA_FLAG, true); // section.setCheckInputs(fp.getBoolean(INPUT_CHECK_INPUTS)); errors = new HashMap(); // ArrayList items = section.getItems(); discNotes = (FormDiscrepancyNotes) session .getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME); if (discNotes == null) { discNotes = new FormDiscrepancyNotes(); } // populateNotesWithDBNoteCounts(discNotes, section); // all items- inlcude items in item groups and other single items List<DisplayItemWithGroupBean> allItems = section.getDisplayItemGroups(); String attachedFilePath = Utils.getAttachedFilePath(currentStudy); DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes); RuleValidator ruleValidator = new RuleValidator(request); LOGGER.debug("SZE 1 :: " + allItems.size()); logMe("Looping inside !submitted " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); i++) { LOGGER.trace("===itering through items: " + i); DisplayItemWithGroupBean diwg = allItems.get(i); if (diwg.isInGroup()) { // for the items in groups DisplayItemGroupBean dgb = diwg.getItemGroup(); List<DisplayItemGroupBean> dbGroups = diwg.getDbItemGroups(); //dbGroups = diwg.getItemGroups(); List<DisplayItemGroupBean> formGroups = new ArrayList<DisplayItemGroupBean>(); LOGGER.debug("got db item group size " + dbGroups.size()); if (validate) { // int manualGroups = getManualRows(dbGroups2); // logger.debug("+++ found manual rows from db group 2: " + manualGroups); LOGGER.debug("===IF VALIDATE NOT A SINGLE ITEM: got to this part in the validation loop: " + dgb.getGroupMetaBean().getName()); // TODO next marker tbh 112007 // formGroups = validateDisplayItemGroupBean(v, // dgb,dbGroups, formGroups, // ruleValidator,groupOrdinalPLusItemOid); formGroups = validateDisplayItemGroupBean(v, dgb, dbGroups, formGroups, request, response); LOGGER.debug("form group size after validation " + formGroups.size()); } else { LOGGER.debug("+++ELSE NOT A SINGLE ITEM: got to this part in the validation loop: " + dgb.getGroupMetaBean().getName()); formGroups = loadFormValueForItemGroup(dgb, dbGroups, formGroups, eventDefinitionCRFId, request); LOGGER.debug("form group size without validation " + formGroups.size()); } diwg.setItemGroup(dgb); diwg.setItemGroups(formGroups); allItems.set(i, diwg); } else {// other single items DisplayItemBean dib = diwg.getSingleItem(); // dib = (DisplayItemBean) allItems.get(i); if (validate) { // generate input name here? // DisplayItemGroupBean dgb = diwg.getItemGroup(); String itemName = getInputName(dib); // no Item group for single item, so just use blank // string as parameter for inputName dib = validateDisplayItemBean(v, dib, "", request);// this // should be // used, // otherwise, // DDE not // working-jxu LOGGER.debug("&&& found name: " + itemName); LOGGER.debug("input VALIDATE " + itemName + ": " + fp.getString(itemName)); // dib.loadFormValue(fp.getString(itemName)); LOGGER.debug("input " + itemName + " has a response set of " + dib.getMetadata().getResponseSet().getOptions().size() + " options"); } else { String itemName = getInputName(dib); LOGGER.debug("input NONVALIDATE " + itemName + ": " + fp.getString(itemName)); // dib.loadFormValue(itemName); dib = loadFormValue(dib, request); // String itemName = getInputName(dib); // dib = loadFormValue(itemName); } ArrayList children = dib.getChildren(); for (int j = 0; j < children.size(); j++) { DisplayItemBean child = (DisplayItemBean) children.get(j); // DisplayItemGroupBean dgb = diwg.getItemGroup(); String itemName = getInputName(child); child.loadFormValue(fp.getString(itemName)); if (validate) { // child = validateDisplayItemBean(v, child, // itemName, ruleValidator, groupOrdinalPLusItemOid, // false); child = validateDisplayItemBean(v, child, itemName, request); // was null changed value 092007 tbh } else { // child.loadFormValue(itemName); child = loadFormValue(child, request); } LOGGER.debug("Checking child value for " + itemName + ": " + child.getData().getValue()); children.set(j, child); } dib.setChildren(children); diwg.setSingleItem(runDynamicsItemCheck(dib, null, request)); // logger.trace("just set single item on line 447: // "+dib.getData().getValue()); // items.set(i, dib); LOGGER.debug(" I : " + i); allItems.set(i, diwg); } } logMe("Loop ended " + System.currentTimeMillis()); //JN: This is the list that contains all the scd-shown items. List<ItemBean> itemBeansWithSCDShown = new ArrayList<ItemBean>(); if (validate && section.getSection().hasSCDItem()) { logMe(" Validate and Loop " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); ++i) { DisplayItemBean dib = allItems.get(i).getSingleItem(); ItemFormMetadataBean ifmb = dib.getMetadata(); if (ifmb.getParentId() == 0) { if (dib.getScdData().getScdSetsForControl().size() > 0) { //for control item //dib has to loadFormValue first. Here loadFormValue has been done in validateDisplayItemBean(v, dib, "") section.setShowSCDItemIds(SimpleConditionalDisplayService .conditionalDisplayToBeShown(dib, section.getShowSCDItemIds())); } if (dib.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) { //for scd item //a control item is always before its scd item dib.setIsSCDtoBeShown( section.getShowSCDItemIds().contains(dib.getMetadata().getItemId())); if (dib.getIsSCDtoBeShown()) itemBeansWithSCDShown.add(dib.getItem()); validateSCDItemBean(v, dib); } ArrayList<DisplayItemBean> children = dib.getChildren(); for (int j = 0; j < children.size(); j++) { DisplayItemBean child = children.get(j); if (child.getScdData().getScdSetsForControl().size() > 0) { //for control item //dib has to loadFormValue first. Here loadFormValue has been done in validateDisplayItemBean(v, dib, "") section.setShowSCDItemIds(SimpleConditionalDisplayService .conditionalDisplayToBeShown(child, section.getShowSCDItemIds())); } if (child.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) { //for scd item //a control item is always before its scd item child.setIsSCDtoBeShown( section.getShowSCDItemIds().contains(child.getMetadata().getItemId())); if (child.getIsSCDtoBeShown()) itemBeansWithSCDShown.add(dib.getItem()); validateSCDItemBean(v, child); } } } } logMe(" Validate and Loop end " + System.currentTimeMillis()); } logMe(" Validate and Loop end " + System.currentTimeMillis()); //JN:calling again here, for the items with simple conditional display and rules. List<RuleSetBean> ruleSets = createAndInitializeRuleSet(currentStudy, studyEventDefinition, crfVersionBean, studyEventBean, ecb, true, request, response, itemBeansWithSCDShown); boolean shouldRunRules = getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets, phase2); // this.getItemMetadataService().resetItemCounter(); HashMap<String, ArrayList<String>> groupOrdinalPLusItemOid = null; groupOrdinalPLusItemOid = runRules(allItems, ruleSets, true, shouldRunRules, MessageType.ERROR, phase2, ecb, request); logMe("allItems Loop begin " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); i++) { DisplayItemWithGroupBean diwg = allItems.get(i); if (diwg.isInGroup()) { // for the items in groups DisplayItemGroupBean dgb = diwg.getItemGroup(); List<DisplayItemGroupBean> dbGroups = diwg.getDbItemGroups(); //dbGroups = diwg.getItemGroups(); // tbh 01/2010 change the group list? List<DisplayItemGroupBean> formGroups = new ArrayList<DisplayItemGroupBean>(); // List<DisplayItemGroupBean> dbGroups2 = loadFormValueForItemGroup(dgb, dbGroups, formGroups, eventDefinitionCRFId); // jxu- this part need to be refined, why need to validate // items again? if (validate) { // int manualGroups = getManualRows(dbGroups2); // logger.debug("+++ found manual rows for db group2: " + manualGroups); formGroups = validateDisplayItemGroupBean(v, dgb, dbGroups, formGroups, ruleValidator, groupOrdinalPLusItemOid, request, response); // formGroups = validateDisplayItemGroupBean(v, dgb, // dbGroups, formGroups); LOGGER.debug("*** form group size after validation " + formGroups.size()); } diwg.setItemGroup(dgb); diwg.setItemGroups(formGroups); allItems.set(i, diwg); } else {// other single items DisplayItemBean dib = diwg.getSingleItem(); // dib = (DisplayItemBean) allItems.get(i); if (validate) { String itemName = getInputName(dib); dib = validateDisplayItemBean(v, dib, "", ruleValidator, groupOrdinalPLusItemOid, false, null, request);// // / dib = validateDisplayItemBean(v, dib, "");// this } ArrayList children = dib.getChildren(); for (int j = 0; j < children.size(); j++) { DisplayItemBean child = (DisplayItemBean) children.get(j); // DisplayItemGroupBean dgb = diwg.getItemGroup(); String itemName = getInputName(child); child.loadFormValue(fp.getString(itemName)); if (validate) { child = validateDisplayItemBean(v, child, "", ruleValidator, groupOrdinalPLusItemOid, false, null, request); // child = validateDisplayItemBean(v, child, // itemName); } children.set(j, child); LOGGER.debug(" J (children): " + j); } dib.setChildren(children); diwg.setSingleItem(runDynamicsItemCheck(dib, null, request)); LOGGER.debug(" I : " + i); allItems.set(i, diwg); } } logMe("allItems Loop end " + System.currentTimeMillis()); // YW, 2-1-2008 << // A map from item name to item bean object. HashMap<String, ItemBean> scoreItems = new HashMap<String, ItemBean>(); HashMap<String, String> scoreItemdata = new HashMap<String, String>(); HashMap<String, ItemDataBean> oldItemdata = prepareSectionItemdataObject(sb.getId(), request); // hold all item names of changed ItemBean in current section TreeSet<String> changedItems = new TreeSet<String>(); // holds complete disply item beans for checking against 'request // for change' restriction ArrayList<DisplayItemBean> changedItemsList = new ArrayList<DisplayItemBean>(); // key is repeating item name, value is its display item group bean HashMap<String, DisplayItemGroupBean> changedItemsMap = new HashMap<String, DisplayItemGroupBean>(); // key is itemid, value is set of itemdata-ordinal HashMap<Integer, TreeSet<Integer>> itemOrdinals = prepareItemdataOrdinals(request); // prepare item data for scoring updateDataOrdinals(allItems); section.setDisplayItemGroups(allItems); scoreItems = prepareScoreItems(request); scoreItemdata = prepareScoreItemdata(request); logMe("allItems 2 Loop begin " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); i++) { DisplayItemWithGroupBean diwb = allItems.get(i); if (diwb.isInGroup()) { List<DisplayItemGroupBean> dbGroups = diwb.getDbItemGroups(); for (int j = 0; j < dbGroups.size(); j++) { DisplayItemGroupBean displayGroup = dbGroups.get(j); List<DisplayItemBean> items = displayGroup.getItems(); if ("remove".equalsIgnoreCase(displayGroup.getEditFlag())) { for (DisplayItemBean displayItem : items) { int itemId = displayItem.getItem().getId(); int ordinal = displayItem.getData().getOrdinal(); if (itemOrdinals.containsKey(itemId)) { itemOrdinals.get(itemId).remove(ordinal); } if (scoreItemdata.containsKey(itemId + "_" + ordinal)) { scoreItemdata.remove(itemId + "_" + ordinal); } changedItems.add(displayItem.getItem().getName()); changedItemsList.add(displayItem); String formName = displayItem.getItem().getName(); // logger.debug("SET: formName:" + formName); if (displayGroup.isAuto()) { formName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("GET: changed formName to " + formName); } else { formName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("GET-MANUAL: changed formName to " + formName); } changedItemsMap.put(formName, displayGroup); LOGGER.debug("adding to changed items map: " + formName); } } } List<DisplayItemGroupBean> dgbs = diwb.getItemGroups(); int groupsize = dgbs.size(); HashMap<Integer, Integer> maxOrdinals = new HashMap<Integer, Integer>(); boolean first = true; for (int j = 0; j < dgbs.size(); j++) { DisplayItemGroupBean displayGroup = dgbs.get(j); List<DisplayItemBean> items = displayGroup.getItems(); boolean isAdd = "add".equalsIgnoreCase(displayGroup.getEditFlag()) ? true : false; for (DisplayItemBean displayItem : items) { ItemBean ib = displayItem.getItem(); String itemName = ib.getName(); int itemId = ib.getId(); if (first) { maxOrdinals.put(itemId, iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean())); } ItemDataBean idb = displayItem.getData(); String value = idb.getValue(); scoreItems.put(itemName, ib); int ordinal = displayItem.getData().getOrdinal(); if (isAdd && scoreItemdata.containsKey(itemId + "_" + ordinal)) { int formMax = 1; if (maxOrdinals.containsKey(itemId)) { formMax = maxOrdinals.get(itemId); } int dbMax = iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean()); ordinal = ordinal >= dbMax ? formMax + 1 : ordinal; maxOrdinals.put(itemId, ordinal); displayItem.getData().setOrdinal(ordinal); scoreItemdata.put(itemId + "_" + ordinal, value); } else { scoreItemdata.put(itemId + "_" + ordinal, value); } if (itemOrdinals.containsKey(itemId)) { itemOrdinals.get(itemId).add(ordinal); } else { TreeSet<Integer> ordinalSet = new TreeSet<Integer>(); ordinalSet.add(ordinal); itemOrdinals.put(itemId, ordinalSet); } if (isChanged(displayItem, oldItemdata, attachedFilePath)) { changedItems.add(itemName); changedItemsList.add(displayItem); String formName = displayItem.getItem().getName(); // logger.debug("SET: formName:" + formName); if (displayGroup.isAuto()) { formName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("RESET: formName group-item-input:" + formName); } else { formName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("RESET: formName group-item-input-manual:" + formName); } changedItemsMap.put(formName, displayGroup); LOGGER.debug("adding to changed items map: " + formName); } } first = false; } } else { DisplayItemBean dib = diwb.getSingleItem(); ItemBean ib = dib.getItem(); ItemDataBean idb = dib.getData(); int itemId = ib.getId(); String itemName = ib.getName(); String value = idb.getValue(); scoreItems.put(itemName, ib); // for items which are not in any group, their ordinal is // set as 1 TreeSet<Integer> ordinalset = new TreeSet<Integer>(); ordinalset.add(1); itemOrdinals.put(itemId, ordinalset); scoreItemdata.put(itemId + "_" + 1, value); if (isChanged(idb, oldItemdata, dib, attachedFilePath)) { changedItems.add(itemName); changedItemsList.add(dib); // changedItemsMap.put(dib.getItem().getName(), new // DisplayItemGroupBean()); } ArrayList children = dib.getChildren(); for (int j = 0; j < children.size(); j++) { DisplayItemBean child = (DisplayItemBean) children.get(j); ItemBean cib = child.getItem(); scoreItems.put(cib.getName(), cib); TreeSet<Integer> cordinalset = new TreeSet<Integer>(); cordinalset.add(1); itemOrdinals.put(itemId, cordinalset); scoreItemdata.put(cib.getId() + "_" + 1, child.getData().getValue()); if (isChanged(child.getData(), oldItemdata, child, attachedFilePath)) { changedItems.add(itemName); changedItemsList.add(child); // changedItemsMap.put(itemName, new // DisplayItemGroupBean()); } } } } logMe("allItems 2 Loop end " + System.currentTimeMillis()); // do calculation for 'calculation' and 'group-calculation' type // items // and write the result in DisplayItemBean's ItemDateBean - data ScoreItemValidator sv = new ScoreItemValidator(request, discNotes); // *** doing calc here, load it where? *** SessionManager sm = (SessionManager) request.getSession().getAttribute("sm"); ScoreCalculator sc = new ScoreCalculator(sm, ecb, ub); logMe("allItems 3 Loop begin " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); i++) { DisplayItemWithGroupBean diwb = allItems.get(i); if (diwb.isInGroup()) { List<DisplayItemGroupBean> dgbs = diwb.getItemGroups(); for (int j = 0; j < dgbs.size(); j++) { DisplayItemGroupBean displayGroup = dgbs.get(j); List<DisplayItemBean> items = displayGroup.getItems(); for (DisplayItemBean displayItem : items) { ItemFormMetadataBean ifmb = displayItem.getMetadata(); int responseTypeId = ifmb.getResponseSet().getResponseTypeId(); if (responseTypeId == 8 || responseTypeId == 9) { StringBuffer err = new StringBuffer(); ResponseOptionBean robBean = (ResponseOptionBean) ifmb.getResponseSet().getOptions() .get(0); String value = ""; String inputName = ""; // note that we have to use // getFormInputOrdinal() here, tbh 06/2009 if (displayGroup.isAuto()) { inputName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("returning input name: " + inputName); } else { inputName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem); LOGGER.debug("returning input name: " + inputName); } if (robBean.getValue().startsWith("func: getexternalvalue") || robBean.getValue().startsWith("func: getExternalValue")) { value = fp.getString(inputName); LOGGER.debug("*** just set " + fp.getString(inputName) + " for line 815 " + displayItem.getItem().getName() + " with input name " + inputName); } else { value = sc.doCalculation(displayItem, scoreItems, scoreItemdata, itemOrdinals, err, displayItem.getData().getOrdinal()); } displayItem.loadFormValue(value); if (isChanged(displayItem, oldItemdata, attachedFilePath)) { changedItems.add(displayItem.getItem().getName()); changedItemsList.add(displayItem); } request.setAttribute(inputName, value); if (validate) { displayItem = validateCalcTypeDisplayItemBean(sv, displayItem, inputName, request); if (err.length() > 0) { Validation validation = new Validation(Validator.CALCULATION_FAILED); validation.setErrorMessage(err.toString()); sv.addValidation(inputName, validation); } } } } } } else { DisplayItemBean dib = diwb.getSingleItem(); ItemFormMetadataBean ifmb = dib.getMetadata(); int responseTypeId = ifmb.getResponseSet().getResponseTypeId(); if (responseTypeId == 8 || responseTypeId == 9) { StringBuffer err = new StringBuffer(); ResponseOptionBean robBean = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0); String value = ""; if (robBean.getValue().startsWith("func: getexternalvalue") || robBean.getValue().startsWith("func: getExternalValue")) { String itemName = getInputName(dib); value = fp.getString(itemName); LOGGER.debug("just set " + fp.getString(itemName) + " for " + dib.getItem().getName()); LOGGER.debug("found in fp: " + fp.getString(dib.getItem().getName())); // logger.debug("scoreitemdata: " + // scoreItemdata.toString()); } else { value = sc.doCalculation(dib, scoreItems, scoreItemdata, itemOrdinals, err, 1); } dib.loadFormValue(value); if (isChanged(dib.getData(), oldItemdata, dib, attachedFilePath)) { changedItems.add(dib.getItem().getName()); changedItemsList.add(dib); // changedItemsMap.put(dib.getItem().getName(), new // DisplayItemGroupBean()); } String inputName = getInputName(dib); request.setAttribute(inputName, value); if (validate) { dib = validateCalcTypeDisplayItemBean(sv, dib, "", request); if (err.length() > 0) { Validation validation = new Validation(Validator.CALCULATION_FAILED); validation.setErrorMessage(err.toString()); sv.addValidation(inputName, validation); } } } ArrayList children = dib.getChildren(); for (int j = 0; j < children.size(); j++) { DisplayItemBean child = (DisplayItemBean) children.get(j); ItemFormMetadataBean cifmb = child.getMetadata(); int resTypeId = cifmb.getResponseSet().getResponseTypeId(); if (resTypeId == 8 || resTypeId == 9) { StringBuffer cerr = new StringBuffer(); child.getDbData().setValue(child.getData().getValue()); ResponseOptionBean crobBean = (ResponseOptionBean) cifmb.getResponseSet().getOptions() .get(0); String cvalue = ""; if (crobBean.getValue().startsWith("func: getexternalvalue") || crobBean.getValue().startsWith("func: getExternalValue")) { String itemName = getInputName(child); cvalue = fp.getString(itemName); LOGGER.debug( "just set " + fp.getString(itemName) + " for " + child.getItem().getName()); } else { cvalue = sc.doCalculation(child, scoreItems, scoreItemdata, itemOrdinals, cerr, 1); } child.loadFormValue(cvalue); if (isChanged(child.getData(), oldItemdata, child, attachedFilePath)) { changedItems.add(child.getItem().getName()); changedItemsList.add(child); // changedItemsMap.put(child.getItem().getName(), // new DisplayItemGroupBean()); } String cinputName = getInputName(child); request.setAttribute(cinputName, cvalue); if (validate) { child = validateCalcTypeDisplayItemBean(sv, child, "", request); if (cerr.length() > 0) { Validation cvalidation = new Validation(Validator.CALCULATION_FAILED); cvalidation.setErrorMessage(cerr.toString()); sv.addValidation(cinputName, cvalidation); } } } children.set(j, child); } } } logMe("allItems 3 Loop end " + System.currentTimeMillis()); // YW >> // we have to do this since we loaded all the form values into the // display // item beans above // section.setItems(items); // setting this AFTER we populate notes - will that make a difference? section.setDisplayItemGroups(allItems); // logger.debug("+++ try to populate notes"); section = populateNotesWithDBNoteCounts(discNotes, section, request); populateInstantOnChange(request.getSession(), ecb, section); // logger.debug("+++ try to populate notes, got count of field notes: " + discNotes.getFieldNotes().toString()); if (currentStudy.getStudyParameterConfig().getInterviewerNameRequired().equals("yes")) { v.addValidation(INPUT_INTERVIEWER, Validator.NO_BLANKS); } if (currentStudy.getStudyParameterConfig().getInterviewDateRequired().equals("yes")) { v.addValidation(INPUT_INTERVIEW_DATE, Validator.NO_BLANKS); } if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) { v.addValidation(INPUT_INTERVIEW_DATE, Validator.IS_A_DATE); v.alwaysExecuteLastValidation(INPUT_INTERVIEW_DATE); } if (section.getSection().hasSCDItem()) { section = SCDItemDisplayInfo.generateSCDDisplayInfo(section, this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request)); } // logger.debug("about to validate: " + v.getKeySet()); errors = v.validate(); // tbh >> if (this.isAdminForcedReasonForChange(request) && this.isAdministrativeEditing() && errors.isEmpty()) { // "You have changed data after this CRF was marked complete. " // + // "You must provide a Reason For Change discrepancy note for this item before you can save this updated information." String error = respage.getString("reason_for_change_error"); // "Please enter a reason for change discrepancy note before saving." // ; int nonforcedChanges = 0; // change everything here from changed items list to changed // items map if (changedItemsList.size() > 0) { LOGGER.debug("found admin force reason for change: changed items " + changedItems.toString() + " and changed items list: " + changedItemsList.toString() + " changed items map: " + changedItemsMap.toString()); logMe("DisplayItemBean Loop begin " + System.currentTimeMillis()); for (DisplayItemBean displayItem : changedItemsList) { String formName = getInputName(displayItem); ItemDataBean idb = displayItem.getData(); ItemBean item_bean = displayItem.getItem(); ItemFormMetadataBean ifmb = displayItem.getMetadata(); LOGGER.debug("-- found group label " + ifmb.getGroupLabel()); if (!ifmb.getGroupLabel().equalsIgnoreCase("Ungrouped") && !ifmb.getGroupLabel().equalsIgnoreCase("")) { // << tbh 11/2009 sometimes the group label is blank instead of ungrouped??? Iterator iter = changedItemsMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, DisplayItemGroupBean> pairs = (Map.Entry) iter.next(); String formName2 = pairs.getKey(); DisplayItemGroupBean dgb = pairs.getValue(); // logger.debug("found auto: " + // dgb.isAuto()); String testFormName = ""; if (dgb.isAuto()) { // testFormName = getGroupItemInputName(dgb, dgb.getFormInputOrdinal(), getManualRows(dgbs), displayItem); testFormName = getGroupItemInputName(dgb, dgb.getFormInputOrdinal(), displayItem); } else { testFormName = getGroupItemManualInputName(dgb, dgb.getFormInputOrdinal(), displayItem); } LOGGER.debug("found test form name: " + testFormName); // if our test is the same with both the display // item and the display group ... // logger.debug("comparing " + // testFormName + " and " + formName2); int existingNotes = dndao.findNumExistingNotesForItem(idb.getId()); if (testFormName.equals(formName2)) { formName = formName2; this.setReasonForChangeError(ecb, item_bean, idb, formName, error, request); changedItemsMap.remove(formName2); LOGGER.debug("form name changed: " + formName); break; // .., send it as the form name } // ... otherwise, don't touch it // how to tell vs. manual and just plain input? } } else { this.setReasonForChangeError(ecb, item_bean, idb, formName, error, request); LOGGER.debug("form name added: " + formName); } } logMe("DisplayItemBean Loop end " + System.currentTimeMillis()); } if (nonforcedChanges > 0) { // do smething here? } } LOGGER.debug("errors here: " + errors.toString()); // << logMe("error check Loop begin " + System.currentTimeMillis()); if (errors.isEmpty() && shouldRunRules) { LOGGER.debug("Errors was empty"); if (session.getAttribute("rulesErrors") != null) { // rules have already generated errors, Let's compare old // error list with new // error list, if lists not same show errors. HashMap h = ruleValidator.validate(); Set<String> a = (Set<String>) session.getAttribute("rulesErrors"); Set<String> ba = h.keySet(); Boolean showErrors = false; for (Object key : ba) { if (!a.contains(key)) { showErrors = true; } } if (showErrors) { errors = h; if (errors.size() > 0) { session.setAttribute("shouldRunValidation", "1"); session.setAttribute("rulesErrors", errors.keySet()); } else { session.setAttribute("shouldRunValidation", null); session.setAttribute("rulesErrors", null); } } else { session.setAttribute("shouldRunValidation", null); session.setAttribute("rulesErrors", null); } } else if (session.getAttribute("shouldRunValidation") != null && session.getAttribute("shouldRunValidation").toString().equals("1")) { session.setAttribute("shouldRunValidation", null); session.setAttribute("rulesErrors", null); } else { errors = ruleValidator.validate(); if (errors.size() > 0) { session.setAttribute("shouldRunValidation", "1"); session.setAttribute("rulesErrors", errors.keySet()); } } } if (!errors.isEmpty()) { LOGGER.debug("threw an error with data entry..."); // copying below three lines, tbh 03/2010 String[] textFields = { INPUT_INTERVIEWER, INPUT_INTERVIEW_DATE }; fp.setCurrentStringValuesAsPreset(textFields); setPresetValues(fp.getPresetValues(), request); // YW, 2-4-2008 << logMe("!errors if Loop begin " + System.currentTimeMillis()); HashMap<String, ArrayList<String>> siErrors = sv.validate(); if (siErrors != null && !siErrors.isEmpty()) { Iterator iter = siErrors.keySet().iterator(); while (iter.hasNext()) { String fieldName = iter.next().toString(); errors.put(fieldName, siErrors.get(fieldName)); } } // we should 'shift' the names here, tbh 02/2010 // need: total number of rows, manual rows, all row names // plus: error names Iterator iter2 = errors.keySet().iterator(); while (iter2.hasNext()) { String fieldName = iter2.next().toString(); LOGGER.debug("found error " + fieldName); } // for (int i = 0; i < allItems.size(); i++) { // DisplayItemWithGroupBean diwb = allItems.get(i); // // if (diwb.isInGroup()) { // List<DisplayItemGroupBean> dgbs = diwb.getItemGroups(); // logger.debug("found manual rows " + getManualRows(dgbs) + " and total rows " + dgbs.size() + " from ordinal " + diwb.getOrdinal()); // } // } errors = reshuffleErrorGroupNamesKK(errors, allItems, request); reshuffleReasonForChangeHashAndDiscrepancyNotes(allItems, request, ecb); // reset manual rows, so that we can catch errors correctly // but it needs to be set per block of repeating items? what if there are two or more? /* int manualRows = 0; // getManualRows(formGroups); for (int i = 0; i < allItems.size(); i++) { DisplayItemWithGroupBean diwb = allItems.get(i); if (diwb.isInGroup()) { List<DisplayItemGroupBean> dgbs = diwb.getItemGroups(); manualRows = getManualRows(dgbs); } } */ //request.setAttribute("manualRows", new Integer(manualRows)); Iterator iter3 = errors.keySet().iterator(); while (iter3.hasNext()) { String fieldName = iter3.next().toString(); LOGGER.debug("found error after shuffle " + fieldName); } //Mantis Issue: 8116. Parsist the markComplete chebox on error request.setAttribute("markComplete", fp.getString(INPUT_MARK_COMPLETE)); // << tbh, 02/2010 // YW >> // copied request.setAttribute(BEAN_DISPLAY, section); request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS)); setInputMessages(errors, request); addPageMessage(respage.getString("errors_in_submission_see_below"), request); request.setAttribute("hasError", "true"); // addPageMessage("To override these errors and keep the data as // you // entered it, click one of the \"Confirm\" buttons. "); // if (section.isCheckInputs()) { // addPageMessage("Please notice that you must enter data for // the // <b>required</b> entries."); // } // we do not save any DNs if we get here, so we have to set it back into session... session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes); // << tbh 01/2010 setUpPanel(section); forwardPage(getJSPPage(), request, response); } else { //reshuffleReasonForChangeHashAndDiscrepancyNotes( allItems, request, ecb); LOGGER.debug("Do we hit this in save ?????"); logMe("Do we hit this in save ???? " + System.currentTimeMillis()); boolean success = true; boolean temp = true; // save interviewer name and date into DB ecb.setInterviewerName(fp.getString(INPUT_INTERVIEWER)); if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) { ecb.setDateInterviewed(fp.getDate(INPUT_INTERVIEW_DATE)); } else { ecb.setDateInterviewed(null); } if (ecdao == null) { ecdao = new EventCRFDAO(getDataSource()); } // set validator id for DDE DataEntryStage stage = ecb.getStage(); if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) { ecb.setValidatorId(ub.getId()); } /* * if(studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus .SIGNED)){ if(edcBean.isDoubleEntry()){ * ecb.setStage(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE); }else{ ecb.setStage(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE); } } */ // for Administrative editing if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) && changedItemsList.size() > 0) { studyEventBean.setSubjectEventStatus(SubjectEventStatus.COMPLETED); studyEventBean.setUpdater(ub); studyEventBean.setUpdatedDate(new Date()); seDao.update(studyEventBean); } // If the Study Subject's Satus is signed and we save a section // , change status to available LOGGER.debug("Status of Study Subject {}", ssb.getStatus().getName()); if (ssb.getStatus() == Status.SIGNED && changedItemsList.size() > 0) { LOGGER.debug("Status of Study Subject is Signed we are updating"); StudySubjectDAO studySubjectDao = new StudySubjectDAO(getDataSource()); ssb.setStatus(Status.AVAILABLE); ssb.setUpdater(ub); ssb.setUpdatedDate(new Date()); studySubjectDao.update(ssb); } if (ecb.isSdvStatus() && changedItemsList.size() > 0) { LOGGER.debug("Status of Study Subject is SDV we are updating"); StudySubjectDAO studySubjectDao = new StudySubjectDAO(getDataSource()); ssb.setStatus(Status.AVAILABLE); ssb.setUpdater(ub); ssb.setUpdatedDate(new Date()); studySubjectDao.update(ssb); ecb.setSdvStatus(false); ecb.setSdvUpdateId(ub.getId()); } ecb = (EventCRFBean) ecdao.update(ecb); // save discrepancy notes into DB FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session .getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME); dndao = new DiscrepancyNoteDAO(getDataSource()); AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEWER, fdn, dndao, ecb.getId(), "EventCRF", currentStudy); AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEW_DATE, fdn, dndao, ecb.getId(), "EventCRF", currentStudy); // items = section.getItems(); allItems = section.getDisplayItemGroups(); int nextOrdinal = 0; LOGGER.debug("all items before saving into DB" + allItems.size()); this.output(allItems); //TODO:Seems longer here, check this logMe("DisplayItemWithGroupBean allitems4 " + System.currentTimeMillis()); for (int i = 0; i < allItems.size(); i++) { DisplayItemWithGroupBean diwb = allItems.get(i); // we don't write success = success && writeToDB here // since the short-circuit mechanism may prevent Java // from executing writeToDB. if (diwb.isInGroup()) { List<DisplayItemGroupBean> dgbs = diwb.getItemGroups(); // using the above gets us the correct number of manual groups, tbh 01/2010 List<DisplayItemGroupBean> dbGroups = diwb.getDbItemGroups(); LOGGER.debug("item group size: " + dgbs.size()); LOGGER.debug("item db-group size: " + dbGroups.size()); for (int j = 0; j < dgbs.size(); j++) { DisplayItemGroupBean displayGroup = dgbs.get(j); List<DisplayItemBean> items = displayGroup.getItems(); // this ordinal will only useful to create a new // item data // update an item data won't touch its ordinal // int nextOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean()) + 1; // Determine if any items in this group have data. If so we need to undelete and previously deleted items. boolean undelete = false; for (DisplayItemBean displayItem : items) { String currItemVal = displayItem.getData().getValue(); if (currItemVal != null && !currItemVal.equals("")) { undelete = true; break; } } for (DisplayItemBean displayItem : items) { String fileName = this.addAttachedFilePath(displayItem, attachedFilePath); boolean writeDN = true; displayItem.setEditFlag(displayGroup.getEditFlag()); LOGGER.debug("group item value: " + displayItem.getData().getValue()); // if ("add".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) { // displayItem.getData().setValue(""); // } //15350, this particular logic, takes into consideration that a DN is created properly as long as the item data record exists and it fails to get created when it doesnt. //so, we are expanding the logic from writeToDb method to avoid creating duplicate records. writeDN = writeDN(displayItem); //pulling from dataset instead of database and correcting the flawed logic of using the database ordinals as max ordinal... nextOrdinal = displayItem.getData().getOrdinal(); temp = writeToDB(displayItem, iddao, nextOrdinal, request); LOGGER.debug("just executed writeToDB - 1"); LOGGER.debug("next ordinal: " + nextOrdinal); // Undelete item if any item in the repeating group has data. if (undelete && displayItem.getDbData() != null && displayItem.getDbData().isDeleted()) { iddao.undelete(displayItem.getDbData().getId(), ub.getId()); } if (temp && newUploadedFiles.containsKey(fileName)) { newUploadedFiles.remove(fileName); } // maybe put ordinal in the place of j? maybe subtract max rows from next ordinal if j is gt // next ordinal? String inputName = getGroupItemInputName(displayGroup, j, displayItem); // String inputName2 = getGroupItemManualInputName(displayGroup, j, displayItem); if (!displayGroup.isAuto()) { LOGGER.trace("not auto"); inputName = this.getGroupItemManualInputName(displayGroup, j, displayItem); } //htaycher last DN is not stored for new rows // if (j == dgbs.size() - 1) { // // LAST ONE // logger.trace("last one"); // int ordinal = j - this.getManualRows(dgbs); // logger.debug("+++ found manual rows from line 1326: " + ordinal); // inputName = getGroupItemInputName(displayGroup, ordinal, displayItem); // } // logger.trace("&&& we get previous looking at input name: " + inputName + " " + inputName2); LOGGER.trace("&&& we get previous looking at input name: " + inputName); // input name 2 removed from below inputName = displayItem.getFieldName(); if (writeDN) { AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, displayItem.getData().getId(), "itemData", currentStudy, ecb.getId()); } success = success && temp; } } for (int j = 0; j < dbGroups.size(); j++) { DisplayItemGroupBean displayGroup = dbGroups.get(j); //JN: Since remove button is gone, the following code can be commented out, however it needs to be tested? Can be tackled when handling discrepancy note w/repeating groups issues. if ("remove".equalsIgnoreCase(displayGroup.getEditFlag())) { List<DisplayItemBean> items = displayGroup.getItems(); for (DisplayItemBean displayItem : items) { String fileName = this.addAttachedFilePath(displayItem, attachedFilePath); displayItem.setEditFlag(displayGroup.getEditFlag()); LOGGER.debug("group item value: " + displayItem.getData().getValue()); // if ("add".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) { // displayItem.getData().setValue(""); // } temp = writeToDB(displayItem, iddao, 0, request); LOGGER.debug("just executed writeToDB - 2"); if (temp && newUploadedFiles.containsKey(fileName)) { newUploadedFiles.remove(fileName); } // just use 0 here since update doesn't // touch ordinal success = success && temp; } } } } else { DisplayItemBean dib = diwb.getSingleItem(); // TODO work on this line // this.addAttachedFilePath(dib, attachedFilePath); String fileName = addAttachedFilePath(dib, attachedFilePath); boolean writeDN = writeDN(dib); temp = writeToDB(dib, iddao, 1, request); LOGGER.debug("just executed writeToDB - 3"); if (temp && (newUploadedFiles.containsKey(dib.getItem().getId() + "") || newUploadedFiles.containsKey(fileName))) { // so newUploadedFiles will contain only failed file // items; newUploadedFiles.remove(dib.getItem().getId() + ""); newUploadedFiles.remove(fileName); } String inputName = getInputName(dib); LOGGER.trace("3 - found input name: " + inputName); if (writeDN) AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, dib.getData().getId(), "itemData", currentStudy, ecb.getId()); success = success && temp; ArrayList childItems = dib.getChildren(); for (int j = 0; j < childItems.size(); j++) { DisplayItemBean child = (DisplayItemBean) childItems.get(j); this.addAttachedFilePath(child, attachedFilePath); writeDN = writeDN(child); temp = writeToDB(child, iddao, 1, request); LOGGER.debug("just executed writeToDB - 4"); if (temp && newUploadedFiles.containsKey(child.getItem().getId() + "")) { // so newUploadedFiles will contain only failed // file items; newUploadedFiles.remove(child.getItem().getId() + ""); } inputName = getInputName(child); if (writeDN) AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, child.getData().getId(), "itemData", currentStudy, ecb.getId()); success = success && temp; } } } logMe("DisplayItemWithGroupBean allitems4 end " + System.currentTimeMillis()); LOGGER.debug("running rules: " + phase2.name()); List<Integer> prevShownDynItemDataIds = shouldRunRules ? this.getItemMetadataService().getDynamicsItemFormMetadataDao() .findShowItemDataIdsInSection(section.getSection().getId(), ecb.getCRFVersionId(), ecb.getId()) : new ArrayList<Integer>(); logMe("DisplayItemWithGroupBean dryrun start" + System.currentTimeMillis()); HashMap<String, ArrayList<String>> rulesPostDryRun = runRules(allItems, ruleSets, false, shouldRunRules, MessageType.WARNING, phase2, ecb, request); HashMap<String, ArrayList<String>> errorsPostDryRun = new HashMap<String, ArrayList<String>>(); // additional step needed, run rules and see if any items are 'shown' AFTER saving data logMe("DisplayItemWithGroupBean dryrun end" + System.currentTimeMillis()); boolean inSameSection = false; logMe("DisplayItemWithGroupBean allitems4 " + System.currentTimeMillis()); if (!rulesPostDryRun.isEmpty()) { // in same section? // iterate through the OIDs and see if any of them belong to this section Iterator iter3 = rulesPostDryRun.keySet().iterator(); while (iter3.hasNext()) { String fieldName = iter3.next().toString(); LOGGER.debug("found oid after post dry run " + fieldName); // set up a listing of OIDs in the section // BUT: Oids can have the group name in them. int ordinal = -1; String newFieldName = fieldName; String[] fieldNames = fieldName.split("\\."); if (fieldNames.length == 2) { newFieldName = fieldNames[1]; // check items in item groups here? if (fieldNames[0].contains("[")) { int p1 = fieldNames[0].indexOf("["); int p2 = fieldNames[0].indexOf("]"); try { ordinal = Integer.valueOf(fieldNames[0].substring(p1 + 1, p2)); } catch (NumberFormatException e) { ordinal = -1; } fieldNames[0] = fieldNames[0].substring(0, p1); } } List<DisplayItemWithGroupBean> displayGroupsWithItems = section.getDisplayItemGroups(); //ArrayList<DisplayItemBean> displayItems = section.getItems(); for (int i = 0; i < displayGroupsWithItems.size(); i++) { DisplayItemWithGroupBean itemWithGroup = displayGroupsWithItems.get(i); if (itemWithGroup.isInGroup()) { LOGGER.debug("found group: " + fieldNames[0]); // do something there List<DisplayItemGroupBean> digbs = itemWithGroup.getItemGroups(); LOGGER.debug("digbs size: " + digbs.size()); for (int j = 0; j < digbs.size(); j++) { DisplayItemGroupBean displayGroup = digbs.get(j); if (displayGroup.getItemGroupBean().getOid().equals(fieldNames[0]) && displayGroup.getOrdinal() == ordinal - 1) { List<DisplayItemBean> items = displayGroup.getItems(); for (int k = 0; k < items.size(); k++) { DisplayItemBean dib = items.get(k); if (dib.getItem().getOid().equals(newFieldName)) { //inSameSection = true; if (!dib.getMetadata().isShowItem()) { LOGGER.debug("found item in group " + this.getGroupItemInputName(displayGroup, j, dib) + " vs. " + fieldName + " and is show item: " + dib.getMetadata().isShowItem()); dib.getMetadata().setShowItem(true); } if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds .contains(dib.getData().getId())) { inSameSection = true; errorsPostDryRun.put( this.getGroupItemInputName(displayGroup, j, dib), rulesPostDryRun.get(fieldName)); } } items.set(k, dib); } displayGroup.setItems(items); digbs.set(j, displayGroup); } } itemWithGroup.setItemGroups(digbs); } else { DisplayItemBean displayItemBean = itemWithGroup.getSingleItem(); ItemBean itemBean = displayItemBean.getItem(); if (newFieldName.equals(itemBean.getOid())) { //System.out.println("is show item for " + displayItemBean.getItem().getId() + ": " + displayItemBean.getMetadata().isShowItem()); //System.out.println("check run dynamics item check " + runDynamicsItemCheck(displayItemBean).getMetadata().isShowItem()); if (!displayItemBean.getMetadata().isShowItem()) { // double check there? LOGGER.debug("found item " + this.getInputName(displayItemBean) + " vs. " + fieldName + " and is show item: " + displayItemBean.getMetadata().isShowItem()); // if is repeating, use the other input name? no displayItemBean.getMetadata().setShowItem(true); if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds .contains(displayItemBean.getData().getId())) { inSameSection = true; errorsPostDryRun.put(this.getInputName(displayItemBean), rulesPostDryRun.get(fieldName)); } } } itemWithGroup.setSingleItem(displayItemBean); } displayGroupsWithItems.set(i, itemWithGroup); } logMe("DisplayItemWithGroupBean allitems4 end,begin" + System.currentTimeMillis()); // check groups //List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>(); //itemGroups = section.getDisplayFormGroups(); // But in jsp: section.displayItemGroups.itemGroup.groupMetaBean.showGroup List<DisplayItemWithGroupBean> itemGroups = section.getDisplayItemGroups(); // List<DisplayItemGroupBean> newItemGroups = new ArrayList<DisplayItemGroupBean>(); for (DisplayItemWithGroupBean itemGroup : itemGroups) { DisplayItemGroupBean displayGroup = itemGroup.getItemGroup(); if (newFieldName.equals(displayGroup.getItemGroupBean().getOid())) { if (!displayGroup.getGroupMetaBean().isShowGroup()) { inSameSection = true; LOGGER.debug("found itemgroup " + displayGroup.getItemGroupBean().getOid() + " vs. " + fieldName + " and is show item: " + displayGroup.getGroupMetaBean().isShowGroup()); // hmmm how to set highlighting for a group? errorsPostDryRun.put(displayGroup.getItemGroupBean().getOid(), rulesPostDryRun.get(fieldName)); displayGroup.getGroupMetaBean().setShowGroup(true); // add necessary rows to the display group here???? // we have to set the items in the itemGroup for the displayGroup loadItemsWithGroupRows(itemGroup, sb, edcb, ecb, request); } } // newItemGroups.add(displayGroup); } logMe("DisplayItemWithGroupBean allitems4 end,end" + System.currentTimeMillis()); // trying to reset the display form groups here, tbh // section.setItems(displayItems); section.setDisplayItemGroups(displayGroupsWithItems); populateInstantOnChange(request.getSession(), ecb, section); // section.setDisplayFormGroups(newDisplayBean.getDisplayFormGroups()); } // this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups, section.getSection().getId(), ecb); toc = TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY), (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()) .getBean("dynamicsMetadataService")); request.setAttribute(TOC_DISPLAY, toc); sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc); sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc); previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex); nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex); section.setFirstSection(!previousSec.isActive()); section.setLastSection(!nextSec.isActive()); // // we need the following for repeating groups, tbh // >> tbh 06/2010 // List<DisplayItemWithGroupBean> displayItemWithGroups2 = createItemWithGroups(section, hasGroup, eventDefinitionCRFId); // section.setDisplayItemGroups(displayItemWithGroups2); // if so, stay at this section LOGGER.debug(" in same section: " + inSameSection); if (inSameSection) { // copy of one line from early on around line 400, forcing a re-show of the items // section = getDisplayBean(hasGroup, true);// include all items, tbh // below a copy of three lines from the if errors = true line, tbh 03/2010 String[] textFields = { INPUT_INTERVIEWER, INPUT_INTERVIEW_DATE }; fp.setCurrentStringValuesAsPreset(textFields); setPresetValues(fp.getPresetValues(), request); // below essetially a copy except for rulesPostDryRun request.setAttribute(BEAN_DISPLAY, section); request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS)); setInputMessages(errorsPostDryRun, request); addPageMessage(respage.getString("your_answers_activated_hidden_items"), request); request.setAttribute("hasError", "true"); request.setAttribute("hasShown", "true"); session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes); setUpPanel(section); forwardPage(getJSPPage(), request, response); } } if (!inSameSection) {// else if not in same section, progress as usual /* toc = TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY), (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService")); request.setAttribute(TOC_DISPLAY, toc); sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc); sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc); previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex); nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex); section.setFirstSection(!previousSec.isActive()); section.setLastSection(!nextSec.isActive()); */ // can we just forward page or do we actually need an ELSE here? // yes, we do. tbh 05/03/2010 ArrayList<String> updateFailedItems = sc.redoCalculations(scoreItems, scoreItemdata, changedItems, itemOrdinals, sb.getId()); success = updateFailedItems.size() > 0 ? false : true; // now check if CRF is marked complete boolean markComplete = fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES); boolean markSuccessfully = false; // if the CRF was marked // complete // successfully if (markComplete && section.isLastSection()) { LOGGER.debug("need to mark CRF as complete"); markSuccessfully = markCRFComplete(request); LOGGER.debug("...marked CRF as complete: " + markSuccessfully); if (!markSuccessfully) { request.setAttribute(BEAN_DISPLAY, section); request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS)); setUpPanel(section); forwardPage(getJSPPage(), request, response); return; } } // now write the event crf bean to the database String annotations = fp.getString(INPUT_ANNOTATIONS); setEventCRFAnnotations(annotations, request); Date now = new Date(); ecb.setUpdatedDate(now); ecb.setUpdater(ub); ecb = (EventCRFBean) ecdao.update(ecb); success = success && ecb.isActive(); StudyEventDAO sedao = new StudyEventDAO(getDataSource()); StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId()); seb.setUpdatedDate(now); seb.setUpdater(ub); seb = (StudyEventBean) sedao.update(seb); success = success && seb.isActive(); request.setAttribute(INPUT_IGNORE_PARAMETERS, Boolean.TRUE); if (newUploadedFiles.size() > 0) { if (this.unloadFiles(newUploadedFiles)) { } else { String missed = ""; Iterator iter = newUploadedFiles.keySet().iterator(); while (iter.hasNext()) { missed += " " + newUploadedFiles.get(iter.next()); } addPageMessage( respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request); } } if (!success) { // YW, 3-6-2008 << if (updateFailedItems.size() > 0) { String mess = ""; for (String ss : updateFailedItems) { mess += ss + ", "; } mess = mess.substring(0, mess.length() - 2); addPageMessage(resexception.getString("item_save_failed_because_database_error") + mess, request); } else { // YW>> addPageMessage(resexception.getString("database_error"), request); } request.setAttribute(BEAN_DISPLAY, section); session.removeAttribute(GROUP_HAS_DATA); session.removeAttribute(HAS_DATA_FLAG); session.removeAttribute(DDE_PROGESS); session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME); LOGGER.debug("try to remove to_create_crf"); session.removeAttribute("to_create_crf"); session.removeAttribute(instantAtt); // forwardPage(Page.SUBMIT_DATA_SERVLET); forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response); // >> changed tbh, 06/2009 } else { boolean forwardingSucceeded = false; if (!fp.getString(GO_PREVIOUS).equals("")) { if (previousSec.isActive()) { forwardingSucceeded = true; request.setAttribute(INPUT_EVENT_CRF, ecb); request.setAttribute(INPUT_SECTION, previousSec); int tabNum = 0; if (fp.getString("tab") == null) { tabNum = 1; } else { tabNum = fp.getInt("tab"); } request.setAttribute("tab", new Integer(tabNum - 1).toString()); // forwardPage(getServletPage(request), request, response); getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response); } } else if (!fp.getString(GO_NEXT).equals("")) { if (nextSec.isActive()) { forwardingSucceeded = true; request.setAttribute(INPUT_EVENT_CRF, ecb); request.setAttribute(INPUT_SECTION, nextSec); int tabNum = 0; if (fp.getString("tab") == null) { tabNum = 1; } else { tabNum = fp.getInt("tab"); } request.setAttribute("tab", new Integer(tabNum + 1).toString()); getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response); //forwardPage(getServletPage(request), request, response); } } if (!forwardingSucceeded) { // request.setAttribute(TableOfContentsServlet. // INPUT_EVENT_CRF_BEAN, // ecb); if (markSuccessfully) { addPageMessage(respage.getString("data_saved_CRF_marked_complete"), request); session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME); session.removeAttribute(GROUP_HAS_DATA); session.removeAttribute(HAS_DATA_FLAG); session.removeAttribute(DDE_PROGESS); session.removeAttribute("to_create_crf"); request.setAttribute("eventId", new Integer(ecb.getStudyEventId()).toString()); forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET, request, response); } else { // use clicked 'save' addPageMessage(respage.getString("data_saved_continue_entering_edit_later"), request); request.setAttribute(INPUT_EVENT_CRF, ecb); request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()).toString()); // forward to the next section if the previous one // is not the last section if (!section.isLastSection()) { request.setAttribute(INPUT_SECTION, nextSec); request.setAttribute(INPUT_SECTION_ID, new Integer(nextSec.getId()).toString()); session.removeAttribute("mayProcessUploading"); } else if (section.isLastSection()) { //JN ADDED TO avoid return down // already the last section, should go back to // view event page session.removeAttribute(GROUP_HAS_DATA); session.removeAttribute(HAS_DATA_FLAG); session.removeAttribute(DDE_PROGESS); session.removeAttribute("to_create_crf"); session.removeAttribute("mayProcessUploading"); request.setAttribute("eventId", new Integer(ecb.getStudyEventId()).toString()); if (fromViewNotes != null && "1".equals(fromViewNotes)) { String viewNotesPageFileName = (String) session .getAttribute("viewNotesPageFileName"); session.removeAttribute("viewNotesPageFileName"); session.removeAttribute("viewNotesURL"); if (viewNotesPageFileName != null && viewNotesPageFileName.length() > 0) { // forwardPage(Page.setNewPage(viewNotesPageFileName, "View Notes"), request, response); getServletContext().getRequestDispatcher(viewNotesPageFileName) .forward(request, response); } } session.removeAttribute(instantAtt); forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET, request, response); return; } int tabNum = 0; if (fp.getString("tab") == null) { tabNum = 1; } else { tabNum = fp.getInt("tab"); } if (!section.isLastSection()) { request.setAttribute("tab", new Integer(tabNum + 1).toString()); } // forwardPage(getServletPage(request), request, response); getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response); } // session.removeAttribute(AddNewSubjectServlet. // FORM_DISCREPANCY_NOTES_NAME); // forwardPage(Page.SUBMIT_DATA_SERVLET); } } } // end of if-block for dynamic rules not in same section, tbh 05/2010 } // end of save } }
From source file:org.jab.docsearch.DocSearch.java
/** * creates a new docSearcher index//from w ww . j a va 2 s. c om * * @param di * DocSearcherIndex * @param isCdRomIndx * is CDROM index * @throws IOException * IO problem */ private void createNewIndex(DocSearcherIndex di, boolean isCdRomIndx) throws IOException { setStatus(I18n.getString("indexing") + " (" + di.getIndexPath() + ") "); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); checkDefaults(); StringBuffer failedBuf = new StringBuffer(); String indexDirNew = di.getIndexPath(); File indexFolder = new File(indexDirNew); long curFileSizeBytes = 0; int addedSuccessfully = 0; StringBuilder noRobotsBuf = new StringBuilder(); noRobotsBuf.append('\n').append(I18n.getString("files_not_indexed_robot")); int numNoIndex = 0; boolean newIndex = false; if (!indexFolder.exists()) { setStatus(indexDirNew + " " + I18n.getString("lower_not_exist")); indexFolder.mkdir(); newIndex = true; } // BUILD THE INDEX File contentFolder = new File(di.getPath()); int totalFolders = 1; int totalFiles = 0; int numErrors = 0; // String urlStr = ""; // String dateStr = ""; // File tempDFile; int curSize = 1; if (contentFolder.exists()) { ArrayList<String> folderList = new ArrayList<String>(); folderList.add(di.getPath()); // add in our contentDir String curFolderString = di.getPath(); String[] filesString; String[] foldersString; File curFolderFile; int curItemNo = 0; int lastItemNo = 0; int numFiles = 0; int numFolders = 0; int curSubNum = 0; int startSubNum = Utils.countSlash(di.getPath()); int maxSubNum = startSubNum + di.getDepth(); // creating the index IndexWriter writer = new IndexWriter(indexDirNew, new StandardAnalyzer(), newIndex); // writer.setUseCompoundFile(true); do { // create our folder file curFolderString = folderList.get(curItemNo); curFolderFile = new File(curFolderString); curSubNum = Utils.countSlash(curFolderString); try { // handle any subfolders --> add them to our folderlist foldersString = curFolderFile.list(ff); numFolders = foldersString.length; for (int i = 0; i < numFolders; i++) { // add them to our folderlist String curFold = curFolderString + pathSep + foldersString[i] + pathSep; curFold = Utils.replaceAll(pathSep + pathSep, curFold, pathSep); folderList.add(curFold); lastItemNo++; totalFolders++; // debug output setStatus(dsFndFldr + " " + curFold); } // end for having more than 0 folder } catch (Exception e) { logger.fatal("createNewIndex() failed", e); setStatus(curFolderString + " : " + e.toString()); } // add our files try { filesString = curFolderFile.list(wf); numFiles = filesString.length; logger.info("createNewIndex() Indexing " + numFiles + " files..."); for (int i = 0; i < numFiles; i++) { // add them to our folderlist String curFi = curFolderString + pathSep + filesString[i]; curFi = Utils.replaceAll(pathSep + pathSep, curFi, pathSep); curFileSizeBytes = FileUtils.getFileSize(curFi); if (curFileSizeBytes > getMaxFileSize()) { setStatus(I18n.getString("skipping_file_too_big") + " (" + curFileSizeBytes + ") " + filesString[i]); } else { // file size is not too big setStatus(I18n.getString("please_wait...") + " " + curFi + " # " + curSize); curSize++; addedSuccessfully = idx.addDocToIndex(curFi, writer, di, isCdRomIndx, null); switch (addedSuccessfully) { case 1: // error numErrors++; if (numErrors < 8) { failedBuf.append('\n').append(curFi); } break; case 2: // meta robots = noindex numNoIndex++; if (numNoIndex < 8) { noRobotsBuf.append('\n').append(curFi); } break; default: // OK totalFiles++; break; } // end of switch } // end for not skipping, file size is not too big } // end for files } // end of trying to get files catch (Exception e) { logger.error("createNewIndex() failed", e); setStatus(I18n.getString("error") + " " + e.toString()); } // increment our curItem folderList.set(curItemNo, null); // remove memory overhead as // you go! curItemNo++; if (curSubNum >= maxSubNum) { break; } } while (curItemNo <= lastItemNo); writer.close(); // close the writer indexes.add(di); } else { hasErr = true; errString = fEnv.getContentDirectory() + " " + I18n.getString("lower_not_exist"); } // end for content dir Missing if (hasErr) { showMessage(I18n.getString("error_creating_index"), errString); } else { StringBuilder resultsBuf = new StringBuilder(); resultsBuf.append(I18n.getString("added_to_index")); resultsBuf.append(" \""); resultsBuf.append(di.getName()); resultsBuf.append("\" "); resultsBuf.append(totalFiles); resultsBuf.append(' '); resultsBuf.append(I18n.getString("files_from")); resultsBuf.append(' '); resultsBuf.append(totalFolders); resultsBuf.append(' '); resultsBuf.append(I18n.getString("folders")); resultsBuf.append("\n\n"); resultsBuf.append(I18n.getString("starting_in_folder")); resultsBuf.append("\n\n\t"); resultsBuf.append(' '); resultsBuf.append(di.getPath()); resultsBuf.append("\n\n"); resultsBuf.append(I18n.getString("for_a_depth_of")); resultsBuf.append(' '); resultsBuf.append(di.getDepth()); resultsBuf.append('.'); if (numErrors > 0) { resultsBuf.append('\n'); resultsBuf.append(numErrors); resultsBuf.append(' '); resultsBuf.append(I18n.getString("files_not_indexed")).append('.'); resultsBuf.append(failedBuf); } if (numNoIndex > 0) { resultsBuf.append("\n\n" + numNoIndex); resultsBuf.append('\n'); resultsBuf.append(I18n.getString("files_not_indexed_robot")); resultsBuf.append(noRobotsBuf); } showMessage(dsIdxCrtd, resultsBuf.toString()); } setStatus(dsIdxCrtd); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
From source file:ffx.algorithms.RotamerOptimization.java
/** * Sorts a passed ArrayList of Residues by global index. * * @param residues ArrayList of Residues to be sorted. */// w w w . j a va 2s. c o m private void sortResidues(ArrayList<Residue> residues) { int nResidues = residues.size(); IndexIndexPair[] residueIndices = new IndexIndexPair[nResidues]; for (int i = 0; i < nResidues; i++) { Residue residuei = residues.get(i); int indexOfI = allResiduesList.indexOf(residuei); residueIndices[i] = new IndexIndexPair(indexOfI, i); } Arrays.sort(residueIndices); ArrayList<Residue> tempWindow = new ArrayList<>(residues); for (int i = 0; i < nResidues; i++) { int indexToGet = residueIndices[i].getReferenceIndex(); residues.set(i, tempWindow.get(indexToGet)); } /*List<ObjectPair<Residue, Integer>> sortedList = residues.parallelStream(). map(r -> new ObjectPair<Residue, Integer>(r, allResiduesList.indexOf(r))). sorted().collect(Collectors.toList()); // Pause here to avoid any concurrency issues when resetting the list. sortedList.stream().forEach(rip -> residues.set(rip.getKey(), rip.getVal())); // ArrayList is not thread-safe, so must set sequential. */ }
From source file:com.lp.server.personal.ejbfac.ZutrittscontrollerFacBean.java
@SuppressWarnings("static-access") public String getZutrittsdatenFuerEinObjektFuerMecs(Integer zutrittsobjektIId, TheClientDto theClientDto) throws EJBExceptionLP { Timestamp d_datum = new Timestamp(System.currentTimeMillis()); d_datum = Helper.cutTimestamp(d_datum); Integer tagesartIId = null;/*from w w w . j a v a 2 s . c o m*/ Calendar c = Calendar.getInstance(); c.setTime(d_datum); ArrayList<String> daten = new ArrayList<String>(); int iTageVorraus = 1; try { ParametermandantDto parameter = getParameterFac().getMandantparameter(theClientDto.getMandant(), ParameterFac.KATEGORIE_PERSONAL, ParameterFac.PARAMETER_ZUTRITT_DATEN_VORLADEN); iTageVorraus = (Integer) parameter.getCWertAsObject(); } catch (RemoteException ex) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex); } for (int i = 0; i < iTageVorraus; i++) { String sDatum = c.get(c.YEAR) + ""; int iMonat = c.get(c.MONTH) + 1; int iTag = c.get(c.DATE); sDatum = sDatum + Helper.fitString2LengthAlignRight(iMonat + "", 2, '0') + Helper.fitString2LengthAlignRight(iTag + "", 2, '0'); // Besucherausweise- Onlinecheck StringBuffer onlinecheck = new StringBuffer(); onlinecheck.append("10"); // readerid onlinecheck.append(Helper.fitString2Length(ZutrittscontrollerFac.ZUTRITTSKLASSE_ONLINECHECK, 3, ' ')); // readerid onlinecheck.append(sDatum); // datum onlinecheck.append("0000"); // vonzeit onlinecheck.append("O"); // status onlinecheck.append("\r\n"); daten.add(new String(onlinecheck)); try { Integer tagesartIId_Feiertag = getZeiterfassungFac() .tagesartFindByCNr(ZeiterfassungFac.TAGESART_FEIERTAG, theClientDto).getIId(); Integer tagesartIId_Halbtag = getZeiterfassungFac() .tagesartFindByCNr(ZeiterfassungFac.TAGESART_HALBTAG, theClientDto).getIId(); tagesartIId = getZeiterfassungFac() .tagesartFindByCNr(Helper.holeTagbezeichnungLang(c.get(c.DAY_OF_WEEK)), theClientDto) .getIId(); ZutrittsobjektDto zutrittsobjektDto = zutrittsobjektFindByPrimaryKey(zutrittsobjektIId); String mandantderTuere = zutrittsobjektDto.getMandantCNr(); if (mandantderTuere == null) { mandantderTuere = getMandantFac() .mandantFindByPrimaryKey(theClientDto.getMandant(), theClientDto).getAnwenderDto() .getMandantCNrHauptmandant(); } BetriebskalenderDto dto = getPersonalFac().betriebskalenderFindByMandantCNrDDatum(d_datum, mandantderTuere, theClientDto); if (dto != null) { if (dto.getReligionIId() == null) { if (dto.getTagesartIId().equals(tagesartIId_Feiertag) || dto.getTagesartIId().equals(tagesartIId_Halbtag)) { tagesartIId = dto.getTagesartIId(); } else { tagesartIId = dto.getTagesartIId(); } } } } catch (RemoteException ex1) { throwEJBExceptionLPRespectOld(ex1); } SessionFactory factory = FLRSessionFactory.getFactory(); Session session = factory.openSession(); org.hibernate.Criteria crit = session.createCriteria(FLRZutrittsklasseobjekt.class).add(Restrictions .eq(ZutrittscontrollerFac.FLR_ZUTRITTSKLASSEOBJEKT_ZUTRITTSOBJEKT_I_ID, zutrittsobjektIId)); crit.addOrder(Order.asc(ZutrittscontrollerFac.FLR_ZUTRITTSKLASSEOBJEKT_ZUTRITTSKLASSE_I_ID)); List<?> resultList = crit.list(); Iterator<?> resultListIterator = resultList.iterator(); while (resultListIterator.hasNext()) { FLRZutrittsklasseobjekt flrzutrittsklasseobjekt = (FLRZutrittsklasseobjekt) resultListIterator .next(); try { Query query = em.createNamedQuery("ZutrittsmodelltagfindByZutrittsmodellIIdTagesartIId"); query.setParameter(1, flrzutrittsklasseobjekt.getZutrittsmodell_i_id()); query.setParameter(2, tagesartIId); Zutrittsmodelltag zutrittsmodelltag = (Zutrittsmodelltag) query.getSingleResult(); Integer zutrittsmodeltagIId = assembleZutrittsmodelltagDto(zutrittsmodelltag).getIId(); query = em.createNamedQuery("ZutrittsmodelltagdetailfindByZutrittsmodelltagIId"); query.setParameter(1, zutrittsmodeltagIId); ZutrittsmodelltagdetailDto[] tagdetaildtos = assembleZutrittsmodelltagdetailDtos( query.getResultList()); for (int detail = 0; detail < tagdetaildtos.length; detail++) { ZutrittsmodelltagdetailDto zutrittsmodelltagdetailDto = tagdetaildtos[detail]; String von = zutrittsmodelltagdetailDto.getUOffenvon().toString(); von = von.substring(0, 2) + von.substring(3, 5); StringBuffer string = new StringBuffer(); string.append("10"); // readerid string.append(Helper.fitString2Length( flrzutrittsklasseobjekt.getFlrzutrittsklasse().getC_nr(), 3, ' ')); // readerid string.append(sDatum); // datum string.append(von); // vonzeit string.append(zutrittsmodelltagdetailDto.getZutrittsoeffnungsartCNr().trim()); // status string.append("\r\n"); daten.add(new String(string)); if (Helper.short2Boolean(zutrittsmodelltagdetailDto.getBRestdestages()) == false) { string = new StringBuffer(); String bis = zutrittsmodelltagdetailDto.getUOffenbis().toString(); bis = bis.substring(0, 2) + bis.substring(3, 5); string.append("10"); // readerid string.append(Helper.fitString2Length( flrzutrittsklasseobjekt.getFlrzutrittsklasse().getC_nr(), 3, ' ')); // readerid string.append(sDatum); // datum string.append(bis); // vonzeit string.append("Z"); // status string.append("\r\n"); daten.add(new String(string)); } } } catch (NoResultException ex) { // nothing here } } session.close(); c.set(c.DATE, c.get(c.DATE) + 1); d_datum = new java.sql.Timestamp(c.getTimeInMillis()); } String datenGesamt = ""; // sortieren for (int i = daten.size() - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (((String) daten.get(j)).compareTo((String) daten.get(j + 1)) > 0) { String lagerbewegungDtoTemp = (String) daten.get(j); daten.set(j, daten.get(j + 1)); daten.set(j + 1, lagerbewegungDtoTemp); } } } for (int i = 0; i < daten.size(); i++) { datenGesamt += daten.get(i); } return new String(datenGesamt); }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
private void sort(ArrayList<String> l, String objectName, String type, String pattern, String order, boolean stopOnFailure, final Object[] customError) { for (int i = 0; i < l.size(); i++) { // System.out.println(l.get(i)); if (l.get(i).equals("")) { l.set(i, " "); }//from ww w.java2 s . com } System.out.println("Unsorted ArrayList in Java : " + l); System.out.println("Order :" + order); System.out.println("Pattern :" + pattern); System.out.println("Type :" + type); List<String> listOrg = new ArrayList<String>(); for (int i = 0; i < l.size(); i++) { listOrg.add(l.get(i).toString()); } ////////////////////////////////////////////////////////////////////////// if (type.equals("string")) { if ("ascending".equals(order) && "alphabetically".equals(pattern)) { //System.out.println("list"+l); //Collections.sort(l, ALPHA_ORDER); Collections.sort(l, String.CASE_INSENSITIVE_ORDER); //System.out.println("Ordered list"+l); if (l.equals(listOrg)) { // System.out.println("In ascending Order alphabetically" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { // System.out.println("Not in ascending Order alphabetically" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("descending".equals(order) && "alphabetically".equals(pattern)) { // Collections.sort(l, ALPHA_ORDER); Collections.sort(l, String.CASE_INSENSITIVE_ORDER); //System.out.println("Ordered list"+l); List<String> listDes = new ArrayList<String>(); for (int i = l.size() - 1; i >= 0; i--) { // System.out.println(l.get(i).toString()); //String s = (String) l.get( i ) ; listDes.add(l.get(i).toString()); } //System.out.println("Ordered list"+listDes); if (listDes.equals(listOrg)) { //System.out.println("In descending Order alphabetically" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not in descending Order alphabetically" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("ascending".equals(order) && "1Aa".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrder1Aa); //Collections.sort(l); //System.out.println("Ordered list"+l); if (l.equals(listOrg)) { //System.out.println("In Ascending Order 1Aa" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not in Ascending Order 1Aa" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("descending".equals(order) && "1Aa".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrder1Aa); List<String> listDes = new ArrayList<String>(); for (int i = l.size() - 1; i >= 0; i--) { // System.out.println(l.get(i).toString()); //String s = (String) l.get( i ) ; listDes.add(l.get(i).toString()); } //System.out.println("Ordered list"+listDes); if (listDes.equals(listOrg)) { //System.out.println("In Descending Order 1Aa" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not in Descending Order 1Aa" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("ascending".equals(order) && "Aa1".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrderAa1); //System.out.println("Ordered list"+l); if (l.equals(listOrg)) { //System.out.println("In Ascending Order Aa1" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not in Ascending Order Aa1" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("descending".equals(order) && "Aa1".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrderAa1); List<String> listDes = new ArrayList<String>(); for (int i = l.size() - 1; i >= 0; i--) { // System.out.println(l.get(i).toString()); //String s = (String) l.get( i ) ; listDes.add(l.get(i).toString()); } //System.out.println("Ordered list"+listDes); if (listDes.equals(listOrg)) { //System.out.println("In Descending Order Aa1" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { // System.out.println("Not in Descending Order Aa1" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("ascending".equals(order) && "aA1".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrderaA1); //System.out.println("Ordered list"+l); if (l.equals(listOrg)) { // System.out.println("In Ascending Order aA1" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { // System.out.println("Not in Ascending Order aA1" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if ("descending".equals(order) && "aA1".equals(pattern)) { Collections.sort(l, DiffSort.diffNaturalOrderaA1); List<String> listDes = new ArrayList<String>(); for (int i = l.size() - 1; i >= 0; i--) { // System.out.println(l.get(i).toString()); //String s = (String) l.get( i ) ; listDes.add(l.get(i).toString()); } //System.out.println("Ordered list"+listDes); if (listDes.equals(listOrg)) { // System.out.println("In Descending Order aA1" ); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not in Descending Order aA1" ); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else { if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } ///////////////////////////////////////////////////////////////////////////////////////// } else if (type.equals("numeric")) { List<Double> DoublelistOrg = new ArrayList<Double>(); List<Double> DoublelistTemp = new ArrayList<Double>(); try { for (int i = 0; i < l.size(); i++) { // System.out.println(l.get(i)); Rs String temp = l.get(i).replace(",", ""); temp = temp.replace("", ""); temp = temp.replace("Rs", ""); temp = temp.replace("$", ""); temp = temp.replace("", ""); // System.out.println(temp); double value = Double.parseDouble(temp); DoublelistOrg.add(value); DoublelistTemp.add(value); } } catch (Exception e) { // e.printStackTrace(); reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + type + ") not match"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + type + ") not match"); } // System.out.println(DoublelistOrg); if (order.equals("ascending")) { Collections.sort(DoublelistTemp); if (DoublelistTemp.equals(DoublelistOrg)) { // System.out.println("ascending"); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not ascending"); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if (order.equals("descending")) { Collections.sort(DoublelistTemp); Collections.reverse(DoublelistTemp); if (DoublelistTemp.equals(DoublelistOrg)) { // System.out.println("descending"); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { // System.out.println("Not descending"); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + order + ") not match"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + order + ") not match"); } } else if (type.equals("date")) { List<Date> datelistOrg = new ArrayList<Date>(); List<Date> datelistTemp = new ArrayList<Date>(); try { for (int i = 0; i < l.size(); i++) { // System.out.println(l.get(i)); Rs SimpleDateFormat formatter = new SimpleDateFormat(pattern); String tempDate = l.get(i); // System.out.println(l.get(i)); Date date = formatter.parse(tempDate); // System.out.println(date); //System.out.println(formatter.format(date)); datelistOrg.add(date); datelistTemp.add(date); } } catch (Exception e) { // e.printStackTrace(); reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + type + ") not match"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + type + ") not match"); } //System.out.println( datelistOrg); if (order.equals("ascending")) { Collections.sort(datelistTemp); if (datelistTemp.equals(datelistOrg)) { // System.out.println("ascending"); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { //System.out.println("Not ascending"); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else if (order.equals("descending")) { Collections.sort(datelistTemp); Collections.reverse(datelistTemp); if (datelistTemp.equals(datelistOrg)) { // System.out.println("descending"); reportresult(true, "CHECK SORTING :", "PASSED", "Check sorting command : Element " + objectName + " sorted"); } else { // System.out.println("Not descending"); if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CHECK SORTING command : Element (" + objectName + ") not sorted"); } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + objectName + ") not sorted"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + objectName + ") not sorted"); } } } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Element (" + order + ") not match"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Element (" + order + ") not match"); } } else { reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED", "CHECK SORTING command : Type (" + type + ") not match"); checkTrue(false, stopOnFailure, "CHECK SORTING command : Type (" + type + ") not match"); } }
From source file:com.jhh.hdb.sqlparser.MySemanticAnalyzer.java
/** * Merges node to target//from w w w . j a va 2s . co m */ private void mergeJoins(QB qb, QBJoinTree node, QBJoinTree target, int pos, int[] tgtToNodeExprMap) { String[] nodeRightAliases = node.getRightAliases(); String[] trgtRightAliases = target.getRightAliases(); String[] rightAliases = new String[nodeRightAliases.length + trgtRightAliases.length]; for (int i = 0; i < trgtRightAliases.length; i++) { rightAliases[i] = trgtRightAliases[i]; } for (int i = 0; i < nodeRightAliases.length; i++) { rightAliases[i + trgtRightAliases.length] = nodeRightAliases[i]; } target.setRightAliases(rightAliases); target.getAliasToOpInfo().putAll(node.getAliasToOpInfo()); String[] nodeBaseSrc = node.getBaseSrc(); String[] trgtBaseSrc = target.getBaseSrc(); String[] baseSrc = new String[nodeBaseSrc.length + trgtBaseSrc.length - 1]; for (int i = 0; i < trgtBaseSrc.length; i++) { baseSrc[i] = trgtBaseSrc[i]; } for (int i = 1; i < nodeBaseSrc.length; i++) { baseSrc[i + trgtBaseSrc.length - 1] = nodeBaseSrc[i]; } target.setBaseSrc(baseSrc); ArrayList<ArrayList<ASTNode>> expr = target.getExpressions(); for (int i = 0; i < nodeRightAliases.length; i++) { List<ASTNode> nodeConds = node.getExpressions().get(i + 1); ArrayList<ASTNode> reordereNodeConds = new ArrayList<ASTNode>(); for (int k = 0; k < tgtToNodeExprMap.length; k++) { reordereNodeConds.add(nodeConds.get(tgtToNodeExprMap[k])); } expr.add(reordereNodeConds); } ArrayList<Boolean> nns = node.getNullSafes(); ArrayList<Boolean> tns = target.getNullSafes(); for (int i = 0; i < tns.size(); i++) { tns.set(i, tns.get(i) & nns.get(i)); // any of condition contains non-NS, non-NS } ArrayList<ArrayList<ASTNode>> filters = target.getFilters(); for (int i = 0; i < nodeRightAliases.length; i++) { filters.add(node.getFilters().get(i + 1)); } if (node.getFilters().get(0).size() != 0) { ArrayList<ASTNode> filterPos = filters.get(pos); filterPos.addAll(node.getFilters().get(0)); } int[][] nmap = node.getFilterMap(); int[][] tmap = target.getFilterMap(); int[][] newmap = new int[tmap.length + nmap.length - 1][]; for (int[] mapping : nmap) { if (mapping != null) { for (int i = 0; i < mapping.length; i += 2) { if (pos > 0 || mapping[i] > 0) { mapping[i] += trgtRightAliases.length; } } } } if (nmap[0] != null) { if (tmap[pos] == null) { tmap[pos] = nmap[0]; } else { int[] appended = new int[tmap[pos].length + nmap[0].length]; System.arraycopy(tmap[pos], 0, appended, 0, tmap[pos].length); System.arraycopy(nmap[0], 0, appended, tmap[pos].length, nmap[0].length); tmap[pos] = appended; } } System.arraycopy(tmap, 0, newmap, 0, tmap.length); System.arraycopy(nmap, 1, newmap, tmap.length, nmap.length - 1); target.setFilterMap(newmap); ArrayList<ArrayList<ASTNode>> filter = target.getFiltersForPushing(); for (int i = 0; i < nodeRightAliases.length; i++) { filter.add(node.getFiltersForPushing().get(i + 1)); } if (node.getFiltersForPushing().get(0).size() != 0) { /* * for each predicate: * - does it refer to one or many aliases * - if one: add it to the filterForPushing list of that alias * - if many: add as a filter from merging trees. */ for (ASTNode nodeFilter : node.getFiltersForPushing().get(0)) { int fPos = ParseUtils.checkJoinFilterRefersOneAlias(target.getBaseSrc(), nodeFilter); if (fPos != -1) { filter.get(fPos).add(nodeFilter); } else { target.addPostJoinFilter(nodeFilter); } } } if (node.getNoOuterJoin() && target.getNoOuterJoin()) { target.setNoOuterJoin(true); } else { target.setNoOuterJoin(false); } if (node.getNoSemiJoin() && target.getNoSemiJoin()) { target.setNoSemiJoin(true); } else { target.setNoSemiJoin(false); } target.mergeRHSSemijoin(node); JoinCond[] nodeCondns = node.getJoinCond(); int nodeCondnsSize = nodeCondns.length; JoinCond[] targetCondns = target.getJoinCond(); int targetCondnsSize = targetCondns.length; JoinCond[] newCondns = new JoinCond[nodeCondnsSize + targetCondnsSize]; for (int i = 0; i < targetCondnsSize; i++) { newCondns[i] = targetCondns[i]; } for (int i = 0; i < nodeCondnsSize; i++) { JoinCond nodeCondn = nodeCondns[i]; if (nodeCondn.getLeft() == 0) { nodeCondn.setLeft(pos); } else { nodeCondn.setLeft(nodeCondn.getLeft() + targetCondnsSize); } nodeCondn.setRight(nodeCondn.getRight() + targetCondnsSize); newCondns[targetCondnsSize + i] = nodeCondn; } target.setJoinCond(newCondns); if (target.isMapSideJoin()) { assert node.isMapSideJoin(); List<String> mapAliases = target.getMapAliases(); for (String mapTbl : node.getMapAliases()) { if (!mapAliases.contains(mapTbl)) { mapAliases.add(mapTbl); } } target.setMapAliases(mapAliases); } }
From source file:v800_trainer.JCicloTronic.java
public void ChangeModel() { setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (Hauptfenster != null) Hauptfenster.setSelectedIndex(0); DataProperty = new java.util.Properties(); jTableaccess = Datentabelle;/*from w ww. j av a 2 s . c om*/ String Filename = ""; String PlaceHolder = " "; File path = new File(Properties.getProperty("data.dir")); final String[] names = { "Datum", "Strecke", "Hhenmeter", "Zeit", "Titel" }; String[] list = path.list(new DirFilter("_Tour.cfg")); RowCount = 0; int Anzahlcfg = 0; if (list != null) Anzahlcfg = list.length; if (Anzahlcfg == 0) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } Object datab[] = new Object[8]; ArrayList<Object[]> data_list = new ArrayList<Object[]>(); String hmString = ""; DecimalFormat form = new DecimalFormat("0");//Format ohne Kommastelle int j = 0; for (int i = 0; i < Anzahlcfg; i++) { //berprfen ob Hhenmeter eingetragen sind - ansonsten ermitteln (gilt fr neue Dateien) Filename = path.getPath() + SystemProperties.getProperty("file.separator") + list[i]; DataProperty = new java.util.Properties(); try { BufferedInputStream in = new BufferedInputStream(new FileInputStream(Filename)); DataProperty.load(in); in.close(); // prfen ob Datei gezeigt werden soll - Visible = 0 wenn Datei gelscht wurde if (!DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1")) continue; // wenn keine Hhenmeter eingetragen wurden (Erstaufruf) dann Hhenmeter ermitteln if (DataProperty.getProperty("Hoehenmeter", "novalue").equalsIgnoreCase("novalue") && DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1") && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { JTourData Dummydata = new JTourData(Filename.substring(0, Filename.lastIndexOf('.')), this); DataProperty.setProperty("Hoehenmeter", form.format(Dummydata.ges_Hoehep)); try { Ausgabedatei = new FileOutputStream(Filename); DataProperty.store(Ausgabedatei, "Tour Eigenschaften: " + DataProperty.getProperty("Jahr") + DataProperty.getProperty("Monat") + DataProperty.getProperty("Tag") + DataProperty.getProperty("Stunde") + DataProperty.getProperty("Minute")); Ausgabedatei.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, " Fehler bei Speichern der DataProperty in ChangeModel", "Achtung!", JOptionPane.ERROR_MESSAGE); } } try { if (Integer.parseInt(DataProperty.getProperty("Visible", "1")) == 1 && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { datab[0] = new String(" " + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Jahr", "1111")); datab[1] = PlaceHolder.substring(0, 9 - DataProperty.getProperty("Strecke", "0").length()) + DataProperty.getProperty("Strecke", "0") + " "; // data[j][1] = new String(DataProperty.getProperty("Strecke") + " "); datab[2] = new String( " " + HMS(java.lang.Integer.parseInt(DataProperty.getProperty("Dauer", "0")))); datab[3] = new String(DataProperty.getProperty("Titel", "---")); datab[4] = new String(DataProperty.getProperty("Jahr", "1111") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Stunde", "12") + "." + DataProperty.getProperty("Minute", "59")); datab[5] = new String(Filename.substring(0, Filename.lastIndexOf('.'))); datab[6] = new String(DataProperty.getProperty("Typ", "unbekannt")); hmString = "" + (int) Float.parseFloat(DataProperty.getProperty("Hoehenmeter", "0")); datab[7] = PlaceHolder.substring(0, 9 - hmString.length()) + hmString + " "; data_list.add(datab.clone()); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Fehler beim Erstellen der Datenliste " + e + " " + j, "Achtung!", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { System.out.println( "NEW IO-Fehler bei " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n " + e + " " + e.getLocalizedMessage() + "--File deleted"); e.printStackTrace(); JOptionPane.showMessageDialog(null, "Fehler beim Einlesen eines cfg Files " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n wurde gelscht!", "Achtung!", JOptionPane.ERROR_MESSAGE); File deletefile = new File( path.getPath() + SystemProperties.getProperty("file.separator") + list[i]); if (deletefile.exists()) deletefile.delete(); ChangeModel(); } } TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return names.length; } @Override public String getColumnName(int column) { return names[column]; } @Override public int getRowCount() { return data_list.size(); } @Override public Object getValueAt(int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); return data[col]; } @Override public void setValueAt(Object Ob, int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); data[col] = Ob; data_list.set(row, data); } }; sorter = new TableSorter(dataModel); DatumColumn = new TableColumn(0); DatumColumn.setHeaderValue(names[0]); DatumColumn.setResizable(false); StreckeColumn = new TableColumn(1); StreckeColumn.setHeaderValue(names[1]); StreckeColumn.setResizable(false); HoeheColumn = new TableColumn(7); HoeheColumn.setHeaderValue(names[2]); HoeheColumn.setResizable(false); ZeitColumn = new TableColumn(2); ZeitColumn.setHeaderValue(names[3]); ZeitColumn.setResizable(false); NotizColumn = new TableColumn(3); NotizColumn.setHeaderValue(names[4]); DatumColumn.setMinWidth((int) 80 * FontSize / 12); StreckeColumn.setMinWidth((int) 65 * FontSize / 12); HoeheColumn.setMinWidth((int) 75 * FontSize / 12); ZeitColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setPreferredWidth((int) 75 * FontSize / 12 + 1000); DefaultTableCellRenderer TableCell = new DefaultTableCellRenderer(); TableCell.setHorizontalAlignment(JLabel.CENTER); HoeheColumn.setCellRenderer(TableCell); StreckeColumn.setCellRenderer(TableCell); DatumColumn.setCellRenderer(TableCell); ZeitColumn.setCellRenderer(TableCell); HoeheColumn.setHeaderRenderer(TableCell); StreckeColumn.setHeaderRenderer(TableCell); DatumColumn.setHeaderRenderer(TableCell); ZeitColumn.setHeaderRenderer(TableCell); NotizColumn.setHeaderRenderer(TableCell); DefaultTableColumnModel FileTableModel = new DefaultTableColumnModel(); FileTableModel.addColumn(DatumColumn); FileTableModel.addColumn(StreckeColumn); FileTableModel.addColumn(HoeheColumn); FileTableModel.addColumn(ZeitColumn); FileTableModel.addColumn(NotizColumn); Datentabelle.setModel(sorter); Datentabelle.setColumnModel(FileTableModel); Datentabelle.setRowHeight(FontSize + 5); sorter.addMouseListenerToHeaderInTable(Datentabelle); sorter.sortByColumn(0, false); Datentabelle.clearSelection(); SelectionChanged = true; JScrollBar verticaldummy = Datenliste_scroll_Panel.getVerticalScrollBar(); verticaldummy.setPreferredSize(new Dimension(FontSize + 10, FontSize + 10)); Datenliste_scroll_Panel.setVerticalScrollBar(verticaldummy); Update = false; Datenliste_Jahr.removeAllItems(); Datenliste_TourTyp.removeAllItems(); Auswahl_bersicht.removeAllItems(); JahrVergleich.removeAllItems(); InitComboJahr(); InitComboTyp(); Update = true; if (Datentabelle.getRowCount() != 0) { Datentabelle.addRowSelectionInterval(0, 0); Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0)); } if (Uebersicht != null) { Uebersicht = null; } jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount()); repaint(); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.java
/** * Merges node to target// ww w. j a va2 s .c om */ private void mergeJoins(QB qb, QBJoinTree node, QBJoinTree target, int pos, int[] tgtToNodeExprMap) { String[] nodeRightAliases = node.getRightAliases(); String[] trgtRightAliases = target.getRightAliases(); String[] rightAliases = new String[nodeRightAliases.length + trgtRightAliases.length]; for (int i = 0; i < trgtRightAliases.length; i++) { rightAliases[i] = trgtRightAliases[i]; } for (int i = 0; i < nodeRightAliases.length; i++) { rightAliases[i + trgtRightAliases.length] = nodeRightAliases[i]; } target.setRightAliases(rightAliases); target.getAliasToOpInfo().putAll(node.getAliasToOpInfo()); String[] nodeBaseSrc = node.getBaseSrc(); String[] trgtBaseSrc = target.getBaseSrc(); String[] baseSrc = new String[nodeBaseSrc.length + trgtBaseSrc.length - 1]; for (int i = 0; i < trgtBaseSrc.length; i++) { baseSrc[i] = trgtBaseSrc[i]; } for (int i = 1; i < nodeBaseSrc.length; i++) { baseSrc[i + trgtBaseSrc.length - 1] = nodeBaseSrc[i]; } target.setBaseSrc(baseSrc); ArrayList<ArrayList<ASTNode>> expr = target.getExpressions(); for (int i = 0; i < nodeRightAliases.length; i++) { List<ASTNode> nodeConds = node.getExpressions().get(i + 1); ArrayList<ASTNode> reordereNodeConds = new ArrayList<ASTNode>(); for (int k = 0; k < tgtToNodeExprMap.length; k++) { reordereNodeConds.add(nodeConds.get(tgtToNodeExprMap[k])); } expr.add(reordereNodeConds); } ArrayList<Boolean> nns = node.getNullSafes(); ArrayList<Boolean> tns = target.getNullSafes(); for (int i = 0; i < tns.size(); i++) { tns.set(i, tns.get(i) & nns.get(i)); // any of condition contains non-NS, non-NS } ArrayList<ArrayList<ASTNode>> filters = target.getFilters(); for (int i = 0; i < nodeRightAliases.length; i++) { filters.add(node.getFilters().get(i + 1)); } if (node.getFilters().get(0).size() != 0) { ArrayList<ASTNode> filterPos = filters.get(pos); filterPos.addAll(node.getFilters().get(0)); } int[][] nmap = node.getFilterMap(); int[][] tmap = target.getFilterMap(); int[][] newmap = new int[tmap.length + nmap.length - 1][]; for (int[] mapping : nmap) { if (mapping != null) { for (int i = 0; i < mapping.length; i += 2) { if (pos > 0 || mapping[i] > 0) { mapping[i] += trgtRightAliases.length; } } } } if (nmap[0] != null) { if (tmap[pos] == null) { tmap[pos] = nmap[0]; } else { int[] appended = new int[tmap[pos].length + nmap[0].length]; System.arraycopy(tmap[pos], 0, appended, 0, tmap[pos].length); System.arraycopy(nmap[0], 0, appended, tmap[pos].length, nmap[0].length); tmap[pos] = appended; } } System.arraycopy(tmap, 0, newmap, 0, tmap.length); System.arraycopy(nmap, 1, newmap, tmap.length, nmap.length - 1); target.setFilterMap(newmap); ArrayList<ArrayList<ASTNode>> filter = target.getFiltersForPushing(); for (int i = 0; i < nodeRightAliases.length; i++) { filter.add(node.getFiltersForPushing().get(i + 1)); } if (node.getFiltersForPushing().get(0).size() != 0) { /* * for each predicate: * - does it refer to one or many aliases * - if one: add it to the filterForPushing list of that alias * - if many: add as a filter from merging trees. */ for (ASTNode nodeFilter : node.getFiltersForPushing().get(0)) { int fPos = ParseUtils.checkJoinFilterRefersOneAlias(target.getBaseSrc(), nodeFilter); if (fPos != -1) { filter.get(fPos).add(nodeFilter); } else { target.addPostJoinFilter(nodeFilter); } } } if (node.getNoOuterJoin() && target.getNoOuterJoin()) { target.setNoOuterJoin(true); } else { target.setNoOuterJoin(false); } if (node.getNoSemiJoin() && target.getNoSemiJoin()) { target.setNoSemiJoin(true); } else { target.setNoSemiJoin(false); } target.mergeRHSSemijoin(node); JoinCond[] nodeCondns = node.getJoinCond(); int nodeCondnsSize = nodeCondns.length; JoinCond[] targetCondns = target.getJoinCond(); int targetCondnsSize = targetCondns.length; JoinCond[] newCondns = new JoinCond[nodeCondnsSize + targetCondnsSize]; for (int i = 0; i < targetCondnsSize; i++) { newCondns[i] = targetCondns[i]; } for (int i = 0; i < nodeCondnsSize; i++) { JoinCond nodeCondn = nodeCondns[i]; if (nodeCondn.getLeft() == 0) { nodeCondn.setLeft(pos); } else { nodeCondn.setLeft(nodeCondn.getLeft() + targetCondnsSize); } nodeCondn.setRight(nodeCondn.getRight() + targetCondnsSize); newCondns[targetCondnsSize + i] = nodeCondn; } target.setJoinCond(newCondns); if (target.isMapSideJoin()) { assert node.isMapSideJoin(); List<String> mapAliases = target.getMapAliases(); for (String mapTbl : node.getMapAliases()) { if (!mapAliases.contains(mapTbl)) { mapAliases.add(mapTbl); } } target.setMapAliases(mapAliases); } if (node.getPostJoinFilters().size() != 0) { // Safety check: if we are merging join operators and there are post-filtering // conditions, they cannot be outer joins assert node.getNoOuterJoin(); if (target.getPostJoinFilters().size() != 0) { assert target.getNoOuterJoin(); } for (ASTNode exprPostFilter : node.getPostJoinFilters()) { target.addPostJoinFilter(exprPostFilter); } } }