EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
HomePageMaintActionForm form = (HomePageMaintActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
initSiteProfiles(form, site);
HomePage homePage = HomePageDAO.load(Format.getLong(form.getHomePageId()));
Content content = ContentDAO.load(site.getSiteId(), Format.getLong(form.getContentId()));
int seqNum = -1;
boolean exist = false;
boolean hasFeature = false;
for (HomePageDetail homePageDetail : homePage.getHomePageDetails()) {
if (homePageDetail.getSeqNum() > seqNum) {
seqNum = homePageDetail.getSeqNum();
}
if (homePageDetail.getFeatureData() == Constants.VALUE_YES) {
hasFeature = true;
}
Content currentContent = homePageDetail.getContent();
if (currentContent == null) {
continue;
}
if (currentContent.getContentId().equals(content.getContentId())) {
exist = true;
break;
}
}
if (!exist) {
HomePageDetail homePageDetail = new HomePageDetail();
homePageDetail.setRecUpdateBy(adminBean.getUser().getUserId());
homePageDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
homePageDetail.setRecCreateBy(adminBean.getUser().getUserId());
homePageDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
homePageDetail.setContent(content);
homePageDetail.setSeqNum(seqNum + 1);
homePageDetail.setFeatureData(hasFeature ? Constants.ACTIVE_NO : Constants.VALUE_YES);
homePage.getHomePageDetails().add(homePageDetail);
em.persist(homePageDetail);
}
JSONEscapeObject JSONEscapeObject = new JSONEscapeObject();
JSONEscapeObject.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);