Package com.psddev.dari.db

Examples of com.psddev.dari.db.State


            page.writeEnd();
        }

        @Override
        public void renderRow(Object item) throws IOException {
            State itemState = State.getInstance(item);
            String permalink = itemState.as(Directory.ObjectModification.class).getPermalink();

            page.writeStart("tr", "data-preview-url", permalink);
                page.writeStart("td", "style", "width: 20px;");
                    page.writeElement("input",
                            "type", "checkbox",
                            "name", ITEMS_PARAMETER,
                            "value", itemState.getId());

                page.writeEnd();

                page.writeStart("td");
                    page.writeHtml(page.getTypeLabel(item));
View Full Code Here


     */
    public Object next(ToolUser user) {
        ErrorUtils.errorIfNull(user, "user");

        String userId = user.getId().toString();
        State next = currentItems != null ?
                State.getInstance(Query.from(Object.class).where("_id = ?", currentItems.get(userId)).first()) :
                null;

        if (next != null &&
                (next.as(Data.class).isComplete(this) ||
                (skippedItems != null && skippedItems.get(userId) != null && skippedItems.get(userId).contains(next.getId())))) {
            next = null;
        }

        if (next == null) {
            Query<?> query = getQuery().clone().
                    not("cms.workstream.completeIds ^= ?", getId().toString() + ",");

            if (currentItems != null) {
                query.and("_id != ?", currentItems.values());
            }

            if (skippedItems != null) {
                query.and("_id != ?", skippedItems.get(userId));
            }

            next = State.getInstance(query.first());

            if (next != null) {
                getState().putAtomically("currentItems/" + userId, next.getId());
                save();
            }
        }

        return next != null ? next.getOriginalObject() : null;
    }
View Full Code Here

    protected History() {
    }

    /** Creates an instance based on the given {@code object}. */
    public History(ToolUser user, Object object) {
        State objectState = State.getInstance(object);
        getState().setDatabase(objectState.getDatabase());
        this.updateDate = new Date();
        this.updateUser = user;
        this.objectType = objectState.getType();
        this.objectId = objectState.getId();
        this.objectOriginals = objectState.getSimpleValues();
    }
View Full Code Here

    public Object getObject() {
        if (objectType == null) {
            return null;
        } else {
            Object object = objectType.createObject(objectId);
            State state = State.getInstance(object);
            if (objectOriginals != null) {
                state.getValues().putAll(objectOriginals);
            }
            return object;
        }
    }
View Full Code Here

                if (!automaticallySavedDrafts.isEmpty()) {
                    boolean removed = false;

                    for (Iterator<Object> i = automaticallySavedDrafts.iterator(); i.hasNext();) {
                        State draft = State.getInstance(i.next());

                        if (!draft.as(Content.ObjectModification.class).isDraft()) {
                            removed = true;

                            automaticallySavedDraftIds.remove(draft.getId());
                            i.remove();
                        }
                    }

                    if (removed) {
                        user.save();
                    }

                    if (!automaticallySavedDrafts.isEmpty()) {
                        page.writeStart("h2").writeHtml("Automatically Saved Drafts").writeEnd();

                        page.writeStart("ul", "class", "links");
                            for (Object draft : automaticallySavedDrafts) {
                                page.writeStart("li");
                                    page.writeStart("a",
                                            "target", "_top",
                                            "href", page.objectUrl("/content/edit.jsp", draft));
                                        page.writeTypeObjectLabel(draft);
                                    page.writeEnd();
                                page.writeEnd();
                            }
                        page.writeEnd();
                    }
                }

                page.writeStart("div", "style", page.cssString(
                        "-moz-box-sizing", "border-box",
                        "-webkit-box-sizing", "border-box",
                        "box-sizing", "border-box",
                        "float", "left",
                        "padding-right", "5px",
                        "width", "50%"));
                    page.writeStart("h2").writeHtml("Create New").writeEnd();

                    page.writeStart("ul", "class", "links pageThumbnails");
                        for (TypeTemplate typeTemplate : favorites) {
                            ObjectType type = typeTemplate.type;
                            Template template = typeTemplate.template;
                            State state = State.getInstance(Query.fromType(type).where("cms.template.default = ?", template).first());
                            String permalink = null;

                            if (state != null) {
                                permalink = state.as(Directory.ObjectModification.class).getPermalink();
                            }

                            page.writeStart("li", "data-preview-url", permalink);
                                page.writeStart("a",
                                        "target", "_top",
View Full Code Here

            Object mainObject = PageFilter.Static.getMainObject(request);
            Set<UUID> displayIds = Static.getDisplayIds(request);

            if (mainObject != null) {
                State mainState = State.getInstance(mainObject);

                displayIds.add(mainState.getId());
                addDisplayIds(displayIds, mainState.getSimpleValues());
            }

            FieldAccessListener listener = new FieldAccessListener(request);

            try {
View Full Code Here

        public static Template findRenderable(Object object, Site site) {
            if (object == null) {
                return null;
            }

            State objectState = State.getInstance(object);
            Template template = objectState.as(ObjectModification.class).getDefault();
            if (template != null && Site.Static.isObjectAccessible(site, template)) {
                return template;
            }

            ObjectType objectType = objectState.getType();
            List<Template> usable = new ArrayList<Template>();

            for (Template t : Query.from(Template.class).sortAscending("name").selectAll()) {
                if (Site.Static.isObjectAccessible(site, t) &&
                        t.getContentTypes().contains(objectType)) {
View Full Code Here

         */
        public static List<Template> findUsable(Object object) {
            List<Template> templates = new ArrayList<Template>();

            if (object != null) {
                State state = State.getInstance(object);
                Site owner = state.as(Site.ObjectModification.class).getOwner();
                ObjectType type = state.getType();

                for (Template template : Query.from(Template.class).sortAscending("name").selectAll()) {
                    if (template.getContentTypes().contains(type) &&
                            (owner == null ||
                            Site.Static.isObjectAccessible(owner, template))) {
View Full Code Here

    public <T> T clean(T object) {
        if (object == null) {
            return null;
        }

        State state = State.getInstance(object);
        ObjectType type = state.getType();

        if (type != null) {
            for (ObjectField field : type.getFields()) {
                if (field.as(ToolUi.class).isRichText()) {
                    String fieldName = field.getInternalName();
                    Object value = state.get(fieldName);

                    if (value instanceof String) {
                        state.put(fieldName, PUBLISHABLES.getUnchecked((String) value));
                    }
                }
            }
        }
View Full Code Here

         *
         * @deprecated Use {@link #trash} instead.
         */
        @Deprecated
        public static Trash deleteSoftly(Object object, Site site, ToolUser user) {
            State objectState = State.getInstance(object);
            Site.ObjectModification objectSiteMod = objectState.as(Site.ObjectModification.class);

            if (site == null || ObjectUtils.equals(objectSiteMod.getOwner(), site)) {
                Trash trash = new Trash(user, object);
                try {
                    trash.beginWrites();
                    objectState.delete();
                    trash.save();
                    trash.commitWrites();
                    return trash;
                } finally {
                    trash.endWrites();
                }

            } else {
                objectSiteMod.getConsumers().remove(site);
                if (objectSiteMod.isGlobal()) {
                    objectSiteMod.getBlacklist().add(site);
                }
                objectState.save();
                return null;
            }
        }
View Full Code Here

TOP

Related Classes of com.psddev.dari.db.State

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.