Hi there,
Could you please help with 6.5 code in sling model for below WCMUsePojo ?
package com.fpt.asr.commons.components.models;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
import org.apache.sling.api.resource.ValueMap;
import com.adobe.cq.sightly.WCMUsePojo;
import com.fpt.asr.commons.beans.FaqListBean;
import com.fpt.asr.commons.beans.MemberBenefitFAQBean;
import com.fpt.asr.commons.constants.PropertiesConstants;
import com.fpt.asr.commons.utils.JsonUtils;
import com.fpt.asr.commons.utils.MultifieldUtils;
import lombok.Getter;
import lombok.Setter;
@Setter
@getter
public class MemberBenefitFAQModel extends WCMUsePojo {
private String title;
private String[] itemFAQ;
private String item;
private List<Integer> ids;
private List<MemberBenefitFAQBean> memberBenefitFAQBeans;
@Override
public void activate() throws Exception {
ArrayList<Integer> ids = new ArrayList<>();
String path = get("path", String.class);
ValueMap properties = getProperties();
setTitle(properties.get(PropertiesConstants.Component.TITLE, String.class));
String[] itemFAQ = properties.get(PropertiesConstants.Component.ITEM_FAQ, String[].class);
this.setMemberBenefitFAQBeans(JsonUtils.parseAsList(JsonUtils.convertJson(itemFAQ), MemberBenefitFAQBean.class));
List<String> strings = new ArrayList<>();
for (MemberBenefitFAQBean faq : this.getMemberBenefitFAQBeans()) {
List<FaqListBean> faqList = faq.getFaqList();
if (faqList != null) {
for (FaqListBean faqListBean : faqList) {
if (faqListBean.getQuestionId() == 0) {
faqListBean.setQuestionId(MultifieldUtils.randomIdMultifield());
}
ids.add(faqListBean.getQuestionId());
}
}
strings.add(JsonUtils.stringify(faq));
}
this.setItem(JsonUtils.stringify(this.memberBenefitFAQBeans));
this.setIds(ids);
String[] memberBenefitFAQBean = new String[strings.size()];
strings.toArray(memberBenefitFAQBean);
Node rootNode = getRequest().getResourceResolver().resolve(getRequest(), path).adaptTo(Node.class);
if (!this.memberBenefitFAQBeans.isEmpty()) {
MultifieldUtils.convertData(rootNode, "itemFAQ", memberBenefitFAQBean,
JsonUtils.stringify(this.memberBenefitFAQBeans.get(0)));
}
MultifieldUtils.deleteGarbage(ids, rootNode, "faq-{0}");
}
}