コード例 #1
0
 private void createSystemUser() {
   systemUser = new SystemUser();
   systemUser.setId(currentUserId);
   SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
   systemUserDAO.getData(systemUser);
 }
  protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");

    BaseActionForm dynaForm = (BaseActionForm) form;
    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);

    // bugzilla 2614 allow for NB domain samples
    String selectedTestId = "";

    String referenceTableId = SystemConfiguration.getInstance().getResultReferenceTableId();
    String refId = (String) dynaForm.get("noteRefId");

    String noteIds = (String) dynaForm.get("noteIds");
    String noteSubjects = (String) dynaForm.get("noteSubjects");
    String noteTexts = (String) dynaForm.get("noteTexts");
    String noteTypes = (String) dynaForm.get("noteTypes");
    String noteLastupdateds = (String) dynaForm.get("noteLastupdateds");

    List noteIdList = new ArrayList();
    List noteSubjectList = new ArrayList();
    List noteTextList = new ArrayList();
    List noteTypeList = new ArrayList();
    List noteLastupdatedList = new ArrayList();

    String textSeparator = SystemConfiguration.getInstance().getDefaultTextSeparator();

    NoteDAO noteDAO = new NoteDAOImpl();
    SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
    // bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
    ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();

    // get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    try {

      textSeparator = StringUtil.convertStringToRegEx(textSeparator);

      SystemUser systemUser = new SystemUser();
      systemUser.setId(sysUserId);
      systemUserDAO.getData(systemUser);

      // get all the data required to forward to correct page

      // get analysis id from result
      ResultDAO resultDAO = new ResultDAOImpl();
      Result result = new Result();
      result.setId(refId);
      resultDAO.getData(result);

      String analysisId = result.getAnalysis().getId();

      AnalysisDAO analysisDAO = new AnalysisDAOImpl();
      Analysis analysis = new Analysis();
      analysis.setId(analysisId);
      analysisDAO.getData(analysis);

      // get test id from analysis
      selectedTestId = analysis.getTest().getId();

      // get domain from sample
      SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
      SampleItem sampleItem = new SampleItem();
      sampleItem.setId(analysis.getSampleItem().getId());
      sampleItemDAO.getData(sampleItem);

      SampleDAO sampleDAO = new SampleDAOImpl();
      Sample sample = new Sample();
      // bugzilla 1773 need to store sample not sampleId for use in sorting
      sample.setId(sampleItem.getSample().getId());
      sampleDAO.getData(sample);

      // bugzilla 2614 allow for NB domain samples
      // now that we have the domain (for forwarding to correct fail page)
      // validate note popup form data!
      try {
        // bugzilla 2254 moved loadListFromStringOfElements to StringUtil
        noteIdList = StringUtil.loadListFromStringOfElements(noteIds, textSeparator, false);
        noteLastupdatedList =
            StringUtil.loadListFromStringOfElements(noteLastupdateds, textSeparator, false);
        // these three need to be validated for empty strings
        noteSubjectList =
            StringUtil.loadListFromStringOfElements(noteSubjects, textSeparator, true);
        noteTextList = StringUtil.loadListFromStringOfElements(noteTexts, textSeparator, true);
        noteTypeList = StringUtil.loadListFromStringOfElements(noteTypes, textSeparator, true);

      } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("ResultsEntryNotesUpdateAction", "performAction()", e.toString());
        String messageKey = "note.note";
        ActionError error = new ActionError("errors.invalid", getMessageForKey(messageKey), null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        forward = FWD_FAIL;

        return mapping.findForward(forward);
      }

      for (int i = 0; i < noteIdList.size(); i++) {
        Note note = new Note();

        String noteId = (String) noteIdList.get(i);
        note.setReferenceId(refId);
        // bugzilla 1922
        // bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
        ReferenceTables referenceTables = new ReferenceTables();
        referenceTables.setId(referenceTableId);
        // bugzilla 2571
        referenceTablesDAO.getData(referenceTables);
        note.setReferenceTables(referenceTables);
        note.setSystemUser(systemUser);
        note.setSystemUserId(sysUserId);
        // 1926 for audit trail
        note.setSysUserId(sysUserId);

        if (noteId != null && !noteId.equals("0")) {
          note.setId((String) noteIdList.get(i));
          note.setSubject((String) noteSubjectList.get(i));
          note.setText((String) noteTextList.get(i));
          note.setNoteType((String) noteTypeList.get(i));

          Timestamp noteTimestamp = null;
          if (!StringUtil.isNullorNill((String) noteLastupdatedList.get(i))) {

            noteTimestamp = DateUtil.formatStringToTimestamp((String) noteLastupdatedList.get(i));
          }

          note.setLastupdated(noteTimestamp);

          // UPDATE
          noteDAO.updateData(note);
          // }

        } else {
          // this is a new note
          note.setSubject((String) noteSubjectList.get(i));
          note.setText((String) noteTextList.get(i));
          note.setNoteType((String) noteTypeList.get(i));
          // INSERT
          noteDAO.insertData(note);
        }
      }

      tx.commit();

      return getForward(mapping.findForward(forward), selectedTestId, analysisId);

    } catch (LIMSRuntimeException lre) {
      // bugzilla 2154
      LogEvent.logError("ResultsEntryNotesUpdateAction", "performAction()", lre.toString());
      tx.rollback();
      errors = new ActionMessages();
      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        error = new ActionError("errors.OptimisticLockException", null, null);
      } else {
        if (lre.getException() instanceof LIMSDuplicateRecordException) {
          java.util.Locale locale =
              (java.util.Locale)
                  request.getSession().getAttribute("org.apache.struts.action.LOCALE");
          String messageKey = "note.note";
          String msg =
              ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
          error = new ActionError("errors.DuplicateRecord", msg, null);

        } else {
          error = new ActionError("errors.UpdateException", null, null);
        }
      }
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);

      // disable previous and next
      request.setAttribute(PREVIOUS_DISABLED, "true");
      request.setAttribute(NEXT_DISABLED, "true");

      // default forward fail
      forward = FWD_FAIL;

    } finally {
      HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL)
        || forward.equals(FWD_FAIL_HUMAN)
        || forward.equals(FWD_FAIL_ANIMAL)) return mapping.findForward(forward);

    // initialize the form
    dynaForm.initialize(mapping);

    // we need this for subsequent actions to
    // get data related to note parent for forwarding to next page
    request.setAttribute("refId", refId);
    request.setAttribute(SELECTED_TEST_ID, selectedTestId);

    return mapping.findForward(forward);
  }
コード例 #3
0
  protected List populateHistoryList(
      HttpServletRequest request,
      List historyRecords,
      String rootNodeName,
      String xslMappingFileName)
      throws LIMSRuntimeException {
    List list = new ArrayList();
    try {
      SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
      AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl();

      for (int i = 0; i < historyRecords.size(); i++) {

        History historyRecord = (History) historyRecords.get(i);
        Timestamp date = historyRecord.getTimestamp();
        String stringLocale = SystemConfiguration.getInstance().getDefaultLocale().toString();
        String dateForDisplay = DateUtil.convertTimestampToStringDateAndTime(date, stringLocale);

        SystemUser systemUser = new SystemUser();
        systemUser.setId(historyRecord.getSysUserId());
        systemUserDAO.getData(systemUser);
        String blob = null;
        if (!historyRecord.getActivity().equals(AUDIT_TRAIL_INSERT)) {
          blob = auditTrailDAO.retrieveBlobData(historyRecord.getId());
        }

        // this is temporary until 2593 has been completed

        if (historyRecord.getActivity().equals(IActionConstants.AUDIT_TRAIL_UPDATE)) {
          blob = "<" + rootNodeName + ">" + blob + "</" + rootNodeName + ">";
        }

        if (!StringUtil.isNullorNill(blob)) {
          HistoryXmlHelper historyXmlHelper = new HistoryXmlHelper();
          historyXmlHelper.setActivity(historyRecord.getActivity());
          historyXmlHelper.setUserName(systemUser.getNameForDisplay());

          String media = null, title = null, charset = null, xsldata = "";
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          try {

            //						NOTE!!!!
            //						in order to run this in oc4j I needed to do the following:
            // add this to OC4J startup:
            // -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
            // to make sure that oc4j uses correct XSL processor (else it could not handle "function
            // extensions" used to bring in MessageResources labels
            // place xalan.jar, xml-apis.jar, XercesImpl.jar into the applib folder of the oc4j
            // installation

            TransformerFactory tFactory = TransformerFactory.newInstance();

            HttpSession session = request.getSession();
            ServletContext context = session.getServletContext();

            File xslFile =
                new File(context.getRealPath("/WEB-INF/transformation/" + xslMappingFileName));

            Source stylesheet = new StreamSource(xslFile);

            Transformer transformer = tFactory.newTransformer(stylesheet);

            System.out.println("This is blob " + blob);
            transformer.transform(
                new StreamSource(new StringReader(blob)), new StreamResult(outputStream));

          } catch (TransformerConfigurationException tce) {
            tce.printStackTrace();
          } catch (TransformerException te) {
            te.printStackTrace();
          } catch (Exception e) {
            e.printStackTrace();
          }

          System.out.println("This is xml " + outputStream.toString());
          historyXmlHelper.setChange(outputStream.toString());

          historyXmlHelper.setDate(dateForDisplay);

          if (!StringUtil.isNullorNill(historyXmlHelper.getChange())) {
            historyXmlHelper.setChange(historyXmlHelper.getChange().trim());
          }

          if (!StringUtil.isNullorNill(historyXmlHelper.getChange())) {
            list.add(historyXmlHelper);
          }
        }
      }
    } catch (Exception e) {
      throw new LIMSRuntimeException(e);
    }
    return list;
  }