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);
}
}
}
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());
}
}
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;
}
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;
}
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);
}
}
}
}
}
Aggregations