Package com.psddev.cms.db

Examples of com.psddev.cms.db.ToolUserDevice


        }

        final Map<ToolUserDevice, List<ToolUserAction>> actionsByDevice = new CompactMap<ToolUserDevice, List<ToolUserAction>>();

        for (Map.Entry<String, List<ToolUserDevice>> entry : devicesByUserAgent.entrySet()) {
            ToolUserDevice device = null;
            List<ToolUserAction> actions = null;
            long lastTime = 0;

            for (ToolUserDevice d : entry.getValue()) {
                List<ToolUserAction> a = Query.
                        from(ToolUserAction.class).
                        where("device = ?", d).
                        sortDescending("time").
                        selectAll();

                if (!a.isEmpty()) {
                    long time = a.get(0).getTime();

                    if (lastTime < time) {
                        lastTime = time;
                        device = d;
                        actions = a;
                    }
                }
            }

            if (device != null) {
                actionsByDevice.put(device, actions);
            }
        }

        List<ToolUserDevice> recentDevices = new ArrayList<ToolUserDevice>(actionsByDevice.keySet());

        Collections.sort(recentDevices, new Comparator<ToolUserDevice>() {

            @Override
            public int compare(ToolUserDevice x, ToolUserDevice y) {
                long xTime = actionsByDevice.get(x).get(0).getTime();
                long yTime = actionsByDevice.get(y).get(0).getTime();

                return xTime < yTime ? 1 : (xTime > yTime ? -1 : 0);
            }
        });

        page.writeHeader();
            page.writeStart("div", "class", "widget", "style", "overflow: hidden;");
                page.writeStart("h1", "class", "icon icon-object-history");
                    page.writeHtml("History");
                page.writeEnd();

                page.writeStart("div", "class", "tabbed");
                    for (ToolUserDevice device : recentDevices) {
                        List<ToolUserAction> actions = actionsByDevice.get(device);
                        String lookingGlassUrl = page.cmsUrl("/lookingGlass", "id", device.getOrCreateLookingGlassId());

                        page.writeStart("div", "data-tab", device.getUserAgentDisplay());
                            page.writeStart("div", "style", page.cssString(
                                    "float", "right",
                                    "text-align", "center"));
                                page.writeStart("a",
                                        "class", "icon icon-facetime-video",
View Full Code Here


    protected void doService(ToolPageContext page) throws IOException, ServletException {
        UUID id = page.param(UUID.class, "id");

        if (id == null) {
            ToolUser user = page.getUser();
            ToolUserDevice device = user.findRecentDevice();

            if (device == null) {
                device = user.findOrCreateCurrentDevice(page.getRequest());
            }

            id = device.getOrCreateLookingGlassId();

            page.redirect("", "id", id);
            return;
        }

        ToolUserDevice device = Query.
                from(ToolUserDevice.class).
                where("lookingGlassId = ?", id).
                first();

        if (device == null) {
            throw new IllegalArgumentException(String.format(
                    "No looking glass at [%s]!", id));
        }

        ToolUserAction lastAction = Query.
                from(ToolUserAction.class).
                where("device = ?", device).
                sortDescending("time").
                noCache().
                first();

        if (lastAction != null &&
                "ping".equals(page.param(String.class, "action"))) {
            long end = System.currentTimeMillis() + 30000;

            while (System.currentTimeMillis() < end &&
                    lastAction.getTime() == page.param(long.class, "time")) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException error) {
                    break;
                }

                lastAction = Query.
                        from(ToolUserAction.class).
                        where("device = ?", device).
                        sortDescending("time").
                        noCache().
                        first();
            }

            Map<String, Object> response = new HashMap<String, Object>();

            response.put("changed", lastAction == null || lastAction.getTime() != page.param(long.class, "time"));
            page.getResponse().setContentType("application/json");
            page.writeRaw(ObjectUtils.toJson(response));
            return;
        }

        ToolUser user = device.getUser();

        page.writeHeader();
            page.writeStart("div", "class", "message message-info");
                page.writeHtml("Mirroring ");
                page.writeObjectLabel(user);

                page.writeHtml(" in ");
                page.writeHtml(device.getUserAgentDisplay());

                if (lastAction != null) {
                    Object lastActionContent = lastAction.getContent();

                    if (lastActionContent != null) {
View Full Code Here

TOP

Related Classes of com.psddev.cms.db.ToolUserDevice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.