/// <summary> Attempts to save the answer at the specified FormIndex into the /// datamodel. /// /// </summary> /// <param name="index"> /// </param> /// <param name="data"> /// </param> /// <returns> OK if save was successful, error if a constraint was violated. /// </returns> public virtual int answerQuestion(FormIndex index, IAnswerData data) { QuestionDef q = model.getQuestionPrompt(index).Question; if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) { throw new System.SystemException("Non-Question object at the form index."); } TreeElement element = model.getTreeElement(index); bool complexQuestion = q.Complex; bool hasConstraints = false; if (element.Required && data == null) { return(ANSWER_REQUIRED_BUT_EMPTY); } else if (!complexQuestion && !model.Form.evaluateConstraint(index.Reference, data)) { return(ANSWER_CONSTRAINT_VIOLATED); } else if (!complexQuestion) { commitAnswer(element, index, data); return(ANSWER_OK); } else if (complexQuestion && hasConstraints) { //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet throw new System.SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding."); } else { try { model.Form.copyItemsetAnswer(q, element, data); } catch (InvalidReferenceException ire) { SupportClass.WriteStackTrace(ire, Console.Error); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Invalid reference while copying itemset answer: " + ire.Message); } return(ANSWER_OK); } }
/** * Attempts to save the answer at the specified FormIndex into the * datamodel. * * @param index * @param data * @return OK if save was successful, error if a constraint was violated. */ public int answerQuestion(FormIndex index, IAnswerData data) { QuestionDef q = model.getQuestionPrompt(index).getQuestion(); if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) { throw new SystemException("Non-Question object at the form index."); } TreeElement element = model.getTreeElement(index); Boolean complexQuestion = q.isComplex(); Boolean hasConstraints = false; if (element.required && data == null) { return(ANSWER_REQUIRED_BUT_EMPTY); } else if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(), data)) { return(ANSWER_CONSTRAINT_VIOLATED); } else if (!complexQuestion) { commitAnswer(element, index, data); return(ANSWER_OK); } else if (complexQuestion && hasConstraints) { //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet throw new SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding."); } else { try { model.getForm().copyItemsetAnswer(q, element, data); } catch (InvalidReferenceException ire) { Console.WriteLine(ire.StackTrace); throw new SystemException("Invalid reference while copying itemset answer: " + ire.Message); } return(ANSWER_OK); } }