Search in sources :

Example 1 with ArchiveEntry

use of com.willshex.blogwt.shared.api.datatype.ArchiveEntry in project blogwt by billy1380.

the class GetArchiveEntriesActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(GetArchiveEntriesRequest input, GetArchiveEntriesResponse output) throws Exception {
    ApiValidator.request(input, GetArchiveEntriesRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    output.archive = ArchiveEntryServiceProvider.provide().getArchiveEntries();
    if (output.archive != null) {
        for (ArchiveEntry archiveEntry : output.archive) {
            archiveEntry.posts = PersistenceHelper.typeList(Post.class, archiveEntry.postKeys);
        }
    }
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Example 2 with ArchiveEntry

use of com.willshex.blogwt.shared.api.datatype.ArchiveEntry in project blogwt by billy1380.

the class ArchiveEntryService method generateArchive.

@Override
public void generateArchive() {
    Map<String, ArchiveEntry> archiveEntryLookup = new HashMap<String, ArchiveEntry>();
    List<Post> posts;
    ArchiveEntry archiveEntry;
    Pager pager = PagerHelper.createDefaultPager();
    do {
        posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            PagerHelper.moveForward(pager);
            for (Post post : posts) {
                if (Boolean.TRUE.equals(post.listed) && post.published != null) {
                    Calendar c = ensureCalendar();
                    c.setTime(post.published);
                    Integer month = Integer.valueOf(c.get(java.util.Calendar.MONTH));
                    Integer year = Integer.valueOf(c.get(java.util.Calendar.YEAR));
                    String key = year + "/" + month;
                    if ((archiveEntry = archiveEntryLookup.get(key)) == null) {
                        archiveEntry = new ArchiveEntry().month(month).year(year).posts(new ArrayList<Post>());
                        archiveEntryLookup.put(key, archiveEntry);
                    }
                    archiveEntry.posts.add(post);
                }
            }
        }
    } while (posts != null && posts.size() >= pager.count.intValue());
    if (archiveEntryLookup.size() > 0) {
        addArchiveEntryBatch(archiveEntryLookup.values());
    }
}
Also used : HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) Pager(com.willshex.blogwt.shared.api.Pager) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Example 3 with ArchiveEntry

use of com.willshex.blogwt.shared.api.datatype.ArchiveEntry 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)

Example 4 with ArchiveEntry

use of com.willshex.blogwt.shared.api.datatype.ArchiveEntry in project blogwt by billy1380.

the class ArchiveEntryValidator method lookup.

public static ArchiveEntry lookup(ArchiveEntry archiveEntry, String name) throws InputValidationException {
    if (archiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isYearMonthLookup = false;
    if (archiveEntry.id != null) {
        isIdLookup = true;
    } else if (archiveEntry.year != null && archiveEntry.month != null) {
        isYearMonthLookup = true;
    }
    if (!(isIdLookup || isYearMonthLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    ArchiveEntry lookupArchiveEntry = null;
    if (isIdLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getArchiveEntry(archiveEntry.id);
    } else if (isYearMonthLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getMonthArchiveEntry(archiveEntry.month, archiveEntry.year);
    }
    if (lookupArchiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupArchiveEntry;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Example 5 with ArchiveEntry

use of com.willshex.blogwt.shared.api.datatype.ArchiveEntry in project blogwt by billy1380.

the class GetArchiveEntriesResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("archive")) {
        JsonElement jsonArchive = jsonObject.get("archive");
        if (jsonArchive != null) {
            archive = new ArrayList<ArchiveEntry>();
            ArchiveEntry item = null;
            for (int i = 0; i < jsonArchive.getAsJsonArray().size(); i++) {
                if (jsonArchive.getAsJsonArray().get(i) != null) {
                    (item = new ArchiveEntry()).fromJson(jsonArchive.getAsJsonArray().get(i).getAsJsonObject());
                    archive.add(item);
                }
            }
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Aggregations

ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)8 Post (com.willshex.blogwt.shared.api.datatype.Post)4 JsonElement (com.google.gson.JsonElement)2 Key (com.googlecode.objectify.Key)2 Pager (com.willshex.blogwt.shared.api.Pager)2 Calendar (java.util.Calendar)2 Work (com.googlecode.objectify.Work)1 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1