Package com.psddev.dari.db

Examples of com.psddev.dari.db.State


         * @param site May be {@code null}.
         * @param user May be {@code null}.
         * @return Can be used to revert all changes. May be {@code null}.
         */
        public static History publish(Object object, Site site, ToolUser user) {
            State state = State.getInstance(object);
            ObjectModification contentData = state.as(ObjectModification.class);
            Site.ObjectModification siteData = state.as(Site.ObjectModification.class);

            if (object instanceof Site) {
                site = (Site) object;
                siteData.setOwner(site);

            } else if (state.isNew() &&
                    siteData.getOwner() == null) {
                siteData.setOwner(site);
            }

            Date now = new Date();
            Date publishDate = contentData.getPublishDate();
            ToolUser publishUser = contentData.getPublishUser();

            if (publishDate == null) {
                contentData.setPublishDate(now);
            }

            if (publishUser == null) {
                contentData.setPublishUser(user);
            }

            contentData.setUpdateDate(now);
            contentData.setUpdateUser(user);

            if (object instanceof Draft) {
                state.save();
                return null;

            } else {
                try {
                    History history = new History(user, object);

                    state.beginWrites();
                    state.save();
                    history.save();
                    state.commitWrites();
                    return history;

                } finally {
                    state.endWrites();
                }
            }
        }
View Full Code Here


        /**
         * Trashes the given {@code object} so that it's not usable in
         * the given {@code site}.
         */
        public static void trash(Object object, Site site, ToolUser user) {
            State state = State.getInstance(object);
            Site.ObjectModification siteData = state.as(Site.ObjectModification.class);

            if (object instanceof ToolEntity ||
                    site == null ||
                    ObjectUtils.equals(siteData.getOwner(), site)) {
                ObjectModification contentData = state.as(ObjectModification.class);

                contentData.setTrash(true);
                contentData.setUpdateDate(new Date());
                contentData.setUpdateUser(user);
                state.save();

            } else {
                siteData.getConsumers().remove(site);

                if (siteData.isGlobal()) {
View Full Code Here

        /**
         * Purges the given {@code object} completely, including all of
         * its drafts, histories, and trashes.
         */
        public static void purge(Object object, Site site, ToolUser user) {
            State objectState = State.getInstance(object);
            Site.ObjectModification objectSiteMod = objectState.as(Site.ObjectModification.class);

            if (!ObjectUtils.equals(objectSiteMod.getOwner(), site)) {
                trash(object, site, user);
                return;
            }

            Database database = objectState.getDatabase();
            UUID objectId = objectState.getId();

            try {
                database.beginWrites();
                database.deleteByQuery(Query.from(Draft.class).where("objectId = ?", objectId));
                database.deleteByQuery(Query.from(History.class).where("objectId = ?", objectId));
                database.deleteByQuery(Query.from(Trash.class).where("objectId = ?", objectId));
                objectState.delete();
                database.commitWrites();
            } finally {
                database.endWrites();
            }
        }
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.