Message Boards

When server is down and server is on again, datas disappear!

Seonjune Moon, modified 2 Years ago.

When server is down and server is on again, datas disappear!

New Member Post: 1 Join Date: 1/3/22 Recent Posts

 

i'm on 7.2.

i've been making board with configurationPid function of liferay, but it's not working what i think.

here's the thing

I set up three types of board to use preferences function of liferay.

From divCd information of preferences releated with board portlet keys, i can search boards specific datas.

But the problem is that when i shut down the server, datas diappear only for notice board! (divCd - 1 : NOTICE , divCd - 2 : FAQ, divCd -3 : QNA)

This phenomenon only happend to board table. 

I didn't notice there's problem in my code because in dev server (local server) i've never seen this before.

This only happen in published server. When published server's down, datas of notice board disappear! (not happend to other table yet. :) )

if you know any reasons why board data deleted, Please somebody help me. 

Minor helps can alse be helpful for me! 

 

BoardConfig

package com.osp.board.web.board.config;

import com.liferay.portal.configuration.metatype.annotations.ExtendedObjectClassDefinition;
import com.osp.board.constants.OSPBoardWebPortletKeys;

import aQute.bnd.annotation.metatype.Meta;

@ExtendedObjectClassDefinition(
	category = "board",
	scope = ExtendedObjectClassDefinition.Scope.SYSTEM
)
@Meta.OCD(
		id = OSPBoardWebPortletKeys.BOARD_CONFIG_PORTLET_KEY
		)
public interface BoardConfig {
}

 

BoardConfigHandler

package com.osp.board.web.board.config;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.osp.board.constants.ConstantsPagePath;
import com.osp.board.constants.OSPBoardWebPortletKeys;
import com.osp.board.model.Board;
import com.osp.board.model.BoardDiv;
import com.osp.board.service.BoardDivLocalServiceUtil;
import com.osp.board.service.BoardLocalServiceUtil;
import com.osp.constants.MessageConstants;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;


@Component(
		configurationPid = OSPBoardWebPortletKeys.BOARD_CONFIG_PORTLET_KEY,
		immediate = true,
		service = ConfigurationAction.class,
		property = {
				"javax.portlet.name=" + OSPBoardWebPortletKeys.BOARD_PORTLET_KEY
			}
		)
public class BoardConfigHandler extends DefaultConfigurationAction{
	
	private static final Log _log = LogFactoryUtil.getLog(BoardConfigHandler.class);
	/**
	 * 
	* Method : getJspPath </br>
	* Method Explain : </br>
	*
	* @param httpServletRequest
	* @return String : configuration jsp path (by ConstantsPagePath).
	*
	 */
	@Override
	public String getJspPath(HttpServletRequest httpServletRequest) {
		ThemeDisplay themeDisplay = (ThemeDisplay) httpServletRequest.getAttribute(WebKeys.THEME_DISPLAY);
		long plid = themeDisplay.getPlid();
		String portletKey = OSPBoardWebPortletKeys.BOARD_PORTLET_KEY;
		httpServletRequest.setAttribute("plid", plid);
		httpServletRequest.setAttribute("portletKey", portletKey);

		Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getScopeGroupId());// language
		httpServletRequest.setAttribute("locales", locales);
		
		List<BoardDiv> boardDivs = BoardDivLocalServiceUtil.getBoardDivs();
		
		List<Map<String, Object>> boardDivMaps = new ArrayList<Map<String,Object>>();
		
		// Model to Map for localized title.
		for(int i = 0 ; i < boardDivs.size() ; i++) {
			BoardDiv boardDiv = boardDivs.get(i);
			Map<String, Object> boardDivMap = new HashMap<String, Object>();
			
			boardDivMap.put("divCd", boardDiv.getDivCd());
			for(Locale locale : locales) {
				boardDivMap.put("title_"+LanguageUtil.getLanguageId(locale), boardDiv.getTitle(locale));
			}
			boardDivMap.put("content", boardDiv.getContent());
			boardDivMap.put("divName", boardDiv.getDivName());
			boardDivMap.put("fileUploadUseYn", boardDiv.getFileUpLoadUseYn());
			boardDivMap.put("popupYn", boardDiv.getPopupYn());
			boardDivMap.put("replyYn", boardDiv.getReplyYn());
			
			boardDivMaps.add(boardDivMap);
		}
		
		httpServletRequest.setAttribute("boardDivs", boardDivMaps);
		return ConstantsPagePath.OSP_BOARD_CONFIGURATION;
	}
	
	@Override
	public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException{
		try {
			ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
			String target = ParamUtil.getString(actionRequest, "target", ""); // target entity name
			
			User user = themeDisplay.getUser();
			
			if(target.equals("boardDiv")) {// boardDiv information update.
				long[] idxes = ParamUtil.getLongValues(actionRequest, "idx");
				long[] divCds = ParamUtil.getLongValues(actionRequest, "divCd");
				
				List<BoardDiv> boardDivsForAdd = new ArrayList<BoardDiv>();
				List<BoardDiv> boardDivsForUpdate = new ArrayList<BoardDiv>();
				for(int i = 0 ; i < idxes.length ; i++) {// sort and make BoardDiv.
					/*
						boardDiv parameters :
								title_ko_KR,
								title_en_US,
								content,
								divName,
								fileUploadUseYn,
								popupYn,
								replyYn
					*/
//					long divCd = ParamUtil.getLong(actionRequest, "divCd_"+idxes[i], 0);
					long divCd = divCds[i];
					if(divCd == 0) { //add boardDiv if there is no primary key.
						
						// boardDiv information set.
						BoardDiv boardDiv = BoardDivLocalServiceUtil.createBoardDiv(idxes[i]);
						Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getScopeGroupId());
						for(Locale locale : locales) {
							boardDiv.setTitle(ParamUtil.getString(actionRequest, "title_"+LanguageUtil.getLanguageId(locale)+"_" + idxes[i]), locale);
						}
						boardDiv.setContent(ParamUtil.getString(actionRequest, "content_" + idxes[i]));
						boardDiv.setDivName(ParamUtil.getString(actionRequest, "divName_" + idxes[i]));
						boardDiv.setFileUpLoadUseYn(ParamUtil.getBoolean(actionRequest, "fileUploadUseYn_" + idxes[i]));
						boardDiv.setPopupYn(ParamUtil.getBoolean(actionRequest, "popupYn_" + idxes[i]));
						boardDiv.setReplyYn(ParamUtil.getBoolean(actionRequest, "replyYn_" + idxes[i]));
						
						// etc information set.
						boardDiv.setCompanyId(themeDisplay.getCompanyId());
						boardDiv.setUserId(user.getUserId());
						boardDiv.setUserName(user.getScreenName());
						boardDiv.setCreateDate(new Date());
						boardDiv.setGroupId(themeDisplay.getScopeGroupId());
						
						boardDivsForAdd.add(boardDiv);
					}else {// update boardDiv if there is primary key.
						BoardDiv originBoardDiv = BoardDivLocalServiceUtil.getBoardDiv(divCd);
						Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getScopeGroupId());
						for(Locale locale : locales) {
							originBoardDiv.setTitle(ParamUtil.getString(actionRequest, "title_"+LanguageUtil.getLanguageId(locale)+"_" + idxes[i]), locale);
						}
						originBoardDiv.setContent(ParamUtil.getString(actionRequest, "content_" + idxes[i]));
						originBoardDiv.setDivName(ParamUtil.getString(actionRequest, "divName_" + idxes[i]));
						originBoardDiv.setFileUpLoadUseYn(ParamUtil.getBoolean(actionRequest, "fileUploadUseYn_" + idxes[i]));
						originBoardDiv.setPopupYn(ParamUtil.getBoolean(actionRequest, "popupYn_" + idxes[i]));
						originBoardDiv.setReplyYn(ParamUtil.getBoolean(actionRequest, "replyYn_" + idxes[i]));
						originBoardDiv.setCompanyId(themeDisplay.getCompanyId());
						originBoardDiv.setUserId(user.getUserId());
						originBoardDiv.setUserName(user.getScreenName());
						originBoardDiv.setModifiedDate(new Date());
						originBoardDiv.setGroupId(themeDisplay.getScopeGroupId());
						boardDivsForUpdate.add(originBoardDiv);
					}
				}// end of sorting and making BoardDiv.
				BoardDivLocalServiceUtil.addAndUpdateBoardDivs(boardDivsForAdd, boardDivsForUpdate);
				
			}else if(target.equals("boardRemove")){
				long targetedDivCd = Long.parseLong(ParamUtil.getString(actionRequest, "targetedDivCd", "0")); 
				int boardCount = BoardLocalServiceUtil.getBoardDivBoardsCount(targetedDivCd);
				if(boardCount == 0) {
					BoardDivLocalServiceUtil.deleteBoardDiv(targetedDivCd);
				} else {
					_log.error("##### board is already used. cnt : "  +boardCount );
					SessionErrors.add(actionRequest, MessageConstants.UPDATE_ERROR);
				}
			}else {
				_log.error("##### unexpected target : " + target);
			}
			super.processAction(portletConfig, actionRequest, actionResponse);
		} catch (Exception e) {
			e.printStackTrace();
			SessionErrors.add(actionRequest, MessageConstants.UPDATE_ERROR);
			_log.error("##### Exception("+e+") is occured.");
		}
	}
}