Search in sources :

Example 6 with WebContext

use of org.directwebremoting.WebContext in project libresonic by Libresonic.

the class StarService method getUser.

private String getUser() {
    WebContext webContext = WebContextFactory.get();
    User user = securityService.getCurrentUser(webContext.getHttpServletRequest());
    return user.getUsername();
}
Also used : WebContext(org.directwebremoting.WebContext) User(org.libresonic.player.domain.User)

Example 7 with WebContext

use of org.directwebremoting.WebContext in project libresonic by Libresonic.

the class NowPlayingService method getNowPlayingForCurrentPlayer.

/**
     * Returns details about what the current player is playing.
     *
     * @return Details about what the current player is playing, or <code>null</code> if not playing anything.
     */
public NowPlayingInfo getNowPlayingForCurrentPlayer() throws Exception {
    WebContext webContext = WebContextFactory.get();
    Player player = playerService.getPlayer(webContext.getHttpServletRequest(), webContext.getHttpServletResponse());
    for (NowPlayingInfo info : getNowPlaying()) {
        if (player.getId().equals(info.getPlayerId())) {
            return info;
        }
    }
    return null;
}
Also used : WebContext(org.directwebremoting.WebContext)

Example 8 with WebContext

use of org.directwebremoting.WebContext in project jaffa-framework by jaffa-projects.

the class JaffaDateConverter method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
    // Error out if an unsupported class is passed
    if (paramType != DateOnly.class && paramType != DateTime.class) {
        log.warn("Unsupported input. Class=" + paramType);
        throw new MarshallException(paramType);
    }
    // Extract Char Encoding from the Web Context
    String charEncoding = null;
    WebContext context = WebContextFactory.get();
    if (context != null) {
        HttpServletRequest req = context.getHttpServletRequest();
        if (req != null)
            charEncoding = req.getCharacterEncoding();
    }
    if (charEncoding == null)
        charEncoding = CHAR_ENCODER;
    String value = iv.getValue();
    // If the text is null then the whole bean is null
    if (value.trim().equals(ProtocolConstants.INBOUND_NULL))
        return null;
    Object output;
    try {
        // Handle a millisecond input
        long millis = 0;
        if (value.length() > 0)
            millis = Long.parseLong(value);
        // DWR returns null dates as '0', so we must return a null in this case
        if (millis == 0)
            return null;
        Boolean useServerTime = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(RULE_NAME_USE_SERVER_TIME));
        if (useServerTime != null && useServerTime) {
            if (log.isInfoEnabled())
                log.info("A String representation of a date should be posted by the client, since the application rule '" + RULE_NAME_USE_SERVER_TIME + "' is set");
        }
        output = paramType == DateOnly.class ? new DateOnly(millis) : new DateTime(millis);
    } catch (NumberFormatException e) {
        try {
            // Handle a String input
            if (log.isDebugEnabled())
                log.debug("Error in parsing '" + value + "' as milliseconds since 1970. Will attempt to parse it as a String representation of a date");
            output = paramType == DateOnly.class ? DateTime.toDateOnly(Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME)) : Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME);
        } catch (FormatDateTimeException e1) {
            if (log.isDebugEnabled())
                log.debug("Error in parsing Date '" + value + "' using the format '" + FORMAT_DATE_TIME + '\'', e1);
            throw new MarshallException(DateOnly.class, e1);
        } catch (UnsupportedEncodingException e1) {
            if (log.isDebugEnabled())
                log.debug("Error in encoding Date '" + value + "' using the format '" + charEncoding + '\'', e1);
            throw new MarshallException(DateOnly.class, e1);
        }
    }
    if (log.isDebugEnabled())
        log.debug("Inbound '" + value + "' converted to '" + output + '\'');
    return output;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebContext(org.directwebremoting.WebContext) MarshallException(org.directwebremoting.extend.MarshallException) DateOnly(org.jaffa.datatypes.DateOnly) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateTime(org.jaffa.datatypes.DateTime) FormatDateTimeException(org.jaffa.datatypes.exceptions.FormatDateTimeException)

Example 9 with WebContext

use of org.directwebremoting.WebContext in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method getViewPointData.

private List<ViewComponentState> getViewPointData(User user, GraphicalView view, boolean edit) {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    List<ViewComponentState> states = new ArrayList<ViewComponentState>();
    Map<String, Object> model = new HashMap<String, Object>();
    for (ViewComponent viewComponent : view.getViewComponents()) {
        // Are we to update this component
        boolean update = System.currentTimeMillis() >= (viewComponent.getLastUpdated() + Common.getMillis(viewComponent.getUpdatePeriodType(), viewComponent.getUpdatePeriods()));
        if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) {
            CompoundComponent compoundComponent = (CompoundComponent) viewComponent;
            boolean imageChart = compoundComponent instanceof ImageChartComponent;
            // Add states for each of the children
            for (CompoundChild child : compoundComponent.getChildComponents()) addPointComponentState(child.getViewComponent(), update, Common.runtimeManager, model, request, view, user, states, edit, !imageChart);
            // Add a state for the compound component.
            ViewComponentState state = new ViewComponentState();
            state.setId(compoundComponent.getId());
            model.clear();
            model.put("compoundComponent", compoundComponent);
            List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>();
            for (CompoundChild child : compoundComponent.getChildComponents()) {
                if (child.getViewComponent().isPointComponent()) {
                    DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint();
                    if (point != null) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        if (imageChart)
                            map.put("name", point.getName());
                        else
                            map.put("name", translate(child.getDescription()));
                        map.put("point", point);
                        map.put("pointValue", point.lastValue());
                        childData.add(map);
                    }
                }
            }
            model.put("childData", childData);
            if (compoundComponent.hasInfo())
                state.setInfo(generateViewContent(compoundComponent, update, request, "compoundInfoContent.jsp", model));
            if (imageChart) {
                state.setContent(((ImageChartComponent) compoundComponent).getImageChartData(getTranslations()));
            } else if (!edit) {
                state.setChart(compoundComponent.getImageChartData(getTranslations()));
            }
            states.add(state);
        } else
            addPointComponentState(viewComponent, update, Common.runtimeManager, model, request, view, user, states, edit, true);
        // Save the last time we updated
        if (update)
            viewComponent.setLastUpdated(System.currentTimeMillis());
    }
    return states;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) WebContext(org.directwebremoting.WebContext) HashMap(java.util.HashMap) PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) ArrayList(java.util.ArrayList) CompoundChild(com.serotonin.m2m2.gviews.component.CompoundChild) SimpleCompoundComponent(com.serotonin.m2m2.gviews.component.SimpleCompoundComponent) CompoundComponent(com.serotonin.m2m2.gviews.component.CompoundComponent) HttpServletRequest(javax.servlet.http.HttpServletRequest) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) ImageChartComponent(com.serotonin.m2m2.gviews.component.ImageChartComponent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with WebContext

use of org.directwebremoting.WebContext in project ma-modules-public by infiniteautomation.

the class ReportsDwr method runReport.

@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult runReport(String xid, String name, List<ReportPointVO> points, String template, int includeEvents, boolean includeUserComments, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, boolean email, boolean includeData, boolean zipData, List<RecipientListEntryBean> recipients) {
    ProcessResult response = new ProcessResult();
    // Basic validation
    // TODO Replace with vo.validate()
    validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
    if (!response.getHasMessages()) {
        ReportVO report = new ReportVO();
        report.setXid(xid);
        report.setName(name);
        report.setUserId(Common.getUser().getId());
        report.setPoints(points);
        report.setTemplate(template);
        report.setIncludeEvents(includeEvents);
        report.setIncludeUserComments(includeUserComments);
        report.setDateRangeType(dateRangeType);
        report.setRelativeDateType(relativeDateType);
        report.setPreviousPeriodCount(previousPeriodCount);
        report.setPreviousPeriodType(previousPeriodType);
        report.setPastPeriodCount(pastPeriodCount);
        report.setPastPeriodType(pastPeriodType);
        report.setFromNone(fromNone);
        report.setFromYear(fromYear);
        report.setFromMonth(fromMonth);
        report.setFromDay(fromDay);
        report.setFromHour(fromHour);
        report.setFromMinute(fromMinute);
        report.setToNone(toNone);
        report.setToYear(toYear);
        report.setToMonth(toMonth);
        report.setToDay(toDay);
        report.setToHour(toHour);
        report.setToMinute(toMinute);
        // Never allow schedule when running from UI
        report.setSchedule(false);
        report.setEmail(email);
        report.setIncludeData(includeData);
        report.setZipData(zipData);
        report.setRecipients(recipients);
        String host = "";
        WebContext webContext = WebContextFactory.get();
        int port;
        if (webContext != null) {
            HttpServletRequest req = webContext.getHttpServletRequest();
            host = req.getServerName();
            port = req.getLocalPort();
        } else {
            port = Common.envProps.getInt("web.port", 8080);
        }
        ReportWorkItem.queueReport(host, port, report);
    }
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebContext(org.directwebremoting.WebContext) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

WebContext (org.directwebremoting.WebContext)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 Iterator (java.util.Iterator)3 Creator (org.directwebremoting.extend.Creator)3 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)2 Method (java.lang.reflect.Method)2 MarshallException (org.directwebremoting.extend.MarshallException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 IMangoLifecycle (com.serotonin.m2m2.IMangoLifecycle)1 CompoundChild (com.serotonin.m2m2.gviews.component.CompoundChild)1 CompoundComponent (com.serotonin.m2m2.gviews.component.CompoundComponent)1 ImageChartComponent (com.serotonin.m2m2.gviews.component.ImageChartComponent)1 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)1 SimpleCompoundComponent (com.serotonin.m2m2.gviews.component.SimpleCompoundComponent)1 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)1 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 ReportDao (com.serotonin.m2m2.reports.ReportDao)1