Program: 115151
Project: 115151
Buggy source:
@Override protected void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList types=DiscrepancyNoteType.toArrayList();
  request.setAttribute(DIS_TYPES,types);
  request.setAttribute(RES_STATUSES,ResolutionStatus.toArrayList());
  boolean writeToDB=fp.getBoolean(WRITE_TO_DB,true);
  boolean isReasonForChange=fp.getBoolean(IS_REASON_FOR_CHANGE);
  int entityId=fp.getInt(ENTITY_ID);
  int subjectId=fp.getInt(SUBJECT_ID);
  int itemId=fp.getInt(ITEM_ID);
  String entityType=fp.getString(ENTITY_TYPE);
  String field=fp.getString(ENTITY_FIELD);
  String column=fp.getString(ENTITY_COLUMN);
  int parentId=fp.getInt(PARENT_ID);
  boolean isInError=fp.getBoolean(ERROR_FLAG);
  boolean isNew=fp.getBoolean(NEW_NOTE);
  request.setAttribute(NEW_NOTE,isNew ? "String_Node_Str" : "String_Node_Str");
  String strResStatus=fp.getString(PRESET_RES_STATUS);
  if (!strResStatus.equals("String_Node_Str")) {
    request.setAttribute(PRESET_RES_STATUS,strResStatus);
  }
  String monitor=fp.getString("String_Node_Str");
  String enterData=fp.getString("String_Node_Str");
  request.setAttribute("String_Node_Str",enterData);
  boolean enteringData=false;
  if (enterData != null && "String_Node_Str".equalsIgnoreCase(enterData)) {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
    request.setAttribute("String_Node_Str",monitor);
    enteringData=true;
  }
 else   if ("String_Node_Str".equalsIgnoreCase(monitor)) {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
    request.setAttribute("String_Node_Str",monitor);
  }
 else {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
  }
  if ("String_Node_Str".equalsIgnoreCase(entityType) && enteringData) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
  DateFormat dateFormatter=DateFormat.getDateInstance(DateFormat.DEFAULT,locale);
  int preUserId=0;
  if (!StringUtil.isBlank(entityType)) {
    if ("String_Node_Str".equalsIgnoreCase(entityType) || "String_Node_Str".equalsIgnoreCase(entityType)) {
      ItemBean item=(ItemBean)new ItemDAO(sm.getDataSource()).findByPK(itemId);
      ItemDataBean itemData=(ItemDataBean)new ItemDataDAO(sm.getDataSource()).findByPK(entityId);
      request.setAttribute("String_Node_Str",itemData.getValue());
      request.setAttribute("String_Node_Str",item.getName());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      EventCRFBean ec=(EventCRFBean)ecdao.findByPK(itemData.getEventCRFId());
      preUserId=ec.getOwnerId();
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      StudySubjectBean ssub=(StudySubjectBean)new StudySubjectDAO(sm.getDataSource()).findByPK(entityId);
      SubjectBean sub=(SubjectBean)new SubjectDAO(sm.getDataSource()).findByPK(ssub.getSubjectId());
      preUserId=ssub.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (ssub.getEnrollmentDate() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(ssub.getEnrollmentDate()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getGender() + "String_Node_Str");
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getDateOfBirth() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(sub.getDateOfBirth()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getUniqueIdentifier() != null) {
            request.setAttribute("String_Node_Str",sub.getUniqueIdentifier());
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      SubjectBean sub=(SubjectBean)new SubjectDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=sub.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getGender() + "String_Node_Str");
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getDateOfBirth() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(sub.getDateOfBirth()));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getUniqueIdentifier());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      StudyEventBean se=(StudyEventBean)new StudyEventDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=se.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",(se.getLocation().equals("String_Node_Str") || se.getLocation() == null) ? resword.getString("String_Node_Str") : se.getLocation());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (se.getDateStarted() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(se.getDateStarted()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (se.getDateEnded() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(se.getDateEnded()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      EventCRFBean ec=(EventCRFBean)new EventCRFDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=ec.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equals(column)) {
          if (ec.getDateInterviewed() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(ec.getDateInterviewed()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equals(column)) {
          request.setAttribute("String_Node_Str",ec.getInterviewerName());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
  }
  ArrayList notes=(ArrayList)dndao.findAllByEntityAndColumn(entityType,entityId,column);
  DiscrepancyNoteBean parent=new DiscrepancyNoteBean();
  if (parentId > 0) {
    dndao.setFetchMapping(true);
    parent=(DiscrepancyNoteBean)dndao.findByPK(parentId);
    if (parent.isActive()) {
      request.setAttribute("String_Node_Str",parent);
    }
    dndao.setFetchMapping(false);
  }
  FormDiscrepancyNotes newNotes=(FormDiscrepancyNotes)session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
  if (newNotes == null) {
    newNotes=new FormDiscrepancyNotes();
  }
  if (!notes.isEmpty() || !newNotes.getNotes(field).isEmpty()) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
 else {
    request.setAttribute("String_Node_Str","String_Node_Str");
    logger.info("String_Node_Str" + "String_Node_Str");
  }
  if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
    ArrayList<ResolutionStatus> resStatuses=new ArrayList<ResolutionStatus>();
    resStatuses.add(ResolutionStatus.OPEN);
    resStatuses.add(ResolutionStatus.RESOLVED);
    request.setAttribute(RES_STATUSES,resStatuses);
    ArrayList types2=DiscrepancyNoteType.toArrayList();
    types2.remove(DiscrepancyNoteType.QUERY);
    request.setAttribute(DIS_TYPES,types2);
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
  }
 else   if (currentRole.getRole().equals(Role.MONITOR)) {
    ArrayList<ResolutionStatus> resStatuses=new ArrayList();
    resStatuses.add(ResolutionStatus.OPEN);
    resStatuses.add(ResolutionStatus.UPDATED);
    resStatuses.add(ResolutionStatus.CLOSED);
    request.setAttribute(RES_STATUSES,resStatuses);
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
    ArrayList<DiscrepancyNoteType> types2=new ArrayList<DiscrepancyNoteType>();
    types2.add(DiscrepancyNoteType.QUERY);
    request.setAttribute(DIS_TYPES,types2);
  }
 else {
    ArrayList<ResolutionStatus> resStatuses=ResolutionStatus.toArrayList();
    resStatuses.remove(ResolutionStatus.NOT_APPLICABLE);
    request.setAttribute(RES_STATUSES,resStatuses);
    ;
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
  }
  if (!fp.isSubmitted()) {
    DiscrepancyNoteBean dnb=new DiscrepancyNoteBean();
    if (subjectId > 0) {
      StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssub=(StudySubjectBean)ssdao.findByPK(subjectId);
      dnb.setSubjectName(ssub.getName());
      dnb.setSubjectId(ssub.getId());
      dnb.setStudySub(ssub);
    }
    if (itemId > 0) {
      ItemBean item=(ItemBean)new ItemDAO(sm.getDataSource()).findByPK(itemId);
      dnb.setEntityName(item.getName());
      request.setAttribute("String_Node_Str",item);
    }
    dnb.setEntityType(entityType);
    dnb.setColumn(column);
    dnb.setEntityId(entityId);
    dnb.setField(field);
    dnb.setParentDnId(parent.getId());
    dnb.setCreatedDate(new Date());
    if (parent.getId() == 0 || isNew) {
      if (enteringData) {
        if (isInError) {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
        }
 else {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.ANNOTATION.getId());
          dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
        }
        if (isReasonForChange) {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.REASON_FOR_CHANGE.getId());
          dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
        }
        request.setAttribute("String_Node_Str","String_Node_Str");
      }
 else {
        dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.QUERY.getId());
        if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          request.setAttribute("String_Node_Str","String_Node_Str");
          dnb.setAssignedUserId(preUserId);
        }
      }
    }
 else     if (parent.getDiscrepancyNoteTypeId() > 0) {
      dnb.setDiscrepancyNoteTypeId(parent.getDiscrepancyNoteTypeId());
      if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) && currentStudy.getId() != currentStudy.getParentStudyId()) {
        dnb.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
        request.setAttribute("String_Node_Str","String_Node_Str");
      }
 else {
        dnb.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
      }
    }
    dnb.setOwnerId(parent.getOwnerId());
    String detailedDes=fp.getString("String_Node_Str");
    if (detailedDes != null) {
      dnb.setDetailedNotes(detailedDes);
      System.out.println("String_Node_Str" + fp.getString("String_Node_Str"));
    }
    dnb=getNoteInfo(dnb);
    request.setAttribute(DIS_NOTE,dnb);
    request.setAttribute("String_Node_Str","String_Node_Str");
    request.setAttribute(WRITE_TO_DB,writeToDB ? "String_Node_Str" : "String_Node_Str");
    ArrayList userAccounts=this.generateUserAccounts(ub.getActiveStudyId(),subjectId);
    request.setAttribute(USER_ACCOUNTS,userAccounts);
    if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) && currentStudy.getId() != currentStudy.getParentStudyId()) {
      request.setAttribute(USER_ACCOUNT_ID,new Integer(parent.getOwnerId()).toString());
      System.out.println("String_Node_Str" + parent.getOwnerId());
    }
 else     if (dnb.getEventCRFId() > 0) {
      System.out.println("String_Node_Str" + dnb.getEventCRFId());
      EventCRFDAO eventCrfDAO=new EventCRFDAO(sm.getDataSource());
      EventCRFBean eventCrfBean=new EventCRFBean();
      eventCrfBean=(EventCRFBean)eventCrfDAO.findByPK(dnb.getEventCRFId());
      request.setAttribute(USER_ACCOUNT_ID,new Integer(eventCrfBean.getOwnerId()).toString());
      System.out.println("String_Node_Str" + eventCrfBean.getOwnerId());
    }
 else {
    }
    forwardPage(Page.ADD_DISCREPANCY_NOTE);
  }
 else {
    System.out.println("String_Node_Str");
    FormDiscrepancyNotes noteTree=(FormDiscrepancyNotes)session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
    if (noteTree == null) {
      noteTree=new FormDiscrepancyNotes();
      logger.info("String_Node_Str");
    }
    Validator v=new Validator(request);
    String description=fp.getString("String_Node_Str");
    int typeId=fp.getInt("String_Node_Str");
    int assignedUserAccountId=fp.getInt(SUBMITTED_USER_ACCOUNT_ID);
    int resStatusId=fp.getInt(RES_STATUS_ID);
    String detailedDes=fp.getString("String_Node_Str");
    int sectionId=fp.getInt("String_Node_Str");
    String groupLabel=fp.getString("String_Node_Str");
    DiscrepancyNoteBean note=new DiscrepancyNoteBean();
    v.addValidation("String_Node_Str",Validator.NO_BLANKS);
    v.addValidation("String_Node_Str",Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,255);
    v.addValidation("String_Node_Str",Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,1000);
    v.addValidation("String_Node_Str",Validator.NO_BLANKS);
    HashMap errors=v.validate();
    note.setDescription(description);
    note.setDetailedNotes(detailedDes);
    note.setOwner(ub);
    note.setOwnerId(ub.getId());
    note.setCreatedDate(new Date());
    note.setResolutionStatusId(resStatusId);
    note.setDiscrepancyNoteTypeId(typeId);
    note.setParentDnId(parent.getId());
    if (typeId != DiscrepancyNoteType.ANNOTATION.getId() && typeId != DiscrepancyNoteType.FAILEDVAL.getId() && typeId != DiscrepancyNoteType.REASON_FOR_CHANGE.getId()) {
      if (assignedUserAccountId > 0) {
        note.setAssignedUserId(assignedUserAccountId);
        System.out.println("String_Node_Str" + assignedUserAccountId);
      }
 else {
        note.setAssignedUserId(parent.getOwnerId());
        System.out.println("String_Node_Str" + parent.getOwnerId() + "String_Node_Str"+ assignedUserAccountId);
      }
    }
    note.setField(field);
    if (DiscrepancyNoteType.ANNOTATION.getId() == note.getDiscrepancyNoteTypeId()) {
      updateStudyEvent(entityType,entityId);
      updateStudySubjectStatus(entityType,entityId);
    }
    if (DiscrepancyNoteType.ANNOTATION.getId() == note.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.REASON_FOR_CHANGE.getId() == note.getDiscrepancyNoteTypeId()) {
      note.setResStatus(ResolutionStatus.NOT_APPLICABLE);
      note.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
    }
    if (DiscrepancyNoteType.FAILEDVAL.getId() == note.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.QUERY.getId() == note.getDiscrepancyNoteTypeId()) {
      if (ResolutionStatus.NOT_APPLICABLE.getId() == note.getResolutionStatusId()) {
        Validator.addError(errors,RES_STATUS_ID,restext.getString("String_Node_Str"));
      }
    }
    if (!parent.isActive()) {
      note.setEntityId(entityId);
      note.setEntityType(entityType);
      note.setColumn(column);
    }
 else {
      note.setEntityId(parent.getEntityId());
      note.setEntityType(parent.getEntityType());
      if (!StringUtil.isBlank(parent.getColumn())) {
        note.setColumn(parent.getColumn());
      }
 else {
        note.setColumn(column);
      }
      note.setParentDnId(parent.getId());
    }
    note.setStudyId(currentStudy.getId());
    note=getNoteInfo(note);
    request.setAttribute(DIS_NOTE,note);
    request.setAttribute(WRITE_TO_DB,writeToDB ? "String_Node_Str" : "String_Node_Str");
    ArrayList userAccounts=this.generateUserAccounts(ub.getActiveStudyId(),subjectId);
    request.setAttribute(USER_ACCOUNT_ID,new Integer(note.getAssignedUserId()).toString());
    Role r=currentRole.getRole();
    if (r.equals(Role.MONITOR) || r.equals(Role.INVESTIGATOR) || r.equals(Role.RESEARCHASSISTANT)|| r.equals(Role.COORDINATOR)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
      System.out.println("String_Node_Str");
    }
 else {
      request.setAttribute("String_Node_Str","String_Node_Str");
      System.out.println("String_Node_Str");
    }
    request.setAttribute(USER_ACCOUNTS,userAccounts);
    if (errors.isEmpty()) {
      if (!writeToDB) {
        System.out.println("String_Node_Str" + field);
        noteTree.addNote(field,note);
        noteTree.addIdNote(note.getEntityId(),field);
        session.setAttribute(FORM_DISCREPANCY_NOTES_NAME,noteTree);
        System.out.println("String_Node_Str");
        manageReasonForChangeState(session,entityId);
        forwardPage(Page.ADD_DISCREPANCY_NOTE_DONE);
      }
 else {
        int pdnId=note != null ? note.getParentDnId() : 0;
        if (pdnId > 0) {
          System.out.println("String_Node_Str" + note.getEntityId());
          DiscrepancyNoteBean pNote=(DiscrepancyNoteBean)dndao.findByPK(pdnId);
          System.out.println("String_Node_Str" + pNote.getOwnerId());
          note.setOwnerId(pNote.getOwnerId());
          if (note.getDiscrepancyNoteTypeId() == pNote.getDiscrepancyNoteTypeId()) {
            if (note.getResolutionStatusId() != pNote.getResolutionStatusId()) {
              pNote.setResolutionStatusId(note.getResolutionStatusId());
              dndao.update(pNote);
            }
            if (note.getAssignedUserId() != pNote.getAssignedUserId()) {
              pNote.setAssignedUserId(note.getAssignedUserId());
              if (pNote.getAssignedUserId() > 0) {
                dndao.updateAssignedUser(pNote);
              }
 else {
                dndao.updateAssignedUserToNull(pNote);
              }
            }
          }
        }
        note=(DiscrepancyNoteBean)dndao.create(note);
        dndao.createMapping(note);
        request.setAttribute(DIS_NOTE,note);
        if (note.getParentDnId() == 0) {
          note.setParentDnId(note.getId());
          note=(DiscrepancyNoteBean)dndao.create(note);
          dndao.createMapping(note);
        }
        manageReasonForChangeState(session,entityId);
        System.out.println("String_Node_Str" + note.getResolutionStatusId());
        String email=fp.getString(EMAIL_USER_ACCOUNT);
        System.out.println("String_Node_Str" + email);
        if (note.getAssignedUserId() > 0 && "String_Node_Str".equals(email.trim()) && DiscrepancyNoteType.QUERY.getId() == note.getDiscrepancyNoteTypeId()) {
          System.out.println("String_Node_Str" + note.getDiscrepancyNoteTypeId() + "String_Node_Str"+ note.getDisType().getName());
          logger.info("String_Node_Str");
          StringBuffer message=new StringBuffer();
          EmailEngine em=new EmailEngine(EmailEngine.getSMTPHost());
          UserAccountDAO userAccountDAO=new UserAccountDAO(sm.getDataSource());
          ItemDAO itemDAO=new ItemDAO(sm.getDataSource());
          ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
          ItemBean item=new ItemBean();
          ItemDataBean itemData=new ItemDataBean();
          SectionBean section=new SectionBean();
          StudyDAO studyDAO=new StudyDAO(sm.getDataSource());
          UserAccountBean assignedUser=(UserAccountBean)userAccountDAO.findByPK(note.getAssignedUserId());
          String alertEmail=assignedUser.getEmail();
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),assignedUser.getFirstName(),assignedUser.getLastName()));
          message.append("String_Node_Str" + SQLInitServlet.getField("String_Node_Str") + "String_Node_Str"+ assignedUser.getName()+ "String_Node_Str"+ note.getEntityName()+ "String_Node_Str"+ SQLInitServlet.getField("String_Node_Str")+ "String_Node_Str");
          message.append(respage.getString("String_Node_Str"));
          StudyBean study=(StudyBean)studyDAO.findByPK(note.getStudyId());
          SectionDAO sectionDAO=new SectionDAO(sm.getDataSource());
          if ("String_Node_Str".equalsIgnoreCase(entityType)) {
            itemData=(ItemDataBean)iddao.findByPK(note.getEntityId());
            item=(ItemBean)itemDAO.findByPK(itemData.getItemId());
            if (sectionId > 0) {
              section=(SectionBean)sectionDAO.findByPK(sectionId);
            }
 else {
            }
          }
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getDescription(),note.getDetailedNotes(),ub.getName()));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),study.getName(),note.getSubjectName()));
          if (!("String_Node_Str".equalsIgnoreCase(entityType) || "String_Node_Str".equalsIgnoreCase(entityType))) {
            message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getEventName()));
            if (!"String_Node_Str".equalsIgnoreCase(note.getEntityType())) {
              message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getCrfName()));
              if (!"String_Node_Str".equalsIgnoreCase(note.getEntityType())) {
                if (sectionId > 0) {
                  message.append(MessageFormat.format(respage.getString("String_Node_Str"),section.getName()));
                }
                message.append(MessageFormat.format(respage.getString("String_Node_Str"),item.getName()));
              }
            }
          }
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),study.getName()));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          String emailBodyString=message.toString();
          sendEmail(alertEmail.trim(),EmailEngine.getAdminEmail(),MessageFormat.format(respage.getString("String_Node_Str"),study.getName(),note.getEntityName()),emailBodyString,true,null,null,true);
        }
 else {
          System.out.println("String_Node_Str");
        }
        addPageMessage(respage.getString("String_Node_Str"));
        addPageMessage(respage.getString("String_Node_Str"));
        System.out.println("String_Node_Str");
        forwardPage(Page.ADD_DISCREPANCY_NOTE_SAVE_DONE);
      }
    }
 else {
      if (parentId > 0) {
        if (note.getResolutionStatusId() == ResolutionStatus.NOT_APPLICABLE.getId()) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
      }
 else {
        if (note.getDiscrepancyNoteTypeId() == DiscrepancyNoteType.QUERY.getId()) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
      }
      setInputMessages(errors);
      forwardPage(Page.ADD_DISCREPANCY_NOTE);
    }
  }
}

Fixed version (ground truth):
@Override protected void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList types=DiscrepancyNoteType.toArrayList();
  request.setAttribute(DIS_TYPES,types);
  request.setAttribute(RES_STATUSES,ResolutionStatus.toArrayList());
  boolean writeToDB=fp.getBoolean(WRITE_TO_DB,true);
  boolean isReasonForChange=fp.getBoolean(IS_REASON_FOR_CHANGE);
  int entityId=fp.getInt(ENTITY_ID);
  int subjectId=fp.getInt(SUBJECT_ID);
  int itemId=fp.getInt(ITEM_ID);
  String entityType=fp.getString(ENTITY_TYPE);
  String field=fp.getString(ENTITY_FIELD);
  String column=fp.getString(ENTITY_COLUMN);
  int parentId=fp.getInt(PARENT_ID);
  boolean isInError=fp.getBoolean(ERROR_FLAG);
  boolean isNew=fp.getBoolean(NEW_NOTE);
  request.setAttribute(NEW_NOTE,isNew ? "String_Node_Str" : "String_Node_Str");
  String strResStatus=fp.getString(PRESET_RES_STATUS);
  if (!strResStatus.equals("String_Node_Str")) {
    request.setAttribute(PRESET_RES_STATUS,strResStatus);
  }
  String monitor=fp.getString("String_Node_Str");
  String enterData=fp.getString("String_Node_Str");
  request.setAttribute("String_Node_Str",enterData);
  boolean enteringData=false;
  if (enterData != null && "String_Node_Str".equalsIgnoreCase(enterData)) {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
    request.setAttribute("String_Node_Str",monitor);
    enteringData=true;
  }
 else   if ("String_Node_Str".equalsIgnoreCase(monitor)) {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
    request.setAttribute("String_Node_Str",monitor);
  }
 else {
    request.setAttribute(CAN_MONITOR,"String_Node_Str");
  }
  if ("String_Node_Str".equalsIgnoreCase(entityType) && enteringData) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
  DateFormat dateFormatter=DateFormat.getDateInstance(DateFormat.DEFAULT,locale);
  int preUserId=0;
  if (!StringUtil.isBlank(entityType)) {
    if ("String_Node_Str".equalsIgnoreCase(entityType) || "String_Node_Str".equalsIgnoreCase(entityType)) {
      ItemBean item=(ItemBean)new ItemDAO(sm.getDataSource()).findByPK(itemId);
      ItemDataBean itemData=(ItemDataBean)new ItemDataDAO(sm.getDataSource()).findByPK(entityId);
      request.setAttribute("String_Node_Str",itemData.getValue());
      request.setAttribute("String_Node_Str",item.getName());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      EventCRFBean ec=(EventCRFBean)ecdao.findByPK(itemData.getEventCRFId());
      preUserId=ec.getOwnerId();
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      StudySubjectBean ssub=(StudySubjectBean)new StudySubjectDAO(sm.getDataSource()).findByPK(entityId);
      SubjectBean sub=(SubjectBean)new SubjectDAO(sm.getDataSource()).findByPK(ssub.getSubjectId());
      preUserId=ssub.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (ssub.getEnrollmentDate() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(ssub.getEnrollmentDate()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getGender() + "String_Node_Str");
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getDateOfBirth() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(sub.getDateOfBirth()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getUniqueIdentifier() != null) {
            request.setAttribute("String_Node_Str",sub.getUniqueIdentifier());
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      SubjectBean sub=(SubjectBean)new SubjectDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=sub.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getGender() + "String_Node_Str");
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (sub.getDateOfBirth() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(sub.getDateOfBirth()));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",sub.getUniqueIdentifier());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      StudyEventBean se=(StudyEventBean)new StudyEventDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=se.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equalsIgnoreCase(column)) {
          request.setAttribute("String_Node_Str",(se.getLocation().equals("String_Node_Str") || se.getLocation() == null) ? resword.getString("String_Node_Str") : se.getLocation());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (se.getDateStarted() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(se.getDateStarted()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equalsIgnoreCase(column)) {
          if (se.getDateEnded() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(se.getDateEnded()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
 else     if ("String_Node_Str".equalsIgnoreCase(entityType)) {
      EventCRFBean ec=(EventCRFBean)new EventCRFDAO(sm.getDataSource()).findByPK(entityId);
      preUserId=ec.getOwnerId();
      if (!StringUtil.isBlank(column)) {
        if ("String_Node_Str".equals(column)) {
          if (ec.getDateInterviewed() != null) {
            request.setAttribute("String_Node_Str",dateFormatter.format(ec.getDateInterviewed()));
          }
 else {
            request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
          }
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
 else         if ("String_Node_Str".equals(column)) {
          request.setAttribute("String_Node_Str",ec.getInterviewerName());
          request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
        }
      }
    }
  }
  ArrayList notes=(ArrayList)dndao.findAllByEntityAndColumn(entityType,entityId,column);
  DiscrepancyNoteBean parent=new DiscrepancyNoteBean();
  if (parentId > 0) {
    dndao.setFetchMapping(true);
    parent=(DiscrepancyNoteBean)dndao.findByPK(parentId);
    if (parent.isActive()) {
      request.setAttribute("String_Node_Str",parent);
    }
    dndao.setFetchMapping(false);
  }
  FormDiscrepancyNotes newNotes=(FormDiscrepancyNotes)session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
  if (newNotes == null) {
    newNotes=new FormDiscrepancyNotes();
  }
  if (!notes.isEmpty() || !newNotes.getNotes(field).isEmpty()) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
 else {
    request.setAttribute("String_Node_Str","String_Node_Str");
    logger.info("String_Node_Str" + "String_Node_Str");
  }
  if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
    ArrayList<ResolutionStatus> resStatuses=new ArrayList<ResolutionStatus>();
    resStatuses.add(ResolutionStatus.OPEN);
    resStatuses.add(ResolutionStatus.RESOLVED);
    request.setAttribute(RES_STATUSES,resStatuses);
    ArrayList types2=DiscrepancyNoteType.toArrayList();
    types2.remove(DiscrepancyNoteType.QUERY);
    request.setAttribute(DIS_TYPES,types2);
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
  }
 else   if (currentRole.getRole().equals(Role.MONITOR)) {
    ArrayList<ResolutionStatus> resStatuses=new ArrayList();
    resStatuses.add(ResolutionStatus.OPEN);
    resStatuses.add(ResolutionStatus.UPDATED);
    resStatuses.add(ResolutionStatus.CLOSED);
    request.setAttribute(RES_STATUSES,resStatuses);
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
    ArrayList<DiscrepancyNoteType> types2=new ArrayList<DiscrepancyNoteType>();
    types2.add(DiscrepancyNoteType.QUERY);
    request.setAttribute(DIS_TYPES,types2);
  }
 else {
    ArrayList<ResolutionStatus> resStatuses=ResolutionStatus.toArrayList();
    resStatuses.remove(ResolutionStatus.NOT_APPLICABLE);
    request.setAttribute(RES_STATUSES,resStatuses);
    ;
    request.setAttribute(WHICH_RES_STATUSES,"String_Node_Str");
  }
  if (!fp.isSubmitted()) {
    DiscrepancyNoteBean dnb=new DiscrepancyNoteBean();
    if (subjectId > 0) {
      StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssub=(StudySubjectBean)ssdao.findByPK(subjectId);
      dnb.setSubjectName(ssub.getName());
      dnb.setSubjectId(ssub.getId());
      dnb.setStudySub(ssub);
    }
    if (itemId > 0) {
      ItemBean item=(ItemBean)new ItemDAO(sm.getDataSource()).findByPK(itemId);
      dnb.setEntityName(item.getName());
      request.setAttribute("String_Node_Str",item);
    }
    dnb.setEntityType(entityType);
    dnb.setColumn(column);
    dnb.setEntityId(entityId);
    dnb.setField(field);
    dnb.setParentDnId(parent.getId());
    dnb.setCreatedDate(new Date());
    if (parent.getId() == 0 || isNew) {
      if (enteringData) {
        if (isInError) {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
        }
 else {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.ANNOTATION.getId());
          dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
        }
        if (isReasonForChange) {
          dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.REASON_FOR_CHANGE.getId());
          dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
        }
        request.setAttribute("String_Node_Str","String_Node_Str");
      }
 else {
        dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.QUERY.getId());
        if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          request.setAttribute("String_Node_Str","String_Node_Str");
          dnb.setAssignedUserId(preUserId);
        }
      }
    }
 else     if (parent.getDiscrepancyNoteTypeId() > 0) {
      dnb.setDiscrepancyNoteTypeId(parent.getDiscrepancyNoteTypeId());
      if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) && currentStudy.getId() != currentStudy.getParentStudyId()) {
        dnb.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
        request.setAttribute("String_Node_Str","String_Node_Str");
      }
 else {
        dnb.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
      }
    }
    dnb.setOwnerId(parent.getOwnerId());
    String detailedDes=fp.getString("String_Node_Str");
    if (detailedDes != null) {
      dnb.setDetailedNotes(detailedDes);
      System.out.println("String_Node_Str" + fp.getString("String_Node_Str"));
    }
    dnb=getNoteInfo(dnb);
    if (dnb.getEventName() == null || dnb.getEventName().equals("String_Node_Str")) {
      dnb.setEventName(fp.getString("String_Node_Str"));
    }
    if (dnb.getEventStart() == null) {
      dnb.setEventStart(fp.getDate("String_Node_Str"));
    }
    if (dnb.getCrfName() == null || dnb.getCrfName().equals("String_Node_Str")) {
      dnb.setCrfName(fp.getString("String_Node_Str"));
    }
    request.setAttribute(DIS_NOTE,dnb);
    request.setAttribute("String_Node_Str","String_Node_Str");
    request.setAttribute(WRITE_TO_DB,writeToDB ? "String_Node_Str" : "String_Node_Str");
    ArrayList userAccounts=this.generateUserAccounts(ub.getActiveStudyId(),subjectId);
    request.setAttribute(USER_ACCOUNTS,userAccounts);
    if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) && currentStudy.getId() != currentStudy.getParentStudyId()) {
      request.setAttribute(USER_ACCOUNT_ID,new Integer(parent.getOwnerId()).toString());
      System.out.println("String_Node_Str" + parent.getOwnerId());
    }
 else     if (dnb.getEventCRFId() > 0) {
      System.out.println("String_Node_Str" + dnb.getEventCRFId());
      EventCRFDAO eventCrfDAO=new EventCRFDAO(sm.getDataSource());
      EventCRFBean eventCrfBean=new EventCRFBean();
      eventCrfBean=(EventCRFBean)eventCrfDAO.findByPK(dnb.getEventCRFId());
      request.setAttribute(USER_ACCOUNT_ID,new Integer(eventCrfBean.getOwnerId()).toString());
      System.out.println("String_Node_Str" + eventCrfBean.getOwnerId());
    }
 else {
    }
    forwardPage(Page.ADD_DISCREPANCY_NOTE);
  }
 else {
    System.out.println("String_Node_Str");
    FormDiscrepancyNotes noteTree=(FormDiscrepancyNotes)session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
    if (noteTree == null) {
      noteTree=new FormDiscrepancyNotes();
      logger.info("String_Node_Str");
    }
    Validator v=new Validator(request);
    String description=fp.getString("String_Node_Str");
    int typeId=fp.getInt("String_Node_Str");
    int assignedUserAccountId=fp.getInt(SUBMITTED_USER_ACCOUNT_ID);
    int resStatusId=fp.getInt(RES_STATUS_ID);
    String detailedDes=fp.getString("String_Node_Str");
    int sectionId=fp.getInt("String_Node_Str");
    String groupLabel=fp.getString("String_Node_Str");
    DiscrepancyNoteBean note=new DiscrepancyNoteBean();
    v.addValidation("String_Node_Str",Validator.NO_BLANKS);
    v.addValidation("String_Node_Str",Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,255);
    v.addValidation("String_Node_Str",Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,1000);
    v.addValidation("String_Node_Str",Validator.NO_BLANKS);
    HashMap errors=v.validate();
    note.setDescription(description);
    note.setDetailedNotes(detailedDes);
    note.setOwner(ub);
    note.setOwnerId(ub.getId());
    note.setCreatedDate(new Date());
    note.setResolutionStatusId(resStatusId);
    note.setDiscrepancyNoteTypeId(typeId);
    note.setParentDnId(parent.getId());
    if (typeId != DiscrepancyNoteType.ANNOTATION.getId() && typeId != DiscrepancyNoteType.FAILEDVAL.getId() && typeId != DiscrepancyNoteType.REASON_FOR_CHANGE.getId()) {
      if (assignedUserAccountId > 0) {
        note.setAssignedUserId(assignedUserAccountId);
        System.out.println("String_Node_Str" + assignedUserAccountId);
      }
 else {
        note.setAssignedUserId(parent.getOwnerId());
        System.out.println("String_Node_Str" + parent.getOwnerId() + "String_Node_Str"+ assignedUserAccountId);
      }
    }
    note.setField(field);
    if (DiscrepancyNoteType.ANNOTATION.getId() == note.getDiscrepancyNoteTypeId()) {
      updateStudyEvent(entityType,entityId);
      updateStudySubjectStatus(entityType,entityId);
    }
    if (DiscrepancyNoteType.ANNOTATION.getId() == note.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.REASON_FOR_CHANGE.getId() == note.getDiscrepancyNoteTypeId()) {
      note.setResStatus(ResolutionStatus.NOT_APPLICABLE);
      note.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
    }
    if (DiscrepancyNoteType.FAILEDVAL.getId() == note.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.QUERY.getId() == note.getDiscrepancyNoteTypeId()) {
      if (ResolutionStatus.NOT_APPLICABLE.getId() == note.getResolutionStatusId()) {
        Validator.addError(errors,RES_STATUS_ID,restext.getString("String_Node_Str"));
      }
    }
    if (!parent.isActive()) {
      note.setEntityId(entityId);
      note.setEntityType(entityType);
      note.setColumn(column);
    }
 else {
      note.setEntityId(parent.getEntityId());
      note.setEntityType(parent.getEntityType());
      if (!StringUtil.isBlank(parent.getColumn())) {
        note.setColumn(parent.getColumn());
      }
 else {
        note.setColumn(column);
      }
      note.setParentDnId(parent.getId());
    }
    note.setStudyId(currentStudy.getId());
    note=getNoteInfo(note);
    request.setAttribute(DIS_NOTE,note);
    request.setAttribute(WRITE_TO_DB,writeToDB ? "String_Node_Str" : "String_Node_Str");
    ArrayList userAccounts=this.generateUserAccounts(ub.getActiveStudyId(),subjectId);
    request.setAttribute(USER_ACCOUNT_ID,new Integer(note.getAssignedUserId()).toString());
    Role r=currentRole.getRole();
    if (r.equals(Role.MONITOR) || r.equals(Role.INVESTIGATOR) || r.equals(Role.RESEARCHASSISTANT)|| r.equals(Role.COORDINATOR)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
      System.out.println("String_Node_Str");
    }
 else {
      request.setAttribute("String_Node_Str","String_Node_Str");
      System.out.println("String_Node_Str");
    }
    request.setAttribute(USER_ACCOUNTS,userAccounts);
    if (errors.isEmpty()) {
      if (!writeToDB) {
        System.out.println("String_Node_Str" + field);
        noteTree.addNote(field,note);
        noteTree.addIdNote(note.getEntityId(),field);
        session.setAttribute(FORM_DISCREPANCY_NOTES_NAME,noteTree);
        System.out.println("String_Node_Str");
        manageReasonForChangeState(session,entityId);
        forwardPage(Page.ADD_DISCREPANCY_NOTE_DONE);
      }
 else {
        int pdnId=note != null ? note.getParentDnId() : 0;
        if (pdnId > 0) {
          System.out.println("String_Node_Str" + note.getEntityId());
          DiscrepancyNoteBean pNote=(DiscrepancyNoteBean)dndao.findByPK(pdnId);
          System.out.println("String_Node_Str" + pNote.getOwnerId());
          note.setOwnerId(pNote.getOwnerId());
          if (note.getDiscrepancyNoteTypeId() == pNote.getDiscrepancyNoteTypeId()) {
            if (note.getResolutionStatusId() != pNote.getResolutionStatusId()) {
              pNote.setResolutionStatusId(note.getResolutionStatusId());
              dndao.update(pNote);
            }
            if (note.getAssignedUserId() != pNote.getAssignedUserId()) {
              pNote.setAssignedUserId(note.getAssignedUserId());
              if (pNote.getAssignedUserId() > 0) {
                dndao.updateAssignedUser(pNote);
              }
 else {
                dndao.updateAssignedUserToNull(pNote);
              }
            }
          }
        }
        note=(DiscrepancyNoteBean)dndao.create(note);
        dndao.createMapping(note);
        request.setAttribute(DIS_NOTE,note);
        if (note.getParentDnId() == 0) {
          note.setParentDnId(note.getId());
          note=(DiscrepancyNoteBean)dndao.create(note);
          dndao.createMapping(note);
        }
        manageReasonForChangeState(session,entityId);
        System.out.println("String_Node_Str" + note.getResolutionStatusId());
        String email=fp.getString(EMAIL_USER_ACCOUNT);
        System.out.println("String_Node_Str" + email);
        if (note.getAssignedUserId() > 0 && "String_Node_Str".equals(email.trim()) && DiscrepancyNoteType.QUERY.getId() == note.getDiscrepancyNoteTypeId()) {
          System.out.println("String_Node_Str" + note.getDiscrepancyNoteTypeId() + "String_Node_Str"+ note.getDisType().getName());
          logger.info("String_Node_Str");
          StringBuffer message=new StringBuffer();
          EmailEngine em=new EmailEngine(EmailEngine.getSMTPHost());
          UserAccountDAO userAccountDAO=new UserAccountDAO(sm.getDataSource());
          ItemDAO itemDAO=new ItemDAO(sm.getDataSource());
          ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
          ItemBean item=new ItemBean();
          ItemDataBean itemData=new ItemDataBean();
          SectionBean section=new SectionBean();
          StudyDAO studyDAO=new StudyDAO(sm.getDataSource());
          UserAccountBean assignedUser=(UserAccountBean)userAccountDAO.findByPK(note.getAssignedUserId());
          String alertEmail=assignedUser.getEmail();
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),assignedUser.getFirstName(),assignedUser.getLastName()));
          message.append("String_Node_Str" + SQLInitServlet.getField("String_Node_Str") + "String_Node_Str"+ assignedUser.getName()+ "String_Node_Str"+ note.getEntityName()+ "String_Node_Str"+ SQLInitServlet.getField("String_Node_Str")+ "String_Node_Str");
          message.append(respage.getString("String_Node_Str"));
          StudyBean study=(StudyBean)studyDAO.findByPK(note.getStudyId());
          SectionDAO sectionDAO=new SectionDAO(sm.getDataSource());
          if ("String_Node_Str".equalsIgnoreCase(entityType)) {
            itemData=(ItemDataBean)iddao.findByPK(note.getEntityId());
            item=(ItemBean)itemDAO.findByPK(itemData.getItemId());
            if (sectionId > 0) {
              section=(SectionBean)sectionDAO.findByPK(sectionId);
            }
 else {
            }
          }
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getDescription(),note.getDetailedNotes(),ub.getName()));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),study.getName(),note.getSubjectName()));
          if (!("String_Node_Str".equalsIgnoreCase(entityType) || "String_Node_Str".equalsIgnoreCase(entityType))) {
            message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getEventName()));
            if (!"String_Node_Str".equalsIgnoreCase(note.getEntityType())) {
              message.append(MessageFormat.format(respage.getString("String_Node_Str"),note.getCrfName()));
              if (!"String_Node_Str".equalsIgnoreCase(note.getEntityType())) {
                if (sectionId > 0) {
                  message.append(MessageFormat.format(respage.getString("String_Node_Str"),section.getName()));
                }
                message.append(MessageFormat.format(respage.getString("String_Node_Str"),item.getName()));
              }
            }
          }
          message.append(respage.getString("String_Node_Str"));
          message.append(MessageFormat.format(respage.getString("String_Node_Str"),study.getName()));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          message.append(respage.getString("String_Node_Str"));
          String emailBodyString=message.toString();
          sendEmail(alertEmail.trim(),EmailEngine.getAdminEmail(),MessageFormat.format(respage.getString("String_Node_Str"),study.getName(),note.getEntityName()),emailBodyString,true,null,null,true);
        }
 else {
          System.out.println("String_Node_Str");
        }
        addPageMessage(respage.getString("String_Node_Str"));
        addPageMessage(respage.getString("String_Node_Str"));
        System.out.println("String_Node_Str");
        forwardPage(Page.ADD_DISCREPANCY_NOTE_SAVE_DONE);
      }
    }
 else {
      if (parentId > 0) {
        if (note.getResolutionStatusId() == ResolutionStatus.NOT_APPLICABLE.getId()) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
      }
 else {
        if (note.getDiscrepancyNoteTypeId() == DiscrepancyNoteType.QUERY.getId()) {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
 else {
          request.setAttribute("String_Node_Str","String_Node_Str");
        }
      }
      setInputMessages(errors);
      forwardPage(Page.ADD_DISCREPANCY_NOTE);
    }
  }
}