Package com.psddev.cms.db

Examples of com.psddev.cms.db.ToolUser


        boolean newSchedule = schedule.getState().isNew();

        if (page.isFormPost()) {
            try {
                if (page.param(String.class, "action-save") != null) {
                    ToolUser toolUser = page.getUser();

                    page.include("/WEB-INF/objectPost.jsp", "object", schedule);

                    if (newSchedule) {
                        schedule.setTriggerUser(toolUser);
                        schedule.setTriggerSite(page.getSite());
                    }

                    schedule.save();

                    if (newSchedule) {
                        toolUser.setCurrentSchedule(schedule);
                        toolUser.save();
                    }

                } else if (page.param(String.class, "action-delete") != null) {
                    try {
                        schedule.beginWrites();
View Full Code Here


        } else {
            ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
            Database database = page.getTool().getState().getDatabase();

            try {
                ToolUser user = Query.findById(ToolUser.class, page.param(UUID.class, RemoteWidget.USER_ID_PARAMETER));

                if (user != null) {
                    AuthenticationFilter.Static.logIn(request, response, user);
                }
View Full Code Here

                for (String value : page.params(name)) {
                    pairs.add(new BasicNameValuePair(name, value));
                }
            }

            ToolUser user = page.getUser();
            if (user != null) {
                pairs.add(new BasicNameValuePair(USER_ID_PARAMETER, user.getId().toString()));
            }

            pairs.add(new BasicNameValuePair(OBJECT_PARAMETER, getJson(object)));
            pairs.add(new BasicNameValuePair(WIDGET_PARAMETER, getJson(widget)));
            post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
View Full Code Here

    @Override
    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);
View Full Code Here

    public History getOverlaidHistory(Object object) {
        return (History) State.getInstance(object).getExtra(OVERLAID_HISTORY_EXTRA);
    }

    public Predicate siteItemsPredicate() {
        ToolUser user = getUser();

        if (user != null) {
            Site site = user.getCurrentSite();

            if (site != null) {
                return site.itemsPredicate();
            }
        }
View Full Code Here

     *
     * @return Never {@code null}.
     */
    public DateTimeZone getUserDateTimeZone() {
        DateTimeZone timeZone = null;
        ToolUser user = getUser();

        if (user != null) {
            String timeZoneId = user.getTimeZone();

            if (!ObjectUtils.isBlank(timeZoneId)) {
                try {
                    timeZone = DateTimeZone.forID(timeZoneId);
                } catch (IllegalArgumentException error) {
View Full Code Here

        CmsTool cms = getCmsTool();
        Area area = getArea();
        String companyName = cms.getCompanyName();
        String environment = cms.getEnvironment();
        ToolUser user = getUser();

        if (ObjectUtils.isBlank(companyName)) {
            companyName = "Brightspot";
        }

        Site site = getSite();
        StorageItem companyLogo = site != null ? site.getCmsLogo() : null;

        if (companyLogo == null) {
            companyLogo = cms.getCompanyLogo();
        }

        writeTag("!doctype html");
        writeTag("html", "class", site != null ? site.getCmsCssClass() : null);
            writeStart("head");
                writeStart("title");
                    if (!ObjectUtils.isBlank(title)) {
                        writeHtml(title);
                        writeHtml(" | ");

                    } else if (area != null) {
                        writeObjectLabel(area);
                        writeHtml(" | ");
                    }

                    writeHtml("CMS | ");
                    writeHtml(companyName);
                writeEnd();

                writeElement("meta", "name", "robots", "content", "noindex");
                writeStylesAndScripts();
            writeEnd();

            Schedule currentSchedule = getUser() != null ? getUser().getCurrentSchedule() : null;
            String broadcastMessage = cms.getBroadcastMessage();
            Date broadcastExpiration = cms.getBroadcastExpiration();
            boolean hasBroadcast = !ObjectUtils.isBlank(broadcastMessage) &&
                    (broadcastExpiration == null ||
                    broadcastExpiration.after(new Date()));

            writeTag("body", "class",
                    (currentSchedule != null || hasBroadcast ? "hasToolBroadcast " : "") +
                    (user != null ? "" : "noToolUser "));
                if (currentSchedule != null || hasBroadcast) {
                    writeStart("div", "class", "toolBroadcast");
                        if (currentSchedule != null) {
                            writeHtml("All editorial changes will be scheduled for: ");

                            writeStart("a",
                                    "href", cmsUrl("/scheduleEdit", "id", currentSchedule.getId()),
                                    "target", "scheduleEdit");
                                writeHtml(getObjectLabel(currentSchedule));
                            writeEnd();

                            writeHtml(" - ");

                            writeStart("form",
                                    "method", "post",
                                    "style", "display: inline;",
                                    "action", cmsUrl("/misc/updateUserSettings",
                                            "action", "scheduleSet",
                                            "returnUrl", url("")));
                                writeStart("button",
                                        "class", "link icon icon-action-cancel");
                                    writeHtml("Stop Scheduling");
                                writeEnd();
                            writeEnd();
                        }

                        if (hasBroadcast) {
                            writeHtml(" - ");
                            writeHtml(broadcastMessage);
                        }
                    writeEnd();
                }

                writeStart("div", "class", "toolHeader" + (!ObjectUtils.isBlank(environment) ? " toolHeader-hasEnvironment" : ""));

                    writeStart("h1", "class", "toolTitle");
                        writeStart("a", "href", cmsUrl("/"));
                            if (companyLogo != null) {
                                writeElement("img", "src", companyLogo.getPublicUrl(), "alt", companyName);
                            } else {
                                writeHtml(companyName);
                            }
                        writeEnd();
                    writeEnd();

                    if (!ObjectUtils.isBlank(environment)) {
                        writeStart("div", "class", "toolEnv");
                            writeHtml(environment);
                        writeEnd();
                    }

                    if (user != null) {
                        int nowHour = new DateTime().getHourOfDay();

                        writeStart("div", "class", "toolAvatar");

                            StorageItem avatar = user.getAvatar();

                            if (avatar != null) {
                                writeStart("a", "href", cmsUrl("/misc/settings.jsp"));
                                    writeTag("img",
                                            "src", ImageEditor.Static.resize(ImageEditor.Static.getDefault(), avatar, null, 50, 50).getPublicUrl());
                                writeEnd();
                            }
                        writeEnd();

                        writeStart("div", "class", "toolProfile");
                            writeHtml("Good ");
                            writeHtml(nowHour >= 2 && nowHour < 12 ? "Morning" : (nowHour >= 12 && nowHour < 18 ? "Afternoon" : "Evening"));
                            writeHtml(", ");
                            writeHtml(getObjectLabel(user));

                            writeStart("ul");
                                if (!Site.Static.findAll().isEmpty()) {
                                    Site currentSite = user.getCurrentSite();

                                    writeStart("li");
                                        writeHtml("Site: ");
                                        writeStart("a", "href", cmsUrl("/misc/sites.jsp"), "target", "misc");
                                            writeHtml(currentSite != null ? currentSite.getLabel() : "Global");
View Full Code Here

                                // Ignore invalid site URL.
                            }
                        }
                    }

                    ToolUser user = getUser();
                    String userId = user != null ? user.getId().toString() : UUID.randomUUID().toString();
                    String signature = StringUtils.hex(StringUtils.hmacSha1(Settings.getSecret(), userId));
                    String cookiePath = StringUtils.addQueryParameters(
                            cmsUrl("/inlineEditorCookie"),
                            "userId", userId,
                            "signature", signature).
View Full Code Here

            return false;
        }

        State state = State.getInstance(object);
        Content.ObjectModification contentData = state.as(Content.ObjectModification.class);
        ToolUser user = getUser();

        if (state.isNew() ||
                object instanceof Draft ||
                contentData.isDraft() ||
                state.as(Workflow.Data.class).getCurrentState() != null) {
            if (getContentFormPublishDate() != null) {
                setContentFormScheduleDate(object);

            } else {
                contentData.setPublishDate(new Date());
                contentData.setPublishUser(user);
            }
        }

        Draft draft = getOverlaidDraft(object);
        UUID variationId = param(UUID.class, "variationId");
        Site site = getSite();

        try {
            state.beginWrites();
            state.as(Workflow.Data.class).changeState(null, user, (WorkflowLog) null);

            if (variationId == null ||
                    (site != null &&
                    ((state.isNew() && site.getDefaultVariation() != null) ||
                    ObjectUtils.equals(site.getDefaultVariation(), state.as(Variation.Data.class).getInitialVariation())))) {
                if (state.isNew() && site != null && site.getDefaultVariation() != null) {
                    state.as(Variation.Data.class).setInitialVariation(site.getDefaultVariation());
                }

                getRequest().setAttribute("original", object);
                includeFromCms("/WEB-INF/objectPost.jsp", "object", object, "original", object);
                updateUsingAllWidgets(object);

                if (variationId != null &&
                        variationId.equals(state.as(Variation.Data.class).getInitialVariation())) {
                    state.putByPath("variations/" + variationId.toString(), null);
                }

            } else {
                Object original = Query.
                        from(Object.class).
                        where("_id = ?", state.getId()).
                        noCache().
                        first();
                Map<String, Object> oldStateValues = State.getInstance(original).getSimpleValues();

                getRequest().setAttribute("original", original);
                includeFromCms("/WEB-INF/objectPost.jsp", "object", object, "original", original);
                updateUsingAllWidgets(object);

                Map<String, Object> newStateValues = state.getSimpleValues();
                Set<String> stateKeys = new LinkedHashSet<String>();
                Map<String, Object> stateValues = new LinkedHashMap<String, Object>();

                stateKeys.addAll(oldStateValues.keySet());
                stateKeys.addAll(newStateValues.keySet());

                for (String key : stateKeys) {
                    Object value = newStateValues.get(key);
                    if (!ObjectUtils.equals(oldStateValues.get(key), value)) {
                        stateValues.put(key, value);
                    }
                }

                State.getInstance(original).putByPath("variations/" + variationId.toString(), stateValues);
                State.getInstance(original).getExtras().put("cms.variedObject", object);
                object = original;
                state = State.getInstance(object);
            }

            Schedule schedule = user.getCurrentSchedule();
            Date publishDate = null;

            if (schedule == null) {
                publishDate = getContentFormPublishDate();
View Full Code Here

    /**
     * Returns the site that the {@linkplain #getUser current user}
     * is accessing.
     */
    public Site getSite() {
        ToolUser user = getUser();
        return user != null ? user.getCurrentSite() : null;
    }
View Full Code Here

TOP

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

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.