use of org.mifos.platform.questionnaire.service.QuestionLinkDetail in project head by mifos.
the class QuestionnaireServiceImpl method createQuestionLinks.
public void createQuestionLinks(List<QuestionLinkDetail> questionLinks) {
for (QuestionLinkDetail questionLinkDetail : questionLinks) {
QuestionGroupLink questionGroupLink = questionnaireMapper.mapToQuestionGroupLink(questionLinkDetail, null);
questionGroupLinkDao.saveOrUpdate(questionGroupLink);
SectionQuestionLink sectionQuestionLink = questionnaireMapper.mapToQuestionLink(questionLinkDetail, questionGroupLink);
sectionQuestionLinkDao.saveOrUpdate(sectionQuestionLink);
}
}
use of org.mifos.platform.questionnaire.service.QuestionLinkDetail in project head by mifos.
the class QuestionnaireMapperImpl method mapToQuestionLinkDetails.
public List<QuestionLinkDetail> mapToQuestionLinkDetails(List<SectionQuestionLink> sectionQuestionLinks) {
List<QuestionLinkDetail> questionLinkDetails = new ArrayList<QuestionLinkDetail>();
for (SectionQuestionLink sectionQuestionLink : sectionQuestionLinks) {
QuestionLinkDetail questionLinkDetail = new QuestionLinkDetail();
questionLinkDetail.setValue(sectionQuestionLink.getQuestionGroupLink().getValue());
questionLinkDetail.setAdditionalValue(sectionQuestionLink.getQuestionGroupLink().getAdditionalValue());
questionLinkDetail.setLinkType(sectionQuestionLink.getQuestionGroupLink().getConditionTypeId());
questionLinkDetail.setProperLinkTypeDisplay(sectionQuestionLink.getQuestionGroupLink().getConditionType());
questionLinkDetail.setLinkId(sectionQuestionLink.getId());
questionLinkDetail.setQuestionGroupLinkId(sectionQuestionLink.getQuestionGroupLink().getId());
questionLinkDetail.setState(true);
SectionQuestion sectionQuestion = sectionQuestionLink.getQuestionGroupLink().getSourceSectionQuestion();
questionLinkDetail.setSourceQuestion(mapToSectionQuestionDetail(sectionQuestion, sectionQuestion.isRequired(), sectionQuestion.isShowOnPage(), (mapToQuestionDetail(sectionQuestion.getQuestion(), mapToQuestionType(sectionQuestion.getQuestion().getAnswerTypeAsEnum())))));
sectionQuestion = sectionQuestionLink.getAffectedSectionQuestion();
questionLinkDetail.setAffectedQuestion(mapToSectionQuestionDetail(sectionQuestion, sectionQuestion.isRequired(), sectionQuestion.isShowOnPage(), (mapToQuestionDetail(sectionQuestion.getQuestion(), mapToQuestionType(sectionQuestion.getQuestion().getAnswerTypeAsEnum())))));
questionLinkDetails.add(questionLinkDetail);
}
return questionLinkDetails;
}
use of org.mifos.platform.questionnaire.service.QuestionLinkDetail in project head by mifos.
the class QuestionGroupController method setFilledQuestionDetailForQuestionLinks.
public List<QuestionLinkDetail> setFilledQuestionDetailForQuestionLinks(List<QuestionLinkDetail> questionLinkDetails, QuestionGroupDetail questionGroupDetail) {
for (QuestionLinkDetail questionLinkDetail : questionLinkDetails) {
questionLinkDetail.setSourceQuestion(findQuestionDetailByNickname(questionGroupDetail, String.valueOf(questionLinkDetail.getSourceQuestion().getQuestionDetail().getNickname())));
questionLinkDetail.setAffectedQuestion(findQuestionDetailByNickname(questionGroupDetail, String.valueOf(questionLinkDetail.getAffectedQuestion().getQuestionDetail().getNickname())));
}
return questionLinkDetails;
}
use of org.mifos.platform.questionnaire.service.QuestionLinkDetail in project head by mifos.
the class QuestionGroupController method addLink.
public String addLink(QuestionGroupForm questionGroupForm, String sourceQuestionId, String linkType, String appliesTo, String affectedQuestionId, String affectedSectionName, String value, String additionalValue, Map<String, String> linkTypes, RequestContext requestContext) {
String result = "success";
if (!questionGroupLinkHasErrors(questionGroupForm, requestContext, sourceQuestionId, linkType, appliesTo, affectedQuestionId, affectedSectionName, value, additionalValue)) {
if (appliesTo.equals("question")) {
QuestionLinkDetail questionLink = setQuestionLinkDetail(questionGroupForm, sourceQuestionId, affectedQuestionId, value, additionalValue, linkType, linkTypes.get(linkType));
questionGroupForm.getQuestionLinks().add(questionLink);
} else {
SectionLinkDetail sectionLink = setSectionLinkDetail(questionGroupForm, sourceQuestionId, affectedSectionName, value, additionalValue, linkType, linkTypes.get(linkType));
questionGroupForm.getSectionLinks().add(sectionLink);
}
} else {
result = "failure";
}
return result;
}
use of org.mifos.platform.questionnaire.service.QuestionLinkDetail in project head by mifos.
the class QuestionGroupForm method removeSection.
public void removeSection(String sectionName) {
SectionDetail sectionToDelete = null;
for (Iterator<SectionDetailForm> iterator = sections.iterator(); iterator.hasNext(); ) {
SectionDetailForm section = iterator.next();
if (StringUtils.equalsIgnoreCase(sectionName, section.getName())) {
sectionToDelete = section.getSectionDetail();
iterator.remove();
break;
}
}
if (sectionToDelete != null) {
List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
int sequence = 0;
for (SectionDetailForm sectionDetailForm : sections) {
SectionDetail sectionDetail = sectionDetailForm.getSectionDetail();
sectionDetail.setSequenceNumber(sequence++);
sectionDetails.add(sectionDetail);
}
markQuestionsOptionalAndReturnToPool(sectionToDelete);
questionGroupDetail.setSectionDetails(sectionDetails);
for (int i = 0; i < sectionsToAdd.size(); i++) {
String name = sectionsToAdd.get(i);
if (name.equals(sectionName)) {
sectionsToAdd.remove(i);
break;
}
}
for (Iterator<SectionLinkDetail> iterator = sectionLinks.iterator(); iterator.hasNext(); ) {
SectionLinkDetail sectionLinkDetail = iterator.next();
if (sectionLinkDetail.getAffectedSection().getName().equals(sectionToDelete.getName()))
iterator.remove();
for (SectionQuestionDetail sectionQuestionDetail : sectionToDelete.getQuestionDetails()) {
if (sectionLinkDetail.getSourceQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionDetail().getId()))
iterator.remove();
}
}
for (SectionQuestionDetail sectionQuestionDetail : sectionToDelete.getQuestionDetails()) {
for (Iterator<QuestionLinkDetail> iterator = questionLinks.iterator(); iterator.hasNext(); ) {
QuestionLinkDetail questionLinkDetail = iterator.next();
if (questionLinkDetail.getSourceQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionId()))
iterator.remove();
if (questionLinkDetail.getAffectedQuestion().getQuestionDetail().getId().equals(sectionQuestionDetail.getQuestionId()))
iterator.remove();
}
}
}
}
Aggregations