Search in sources :

Example 1 with ServerContext

use of org.adempiere.webui.session.ServerContext in project adempiere by adempiere.

the class ServerContextCallback method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    ServerContext context = ServerContext.getCurrentInstance();
    //optimize for the 2 most common access
    if (method.getName().equals("getProperty")) {
        Class<?>[] types = method.getParameterTypes();
        if (types != null && types.length == 1 && types[0] == String.class && args != null && args.length == 1 && args[0] instanceof String) {
            return context.getProperty((String) args[0]);
        } else if (types != null && types.length == 2 && types[0] == String.class && types[1] == String.class && args != null && args[0] instanceof String && args[1] instanceof String)
            return context.getProperty((String) args[0], (String) args[1]);
    }
    Method m = context.getClass().getMethod(method.getName(), method.getParameterTypes());
    return m.invoke(context, args);
}
Also used : ServerContext(org.adempiere.webui.session.ServerContext) Method(java.lang.reflect.Method)

Example 2 with ServerContext

use of org.adempiere.webui.session.ServerContext in project adempiere by adempiere.

the class TimelineEventFeed method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Properties ctx = (Properties) req.getSession().getAttribute(SessionContextListener.SESSION_CTX);
    if (ctx == null) {
        return;
    }
    ServerContext serverContext = ServerContext.getCurrentInstance();
    if (serverContext == null) {
        serverContext = ServerContext.newInstance();
    }
    serverContext.clear();
    serverContext.putAll(ctx);
    int resourceId = 0;
    String resourceIdParam = req.getParameter("S_Resource_ID");
    if (resourceIdParam != null && resourceIdParam.trim().length() > 0) {
        try {
            resourceId = Integer.parseInt(resourceIdParam.trim());
        } catch (Exception e) {
            return;
        }
    } else {
        return;
    }
    String uuid = req.getParameter("uuid");
    if (uuid == null || uuid.trim().length() == 0)
        return;
    String timeLineId = req.getParameter("tlid");
    Date date = null;
    String dateParam = req.getParameter("date");
    if (dateParam != null && dateParam.trim().length() > 0) {
        try {
            date = DateFormat.getInstance().parse(dateParam);
        } catch (ParseException e) {
            return;
        }
    } else {
        return;
    }
    resp.setContentType("application/xml");
    ScheduleUtil m_model = new ScheduleUtil(Env.getCtx());
    //		Calculate Start Day
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Timestamp startDate = new Timestamp(cal.getTimeInMillis());
    //	Calculate End Date
    cal.add(Calendar.MONTH, 1);
    Timestamp endDate = new Timestamp(cal.getTimeInMillis());
    MAssignmentSlot[] mas = m_model.getAssignmentSlots(resourceId, startDate, endDate, null, true, null);
    if (mas == null || mas.length == 0)
        return;
    StringBuffer xml = new StringBuffer();
    xml.append("<data>").append("\r\n");
    for (MAssignmentSlot slot : mas) {
        xml.append("<event ").append("\r\n");
        xml.append(XmlFns.attr("start", TimelineUtil.formatDateTime(new Date(slot.getStartTime().getTime()))));
        if (slot.getEndTime() != null) {
            xml.append("\r\n");
            xml.append(XmlFns.attr("end", TimelineUtil.formatDateTime(new Date(slot.getEndTime().getTime()))));
            xml.append("\r\n");
            xml.append(XmlFns.attr("isDuration", "true"));
        }
        xml.append(XmlFns.attr("color", "#" + ZkCssHelper.createHexColorString(slot.getColor(true))));
        xml.append("\r\n").append(XmlFns.attr("title", slot.getName())).append("\r\n").append(">");
        if (slot.getDescription() != null && slot.getDescription().trim().length() > 0) {
            xml.append("\r\n").append(XMLs.encodeText(slot.getDescription() + "<br/>"));
        }
        if (slot.getMAssignment() != null) {
            //encode assignment id as coordinate x
            String link = "<a href=\"javascript:void(0)\" onclick=\"" + "ad_closeBuble('" + timeLineId + "');" + "zkau.send({uuid: '" + uuid + "', cmd: 'onClick', data: " + "[" + slot.getMAssignment().getS_ResourceAssignment_ID() + ", 0]" + ", ctl: true})\">Edit</a>";
            xml.append("\r\n").append(XMLs.encodeText(link));
        }
        xml.append("\r\n").append("</event>").append("\r\n");
    }
    xml.append("</data>").append("\r\n");
    PrintWriter writer = resp.getWriter();
    BufferedWriter buffer = new BufferedWriter(writer);
    buffer.write(xml.toString());
    buffer.flush();
}
Also used : ScheduleUtil(org.compiere.model.ScheduleUtil) GregorianCalendar(java.util.GregorianCalendar) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ParseException(java.text.ParseException) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ServerContext(org.adempiere.webui.session.ServerContext) MAssignmentSlot(org.compiere.model.MAssignmentSlot) ParseException(java.text.ParseException) PrintWriter(java.io.PrintWriter)

Example 3 with ServerContext

use of org.adempiere.webui.session.ServerContext in project adempiere by adempiere.

the class DashboardRunnable method refreshDashboard.

/**
	 * Refresh dashboard content
	 */
public void refreshDashboard() {
    ServerPushTemplate template = new ServerPushTemplate(desktop);
    for (int i = 0; i < dashboardPanels.size(); i++) {
        //make sure context is correct
        Properties ctx = (Properties) template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
        if (ctx != null) {
            ServerContext serverContext = ServerContext.getCurrentInstance();
            if (serverContext == null) {
                serverContext = ServerContext.newInstance();
                serverContext.putAll(ctx);
            } else {
                String id = ctx.getProperty(SessionContextListener.SERVLET_SESSION_ID);
                if (id == null || !id.equals(serverContext.getProperty(SessionContextListener.SERVLET_SESSION_ID))) {
                    serverContext.clear();
                    serverContext.putAll(ctx);
                }
            }
        }
        dashboardPanels.get(i).refresh(template);
    }
    //make sure context is correct
    Properties ctx = (Properties) template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
    if (ctx != null) {
        ServerContext serverContext = ServerContext.getCurrentInstance();
        if (serverContext == null) {
            serverContext = ServerContext.newInstance();
            serverContext.putAll(ctx);
        } else {
            String id = ctx.getProperty(SessionContextListener.SERVLET_SESSION_ID);
            if (id == null || !id.equals(serverContext.getProperty(SessionContextListener.SERVLET_SESSION_ID))) {
                serverContext.clear();
                serverContext.putAll(ctx);
            }
        }
    }
    appDesktop.onServerPush(template);
}
Also used : ServerContext(org.adempiere.webui.session.ServerContext) ServerPushTemplate(org.adempiere.webui.util.ServerPushTemplate) Properties(java.util.Properties)

Aggregations

ServerContext (org.adempiere.webui.session.ServerContext)3 Properties (java.util.Properties)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ServletException (javax.servlet.ServletException)1 ServerPushTemplate (org.adempiere.webui.util.ServerPushTemplate)1 MAssignmentSlot (org.compiere.model.MAssignmentSlot)1 ScheduleUtil (org.compiere.model.ScheduleUtil)1