com.alogient.cameleon.sdk.form.util.FormModelToVoConverter Maven / Gradle / Ivy
The newest version!
package com.alogient.cameleon.sdk.form.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.alogient.cameleon.sdk.common.dao.model.Culture;
import com.alogient.cameleon.sdk.form.dao.model.Form;
import com.alogient.cameleon.sdk.form.dao.model.FormCulture;
import com.alogient.cameleon.sdk.form.dao.model.FormElement;
import com.alogient.cameleon.sdk.form.dao.model.FormPage;
import com.alogient.cameleon.sdk.form.dao.model.FormPageCulture;
import com.alogient.cameleon.sdk.form.dao.model.formelement.CheckboxFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.DateFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.DateRangeFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.NumberFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.RadioFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.RatingFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.SelectFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.TextAreaFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.TextBlockFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.TextFEModel;
import com.alogient.cameleon.sdk.form.dao.model.formelement.UploadFEModel;
import com.alogient.cameleon.sdk.form.vo.FormCssVo;
import com.alogient.cameleon.sdk.form.vo.FormEmailVo;
import com.alogient.cameleon.sdk.form.vo.FormStepVo;
import com.alogient.cameleon.sdk.form.vo.FormVo;
import com.alogient.cameleon.sdk.form.vo.FormVo.LabelPosition;
import com.alogient.cameleon.sdk.form.vo.formelement.AbstractElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.CheckboxGroupElementsVo;
import com.alogient.cameleon.sdk.form.vo.formelement.DateElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.DateRangeElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.NumberElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.RadioGroupElementsVo;
import com.alogient.cameleon.sdk.form.vo.formelement.RatingElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.SelectGroupElementsVo;
import com.alogient.cameleon.sdk.form.vo.formelement.TextAreaElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.TextBlockElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.TextElementVo;
import com.alogient.cameleon.sdk.form.vo.formelement.UploadElementVo;
public final class FormModelToVoConverter {
/**
* An utility class should not hava a visible ctor. This private one is used to hide the default public ctor.
*/
private FormModelToVoConverter() {
}
/**
* Used internally to convert a Form model into a form value object
*
* @param srcForm The source data from the DAO
* @param culture The culture to convert into
* @param isLiveMode The mode to convert into
* @return The converted value object
*/
public static FormVo convertToFormVo(Form srcForm, Culture culture, Boolean isLiveMode) {
FormVo formVo = new FormVo();
// Copy the data from the model to the value object
formVo.setId(srcForm.getFormId());
formVo.setFormName(srcForm.getName());
formVo.setShowSummary(srcForm.getShowSummary());
formVo.setRedirectUrl(srcForm.getReturnUrl());
formVo.setKickback(srcForm.getKickback());
if (srcForm.getFormCulture() != null) {
for (FormCulture srcFormCulture : srcForm.getFormCulture()) {
if (culture.equals(srcFormCulture.getCulture())) {
formVo.setCompletedText(isLiveMode ? srcFormCulture.getCompletedTextLive() : srcFormCulture.getCompletedText());
break;
}
}
}
formVo.setLabelPosition(LabelPosition.valueOfDisplayType(srcForm.getDisplayType()));
formVo.setFormEmailVo(convertToFormEmailVo(srcForm, culture, isLiveMode));
formVo.setFormCssVo(convertToFormCssVo(srcForm));
// Process child elements
if (srcForm.getFormPages() != null && srcForm.getFormPages().size() != 0) {
List formSteps = new ArrayList();
for (FormPage srcFormPage : srcForm.getFormPages()) {
if (!srcFormPage.getIsDeleted()) {
formSteps.add(convertToFormStepVo(srcFormPage, culture, isLiveMode));
}
}
formVo.setStepElements(formSteps);
}
return formVo;
}
/**
* Used internally to convert a Form model into a form value object
*
* @param srcForm The source data from the DAO
* @param culture The culture to convert into
* @param isLiveMode The mode to convert into
* @return The converted value object
*/
private static FormEmailVo convertToFormEmailVo(Form srcForm, Culture culture, Boolean isLiveMode) {
FormEmailVo formEmailVo = new FormEmailVo();
formEmailVo.setConfirmEmailAddress(srcForm.getConfirmEmail());
formEmailVo.setFromEmailAddress(srcForm.getEmailFrom());
formEmailVo.setToEmailFormElementId(srcForm.getKickback());
if (srcForm.getFormCulture() != null) {
for (FormCulture srcFormCulture : srcForm.getFormCulture()) {
if (culture.equals(srcFormCulture.getCulture())) {
formEmailVo.setEmailSubject(isLiveMode ? srcFormCulture.getEmailSubjectLive() : srcFormCulture.getEmailSubject());
break;
}
}
}
return formEmailVo;
}
/**
* Used internally to convert a Form model into a form value object
*
* @param srcForm The source data from the DAO
* @return The converted value object
*/
private static FormCssVo convertToFormCssVo(Form srcForm) {
FormCssVo formCssVo = new FormCssVo();
formCssVo.setDivCss(srcForm.getCss());
formCssVo.setNavigationItemCss(srcForm.getPageCss());
formCssVo.setSelectedNavigationItemCss(srcForm.getSelectedPageCss());
return formCssVo;
}
/**
* Used internally to convert a Form model into a form value object
*
* @param srcFormPage The source data from the DAO
* @param culture The culture to convert into
* @param isLiveMode The mode to convert into
* @return The converted value object
*/
private static FormStepVo convertToFormStepVo(FormPage srcFormPage, Culture culture, Boolean isLiveMode) {
FormStepVo formStepVo = new FormStepVo();
formStepVo.setId(srcFormPage.getFormPageId());
if (srcFormPage.getFormPageCultures() != null) {
for (FormPageCulture srcFormPageCulture : srcFormPage.getFormPageCultures()) {
if (culture.equals(srcFormPageCulture.getCulture())) {
formStepVo.setName(isLiveMode ? srcFormPageCulture.getNameLive() : srcFormPageCulture.getNamePreview());
formStepVo.setIsVisible(isLiveMode ? srcFormPageCulture.getVisibleLive() : srcFormPageCulture.getVisiblePreview());
break;
}
}
}
// Process child elements
if (srcFormPage.getFormElements() != null && srcFormPage.getFormElements().size() != 0) {
List> elements = new ArrayList>();
for (FormElement srcElement : srcFormPage.getFormElements()) {
if (!srcElement.getIsDeleted()) {
elements.add(convertToElementVo(srcElement, culture, isLiveMode));
}
}
formStepVo.setElements(elements);
}
return formStepVo;
}
/**
* Used internally to convert a Form model into a form value object
*
* @param srcElement The source data from the DAO
* @param culture The culture to convert into
* @param isLiveMode The mode to convert into
* @return The converted value object
*/
private static AbstractElementVo extends Serializable> convertToElementVo(FormElement srcElement, Culture culture, Boolean isLiveMode) {
if (srcElement instanceof CheckboxFEModel) {
return new CheckboxGroupElementsVo((CheckboxFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof DateFEModel) {
return new DateElementVo((DateFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof DateRangeFEModel) {
return new DateRangeElementVo((DateRangeFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof NumberFEModel) {
return new NumberElementVo((NumberFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof RadioFEModel) {
return new RadioGroupElementsVo((RadioFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof RatingFEModel) {
return new RatingElementVo((RatingFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof SelectFEModel) {
return new SelectGroupElementsVo((SelectFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof TextAreaFEModel) {
return new TextAreaElementVo((TextAreaFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof TextBlockFEModel) {
return new TextBlockElementVo((TextBlockFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof TextFEModel) {
return new TextElementVo((TextFEModel) srcElement, culture, isLiveMode);
} else if (srcElement instanceof UploadFEModel) {
return new UploadElementVo((UploadFEModel) srcElement, culture, isLiveMode);
} else {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy