Program: 114982
Project: 114982
Buggy source:
public void addNodeClinicalData(boolean header,boolean footer,boolean clinical){
  String ODMVersion=this.getODMVersion();
  StringBuffer xml=this.getXmlOutput();
  String indent=this.getIndent();
  String nls=System.getProperty("String_Node_Str");
  if (header) {
    xml.append(indent + "String_Node_Str" + StringEscapeUtils.escapeXml(clinicalData.getStudyOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(this.clinicalData.getMetaDataVersionOID())+ "String_Node_Str");
    xml.append(nls);
  }
  ArrayList<ExportSubjectDataBean> subs=(ArrayList<ExportSubjectDataBean>)this.clinicalData.getExportSubjectData();
  for (  ExportSubjectDataBean sub : subs) {
    xml.append(indent + indent + "String_Node_Str"+ StringEscapeUtils.escapeXml(sub.getSubjectOID()));
    if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
      xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(sub.getStudySubjectId()));
      String uniqueIdentifier=sub.getUniqueIdentifier();
      if (uniqueIdentifier != null && uniqueIdentifier.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(uniqueIdentifier));
      }
      String status=sub.getStatus();
      if (status != null && status.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
      }
      String secondaryId=sub.getSecondaryId();
      if (secondaryId != null && secondaryId.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(secondaryId));
      }
      Integer year=sub.getYearOfBirth();
      if (year != null) {
        xml.append("String_Node_Str" + sub.getYearOfBirth());
      }
 else {
        if (sub.getDateOfBirth() != null) {
          xml.append("String_Node_Str" + sub.getDateOfBirth());
        }
      }
      String gender=sub.getSubjectGender();
      if (gender != null && gender.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(gender));
      }
      String enrollmentDate=sub.getEnrollmentDate();
      if (enrollmentDate != null && enrollmentDate.length() > 0) {
        xml.append("String_Node_Str" + enrollmentDate);
      }
    }
    xml.append("String_Node_Str");
    xml.append(nls);
    ArrayList<ExportStudyEventDataBean> ses=(ArrayList<ExportStudyEventDataBean>)sub.getExportStudyEventData();
    xml.append(indent + indent + indent+ "String_Node_Str");
    xml.append(nls);
    EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(dataSource);
    StudyEventDefinitionDAO<String,ArrayList> seddao=new StudyEventDefinitionDAO(dataSource);
    CRFDAO crfdao=new CRFDAO(dataSource);
    StudyBean parentStudyBean=getParentStudy(clinicalData.getStudyOID());
    List<EventDefinitionCRFBean> edcs=edcdao.findAllByStudy(parentStudyBean);
    for (    EventDefinitionCRFBean edc : edcs) {
      if (!edc.getStatus().equals(Status.AUTO_DELETED) && !edc.getStatus().equals(Status.DELETED) && validateAddNew(sub,edc)) {
        StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(edc.getStudyEventDefinitionId());
        CRFBean crf=(CRFBean)crfdao.findByPK(edc.getCrfId());
        xml.append(indent + indent + indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sed.getOid() + "String_Node_Str" + crf.getOid())+ "String_Node_Str"+ "String_Node_Str"+ StringEscapeUtils.escapeXml(clinicalData.getStudyOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sub.getSubjectOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sed.getOid())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(crf.getOid())+ "String_Node_Str");
        xml.append("String_Node_Str");
        xml.append(nls);
      }
    }
    xml.append(indent + indent + indent+ "String_Node_Str");
    xml.append(nls);
    for (    ExportStudyEventDataBean se : ses) {
      if (!clinical || (clinical && !se.getStatus().equals(SubjectEventStatus.INVALID.getI18nDescription(getLocale())))) {
        xml.append(indent + indent + indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(se.getStudyEventOID()));
        if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
          xml.append("String_Node_Str" + se.getStudyEventRepeatKey());
          String eventName=se.getEventName();
          if (eventName != null && eventName.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(eventName));
          }
          String location=se.getLocation();
          if (location != null && location.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(location));
          }
          String startDate=se.getStartDate();
          if (startDate != null && startDate.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(startDate));
          }
          String endDate=se.getEndDate();
          if (endDate != null && endDate.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(endDate));
          }
          String status=se.getStatus();
          if (status != null && status.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
          }
          if (se.getAgeAtEvent() != null) {
            xml.append("String_Node_Str" + se.getAgeAtEvent());
          }
        }
        xml.append("String_Node_Str");
        xml.append(nls);
        StudySubject studySubject=sub.getStudySubject();
        Study study=studySubject.getStudy();
        StudyEvent studyEvent=se.getStudyEvent();
        StudyBean studyBean=CoreResources.getPublicStudy(study.getOc_oid(),dataSource);
        StudyUserRoleBean userRole=userBean.getRoleByStudy(studyBean.getId());
        if (userRole == null || !userRole.isActive())         userRole=userBean.getRoleByStudy(studyBean.getParentStudyId());
        Role role=userRole.getRole();
        if (se.getExportFormData().size() != 0 && !studyEvent.getStudyEventDefinition().getStatus().equals(Status.DELETED) && !studyEvent.getStudyEventDefinition().getStatus().equals(Status.AUTO_DELETED)) {
          xml.append(indent + indent + indent+ indent+ "String_Node_Str");
          xml.append(nls);
          if (studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode()) {
            if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && study.getStatus().equals(Status.AVAILABLE)) {
              String removeUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(removeUrl)+ "String_Node_Str");
              xml.append("String_Node_Str");
              xml.append(nls);
            }
          }
 else {
            if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && study.getStatus().equals(Status.AVAILABLE)&& studyEvent.getStudyEventDefinition().getStatus().equals(Status.AVAILABLE)) {
              String restoreUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(restoreUrl)+ "String_Node_Str");
              xml.append("String_Node_Str");
              xml.append(nls);
            }
          }
          if (role.equals(Role.INVESTIGATOR) && (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.COMPLETED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SKIPPED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.STOPPED.getCode()) && studySubject.getStatus().equals(Status.AVAILABLE)&& study.getStatus().equals(Status.AVAILABLE)) {
            String signUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId()+ "String_Node_Str";
            xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(signUrl)+ "String_Node_Str");
            xml.append("String_Node_Str");
            xml.append(nls);
          }
          if (studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && studySubject.getStatus().equals(Status.AVAILABLE) && study.getStatus().equals(Status.AVAILABLE)) {
            if ((!studyEvent.getStudyEventDefinition().getType().equals(COMMON) && !role.equals(Role.MONITOR)) || (studyEvent.getStudyEventDefinition().getType().equals(COMMON) && (role.equals(Role.STUDY_STUDYDIRECTOR) || role.equals(Role.COORDINATOR)))) {
              String lockUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(lockUrl)+ "String_Node_Str");
              xml.append("String_Node_Str");
              xml.append(nls);
              xml.append(indent + indent + indent+ indent+ "String_Node_Str");
              xml.append(nls);
            }
          }
        }
        ArrayList<ExportFormDataBean> forms=se.getExportFormData();
        for (        ExportFormDataBean form : forms) {
          if (!clinical || (clinical && !form.getStatus().equals(EventCRFStatus.INVALID.getI18nDescription(getLocale())))) {
            xml.append(indent + indent + indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(form.getFormOID()));
            if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
              String formName=form.getFormName();
              if (!StringUtils.isEmpty(formName)) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(formName));
              }
              String formLayout=form.getFormLayoutName();
              if (!StringUtils.isEmpty(formLayout)) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(formLayout));
              }
              String interviewerName=form.getInterviewerName();
              if (interviewerName != null && interviewerName.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(interviewerName));
              }
              if (form.getInterviewDate() != null && form.getInterviewDate().length() > 0) {
                xml.append("String_Node_Str" + form.getInterviewDate());
              }
              Date createdDate=form.getCreatedDate();
              if (createdDate != null) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(new SimpleDateFormat("String_Node_Str").format(createdDate)));
              }
              String createdBy=form.getCreatedBy();
              if (createdBy != null && createdBy.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(createdBy));
              }
              Date updatedDate=form.getUpdatedDate();
              if (updatedDate != null) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(new SimpleDateFormat("String_Node_Str").format(updatedDate)));
              }
              String updatedBy=form.getUpdatedBy();
              if (updatedBy != null && updatedBy.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(updatedBy));
              }
              String status=form.getStatus();
              if (status != null && status.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
              }
            }
            xml.append("String_Node_Str");
            xml.append(nls);
            EventCrf eventCrf=form.getEventCrf();
            FormLayout formLayout=form.getFormLayout();
            EventDefinitionCrf eventDefinitionCrf=form.getEventDefinitionCrf();
            xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
            xml.append(nls);
            String formUrl="String_Node_Str" + formLayout.getFormLayoutId() + "String_Node_Str"+ studyEvent.getStudyEventId()+ "String_Node_Str"+ eventCrf.getEventCrfId()+ "String_Node_Str"+ studySubject.getStudySubjectId();
            xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(formUrl + "String_Node_Str")+ "String_Node_Str");
            xml.append("String_Node_Str");
            xml.append(nls);
            if (!(form.getEventDefinitionCrf().getStatusId() == Status.DELETED.getCode()) && !(form.getEventDefinitionCrf().getStatusId() == Status.AUTO_DELETED.getCode())) {
              if (!role.equals(Role.MONITOR) && eventCrf.getStatusId() != Status.DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode() && eventCrf.getStatusId() != Status.LOCKED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.LOCKED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.SKIPPED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.STOPPED.getCode() && studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && study.getStatus().equals(Status.AVAILABLE)) {
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(formUrl + "String_Node_Str")+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
              if (!studyEvent.getStudyEventDefinition().getType().equals(COMMON)) {
                if (eventCrf.getStatusId() != Status.DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode()) {
                  if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && study.getStatus().equals(Status.AVAILABLE)) {
                    String removeUrl="String_Node_Str" + eventCrf.getEventCrfId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(removeUrl)+ "String_Node_Str");
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
 else {
                  if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode() && studySubject.getStatus().equals(Status.AVAILABLE) && studyEvent.getStatusId() == Status.AVAILABLE.getCode() && study.getStatus().equals(Status.AVAILABLE)) {
                    String restoreUrl="String_Node_Str" + eventCrf.getEventCrfId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(restoreUrl)+ "String_Node_Str");
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
              }
              if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && study.getStatus().equals(Status.AVAILABLE) && !(studyEvent.getSubjectEventStatusId() == SubjectEventStatus.LOCKED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SKIPPED.getCode())) {
                String reassignUrl="String_Node_Str" + formLayout.getCrf().getCrfId() + "String_Node_Str"+ formLayout.getCrf().getName()+ "String_Node_Str"+ formLayout.getFormLayoutId()+ "String_Node_Str"+ form.getFormLayoutName()+ "String_Node_Str"+ studySubject.getLabel()+ "String_Node_Str"+ studySubject.getStudySubjectId()+ "String_Node_Str"+ eventCrf.getEventCrfId()+ "String_Node_Str"+ eventDefinitionCrf.getEventDefinitionCrfId();
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(reassignUrl)+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
            }
            xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
            xml.append(nls);
            ArrayList<ImportItemGroupDataBean> igs=form.getItemGroupData();
            sortImportItemGroupDataBeanList(igs);
            for (            ImportItemGroupDataBean ig : igs) {
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(ig.getItemGroupOID())+ "String_Node_Str");
              if (!"String_Node_Str".equals(ig.getItemGroupRepeatKey())) {
                xml.append("String_Node_Str" + ig.getItemGroupRepeatKey() + "String_Node_Str");
              }
              String itemGroupName=ig.getItemGroupName();
              if (!StringUtils.isEmpty(itemGroupName)) {
                xml.append("String_Node_Str" + itemGroupName + "String_Node_Str");
              }
              if (ig.getItemData().get(0).isDeleted()) {
                xml.append("String_Node_Str" + (ig.getItemData().get(0).isDeleted() ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
              }
              xml.append("String_Node_Str");
              xml.append(nls);
              ArrayList<ImportItemDataBean> items=ig.getItemData();
              sortImportItemDataBeanList(items);
              for (              ImportItemDataBean item : items) {
                boolean printValue=true;
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(item.getItemOID())+ "String_Node_Str");
                String itemName=item.getItemName();
                if (!StringUtils.isEmpty(itemName)) {
                  xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(itemName) + "String_Node_Str");
                }
                if ("String_Node_Str".equals(item.getIsNull())) {
                  xml.append("String_Node_Str");
                  if (!item.isHasValueWithNull()) {
                    printValue=false;
                  }
                  if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
                    xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(item.getReasonForNull()) + "String_Node_Str");
                    if (!printValue) {
                      xml.append("String_Node_Str");
                      xml.append(nls);
                    }
                  }
                }
                if (printValue) {
                  Boolean hasElm=false;
                  xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(item.getValue()) + "String_Node_Str");
                  String muRefOid=item.getMeasurementUnitRef().getElementDefOID();
                  if (muRefOid != null && muRefOid.length() > 0) {
                    if (hasElm) {
                    }
 else {
                      xml.append("String_Node_Str");
                      xml.append(nls);
                      hasElm=true;
                    }
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(muRefOid)+ "String_Node_Str");
                    xml.append(nls);
                  }
                  if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
                    if (item.getAuditLogs() != null && item.getAuditLogs().getAuditLogs().size() > 0) {
                      if (hasElm) {
                      }
 else {
                        xml.append("String_Node_Str");
                        xml.append(nls);
                        hasElm=true;
                      }
                      this.addAuditLogs(item.getAuditLogs(),indent + indent + indent+ indent+ indent+ indent+ indent,"String_Node_Str");
                    }
                    if (item.getDiscrepancyNotes() != null && item.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
                      if (hasElm) {
                      }
 else {
                        xml.append("String_Node_Str");
                        xml.append(nls);
                        hasElm=true;
                      }
                      this.addDiscrepancyNotes(item.getDiscrepancyNotes(),indent + indent + indent+ indent+ indent+ indent+ indent);
                    }
                  }
                  if (hasElm) {
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str");
                    xml.append(nls);
                    hasElm=false;
                  }
 else {
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
              }
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
              xml.append(nls);
            }
            if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
              if (form.getAuditLogs() != null && form.getAuditLogs().getAuditLogs().size() > 0) {
                this.addAuditLogs(form.getAuditLogs(),indent + indent + indent+ indent+ indent,"String_Node_Str");
              }
              if (form.getDiscrepancyNotes() != null && form.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
                this.addDiscrepancyNotes(form.getDiscrepancyNotes(),indent + indent + indent+ indent+ indent);
              }
            }
            xml.append(indent + indent + indent+ indent+ "String_Node_Str");
            xml.append(nls);
          }
        }
        if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
          if (se.getAuditLogs() != null && se.getAuditLogs().getAuditLogs().size() > 0) {
            this.addAuditLogs(se.getAuditLogs(),indent + indent + indent+ indent,"String_Node_Str");
          }
          if (se.getDiscrepancyNotes() != null && se.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
            this.addDiscrepancyNotes(se.getDiscrepancyNotes(),indent + indent + indent+ indent);
          }
        }
        xml.append(indent + indent + indent+ "String_Node_Str");
        xml.append(nls);
      }
    }
    if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
      ArrayList<SubjectGroupDataBean> sgddata=(ArrayList<SubjectGroupDataBean>)sub.getSubjectGroupData();
      if (sgddata.size() > 0) {
        for (        SubjectGroupDataBean sgd : sgddata) {
          String cid=sgd.getStudyGroupClassId() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassId()) + "String_Node_Str" : "String_Node_Str";
          if (cid.length() > 0) {
            String cn=sgd.getStudyGroupClassName() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassName()) + "String_Node_Str" : "String_Node_Str";
            String gn=sgd.getStudyGroupName() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupName()) + "String_Node_Str" : "String_Node_Str";
            xml.append(indent + indent + indent+ "String_Node_Str"+ cid+ cn+ gn);
          }
          xml.append("String_Node_Str");
          xml.append(nls);
        }
      }
      if (sub.getAuditLogs() != null && sub.getAuditLogs().getAuditLogs().size() > 0) {
        this.addAuditLogs(sub.getAuditLogs(),indent + indent + indent,"String_Node_Str");
      }
      if (sub.getDiscrepancyNotes() != null && sub.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
        this.addDiscrepancyNotes(sub.getDiscrepancyNotes(),indent + indent + indent);
      }
    }
    xml.append(indent + indent + "String_Node_Str");
    xml.append(nls);
  }
  if (footer) {
    xml.append(indent + "String_Node_Str");
    xml.append(nls);
  }
}

Fixed version (ground truth):
public void addNodeClinicalData(boolean header,boolean footer,boolean clinical){
  String ODMVersion=this.getODMVersion();
  StringBuffer xml=this.getXmlOutput();
  String indent=this.getIndent();
  String nls=System.getProperty("String_Node_Str");
  if (header) {
    xml.append(indent + "String_Node_Str" + StringEscapeUtils.escapeXml(clinicalData.getStudyOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(this.clinicalData.getMetaDataVersionOID())+ "String_Node_Str");
    xml.append(nls);
  }
  ArrayList<ExportSubjectDataBean> subs=(ArrayList<ExportSubjectDataBean>)this.clinicalData.getExportSubjectData();
  for (  ExportSubjectDataBean sub : subs) {
    xml.append(indent + indent + "String_Node_Str"+ StringEscapeUtils.escapeXml(sub.getSubjectOID()));
    if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
      xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(sub.getStudySubjectId()));
      String uniqueIdentifier=sub.getUniqueIdentifier();
      if (uniqueIdentifier != null && uniqueIdentifier.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(uniqueIdentifier));
      }
      String status=sub.getStatus();
      if (status != null && status.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
      }
      String secondaryId=sub.getSecondaryId();
      if (secondaryId != null && secondaryId.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(secondaryId));
      }
      Integer year=sub.getYearOfBirth();
      if (year != null) {
        xml.append("String_Node_Str" + sub.getYearOfBirth());
      }
 else {
        if (sub.getDateOfBirth() != null) {
          xml.append("String_Node_Str" + sub.getDateOfBirth());
        }
      }
      String gender=sub.getSubjectGender();
      if (gender != null && gender.length() > 0) {
        xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(gender));
      }
      String enrollmentDate=sub.getEnrollmentDate();
      if (enrollmentDate != null && enrollmentDate.length() > 0) {
        xml.append("String_Node_Str" + enrollmentDate);
      }
    }
    xml.append("String_Node_Str");
    xml.append(nls);
    ArrayList<ExportStudyEventDataBean> ses=(ArrayList<ExportStudyEventDataBean>)sub.getExportStudyEventData();
    xml.append(indent + indent + indent+ "String_Node_Str");
    xml.append(nls);
    EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(dataSource);
    StudyEventDefinitionDAO<String,ArrayList> seddao=new StudyEventDefinitionDAO(dataSource);
    CRFDAO crfdao=new CRFDAO(dataSource);
    StudyBean parentStudyBean=getParentStudy(clinicalData.getStudyOID());
    StudyBean studyBean=getStudy(clinicalData.getStudyOID());
    List<EventDefinitionCRFBean> edcs=(List<EventDefinitionCRFBean>)edcdao.findAllStudySiteFiltered(studyBean);
    for (    EventDefinitionCRFBean edc : edcs) {
      if (!edc.getStatus().equals(org.akaza.openclinica.bean.core.Status.AUTO_DELETED) && !edc.getStatus().equals(org.akaza.openclinica.bean.core.Status.DELETED) && validateAddNew(sub,edc)&& !edc.isHideCrf()) {
        StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(edc.getStudyEventDefinitionId());
        CRFBean crf=(CRFBean)crfdao.findByPK(edc.getCrfId());
        if (!sed.getType().equals(COMMON)) {
          continue;
        }
        xml.append(indent + indent + indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sed.getOid() + "String_Node_Str" + crf.getOid())+ "String_Node_Str"+ "String_Node_Str"+ StringEscapeUtils.escapeXml(clinicalData.getStudyOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sub.getSubjectOID())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(sed.getOid())+ "String_Node_Str"+ StringEscapeUtils.escapeXml(crf.getOid())+ "String_Node_Str");
        xml.append("String_Node_Str");
        xml.append(nls);
      }
    }
    xml.append(indent + indent + indent+ "String_Node_Str");
    xml.append(nls);
    for (    ExportStudyEventDataBean se : ses) {
      if (!clinical || (clinical && !se.getStatus().equals(SubjectEventStatus.INVALID.getI18nDescription(getLocale())))) {
        xml.append(indent + indent + indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(se.getStudyEventOID()));
        if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
          xml.append("String_Node_Str" + se.getStudyEventRepeatKey());
          String eventName=se.getEventName();
          if (eventName != null && eventName.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(eventName));
          }
          String location=se.getLocation();
          if (location != null && location.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(location));
          }
          String startDate=se.getStartDate();
          if (startDate != null && startDate.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(startDate));
          }
          String endDate=se.getEndDate();
          if (endDate != null && endDate.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(endDate));
          }
          String status=se.getStatus();
          if (status != null && status.length() > 0) {
            xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
          }
          if (se.getAgeAtEvent() != null) {
            xml.append("String_Node_Str" + se.getAgeAtEvent());
          }
        }
        xml.append("String_Node_Str");
        xml.append(nls);
        StudySubject studySubject=sub.getStudySubject();
        StudyEvent studyEvent=se.getStudyEvent();
        StudyBean publicBean=CoreResources.getPublicStudy(clinicalData.getStudyOID(),dataSource);
        StudyUserRoleBean userRole=userBean.getRoleByStudy(publicBean.getId());
        if (userRole == null || !userRole.isActive())         userRole=userBean.getRoleByStudy(publicBean.getParentStudyId());
        Role role=userRole.getRole();
        xml.append(indent + indent + indent+ indent+ "String_Node_Str");
        xml.append(nls);
        if (se.getExportFormData().size() != 0) {
          if (se.getStudyEventDefinition().getType().equals(COMMON) && se.getExportFormData().get(0).getEventDefinitionCrf().getStatusId() != Status.AUTO_DELETED.getCode() && se.getExportFormData().get(0).getEventDefinitionCrf().getStatusId() != Status.DELETED.getCode()) {
            if (studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode()) {
              if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
                String removeUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(removeUrl)+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
            }
 else {
              if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)&& studyEvent.getStudyEventDefinition().getStatus().equals(Status.AVAILABLE)) {
                String restoreUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(restoreUrl)+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
            }
            if (role.equals(Role.INVESTIGATOR) && (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.COMPLETED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SKIPPED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.STOPPED.getCode()) && studySubject.getStatus().equals(Status.AVAILABLE)&& studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
              String signUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId()+ "String_Node_Str";
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(signUrl)+ "String_Node_Str");
              xml.append("String_Node_Str");
              xml.append(nls);
            }
            if (studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && studySubject.getStatus().equals(Status.AVAILABLE) && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
              if ((!studyEvent.getStudyEventDefinition().getType().equals(COMMON) && !role.equals(Role.MONITOR)) || (studyEvent.getStudyEventDefinition().getType().equals(COMMON) && (role.equals(Role.STUDY_STUDYDIRECTOR) || role.equals(Role.COORDINATOR)))) {
                String lockUrl="String_Node_Str" + studyEvent.getStudyEventId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(lockUrl)+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
            }
          }
        }
        xml.append(indent + indent + indent+ indent+ "String_Node_Str");
        xml.append(nls);
        ArrayList<ExportFormDataBean> forms=se.getExportFormData();
        for (        ExportFormDataBean form : forms) {
          if (!clinical || (clinical && !form.getStatus().equals(EventCRFStatus.INVALID.getI18nDescription(getLocale())))) {
            xml.append(indent + indent + indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(form.getFormOID()));
            if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
              String formName=form.getFormName();
              if (!StringUtils.isEmpty(formName)) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(formName));
              }
              String formLayout=form.getFormLayoutName();
              if (!StringUtils.isEmpty(formLayout)) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(formLayout));
              }
              String interviewerName=form.getInterviewerName();
              if (interviewerName != null && interviewerName.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(interviewerName));
              }
              if (form.getInterviewDate() != null && form.getInterviewDate().length() > 0) {
                xml.append("String_Node_Str" + form.getInterviewDate());
              }
              Date createdDate=form.getCreatedDate();
              if (createdDate != null) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(new SimpleDateFormat("String_Node_Str").format(createdDate)));
              }
              String createdBy=form.getCreatedBy();
              if (createdBy != null && createdBy.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(createdBy));
              }
              Date updatedDate=form.getUpdatedDate();
              if (updatedDate != null) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(new SimpleDateFormat("String_Node_Str").format(updatedDate)));
              }
              String updatedBy=form.getUpdatedBy();
              if (updatedBy != null && updatedBy.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(updatedBy));
              }
              String status=form.getStatus();
              if (status != null && status.length() > 0) {
                xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(status));
              }
            }
            xml.append("String_Node_Str");
            xml.append(nls);
            EventCrf eventCrf=form.getEventCrf();
            FormLayout formLayout=form.getFormLayout();
            EventDefinitionCrf eventDefinitionCrf=form.getEventDefinitionCrf();
            xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
            xml.append(nls);
            String formUrl="String_Node_Str" + formLayout.getFormLayoutId() + "String_Node_Str"+ studyEvent.getStudyEventId()+ "String_Node_Str"+ eventCrf.getEventCrfId()+ "String_Node_Str"+ studySubject.getStudySubjectId();
            xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(formUrl + "String_Node_Str")+ "String_Node_Str");
            xml.append("String_Node_Str");
            xml.append(nls);
            if (!(form.getEventDefinitionCrf().getStatusId() == Status.DELETED.getCode()) && !(form.getEventDefinitionCrf().getStatusId() == Status.AUTO_DELETED.getCode())) {
              if (!role.equals(Role.MONITOR) && eventCrf.getStatusId() != Status.DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode() && eventCrf.getStatusId() != Status.LOCKED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.LOCKED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.SKIPPED.getCode() && studyEvent.getSubjectEventStatusId() != SubjectEventStatus.STOPPED.getCode() && studyEvent.getStatusId() != Status.DELETED.getCode() && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(formUrl + "String_Node_Str")+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
              if (!studyEvent.getStudyEventDefinition().getType().equals(COMMON)) {
                if (eventCrf.getStatusId() != Status.DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode()) {
                  if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studySubject.getStatus().equals(Status.AVAILABLE) && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
                    String removeUrl="String_Node_Str" + eventCrf.getEventCrfId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(removeUrl)+ "String_Node_Str");
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
 else {
                  if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studyEvent.getStatusId() != Status.AUTO_DELETED.getCode() && eventCrf.getStatusId() != Status.AUTO_DELETED.getCode() && studySubject.getStatus().equals(Status.AVAILABLE) && studyEvent.getStatusId() == Status.AVAILABLE.getCode() && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE)) {
                    String restoreUrl="String_Node_Str" + eventCrf.getEventCrfId() + "String_Node_Str"+ studySubject.getStudySubjectId();
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(restoreUrl)+ "String_Node_Str");
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
              }
              if ((role.equals(Role.STUDYDIRECTOR) || role.equals(Role.COORDINATOR)) && studyBean.getStatus().equals(org.akaza.openclinica.bean.core.Status.AVAILABLE) && !(studyEvent.getSubjectEventStatusId() == SubjectEventStatus.LOCKED.getCode() || studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SKIPPED.getCode())) {
                String reassignUrl="String_Node_Str" + formLayout.getCrf().getCrfId() + "String_Node_Str"+ formLayout.getCrf().getName()+ "String_Node_Str"+ formLayout.getFormLayoutId()+ "String_Node_Str"+ form.getFormLayoutName()+ "String_Node_Str"+ studySubject.getLabel()+ "String_Node_Str"+ studySubject.getStudySubjectId()+ "String_Node_Str"+ eventCrf.getEventCrfId()+ "String_Node_Str"+ eventDefinitionCrf.getEventDefinitionCrfId();
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(reassignUrl)+ "String_Node_Str");
                xml.append("String_Node_Str");
                xml.append(nls);
              }
            }
            xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
            xml.append(nls);
            ArrayList<ImportItemGroupDataBean> igs=form.getItemGroupData();
            sortImportItemGroupDataBeanList(igs);
            for (            ImportItemGroupDataBean ig : igs) {
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(ig.getItemGroupOID())+ "String_Node_Str");
              if (!"String_Node_Str".equals(ig.getItemGroupRepeatKey())) {
                xml.append("String_Node_Str" + ig.getItemGroupRepeatKey() + "String_Node_Str");
              }
              String itemGroupName=ig.getItemGroupName();
              if (!StringUtils.isEmpty(itemGroupName)) {
                xml.append("String_Node_Str" + itemGroupName + "String_Node_Str");
              }
              if (ig.getItemData().get(0).isDeleted()) {
                xml.append("String_Node_Str" + (ig.getItemData().get(0).isDeleted() ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
              }
              xml.append("String_Node_Str");
              xml.append(nls);
              ArrayList<ImportItemDataBean> items=ig.getItemData();
              sortImportItemDataBeanList(items);
              for (              ImportItemDataBean item : items) {
                boolean printValue=true;
                xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(item.getItemOID())+ "String_Node_Str");
                String itemName=item.getItemName();
                if (!StringUtils.isEmpty(itemName)) {
                  xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(itemName) + "String_Node_Str");
                }
                if ("String_Node_Str".equals(item.getIsNull())) {
                  xml.append("String_Node_Str");
                  if (!item.isHasValueWithNull()) {
                    printValue=false;
                  }
                  if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
                    xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(item.getReasonForNull()) + "String_Node_Str");
                    if (!printValue) {
                      xml.append("String_Node_Str");
                      xml.append(nls);
                    }
                  }
                }
                if (printValue) {
                  Boolean hasElm=false;
                  xml.append("String_Node_Str" + StringEscapeUtils.escapeXml(item.getValue()) + "String_Node_Str");
                  String muRefOid=item.getMeasurementUnitRef().getElementDefOID();
                  if (muRefOid != null && muRefOid.length() > 0) {
                    if (hasElm) {
                    }
 else {
                      xml.append("String_Node_Str");
                      xml.append(nls);
                      hasElm=true;
                    }
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ indent+ "String_Node_Str"+ StringEscapeUtils.escapeXml(muRefOid)+ "String_Node_Str");
                    xml.append(nls);
                  }
                  if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
                    if (item.getAuditLogs() != null && item.getAuditLogs().getAuditLogs().size() > 0) {
                      if (hasElm) {
                      }
 else {
                        xml.append("String_Node_Str");
                        xml.append(nls);
                        hasElm=true;
                      }
                      this.addAuditLogs(item.getAuditLogs(),indent + indent + indent+ indent+ indent+ indent+ indent,"String_Node_Str");
                    }
                    if (item.getDiscrepancyNotes() != null && item.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
                      if (hasElm) {
                      }
 else {
                        xml.append("String_Node_Str");
                        xml.append(nls);
                        hasElm=true;
                      }
                      this.addDiscrepancyNotes(item.getDiscrepancyNotes(),indent + indent + indent+ indent+ indent+ indent+ indent);
                    }
                  }
                  if (hasElm) {
                    xml.append(indent + indent + indent+ indent+ indent+ indent+ "String_Node_Str");
                    xml.append(nls);
                    hasElm=false;
                  }
 else {
                    xml.append("String_Node_Str");
                    xml.append(nls);
                  }
                }
              }
              xml.append(indent + indent + indent+ indent+ indent+ "String_Node_Str");
              xml.append(nls);
            }
            if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
              if (form.getAuditLogs() != null && form.getAuditLogs().getAuditLogs().size() > 0) {
                this.addAuditLogs(form.getAuditLogs(),indent + indent + indent+ indent+ indent,"String_Node_Str");
              }
              if (form.getDiscrepancyNotes() != null && form.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
                this.addDiscrepancyNotes(form.getDiscrepancyNotes(),indent + indent + indent+ indent+ indent);
              }
            }
            xml.append(indent + indent + indent+ indent+ "String_Node_Str");
            xml.append(nls);
          }
        }
        if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
          if (se.getAuditLogs() != null && se.getAuditLogs().getAuditLogs().size() > 0) {
            this.addAuditLogs(se.getAuditLogs(),indent + indent + indent+ indent,"String_Node_Str");
          }
          if (se.getDiscrepancyNotes() != null && se.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
            this.addDiscrepancyNotes(se.getDiscrepancyNotes(),indent + indent + indent+ indent);
          }
        }
        xml.append(indent + indent + indent+ "String_Node_Str");
        xml.append(nls);
      }
    }
    if ("String_Node_Str".equalsIgnoreCase(ODMVersion) || "String_Node_Str".equalsIgnoreCase(ODMVersion)) {
      ArrayList<SubjectGroupDataBean> sgddata=(ArrayList<SubjectGroupDataBean>)sub.getSubjectGroupData();
      if (sgddata.size() > 0) {
        for (        SubjectGroupDataBean sgd : sgddata) {
          String cid=sgd.getStudyGroupClassId() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassId()) + "String_Node_Str" : "String_Node_Str";
          if (cid.length() > 0) {
            String cn=sgd.getStudyGroupClassName() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassName()) + "String_Node_Str" : "String_Node_Str";
            String gn=sgd.getStudyGroupName() != null ? "String_Node_Str" + StringEscapeUtils.escapeXml(sgd.getStudyGroupName()) + "String_Node_Str" : "String_Node_Str";
            xml.append(indent + indent + indent+ "String_Node_Str"+ cid+ cn+ gn);
          }
          xml.append("String_Node_Str");
          xml.append(nls);
        }
      }
      if (sub.getAuditLogs() != null && sub.getAuditLogs().getAuditLogs().size() > 0) {
        this.addAuditLogs(sub.getAuditLogs(),indent + indent + indent,"String_Node_Str");
      }
      if (sub.getDiscrepancyNotes() != null && sub.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
        this.addDiscrepancyNotes(sub.getDiscrepancyNotes(),indent + indent + indent);
      }
    }
    xml.append(indent + indent + "String_Node_Str");
    xml.append(nls);
  }
  if (footer) {
    xml.append(indent + "String_Node_Str");
    xml.append(nls);
  }
}