use of org.mifos.platform.questionnaire.service.SectionLinkDetail 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();
}
}
}
}
use of org.mifos.platform.questionnaire.service.SectionLinkDetail in project head by mifos.
the class QuestionGroupController method defineQuestionGroup.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode) {
String result = "success";
if (!questionGroupHasErrors(questionGroupForm, requestContext)) {
QuestionGroupDetail questionGroupDetail = null;
try {
if (createMode) {
questionGroupForm.setActive(true);
}
if (questionGroupForm.isActive()) {
questionGroupDetail = questionnaireServiceFacade.createActiveQuestionGroup(questionGroupForm.getQuestionGroupDetail());
} else {
questionGroupDetail = questionnaireServiceFacade.createQuestionGroup(questionGroupForm.getQuestionGroupDetail());
}
if (containsCreateLoanEventSource(questionGroupForm.getEventSources()) && questionGroupForm.getApplyToAllLoanProducts()) {
questionnaireServiceFacade.applyToAllLoanProducts(questionGroupDetail.getId());
}
List<QuestionLinkDetail> questionLinkDetails = setFilledQuestionDetailForQuestionLinks(questionGroupForm.getQuestionLinks(), questionGroupDetail);
List<SectionLinkDetail> sectionLinkDetails = setFilledSectionDetailForQuestionLinks(questionGroupForm.getSectionLinks(), questionGroupDetail);
questionnaireServiceFacade.createQuestionLinks(questionLinkDetails);
questionnaireServiceFacade.createSectionLinks(sectionLinkDetails);
} catch (AccessDeniedException e) {
constructAndLogSystemError(requestContext.getMessageContext(), new SystemException(QuestionnaireConstants.MISSING_PERMISSION_TO_ACTIVATE_QG, e));
result = "failure";
} catch (SystemException e) {
constructAndLogSystemError(requestContext.getMessageContext(), e);
result = "failure";
}
} else {
result = "failure";
}
return result;
}
Aggregations