public void createMainGuestbook() {
try {
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
long scopeGroupId = liferayFacesContext.getScopeGroupId();
com.liferay.docs.guestbook.model.Guestbook defaultGuestbook = (com.liferay.docs.guestbook.model.Guestbook)
GuestbookLocalServiceUtil.getFirstGuestbookByName(scopeGroupId, DEFAULT_GUESTBOOK_NAME);
// Create the default guestbook if it does not exist in the database
if (defaultGuestbook == null) {
logger.info("postConstruct: creating a default guestbook named " + DEFAULT_GUESTBOOK_NAME + " ...");
Guestbook guestbook = new Guestbook(GuestbookUtil.create(0L));
guestbook.setName(DEFAULT_GUESTBOOK_NAME);
guestbook.setGroupId(scopeGroupId);
guestbook.setCompanyId(liferayFacesContext.getCompanyId());
guestbook.setUserId(liferayFacesContext.getUserId());
GuestbookLocalServiceUtil.addGuestbook(guestbook);
}
}
catch (Exception e) {
e.printStackTrace();