Program: 115006
Project: 115006
Buggy source:
@Override public void processRequest() throws Exception {
  StudySubjectDAO subdao=new StudySubjectDAO(sm.getDataSource());
  SubjectDAO sdao=new SubjectDAO(sm.getDataSource());
  AuditDAO adao=new AuditDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
  StudyDAO studydao=new StudyDAO(sm.getDataSource());
  CRFDAO cdao=new CRFDAO(sm.getDataSource());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  StudySubjectBean studySubject=null;
  SubjectBean subject=null;
  ArrayList events=null;
  ArrayList studySubjectAudits=new ArrayList();
  ArrayList eventCRFAudits=new ArrayList();
  ArrayList studyEventAudits=new ArrayList();
  ArrayList allDeletedEventCRFs=new ArrayList();
  ArrayList allEventCRFs=new ArrayList();
  ArrayList allEventCRFItems=new ArrayList();
  String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
  FormProcessor fp=new FormProcessor(request);
  int studySubId=fp.getInt("String_Node_Str",true);
  if (studySubId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_STUDY_SUBJECTS);
  }
 else {
    studySubject=(StudySubjectBean)subdao.findByPK(studySubId);
    StudyBean study=(StudyBean)studydao.findByPK(studySubject.getStudyId());
    if (studySubject.getStudyId() != currentStudy.getId()) {
      if (currentStudy.getParentStudyId() > 0) {
        addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"));
        forwardPage(Page.MENU_SERVLET);
        return;
      }
 else {
        Collection sites=studydao.findOlnySiteIdsByStudy(currentStudy);
        if (!sites.contains(study.getId())) {
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"));
          forwardPage(Page.MENU_SERVLET);
          return;
        }
      }
    }
    subject=(SubjectBean)sdao.findByPK(studySubject.getSubjectId());
    Collection studySubjectAuditEvents=adao.findStudySubjectAuditEvents(studySubject.getId());
    for (Iterator iterator=studySubjectAuditEvents.iterator(); iterator.hasNext(); ) {
      AuditBean auditBean=(AuditBean)iterator.next();
      if (auditBean.getAuditEventTypeId() == 3) {
        auditBean.setOldValue(Status.get(Integer.parseInt(auditBean.getOldValue())).getName());
        auditBean.setNewValue(Status.get(Integer.parseInt(auditBean.getNewValue())).getName());
      }
    }
    studySubjectAudits.addAll(studySubjectAuditEvents);
    studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
    studySubjectAudits.addAll(adao.findStudySubjectGroupAssignmentAuditEvents(studySubject.getId()));
    events=sedao.findAllByStudySubject(studySubject);
    for (int i=0; i < events.size(); i++) {
      StudyEventBean studyEvent=(StudyEventBean)events.get(i);
      studyEvent.setStudyEventDefinition((StudyEventDefinitionBean)seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
      studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
      List deletedEventCRFs=adao.findDeletedEventCRFsFromAuditEvent(studyEvent.getId());
      allDeletedEventCRFs.addAll(deletedEventCRFs);
      List eventCRFs=(List)adao.findAllEventCRFAuditEvents(studyEvent.getId());
      allEventCRFs.addAll(eventCRFs);
      List eventCRFItems=(List)adao.findAllEventCRFAuditEventsWithItemDataType(studyEvent.getId());
      allEventCRFItems.addAll(eventCRFItems);
      logger.info("String_Node_Str" + deletedEventCRFs.size() + "String_Node_Str");
      logger.info("String_Node_Str" + allEventCRFItems.size() + "String_Node_Str");
    }
    for (int i=0; i < events.size(); i++) {
      StudyEventBean studyEvent=(StudyEventBean)events.get(i);
      studyEventAudits.addAll(adao.findStudyEventAuditEvents(studyEvent.getId()));
      ArrayList eventCRFs=studyEvent.getEventCRFs();
      for (int j=0; j < eventCRFs.size(); j++) {
        EventCRFBean eventCRF=(EventCRFBean)eventCRFs.get(j);
        eventCRF.setCrfVersion((CRFVersionBean)cvdao.findByPK(eventCRF.getCRFVersionId()));
        eventCRF.setCrf(cdao.findByVersionId(eventCRF.getCRFVersionId()));
        eventCRFAudits.addAll(adao.findEventCRFAuditEventsWithItemDataType(eventCRF.getId()));
        logger.info("String_Node_Str" + eventCRFAudits.size() + "String_Node_Str"+ eventCRF.getId()+ "String_Node_Str");
      }
    }
    ItemDataDAO itemDataDao=new ItemDataDAO(sm.getDataSource());
    for (    Object o : eventCRFAudits) {
      AuditBean ab=(AuditBean)o;
      if (ab.getAuditTable().equalsIgnoreCase("String_Node_Str")) {
        ItemDataBean idBean=(ItemDataBean)itemDataDao.findByPK(ab.getEntityId());
        ab.setOrdinal(idBean.getOrdinal());
      }
    }
  }
  try {
    WritableFont headerFormat=new WritableFont(WritableFont.ARIAL,8,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE2);
    WritableCellFormat cellFormat=new WritableCellFormat();
    cellFormat.setFont(headerFormat);
    response.setContentType("String_Node_Str");
    response.setHeader("String_Node_Str","String_Node_Str");
    WorkbookSettings wbSettings=new WorkbookSettings();
    wbSettings.setLocale(new Locale("String_Node_Str","String_Node_Str"));
    WritableWorkbook workbook=Workbook.createWorkbook(response.getOutputStream(),wbSettings);
    int row=0;
    workbook.createSheet("String_Node_Str",0);
    WritableSheet excelSheet=workbook.getSheet(0);
    String[] excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    excelRow=new String[]{studySubject.getLabel(),studySubject.getSecondaryLabel(),dateFormat(subject.getDateOfBirth()),subject.getUniqueIdentifier(),studySubject.getOwner().getName(),studySubject.getStatus().getName()};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    row++;
    excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    for (int j=0; j < studySubjectAudits.size(); j++) {
      AuditBean audit=(AuditBean)studySubjectAudits.get(j);
      excelRow=new String[]{audit.getAuditEventTypeName(),dateTimeFormat(audit.getAuditDate()),audit.getUserName(),audit.getEntityName(),audit.getOldValue(),audit.getNewValue()};
      for (int i=0; i < excelRow.length; i++) {
        Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
    }
    row++;
    excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    for (int j=0; j < events.size(); j++) {
      StudyEventBean event=(StudyEventBean)events.get(j);
      if (event.getStartTimeFlag()) {
        excelRow=new String[]{event.getStudyEventDefinition().getName(),event.getLocation(),dateTimeFormat(event.getDateStarted()),Integer.toString(event.getSampleOrdinal())};
      }
 else {
        excelRow=new String[]{event.getStudyEventDefinition().getName(),event.getLocation(),dateFormat(event.getDateStarted()),Integer.toString(event.getSampleOrdinal())};
      }
      for (int i=0; i < excelRow.length; i++) {
        Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
    }
    autoSizeColumns(excelSheet);
    int sheet=0;
    for (int eventCount=0; eventCount < events.size(); eventCount++) {
      row=0;
      sheet++;
      StudyEventBean event=(StudyEventBean)events.get(eventCount);
      workbook.createSheet(event.getStudyEventDefinition().getName().replace("String_Node_Str","String_Node_Str") + "String_Node_Str" + event.getSampleOrdinal(),sheet);
      excelSheet=workbook.getSheet(sheet);
      Label label=null;
      label=new Label(0,row,ResourceBundleProvider.getResWord("String_Node_Str"),cellFormat);
      excelSheet.addCell(label);
      label=new Label(1,row,event.getStudyEventDefinition().getName(),cellFormat);
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      label=new Label(1,row,event.getLocation());
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      if (event.getStartTimeFlag()) {
        label=new Label(1,row,dateTimeFormat(event.getDateStarted()));
      }
 else {
        label=new Label(1,row,dateFormat(event.getDateStarted()));
      }
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      label=new Label(1,row,event.getSubjectEventStatus().getName());
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,ResourceBundleProvider.getResWord("String_Node_Str"));
      excelSheet.addCell(label);
      label=new Label(1,row,Integer.toString(event.getSampleOrdinal()));
      excelSheet.addCell(label);
      row++;
      row++;
      excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      for (int i=0; i < excelRow.length; i++) {
        label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
      for (int j=0; j < allDeletedEventCRFs.size(); j++) {
        DeletedEventCRFBean deletedEventCRF=(DeletedEventCRFBean)allDeletedEventCRFs.get(j);
        if (deletedEventCRF.getStudyEventId() == event.getId()) {
          excelRow=new String[]{deletedEventCRF.getCrfName(),deletedEventCRF.getFormLayout(),deletedEventCRF.getDeletedBy(),dateFormat(deletedEventCRF.getDeletedDate())};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
        }
      }
      row++;
      row++;
      excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      for (int i=0; i < excelRow.length; i++) {
        label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
      for (int j=0; j < studyEventAudits.size(); j++) {
        AuditBean studyEvent=(AuditBean)studyEventAudits.get(j);
        if (studyEvent.getEntityId() == event.getId()) {
          String getOld=studyEvent.getOldValue();
          String oldValue="String_Node_Str";
          if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           oldValue=studyEvent.getOldValue();
          String getNew=studyEvent.getNewValue();
          String newValue="String_Node_Str";
          if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           newValue=studyEvent.getNewValue();
          excelRow=new String[]{studyEvent.getAuditEventTypeName(),dateTimeFormat(studyEvent.getAuditDate()),studyEvent.getUserName(),studyEvent.getEntityName() + "String_Node_Str" + studyEvent.getOrdinal()+ "String_Node_Str",oldValue,newValue};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
        }
      }
      row++;
      row++;
      for (int j=0; j < allEventCRFs.size(); j++) {
        AuditBean auditBean=(AuditBean)allEventCRFs.get(j);
        if (auditBean.getStudyEventId() == event.getId()) {
          excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          excelRow=new String[]{auditBean.getCrfName(),auditBean.getCrfVersionName(),dateFormat(auditBean.getDateInterviewed()),auditBean.getInterviewerName(),auditBean.getUserName()};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          row++;
          excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          row++;
          for (int k=0; k < allEventCRFItems.size(); k++) {
            row--;
            AuditBean eventCrfAudit=(AuditBean)allEventCRFItems.get(k);
            if (eventCrfAudit.getStudyEventId() == event.getId() && eventCrfAudit.getEventCrfVersionId() == auditBean.getEventCrfVersionId()) {
              String oldValue="String_Node_Str";
              String newValue="String_Node_Str";
              if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("String_Node_Str")) {
                String getOld=eventCrfAudit.getOldValue();
                if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else {
                  oldValue=getOld;
                }
              }
 else               if (eventCrfAudit.getAuditEventTypeId() == 32) {
                String getOld=eventCrfAudit.getOldValue();
                if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else {
                  oldValue=getOld;
                }
              }
 else {
                oldValue=eventCrfAudit.getOldValue();
              }
              if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("String_Node_Str")) {
                String getNew=eventCrfAudit.getNewValue();
                if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else {
                  newValue=getNew;
                }
              }
 else               if (eventCrfAudit.getAuditEventTypeId() == 32) {
                String getNew=eventCrfAudit.getNewValue();
                if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else {
                  newValue=getNew;
                }
              }
 else {
                newValue=eventCrfAudit.getNewValue();
              }
              String ordinal="String_Node_Str";
              if (eventCrfAudit.getOrdinal() != 0) {
                ordinal="String_Node_Str" + eventCrfAudit.getOrdinal() + "String_Node_Str";
              }
 else               if (eventCrfAudit.getOrdinal() == 0 && eventCrfAudit.getItemDataRepeatKey() != 0) {
                ordinal="String_Node_Str" + eventCrfAudit.getItemDataRepeatKey() + "String_Node_Str";
              }
              excelRow=new String[]{eventCrfAudit.getAuditEventTypeName(),dateTimeFormat(eventCrfAudit.getAuditDate()),eventCrfAudit.getUserName(),eventCrfAudit.getEntityName() + ordinal,oldValue,newValue};
              for (int i=0; i < excelRow.length; i++) {
                label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
                excelSheet.addCell(label);
              }
              row++;
              row++;
            }
            row++;
          }
          row++;
        }
        autoSizeColumns(excelSheet);
      }
    }
    workbook.write();
    workbook.close();
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
  }
 catch (  Exception e) {
    throw e;
  }
 finally {
  }
}

Fixed version (ground truth):
@Override public void processRequest() throws Exception {
  StudySubjectDAO subdao=new StudySubjectDAO(sm.getDataSource());
  SubjectDAO sdao=new SubjectDAO(sm.getDataSource());
  AuditDAO adao=new AuditDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
  StudyDAO studydao=new StudyDAO(sm.getDataSource());
  CRFDAO cdao=new CRFDAO(sm.getDataSource());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  StudySubjectBean studySubject=null;
  SubjectBean subject=null;
  ArrayList events=null;
  ArrayList studySubjectAudits=new ArrayList();
  ArrayList eventCRFAudits=new ArrayList();
  ArrayList studyEventAudits=new ArrayList();
  ArrayList allDeletedEventCRFs=new ArrayList();
  ArrayList allEventCRFs=new ArrayList();
  ArrayList allEventCRFItems=new ArrayList();
  String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
  FormProcessor fp=new FormProcessor(request);
  int studySubId=fp.getInt("String_Node_Str",true);
  if (studySubId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_STUDY_SUBJECTS);
  }
 else {
    studySubject=(StudySubjectBean)subdao.findByPK(studySubId);
    StudyBean study=(StudyBean)studydao.findByPK(studySubject.getStudyId());
    if (studySubject.getStudyId() != currentStudy.getId()) {
      if (currentStudy.getParentStudyId() > 0) {
        addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"));
        forwardPage(Page.MENU_SERVLET);
        return;
      }
 else {
        Collection sites=studydao.findOlnySiteIdsByStudy(currentStudy);
        if (!sites.contains(study.getId())) {
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"));
          forwardPage(Page.MENU_SERVLET);
          return;
        }
      }
    }
    subject=(SubjectBean)sdao.findByPK(studySubject.getSubjectId());
    Collection studySubjectAuditEvents=adao.findStudySubjectAuditEvents(studySubject.getId());
    for (Iterator iterator=studySubjectAuditEvents.iterator(); iterator.hasNext(); ) {
      AuditBean auditBean=(AuditBean)iterator.next();
      if (auditBean.getAuditEventTypeId() == 3) {
        auditBean.setOldValue(Status.get(Integer.parseInt(auditBean.getOldValue())).getName());
        auditBean.setNewValue(Status.get(Integer.parseInt(auditBean.getNewValue())).getName());
      }
    }
    studySubjectAudits.addAll(studySubjectAuditEvents);
    studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
    studySubjectAudits.addAll(adao.findStudySubjectGroupAssignmentAuditEvents(studySubject.getId()));
    events=sedao.findAllByStudySubject(studySubject);
    for (int i=0; i < events.size(); i++) {
      StudyEventBean studyEvent=(StudyEventBean)events.get(i);
      studyEvent.setStudyEventDefinition((StudyEventDefinitionBean)seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
      studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
      List deletedEventCRFs=adao.findDeletedEventCRFsFromAuditEvent(studyEvent.getId());
      allDeletedEventCRFs.addAll(deletedEventCRFs);
      List eventCRFs=(List)adao.findAllEventCRFAuditEvents(studyEvent.getId());
      allEventCRFs.addAll(eventCRFs);
      List eventCRFItems=(List)adao.findAllEventCRFAuditEventsWithItemDataType(studyEvent.getId());
      allEventCRFItems.addAll(eventCRFItems);
      logger.info("String_Node_Str" + deletedEventCRFs.size() + "String_Node_Str");
      logger.info("String_Node_Str" + allEventCRFItems.size() + "String_Node_Str");
    }
    for (int i=0; i < events.size(); i++) {
      StudyEventBean studyEvent=(StudyEventBean)events.get(i);
      studyEventAudits.addAll(adao.findStudyEventAuditEvents(studyEvent.getId()));
      ArrayList eventCRFs=studyEvent.getEventCRFs();
      for (int j=0; j < eventCRFs.size(); j++) {
        EventCRFBean eventCRF=(EventCRFBean)eventCRFs.get(j);
        eventCRF.setCrfVersion((CRFVersionBean)cvdao.findByPK(eventCRF.getCRFVersionId()));
        eventCRF.setCrf(cdao.findByVersionId(eventCRF.getCRFVersionId()));
        eventCRFAudits.addAll(adao.findEventCRFAuditEventsWithItemDataType(eventCRF.getId()));
        logger.info("String_Node_Str" + eventCRFAudits.size() + "String_Node_Str"+ eventCRF.getId()+ "String_Node_Str");
      }
    }
    ItemDataDAO itemDataDao=new ItemDataDAO(sm.getDataSource());
    for (    Object o : eventCRFAudits) {
      AuditBean ab=(AuditBean)o;
      if (ab.getAuditTable().equalsIgnoreCase("String_Node_Str")) {
        ItemDataBean idBean=(ItemDataBean)itemDataDao.findByPK(ab.getEntityId());
        ab.setOrdinal(idBean.getOrdinal());
      }
    }
  }
  try {
    WritableFont headerFormat=new WritableFont(WritableFont.ARIAL,8,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE2);
    WritableCellFormat cellFormat=new WritableCellFormat();
    cellFormat.setFont(headerFormat);
    response.setContentType("String_Node_Str");
    response.setHeader("String_Node_Str","String_Node_Str");
    WorkbookSettings wbSettings=new WorkbookSettings();
    wbSettings.setLocale(new Locale("String_Node_Str","String_Node_Str"));
    WritableWorkbook workbook=Workbook.createWorkbook(response.getOutputStream(),wbSettings);
    int row=0;
    workbook.createSheet("String_Node_Str",0);
    WritableSheet excelSheet=workbook.getSheet(0);
    String[] excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    excelRow=new String[]{studySubject.getLabel(),studySubject.getSecondaryLabel(),dateFormat(subject.getDateOfBirth()),subject.getUniqueIdentifier(),studySubject.getOwner().getName(),studySubject.getStatus().getName()};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    row++;
    excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    for (int j=0; j < studySubjectAudits.size(); j++) {
      AuditBean audit=(AuditBean)studySubjectAudits.get(j);
      excelRow=new String[]{audit.getAuditEventTypeName(),dateTimeFormat(audit.getAuditDate()),audit.getUserName(),audit.getEntityName(),audit.getOldValue(),audit.getNewValue()};
      for (int i=0; i < excelRow.length; i++) {
        Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
    }
    row++;
    excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
    for (int i=0; i < excelRow.length; i++) {
      Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
      excelSheet.addCell(label);
    }
    row++;
    for (int j=0; j < events.size(); j++) {
      StudyEventBean event=(StudyEventBean)events.get(j);
      if (event.getStartTimeFlag()) {
        excelRow=new String[]{event.getStudyEventDefinition().getName(),event.getLocation(),dateTimeFormat(event.getDateStarted()),Integer.toString(event.getSampleOrdinal())};
      }
 else {
        excelRow=new String[]{event.getStudyEventDefinition().getName(),event.getLocation(),dateFormat(event.getDateStarted()),Integer.toString(event.getSampleOrdinal())};
      }
      for (int i=0; i < excelRow.length; i++) {
        Label label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
    }
    autoSizeColumns(excelSheet);
    int sheet=0;
    for (int eventCount=0; eventCount < events.size(); eventCount++) {
      row=0;
      sheet++;
      StudyEventBean event=(StudyEventBean)events.get(eventCount);
      workbook.createSheet(event.getStudyEventDefinition().getName().replace("String_Node_Str","String_Node_Str") + "String_Node_Str" + event.getSampleOrdinal(),sheet);
      excelSheet=workbook.getSheet(sheet);
      Label label=null;
      label=new Label(0,row,ResourceBundleProvider.getResWord("String_Node_Str"),cellFormat);
      excelSheet.addCell(label);
      label=new Label(1,row,event.getStudyEventDefinition().getName(),cellFormat);
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      label=new Label(1,row,event.getLocation());
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      if (event.getStartTimeFlag()) {
        label=new Label(1,row,dateTimeFormat(event.getDateStarted()));
      }
 else {
        label=new Label(1,row,dateFormat(event.getDateStarted()));
      }
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,"String_Node_Str");
      excelSheet.addCell(label);
      label=new Label(1,row,event.getSubjectEventStatus().getName());
      excelSheet.addCell(label);
      row++;
      label=new Label(0,row,ResourceBundleProvider.getResWord("String_Node_Str"));
      excelSheet.addCell(label);
      label=new Label(1,row,Integer.toString(event.getSampleOrdinal()));
      excelSheet.addCell(label);
      row++;
      row++;
      excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      for (int i=0; i < excelRow.length; i++) {
        label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
      for (int j=0; j < allDeletedEventCRFs.size(); j++) {
        DeletedEventCRFBean deletedEventCRF=(DeletedEventCRFBean)allDeletedEventCRFs.get(j);
        if (deletedEventCRF.getStudyEventId() == event.getId()) {
          excelRow=new String[]{deletedEventCRF.getCrfName(),deletedEventCRF.getFormLayout(),deletedEventCRF.getDeletedBy(),dateFormat(deletedEventCRF.getDeletedDate())};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
        }
      }
      row++;
      row++;
      excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
      for (int i=0; i < excelRow.length; i++) {
        label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
        excelSheet.addCell(label);
      }
      row++;
      for (int j=0; j < studyEventAudits.size(); j++) {
        AuditBean studyEvent=(AuditBean)studyEventAudits.get(j);
        if (studyEvent.getEntityId() == event.getId()) {
          String getOld=studyEvent.getOldValue();
          String oldValue="String_Node_Str";
          if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           if (getOld.equals("String_Node_Str"))           oldValue="String_Node_Str";
 else           oldValue=studyEvent.getOldValue();
          String getNew=studyEvent.getNewValue();
          String newValue="String_Node_Str";
          if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           if (getNew.equals("String_Node_Str"))           newValue="String_Node_Str";
 else           newValue=studyEvent.getNewValue();
          excelRow=new String[]{studyEvent.getAuditEventTypeName(),dateTimeFormat(studyEvent.getAuditDate()),studyEvent.getUserName(),studyEvent.getEntityName() + "String_Node_Str" + studyEvent.getOrdinal()+ "String_Node_Str",oldValue,newValue};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
        }
      }
      row++;
      row++;
      for (int j=0; j < allEventCRFs.size(); j++) {
        AuditBean auditBean=(AuditBean)allEventCRFs.get(j);
        if (auditBean.getStudyEventId() == event.getId()) {
          excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          excelRow=new String[]{auditBean.getCrfName(),auditBean.getFormLayoutName(),dateFormat(auditBean.getDateInterviewed()),auditBean.getInterviewerName(),auditBean.getUserName()};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          row++;
          excelRow=new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
          for (int i=0; i < excelRow.length; i++) {
            label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
            excelSheet.addCell(label);
          }
          row++;
          row++;
          for (int k=0; k < allEventCRFItems.size(); k++) {
            row--;
            AuditBean eventCrfAudit=(AuditBean)allEventCRFItems.get(k);
            if (eventCrfAudit.getStudyEventId() == event.getId() && eventCrfAudit.getEventCrfVersionId() == auditBean.getEventCrfVersionId()) {
              String oldValue="String_Node_Str";
              String newValue="String_Node_Str";
              if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("String_Node_Str")) {
                String getOld=eventCrfAudit.getOldValue();
                if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else {
                  oldValue=getOld;
                }
              }
 else               if (eventCrfAudit.getAuditEventTypeId() == 32) {
                String getOld=eventCrfAudit.getOldValue();
                if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else                 if (getOld.equals("String_Node_Str"))                 oldValue="String_Node_Str";
 else {
                  oldValue=getOld;
                }
              }
 else {
                oldValue=eventCrfAudit.getOldValue();
              }
              if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("String_Node_Str")) {
                String getNew=eventCrfAudit.getNewValue();
                if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else {
                  newValue=getNew;
                }
              }
 else               if (eventCrfAudit.getAuditEventTypeId() == 32) {
                String getNew=eventCrfAudit.getNewValue();
                if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else                 if (getNew.equals("String_Node_Str"))                 newValue="String_Node_Str";
 else {
                  newValue=getNew;
                }
              }
 else {
                newValue=eventCrfAudit.getNewValue();
              }
              String ordinal="String_Node_Str";
              if (eventCrfAudit.getOrdinal() != 0) {
                ordinal="String_Node_Str" + eventCrfAudit.getOrdinal() + "String_Node_Str";
              }
 else               if (eventCrfAudit.getOrdinal() == 0 && eventCrfAudit.getItemDataRepeatKey() != 0) {
                ordinal="String_Node_Str" + eventCrfAudit.getItemDataRepeatKey() + "String_Node_Str";
              }
              excelRow=new String[]{eventCrfAudit.getAuditEventTypeName(),dateTimeFormat(eventCrfAudit.getAuditDate()),eventCrfAudit.getUserName(),eventCrfAudit.getEntityName() + ordinal,oldValue,newValue};
              for (int i=0; i < excelRow.length; i++) {
                label=new Label(i,row,ResourceBundleProvider.getResWord(excelRow[i]),cellFormat);
                excelSheet.addCell(label);
              }
              row++;
              row++;
            }
            row++;
          }
          row++;
        }
        autoSizeColumns(excelSheet);
      }
    }
    workbook.write();
    workbook.close();
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
    session.setAttribute("String_Node_Str",null);
  }
 catch (  Exception e) {
    throw e;
  }
 finally {
  }
}