Program: 115237
Project: 115237
Buggy source:
public ArrayList<String> importProcessedData(DataSource dataSource,CoreResources resources,StudyBean studyBean,UserAccountBean userBean,ODMContainer odmContainer,StringBuffer msg,StringBuffer auditMsg,boolean checkEventCrf) throws Exception {
  List<String> errors=new ArrayList<String>();
  TriggerService triggerService=new TriggerService();
  locale=new Locale("String_Node_Str");
  ResourceBundleProvider.updateLocale(locale);
  respage=ResourceBundleProvider.getPageMessagesBundle();
  ItemDataDAO itemDataDao=new ItemDataDAO(dataSource);
  EventCRFDAO eventCrfDao=new EventCRFDAO(dataSource);
  boolean fail=false;
  try {
    System.out.println("String_Node_Str" + studyBean.getId());
    errors=getImportCRFDataService(dataSource).validateStudyMetadata(odmContainer,studyBean.getId());
  }
 catch (  Exception eee) {
    System.out.println("String_Node_Str" + eee.getMessage());
  }
  if (errors != null) {
    System.out.println(errors.toString());
    for (    String error : errors) {
      msg.append(error + "String_Node_Str");
    }
    if (errors.size() > 0) {
      return getFailReturnList(msg.toString(),auditMsg.toString());
    }
 else {
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
  }
  List<EventCRFBean> eventCRFBeans=getImportCRFDataService(dataSource).fetchEventCRFBeans(odmContainer,userBean);
  ArrayList<Integer> permittedEventCRFIds=new ArrayList<Integer>();
  System.out.println("String_Node_Str" + eventCRFBeans.toString());
  List<DisplayItemBeanWrapper> displayItemBeanWrappers=new ArrayList<DisplayItemBeanWrapper>();
  HashMap<String,String> totalValidationErrors=new HashMap<String,String>();
  HashMap<String,String> hardValidationErrors=new HashMap<String,String>();
  if (!eventCRFBeans.isEmpty()) {
    for (    EventCRFBean eventCRFBean : eventCRFBeans) {
      DataEntryStage dataEntryStage=eventCRFBean.getStage();
      Status eventCRFStatus=eventCRFBean.getStatus();
      System.out.println("String_Node_Str" + eventCRFBean.getId() + "String_Node_Str"+ dataEntryStage.getName()+ "String_Node_Str"+ eventCRFStatus.getName());
      if (eventCRFStatus.equals(Status.AVAILABLE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE)|| dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)|| dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        permittedEventCRFIds.add(new Integer(eventCRFBean.getId()));
      }
 else {
        MessageFormat mf=new MessageFormat("String_Node_Str");
        mf.applyPattern(respage.getString("String_Node_Str"));
        Object[] arguments={"String_Node_Str"};
        msg.append(mf.format(arguments) + "String_Node_Str");
        auditMsg.append(mf.format(arguments) + "String_Node_Str");
        continue;
      }
    }
    if (eventCRFBeans.size() >= permittedEventCRFIds.size()) {
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
 else {
      fail=true;
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
    MockHttpServletRequest request=new MockHttpServletRequest();
    request.addPreferredLocale(locale);
    try {
      List<DisplayItemBeanWrapper> tempDisplayItemBeanWrappers=new ArrayList<DisplayItemBeanWrapper>();
      tempDisplayItemBeanWrappers=getImportCRFDataService(dataSource).lookupValidationErrors(request,odmContainer,userBean,totalValidationErrors,hardValidationErrors,permittedEventCRFIds);
      System.out.println("String_Node_Str" + totalValidationErrors.size());
      displayItemBeanWrappers.addAll(tempDisplayItemBeanWrappers);
    }
 catch (    NullPointerException npe1) {
      npe1.printStackTrace();
      fail=true;
      System.out.println("String_Node_Str");
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      System.out.println("String_Node_Str" + npe1.getMessage());
    }
catch (    OpenClinicaException oce1) {
      fail=true;
      System.out.println("String_Node_Str" + oce1.getOpenClinicaMessage());
      msg.append(oce1.getOpenClinicaMessage() + "String_Node_Str");
      System.out.println("String_Node_Str" + oce1.getOpenClinicaMessage());
    }
  }
 else {
    msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    return getFailReturnList(msg.toString(),auditMsg.toString());
  }
  boolean discNotesGenerated=false;
  if (fail) {
    return getFailReturnList(msg.toString(),auditMsg.toString());
  }
 else {
    msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    System.out.println("String_Node_Str" + totalValidationErrors.size());
    SummaryStatsBean ssBean=getImportCRFDataService(dataSource).generateSummaryStatsBean(odmContainer,displayItemBeanWrappers);
    msg=new StringBuffer("String_Node_Str");
    auditMsg=new StringBuffer("String_Node_Str");
    msg.append(triggerService.generateSummaryStatsMessage(ssBean,respage,totalValidationErrors));
    ArrayList<SubjectDataBean> subjectData=odmContainer.getCrfDataPostImportContainer().getSubjectData();
    if (!hardValidationErrors.isEmpty()) {
      msg.append(triggerService.generateHardValidationErrorMessage(subjectData,hardValidationErrors,false));
    }
 else {
      if (!totalValidationErrors.isEmpty()) {
        msg.append(triggerService.generateHardValidationErrorMessage(subjectData,totalValidationErrors,false));
      }
      msg.append(triggerService.generateValidMessage(subjectData,totalValidationErrors));
    }
    CrfBusinessLogicHelper crfBusinessLogicHelper=new CrfBusinessLogicHelper(dataSource);
    for (    DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
      int eventCrfBeanId=-1;
      EventCRFBean eventCrfBean=new EventCRFBean();
      if (wrapper.isSavable()) {
        ArrayList<Integer> eventCrfInts=new ArrayList<Integer>();
        for (        DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
          eventCrfBeanId=displayItemBean.getData().getEventCRFId();
          eventCrfBean=(EventCRFBean)eventCrfDao.findByPK(eventCrfBeanId);
          ItemDataBean itemDataBean=new ItemDataBean();
          itemDataBean=itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(),eventCrfBean.getId(),displayItemBean.getData().getOrdinal());
          if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
            itemDataBean.setUpdatedDate(new Date());
            itemDataBean.setUpdater(userBean);
            itemDataBean.setValue(displayItemBean.getData().getValue());
            itemDataDao.update(itemDataBean);
            displayItemBean.getData().setId(itemDataBean.getId());
          }
 else {
            itemDataDao.create(displayItemBean.getData());
            System.out.println("String_Node_Str" + displayItemBean.getData().getItemId());
            ItemDataBean itemDataBean2=itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(),eventCrfBean.getId(),displayItemBean.getData().getOrdinal());
            displayItemBean.getData().setId(itemDataBean2.getId());
          }
          ItemDAO idao=new ItemDAO(dataSource);
          ItemBean ibean=(ItemBean)idao.findByPK(displayItemBean.getData().getItemId());
          String itemOid=displayItemBean.getItem().getOid() + "String_Node_Str" + wrapper.getStudyEventRepeatKey()+ "String_Node_Str"+ displayItemBean.getData().getOrdinal()+ "String_Node_Str"+ wrapper.getStudySubjectOid();
          if (wrapper.getValidationErrors().containsKey(itemOid)) {
            ArrayList messageList=(ArrayList)wrapper.getValidationErrors().get(itemOid);
            for (int iter=0; iter < messageList.size(); iter++) {
              String message=(String)messageList.get(iter);
              DiscrepancyNoteBean parentDn=createDiscrepancyNote(ibean,message,eventCrfBean,displayItemBean,null,userBean,dataSource,studyBean);
              createDiscrepancyNote(ibean,message,eventCrfBean,displayItemBean,parentDn.getId(),userBean,dataSource,studyBean);
              discNotesGenerated=true;
              System.out.println("String_Node_Str" + message);
              auditMsg.append(wrapper.getStudySubjectOid() + "String_Node_Str" + ibean.getOid()+ "String_Node_Str"+ message+ "String_Node_Str");
            }
          }
          if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
            crfBusinessLogicHelper.markCRFComplete(eventCrfBean,userBean);
            eventCrfInts.add(new Integer(eventCrfBean.getId()));
          }
        }
      }
    }
  }
  if (!discNotesGenerated) {
    return getSuccessReturnList(msg.toString(),auditMsg.toString());
  }
 else {
    return getWarningReturnList(msg.toString(),auditMsg.toString());
  }
}

Fixed version (ground truth):
public ArrayList<String> importProcessedData(DataSource dataSource,CoreResources resources,StudyBean studyBean,UserAccountBean userBean,ODMContainer odmContainer,StringBuffer msg,StringBuffer auditMsg,boolean checkEventCrf,StudyEventBean studyEventBean) throws Exception {
  List<String> errors=new ArrayList<String>();
  TriggerService triggerService=new TriggerService();
  locale=new Locale("String_Node_Str");
  ResourceBundleProvider.updateLocale(locale);
  respage=ResourceBundleProvider.getPageMessagesBundle();
  ItemDataDAO itemDataDao=new ItemDataDAO(dataSource);
  EventCRFDAO eventCrfDao=new EventCRFDAO(dataSource);
  boolean fail=false;
  try {
    System.out.println("String_Node_Str" + studyBean.getId());
    errors=getImportCRFDataService(dataSource).validateStudyMetadata(odmContainer,studyBean.getId());
  }
 catch (  Exception eee) {
    System.out.println("String_Node_Str" + eee.getMessage());
  }
  if (errors != null) {
    System.out.println(errors.toString());
    for (    String error : errors) {
      msg.append(error + "String_Node_Str");
    }
    if (errors.size() > 0) {
      return getFailReturnList(msg.toString(),auditMsg.toString());
    }
 else {
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
  }
  List<EventCRFBean> eventCRFBeans=getImportCRFDataService(dataSource).fetchEventCRFBeans(odmContainer,userBean,studyEventBean);
  ArrayList<Integer> permittedEventCRFIds=new ArrayList<Integer>();
  System.out.println("String_Node_Str" + eventCRFBeans.toString());
  List<DisplayItemBeanWrapper> displayItemBeanWrappers=new ArrayList<DisplayItemBeanWrapper>();
  HashMap<String,String> totalValidationErrors=new HashMap<String,String>();
  HashMap<String,String> hardValidationErrors=new HashMap<String,String>();
  if (!eventCRFBeans.isEmpty()) {
    for (    EventCRFBean eventCRFBean : eventCRFBeans) {
      DataEntryStage dataEntryStage=eventCRFBean.getStage();
      Status eventCRFStatus=eventCRFBean.getStatus();
      System.out.println("String_Node_Str" + eventCRFBean.getId() + "String_Node_Str"+ dataEntryStage.getName()+ "String_Node_Str"+ eventCRFStatus.getName());
      if (eventCRFStatus.equals(Status.AVAILABLE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE)|| dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)|| dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        permittedEventCRFIds.add(new Integer(eventCRFBean.getId()));
      }
 else {
        MessageFormat mf=new MessageFormat("String_Node_Str");
        mf.applyPattern(respage.getString("String_Node_Str"));
        Object[] arguments={"String_Node_Str"};
        msg.append(mf.format(arguments) + "String_Node_Str");
        auditMsg.append(mf.format(arguments) + "String_Node_Str");
        continue;
      }
    }
    if (eventCRFBeans.size() >= permittedEventCRFIds.size()) {
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
 else {
      fail=true;
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    }
    MockHttpServletRequest request=new MockHttpServletRequest();
    request.addPreferredLocale(locale);
    try {
      List<DisplayItemBeanWrapper> tempDisplayItemBeanWrappers=new ArrayList<DisplayItemBeanWrapper>();
      tempDisplayItemBeanWrappers=getImportCRFDataService(dataSource).lookupValidationErrors(request,odmContainer,userBean,totalValidationErrors,hardValidationErrors,permittedEventCRFIds,studyEventBean);
      System.out.println("String_Node_Str" + totalValidationErrors.size());
      displayItemBeanWrappers.addAll(tempDisplayItemBeanWrappers);
    }
 catch (    NullPointerException npe1) {
      npe1.printStackTrace();
      fail=true;
      System.out.println("String_Node_Str");
      msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
      System.out.println("String_Node_Str" + npe1.getMessage());
    }
catch (    OpenClinicaException oce1) {
      fail=true;
      System.out.println("String_Node_Str" + oce1.getOpenClinicaMessage());
      msg.append(oce1.getOpenClinicaMessage() + "String_Node_Str");
      System.out.println("String_Node_Str" + oce1.getOpenClinicaMessage());
    }
  }
 else {
    msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    return getFailReturnList(msg.toString(),auditMsg.toString());
  }
  boolean discNotesGenerated=false;
  if (fail) {
    return getFailReturnList(msg.toString(),auditMsg.toString());
  }
 else {
    msg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    auditMsg.append(respage.getString("String_Node_Str") + "String_Node_Str");
    System.out.println("String_Node_Str" + totalValidationErrors.size());
    SummaryStatsBean ssBean=getImportCRFDataService(dataSource).generateSummaryStatsBean(odmContainer,displayItemBeanWrappers);
    msg=new StringBuffer("String_Node_Str");
    auditMsg=new StringBuffer("String_Node_Str");
    msg.append(triggerService.generateSummaryStatsMessage(ssBean,respage,totalValidationErrors));
    ArrayList<SubjectDataBean> subjectData=odmContainer.getCrfDataPostImportContainer().getSubjectData();
    if (!hardValidationErrors.isEmpty()) {
      msg.append(triggerService.generateHardValidationErrorMessage(subjectData,hardValidationErrors,false));
    }
 else {
      if (!totalValidationErrors.isEmpty()) {
        msg.append(triggerService.generateHardValidationErrorMessage(subjectData,totalValidationErrors,false));
      }
      msg.append(triggerService.generateValidMessage(subjectData,totalValidationErrors));
    }
    CrfBusinessLogicHelper crfBusinessLogicHelper=new CrfBusinessLogicHelper(dataSource);
    for (    DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
      int eventCrfBeanId=-1;
      EventCRFBean eventCrfBean=new EventCRFBean();
      if (wrapper.isSavable()) {
        ArrayList<Integer> eventCrfInts=new ArrayList<Integer>();
        for (        DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
          eventCrfBeanId=displayItemBean.getData().getEventCRFId();
          eventCrfBean=(EventCRFBean)eventCrfDao.findByPK(eventCrfBeanId);
          ItemDataBean itemDataBean=new ItemDataBean();
          itemDataBean=itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(),eventCrfBean.getId(),displayItemBean.getData().getOrdinal());
          if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
            itemDataBean.setUpdatedDate(new Date());
            itemDataBean.setUpdater(userBean);
            itemDataBean.setValue(displayItemBean.getData().getValue());
            itemDataDao.update(itemDataBean);
            displayItemBean.getData().setId(itemDataBean.getId());
          }
 else {
            itemDataDao.create(displayItemBean.getData());
            System.out.println("String_Node_Str" + displayItemBean.getData().getItemId());
            ItemDataBean itemDataBean2=itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(),eventCrfBean.getId(),displayItemBean.getData().getOrdinal());
            displayItemBean.getData().setId(itemDataBean2.getId());
          }
          ItemDAO idao=new ItemDAO(dataSource);
          ItemBean ibean=(ItemBean)idao.findByPK(displayItemBean.getData().getItemId());
          String itemOid=displayItemBean.getItem().getOid() + "String_Node_Str" + wrapper.getStudyEventRepeatKey()+ "String_Node_Str"+ displayItemBean.getData().getOrdinal()+ "String_Node_Str"+ wrapper.getStudySubjectOid();
          if (wrapper.getValidationErrors().containsKey(itemOid)) {
            ArrayList messageList=(ArrayList)wrapper.getValidationErrors().get(itemOid);
            for (int iter=0; iter < messageList.size(); iter++) {
              String message=(String)messageList.get(iter);
              DiscrepancyNoteBean parentDn=createDiscrepancyNote(ibean,message,eventCrfBean,displayItemBean,null,userBean,dataSource,studyBean);
              createDiscrepancyNote(ibean,message,eventCrfBean,displayItemBean,parentDn.getId(),userBean,dataSource,studyBean);
              discNotesGenerated=true;
              System.out.println("String_Node_Str" + message);
              auditMsg.append(wrapper.getStudySubjectOid() + "String_Node_Str" + ibean.getOid()+ "String_Node_Str"+ message+ "String_Node_Str");
            }
          }
          if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
            crfBusinessLogicHelper.markCRFComplete(eventCrfBean,userBean);
            eventCrfInts.add(new Integer(eventCrfBean.getId()));
          }
        }
      }
    }
  }
  if (!discNotesGenerated) {
    return getSuccessReturnList(msg.toString(),auditMsg.toString());
  }
 else {
    return getWarningReturnList(msg.toString(),auditMsg.toString());
  }
}