/*
* Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package org.entando.entando.apsadmin.tags;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
import org.entando.entando.aps.system.services.actionlog.IActionLogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.agiletec.aps.system.SystemConstants;
import com.agiletec.aps.system.services.user.UserDetails;
import com.agiletec.aps.util.ApsWebApplicationUtils;
import com.opensymphony.xwork2.util.ValueStack;
/**
* @author S.Loru
*/
public class ActivityStreamLastUpdateTag extends StrutsBodyTagSupport {
private static final Logger _logger = LoggerFactory.getLogger(ActivityStreamLastUpdateTag.class);
@Override
public int doEndTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
try {
IActionLogManager loggerManager = (IActionLogManager) ApsWebApplicationUtils.getBean(SystemConstants.ACTION_LOGGER_MANAGER, this.pageContext);
UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
Date lastUpdate = loggerManager.lastUpdateDate(currentUser);
if (null != this.getVar()) {
ValueStack stack = this.getStack();
stack.getContext().put(this.getVar(), lastUpdate);
stack.setValue("#attr['" + this.getVar() + "']", lastUpdate, false);
}
} catch (Throwable t) {
_logger.error("Error on doStartTag", t);
throw new JspException("Error on doStartTag", t);
}
return super.doEndTag();
}
public String getVar() {
return _var;
}
public void setVar(String var) {
this._var = var;
}
private String _var;
}