Program: 115208
Project: 115208
Buggy source:
/** 
 * metadata for ODM extraction only
 */
public void getODMMetadata(int parentStudyId,int studyId,MetaDataVersionBean metadata,String odmVersion){
  String cvIds="String_Node_Str";
  HashMap<Integer,Integer> cvIdPoses=new HashMap<Integer,Integer>();
  this.setStudyEventAndFormMetaTypesExpected();
  logger.debug("String_Node_Str");
  logger.error("String_Node_Str" + this.getStudyEventAndFormMetaSql(parentStudyId,studyId,false));
  ArrayList rows=this.select(this.getStudyEventAndFormMetaSql(parentStudyId,studyId,false));
  Iterator it=rows.iterator();
  String sedprev="String_Node_Str";
  MetaDataVersionProtocolBean protocol=metadata.getProtocol();
  HashMap<Integer,String> nullMap=new HashMap<Integer,String>();
  HashMap<String,String> nullValueCVs=new HashMap<String,String>();
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    Integer sedOrder=(Integer)row.get("String_Node_Str");
    Integer cvId=(Integer)row.get("String_Node_Str");
    String sedOID=(String)row.get("String_Node_Str");
    String sedName=(String)row.get("String_Node_Str");
    Boolean sedRepeat=(Boolean)row.get("String_Node_Str");
    String sedType=(String)row.get("String_Node_Str");
    String cvOID=(String)row.get("String_Node_Str");
    String cvName=(String)row.get("String_Node_Str");
    Boolean cvRequired=(Boolean)row.get("String_Node_Str");
    String nullValue=(String)row.get("String_Node_Str");
    String crfName=(String)row.get("String_Node_Str");
    StudyEventDefBean sedef=new StudyEventDefBean();
    if (sedprev.equals(sedOID)) {
      int p=metadata.getStudyEventDefs().size() - 1;
      sedef=metadata.getStudyEventDefs().get(p);
    }
 else {
      sedprev=sedOID;
      ElementRefBean sedref=new ElementRefBean();
      sedref.setElementDefOID(sedOID);
      sedref.setMandatory("String_Node_Str");
      sedref.setOrderNumber(sedOrder);
      protocol.getStudyEventRefs().add(sedref);
      sedef.setOid(sedOID);
      sedef.setName(sedName);
      sedef.setRepeating(sedRepeat ? "String_Node_Str" : "String_Node_Str");
      String type=sedType.toLowerCase();
      type=type.substring(0,1).toUpperCase() + type.substring(1);
      sedef.setType(type);
      metadata.getStudyEventDefs().add(sedef);
    }
    ElementRefBean formref=new ElementRefBean();
    formref.setElementDefOID(cvOID);
    formref.setMandatory(cvRequired ? "String_Node_Str" : "String_Node_Str");
    sedef.getFormRefs().add(formref);
    if (!cvIdPoses.containsKey(cvId)) {
      FormDefBean formdef=new FormDefBean();
      formdef.setOid(cvOID);
      formdef.setName(crfName + "String_Node_Str" + cvName);
      formdef.setRepeating("String_Node_Str");
      metadata.getFormDefs().add(formdef);
      cvIdPoses.put(cvId,metadata.getFormDefs().size() - 1);
      cvIds+=cvId + "String_Node_Str";
      if (nullValue != null && nullValue.length() > 0) {
        nullMap.put(cvId,nullValue);
        nullValueCVs.put(sedOID + "String_Node_Str" + cvOID,nullValue);
      }
    }
  }
  cvIds=cvIds.substring(0,cvIds.length() - 1);
  metadata.setCvIds(cvIds);
  HashMap<Integer,Integer> maxLengths=new HashMap<Integer,Integer>();
  this.setItemDataMaxLengthTypesExpected();
  rows.clear();
  logger.debug("String_Node_Str");
  rows=select(this.getItemDataMaxLengths(cvIds));
  it=rows.iterator();
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    maxLengths.put((Integer)row.get("String_Node_Str"),(Integer)row.get("String_Node_Str"));
  }
  this.setItemGroupAndItemMetaWithUnitTypesExpected();
  rows.clear();
  logger.debug("String_Node_Str");
  logger.error("String_Node_Str" + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
  rows=select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
  it=rows.iterator();
  ArrayList<ItemGroupDefBean> itemGroupDefs=(ArrayList<ItemGroupDefBean>)metadata.getItemGroupDefs();
  ArrayList<ItemDefBean> itemDefs=(ArrayList<ItemDefBean>)metadata.getItemDefs();
  ArrayList<CodeListBean> codeLists=(ArrayList<CodeListBean>)metadata.getCodeLists();
  ArrayList<MultiSelectListBean> multiSelectLists=(ArrayList<MultiSelectListBean>)metadata.getMultiSelectLists();
  ArrayList<ElementRefBean> itemGroupRefs=new ArrayList<ElementRefBean>();
  Set<String> igset=new HashSet<String>();
  HashMap<String,Integer> igdPos=new HashMap<String,Integer>();
  Set<String> itset=new HashSet<String>();
  Set<Integer> itdset=new HashSet<Integer>();
  Set<Integer> clset=new HashSet<Integer>();
  Set<Integer> mslset=new HashSet<Integer>();
  ItemGroupDefBean igdef=new ItemGroupDefBean();
  HashMap<String,String> igMandatories=new HashMap<String,String>();
  boolean isLatest=false;
  int cvprev=-1;
  String igrprev="String_Node_Str";
  String igdprev="String_Node_Str";
  String itMandatory="String_Node_Str";
  int itOrder=0;
  Integer igId=-1;
  String sectionIds="String_Node_Str";
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    Integer cId=(Integer)row.get("String_Node_Str");
    Integer cvId=(Integer)row.get("String_Node_Str");
    igId=(Integer)row.get("String_Node_Str");
    Integer itId=(Integer)row.get("String_Node_Str");
    Integer rsId=(Integer)row.get("String_Node_Str");
    String cvOID=(String)row.get("String_Node_Str");
    String igOID=(String)row.get("String_Node_Str");
    String itOID=(String)row.get("String_Node_Str");
    String igName=(String)row.get("String_Node_Str");
    String itName=(String)row.get("String_Node_Str");
    Integer dataTypeId=(Integer)row.get("String_Node_Str");
    Integer secId=(Integer)row.get("String_Node_Str");
    String header=(String)row.get("String_Node_Str");
    String left=(String)row.get("String_Node_Str");
    String right=(String)row.get("String_Node_Str");
    Boolean itRequired=(Boolean)row.get("String_Node_Str");
    String regexp=(String)row.get("String_Node_Str");
    String regexpErr=(String)row.get("String_Node_Str");
    String widthDecimal=(String)row.get("String_Node_Str");
    Integer rsTypeId=(Integer)row.get("String_Node_Str");
    String rsText=(String)row.get("String_Node_Str");
    String rsValue=(String)row.get("String_Node_Str");
    String rsLabel=(String)row.get("String_Node_Str");
    String igHeader=(String)row.get("String_Node_Str");
    String itDesc=(String)row.get("String_Node_Str");
    String itQuesNum=(String)row.get("String_Node_Str");
    String muOid=(String)row.get("String_Node_Str");
    if (cvprev != cvId) {
      if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
        String temp=igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
        itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
      }
      itMandatory="String_Node_Str";
      cvprev=cvId;
      FormDefBean formDef=new FormDefBean();
      if (cvIdPoses.containsKey(cvId)) {
        int p=cvIdPoses.get(cvId);
        formDef=metadata.getFormDefs().get(p);
      }
 else {
        logger.debug("String_Node_Str" + cvId + "String_Node_Str");
      }
      itemGroupRefs=(ArrayList<ElementRefBean>)formDef.getItemGroupRefs();
    }
    String igDefKey=igId + "String_Node_Str";
    if (!igdprev.equals(igDefKey)) {
      if (igdPos.containsKey(igDefKey)) {
        igdef=itemGroupDefs.get(igdPos.get(igDefKey));
        isLatest=false;
        itOrder=igdef.getItemRefs().size();
      }
 else {
        igdef=new ItemGroupDefBean();
        itOrder=0;
        igMandatories.put(igdprev,itMandatory);
        isLatest=true;
        igdef.setOid(igOID);
        igdef.setName("String_Node_Str".equalsIgnoreCase(igName) ? igOID : igName);
        igdef.setRepeating("String_Node_Str".equalsIgnoreCase(igName) ? "String_Node_Str" : "String_Node_Str");
        igdef.setComment(igHeader);
        igdef.setPreSASDatasetName(igName.toUpperCase());
        itemGroupDefs.add(igdef);
        igdPos.put(igDefKey,itemGroupDefs.size() - 1);
      }
      igdprev=igDefKey;
    }
    String igRefKey=igId + "String_Node_Str" + cvId;
    if (igrprev.equals(igRefKey)) {
      itMandatory=isLatest && itRequired && "String_Node_Str".equals(itMandatory) ? "String_Node_Str" : itMandatory;
    }
 else {
      if (!igset.contains(igRefKey)) {
        igset.add(igRefKey);
        ElementRefBean igref=new ElementRefBean();
        igref.setElementDefOID(igOID);
        int size=itemGroupRefs.size();
        if (size > 0) {
          String prev=igrprev.split("String_Node_Str")[0].trim();
          String temp=igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
          itemGroupRefs.get(size - 1).setMandatory(temp);
        }
        itemGroupRefs.add(igref);
        itMandatory="String_Node_Str";
      }
      igrprev=igRefKey;
    }
    String mandatory=itRequired ? "String_Node_Str" : "String_Node_Str";
    if (!itset.contains(igDefKey + "String_Node_Str" + itId)) {
      ++itOrder;
      itset.add(igDefKey + "String_Node_Str" + itId);
      ElementRefBean itemRef=new ElementRefBean();
      itemRef.setElementDefOID(itOID);
      if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
        itemRef.setMandatory(mandatory);
      }
      itemRef.setOrderNumber(itOrder);
      igdef.getItemRefs().add(itemRef);
    }
    boolean hasCode=MetadataUnit.needCodeList(rsTypeId,dataTypeId);
    LinkedHashMap<String,String> codes=new LinkedHashMap<String,String>();
    if (hasCode) {
      codes=MetadataUnit.parseCode(rsText,rsValue);
    }
    boolean hasMultiSelect=MetadataUnit.needMultiSelectList(rsTypeId);
    LinkedHashMap<String,String> multi=new LinkedHashMap<String,String>();
    if (hasMultiSelect) {
      multi=MetadataUnit.parseCode(rsText,rsValue);
    }
    String datatype=MetadataUnit.getOdmItemDataType(rsTypeId,dataTypeId,odmVersion);
    if (sectionIds.contains("String_Node_Str" + secId + "String_Node_Str")) {
    }
 else {
      sectionIds+=secId + "String_Node_Str";
    }
    if (!itdset.contains(itId)) {
      itdset.add(itId);
      ItemDefBean idef=new ItemDefBean();
      idef.setOid(itOID);
      idef.setName(itName);
      idef.setComment(itDesc);
      if (muOid != null && muOid.length() > 0) {
        ElementRefBean measurementUnitRef=new ElementRefBean();
        measurementUnitRef.setElementDefOID(muOid);
        idef.setMeasurementUnitRef(measurementUnitRef);
      }
      idef.setPreSASFieldName(itName);
      idef.setCodeListOID(hasCode ? "String_Node_Str" + rsId : "String_Node_Str");
      if (hasMultiSelect) {
        ElementRefBean multiSelectListRef=new ElementRefBean();
        multiSelectListRef.setElementDefOID("String_Node_Str" + rsId);
        idef.setMultiSelectListRef(multiSelectListRef);
      }
      idef.getQuestion().setQuestionNumber(itQuesNum);
      idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header,left,right));
      if (regexp != null && regexp.startsWith("String_Node_Str")) {
        idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(),metadata.getSoftHard(),regexpErr,muOid));
      }
      idef.setDataType(datatype);
      int len=0;
      int sig=0;
      if (widthDecimal != null && widthDecimal.length() > 0) {
        len=parseWidth(widthDecimal);
        sig=parseDecimal(widthDecimal);
      }
      if (rsTypeId == 3 || rsTypeId == 7) {
        len=maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
        len=Math.max(len,Math.max(rsText.length(),rsValue.length()));
        idef.setLength(len);
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength());
        }
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
        }
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
        }
      }
 else {
        idef.setLength(0);
      }
      idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype,codes.keySet(),hasCode));
      itemDefs.add(idef);
    }
    if (hasCode && !clset.contains(rsId)) {
      clset.add(rsId);
      CodeListBean cl=new CodeListBean();
      cl.setOid("String_Node_Str" + rsId);
      cl.setName(rsLabel);
      cl.setPreSASFormatName(rsLabel);
      cl.setDataType(datatype);
      Iterator<String> iter=codes.keySet().iterator();
      while (iter.hasNext()) {
        String de=iter.next();
        CodeListItemBean cli=new CodeListItemBean();
        cli.setCodedValue(de);
        TranslatedTextBean tt=cli.getDecode();
        tt.setText(codes.get(de));
        tt.setXmlLang(CoreResources.getField("String_Node_Str"));
        cli.setDecode(tt);
        cl.getCodeListItems().add(cli);
      }
      codeLists.add(cl);
    }
    if (odmVersion.startsWith("String_Node_Str") && hasMultiSelect && !mslset.contains(rsId)) {
      mslset.add(rsId);
      MultiSelectListBean msl=new MultiSelectListBean();
      msl.setOid("String_Node_Str" + rsId);
      msl.setName(rsLabel);
      msl.setDataType(datatype);
      msl.setActualDataType(datatype);
      Iterator<String> iter=multi.keySet().iterator();
      while (iter.hasNext()) {
        String de=iter.next();
        MultiSelectListItemBean msli=new MultiSelectListItemBean();
        msli.setCodedOptionValue(de);
        TranslatedTextBean tt=new TranslatedTextBean();
        String t=multi.get(de);
        tt.setText(t);
        tt.setXmlLang(CoreResources.getField("String_Node_Str"));
        msli.setDecode(tt);
        msl.getMultiSelectListItems().add(msli);
      }
      multiSelectLists.add(msl);
    }
  }
  if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
    String last=igMandatories.containsKey(igId + "String_Node_Str") ? igMandatories.get(igId + "String_Node_Str") : itMandatory;
    itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
  }
  sectionIds=sectionIds.length() > 0 ? sectionIds.substring(1,sectionIds.length() - 1) : "String_Node_Str";
  metadata.setSectionIds(sectionIds);
}

Fixed version (ground truth):
/** 
 * metadata for ODM extraction only
 */
public void getODMMetadata(int parentStudyId,int studyId,MetaDataVersionBean metadata,String odmVersion){
  String cvIds="String_Node_Str";
  HashMap<Integer,Integer> cvIdPoses=new HashMap<Integer,Integer>();
  this.setStudyEventAndFormMetaTypesExpected();
  logger.debug("String_Node_Str");
  logger.debug("String_Node_Str" + this.getStudyEventAndFormMetaSql(parentStudyId,studyId,false));
  ArrayList rows=this.select(this.getStudyEventAndFormMetaSql(parentStudyId,studyId,false));
  Iterator it=rows.iterator();
  String sedprev="String_Node_Str";
  MetaDataVersionProtocolBean protocol=metadata.getProtocol();
  HashMap<Integer,String> nullMap=new HashMap<Integer,String>();
  HashMap<String,String> nullValueCVs=new HashMap<String,String>();
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    Integer sedOrder=(Integer)row.get("String_Node_Str");
    Integer cvId=(Integer)row.get("String_Node_Str");
    String sedOID=(String)row.get("String_Node_Str");
    String sedName=(String)row.get("String_Node_Str");
    Boolean sedRepeat=(Boolean)row.get("String_Node_Str");
    String sedType=(String)row.get("String_Node_Str");
    String cvOID=(String)row.get("String_Node_Str");
    String cvName=(String)row.get("String_Node_Str");
    Boolean cvRequired=(Boolean)row.get("String_Node_Str");
    String nullValue=(String)row.get("String_Node_Str");
    String crfName=(String)row.get("String_Node_Str");
    StudyEventDefBean sedef=new StudyEventDefBean();
    if (sedprev.equals(sedOID)) {
      int p=metadata.getStudyEventDefs().size() - 1;
      sedef=metadata.getStudyEventDefs().get(p);
    }
 else {
      sedprev=sedOID;
      ElementRefBean sedref=new ElementRefBean();
      sedref.setElementDefOID(sedOID);
      sedref.setMandatory("String_Node_Str");
      sedref.setOrderNumber(sedOrder);
      protocol.getStudyEventRefs().add(sedref);
      sedef.setOid(sedOID);
      sedef.setName(sedName);
      sedef.setRepeating(sedRepeat ? "String_Node_Str" : "String_Node_Str");
      String type=sedType.toLowerCase();
      type=type.substring(0,1).toUpperCase() + type.substring(1);
      sedef.setType(type);
      metadata.getStudyEventDefs().add(sedef);
    }
    ElementRefBean formref=new ElementRefBean();
    formref.setElementDefOID(cvOID);
    formref.setMandatory(cvRequired ? "String_Node_Str" : "String_Node_Str");
    sedef.getFormRefs().add(formref);
    if (!cvIdPoses.containsKey(cvId)) {
      FormDefBean formdef=new FormDefBean();
      formdef.setOid(cvOID);
      formdef.setName(crfName + "String_Node_Str" + cvName);
      formdef.setRepeating("String_Node_Str");
      metadata.getFormDefs().add(formdef);
      cvIdPoses.put(cvId,metadata.getFormDefs().size() - 1);
      cvIds+=cvId + "String_Node_Str";
      if (nullValue != null && nullValue.length() > 0) {
        nullMap.put(cvId,nullValue);
        nullValueCVs.put(sedOID + "String_Node_Str" + cvOID,nullValue);
      }
    }
  }
  cvIds=cvIds.substring(0,cvIds.length() - 1);
  metadata.setCvIds(cvIds);
  HashMap<Integer,Integer> maxLengths=new HashMap<Integer,Integer>();
  this.setItemDataMaxLengthTypesExpected();
  rows.clear();
  logger.debug("String_Node_Str");
  rows=select(this.getItemDataMaxLengths(cvIds));
  it=rows.iterator();
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    maxLengths.put((Integer)row.get("String_Node_Str"),(Integer)row.get("String_Node_Str"));
  }
  this.setItemGroupAndItemMetaWithUnitTypesExpected();
  rows.clear();
  logger.debug("String_Node_Str");
  logger.debug("String_Node_Str" + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
  rows=select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
  it=rows.iterator();
  ArrayList<ItemGroupDefBean> itemGroupDefs=(ArrayList<ItemGroupDefBean>)metadata.getItemGroupDefs();
  ArrayList<ItemDefBean> itemDefs=(ArrayList<ItemDefBean>)metadata.getItemDefs();
  ArrayList<CodeListBean> codeLists=(ArrayList<CodeListBean>)metadata.getCodeLists();
  ArrayList<MultiSelectListBean> multiSelectLists=(ArrayList<MultiSelectListBean>)metadata.getMultiSelectLists();
  ArrayList<ElementRefBean> itemGroupRefs=new ArrayList<ElementRefBean>();
  Set<String> igset=new HashSet<String>();
  HashMap<String,Integer> igdPos=new HashMap<String,Integer>();
  Set<String> itset=new HashSet<String>();
  Set<Integer> itdset=new HashSet<Integer>();
  Set<Integer> clset=new HashSet<Integer>();
  Set<Integer> mslset=new HashSet<Integer>();
  ItemGroupDefBean igdef=new ItemGroupDefBean();
  HashMap<String,String> igMandatories=new HashMap<String,String>();
  boolean isLatest=false;
  int cvprev=-1;
  String igrprev="String_Node_Str";
  String igdprev="String_Node_Str";
  String itMandatory="String_Node_Str";
  int itOrder=0;
  Integer igId=-1;
  String sectionIds="String_Node_Str";
  while (it.hasNext()) {
    HashMap row=(HashMap)it.next();
    Integer cId=(Integer)row.get("String_Node_Str");
    Integer cvId=(Integer)row.get("String_Node_Str");
    igId=(Integer)row.get("String_Node_Str");
    Integer itId=(Integer)row.get("String_Node_Str");
    Integer rsId=(Integer)row.get("String_Node_Str");
    String cvOID=(String)row.get("String_Node_Str");
    String igOID=(String)row.get("String_Node_Str");
    String itOID=(String)row.get("String_Node_Str");
    String igName=(String)row.get("String_Node_Str");
    String itName=(String)row.get("String_Node_Str");
    Integer dataTypeId=(Integer)row.get("String_Node_Str");
    Integer secId=(Integer)row.get("String_Node_Str");
    String header=(String)row.get("String_Node_Str");
    String left=(String)row.get("String_Node_Str");
    String right=(String)row.get("String_Node_Str");
    Boolean itRequired=(Boolean)row.get("String_Node_Str");
    String regexp=(String)row.get("String_Node_Str");
    String regexpErr=(String)row.get("String_Node_Str");
    String widthDecimal=(String)row.get("String_Node_Str");
    Integer rsTypeId=(Integer)row.get("String_Node_Str");
    String rsText=(String)row.get("String_Node_Str");
    String rsValue=(String)row.get("String_Node_Str");
    String rsLabel=(String)row.get("String_Node_Str");
    String igHeader=(String)row.get("String_Node_Str");
    String itDesc=(String)row.get("String_Node_Str");
    String itQuesNum=(String)row.get("String_Node_Str");
    String muOid=(String)row.get("String_Node_Str");
    if (cvprev != cvId) {
      if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
        String temp=igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
        itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
      }
      itMandatory="String_Node_Str";
      cvprev=cvId;
      FormDefBean formDef=new FormDefBean();
      if (cvIdPoses.containsKey(cvId)) {
        int p=cvIdPoses.get(cvId);
        formDef=metadata.getFormDefs().get(p);
      }
 else {
        logger.debug("String_Node_Str" + cvId + "String_Node_Str");
      }
      itemGroupRefs=(ArrayList<ElementRefBean>)formDef.getItemGroupRefs();
    }
    String igDefKey=igId + "String_Node_Str";
    if (!igdprev.equals(igDefKey)) {
      if (igdPos.containsKey(igDefKey)) {
        igdef=itemGroupDefs.get(igdPos.get(igDefKey));
        isLatest=false;
        itOrder=igdef.getItemRefs().size();
      }
 else {
        igdef=new ItemGroupDefBean();
        itOrder=0;
        igMandatories.put(igdprev,itMandatory);
        isLatest=true;
        igdef.setOid(igOID);
        igdef.setName("String_Node_Str".equalsIgnoreCase(igName) ? igOID : igName);
        igdef.setRepeating("String_Node_Str".equalsIgnoreCase(igName) ? "String_Node_Str" : "String_Node_Str");
        igdef.setComment(igHeader);
        igdef.setPreSASDatasetName(igName.toUpperCase());
        itemGroupDefs.add(igdef);
        igdPos.put(igDefKey,itemGroupDefs.size() - 1);
      }
      igdprev=igDefKey;
    }
    String igRefKey=igId + "String_Node_Str" + cvId;
    if (igrprev.equals(igRefKey)) {
      itMandatory=isLatest && itRequired && "String_Node_Str".equals(itMandatory) ? "String_Node_Str" : itMandatory;
    }
 else {
      if (!igset.contains(igRefKey)) {
        igset.add(igRefKey);
        ElementRefBean igref=new ElementRefBean();
        igref.setElementDefOID(igOID);
        int size=itemGroupRefs.size();
        if (size > 0) {
          String prev=igrprev.split("String_Node_Str")[0].trim();
          String temp=igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
          itemGroupRefs.get(size - 1).setMandatory(temp);
        }
        itemGroupRefs.add(igref);
        itMandatory="String_Node_Str";
      }
      igrprev=igRefKey;
    }
    String mandatory=itRequired ? "String_Node_Str" : "String_Node_Str";
    if (!itset.contains(igDefKey + "String_Node_Str" + itId)) {
      ++itOrder;
      itset.add(igDefKey + "String_Node_Str" + itId);
      ElementRefBean itemRef=new ElementRefBean();
      itemRef.setElementDefOID(itOID);
      if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
        itemRef.setMandatory(mandatory);
      }
      itemRef.setOrderNumber(itOrder);
      igdef.getItemRefs().add(itemRef);
    }
    boolean hasCode=MetadataUnit.needCodeList(rsTypeId,dataTypeId);
    LinkedHashMap<String,String> codes=new LinkedHashMap<String,String>();
    if (hasCode) {
      codes=MetadataUnit.parseCode(rsText,rsValue);
    }
    boolean hasMultiSelect=MetadataUnit.needMultiSelectList(rsTypeId);
    LinkedHashMap<String,String> multi=new LinkedHashMap<String,String>();
    if (hasMultiSelect) {
      multi=MetadataUnit.parseCode(rsText,rsValue);
    }
    String datatype=MetadataUnit.getOdmItemDataType(rsTypeId,dataTypeId,odmVersion);
    if (sectionIds.contains("String_Node_Str" + secId + "String_Node_Str")) {
    }
 else {
      sectionIds+=secId + "String_Node_Str";
    }
    if (!itdset.contains(itId)) {
      itdset.add(itId);
      ItemDefBean idef=new ItemDefBean();
      idef.setOid(itOID);
      idef.setName(itName);
      idef.setComment(itDesc);
      if (muOid != null && muOid.length() > 0) {
        ElementRefBean measurementUnitRef=new ElementRefBean();
        measurementUnitRef.setElementDefOID(muOid);
        idef.setMeasurementUnitRef(measurementUnitRef);
      }
      idef.setPreSASFieldName(itName);
      idef.setCodeListOID(hasCode ? "String_Node_Str" + rsId : "String_Node_Str");
      if (hasMultiSelect) {
        ElementRefBean multiSelectListRef=new ElementRefBean();
        multiSelectListRef.setElementDefOID("String_Node_Str" + rsId);
        idef.setMultiSelectListRef(multiSelectListRef);
      }
      idef.getQuestion().setQuestionNumber(itQuesNum);
      idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header,left,right));
      if (regexp != null && regexp.startsWith("String_Node_Str")) {
        idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(),metadata.getSoftHard(),regexpErr,muOid));
      }
      idef.setDataType(datatype);
      int len=0;
      int sig=0;
      if (widthDecimal != null && widthDecimal.length() > 0) {
        len=parseWidth(widthDecimal);
        sig=parseDecimal(widthDecimal);
      }
      if (rsTypeId == 3 || rsTypeId == 7) {
        len=maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
        len=Math.max(len,Math.max(rsText.length(),rsValue.length()));
        idef.setLength(len);
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength());
        }
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
        }
      }
 else       if ("String_Node_Str".equalsIgnoreCase(datatype)) {
        if (len > 0) {
          idef.setLength(len);
        }
 else {
          idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
        }
      }
 else {
        idef.setLength(0);
      }
      idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype,codes.keySet(),hasCode));
      itemDefs.add(idef);
    }
    if (hasCode && !clset.contains(rsId)) {
      clset.add(rsId);
      CodeListBean cl=new CodeListBean();
      cl.setOid("String_Node_Str" + rsId);
      cl.setName(rsLabel);
      cl.setPreSASFormatName(rsLabel);
      cl.setDataType(datatype);
      Iterator<String> iter=codes.keySet().iterator();
      while (iter.hasNext()) {
        String de=iter.next();
        CodeListItemBean cli=new CodeListItemBean();
        cli.setCodedValue(de);
        TranslatedTextBean tt=cli.getDecode();
        tt.setText(codes.get(de));
        tt.setXmlLang(CoreResources.getField("String_Node_Str"));
        cli.setDecode(tt);
        cl.getCodeListItems().add(cli);
      }
      codeLists.add(cl);
    }
    if (odmVersion.startsWith("String_Node_Str") && hasMultiSelect && !mslset.contains(rsId)) {
      mslset.add(rsId);
      MultiSelectListBean msl=new MultiSelectListBean();
      msl.setOid("String_Node_Str" + rsId);
      msl.setName(rsLabel);
      msl.setDataType(datatype);
      msl.setActualDataType(datatype);
      Iterator<String> iter=multi.keySet().iterator();
      while (iter.hasNext()) {
        String de=iter.next();
        MultiSelectListItemBean msli=new MultiSelectListItemBean();
        msli.setCodedOptionValue(de);
        TranslatedTextBean tt=new TranslatedTextBean();
        String t=multi.get(de);
        tt.setText(t);
        tt.setXmlLang(CoreResources.getField("String_Node_Str"));
        msli.setDecode(tt);
        msl.getMultiSelectListItems().add(msli);
      }
      multiSelectLists.add(msl);
    }
  }
  if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
    String last=igMandatories.containsKey(igId + "String_Node_Str") ? igMandatories.get(igId + "String_Node_Str") : itMandatory;
    itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
  }
  sectionIds=sectionIds.length() > 0 ? sectionIds.substring(1,sectionIds.length() - 1) : "String_Node_Str";
  metadata.setSectionIds(sectionIds);
}