Search in sources :

Example 1 with Work

use of com.googlecode.objectify.Work in project blogwt by billy1380.

the class ArchiveEntryService method updateArchiveEntryPost.

@Override
public ArchiveEntry updateArchiveEntryPost(final ArchiveEntry archiveEntry, final Post post) {
    ArchiveEntry updated = null;
    if (Boolean.TRUE.equals(post.listed) && post.published != null) {
        updated = provide().transact(new Work<ArchiveEntry>() {

            @Override
            public ArchiveEntry run() {
                ArchiveEntry latest = getArchiveEntry(archiveEntry.id);
                if (latest.postKeys == null) {
                    latest.postKeys = new ArrayList<Key<Post>>();
                }
                boolean found = false;
                for (Key<Post> key : latest.postKeys) {
                    if (DataTypeHelper.<Post>same(key, post)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    latest.postKeys.add(Key.create(post));
                }
                provide().save().entity(latest).now();
                return latest;
            }
        });
    }
    return updated;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Work(com.googlecode.objectify.Work) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry) Key(com.googlecode.objectify.Key)

Aggregations

Key (com.googlecode.objectify.Key)1 Work (com.googlecode.objectify.Work)1 ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)1 Post (com.willshex.blogwt.shared.api.datatype.Post)1