import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
* {@inheritDoc}
*/
@Override
- public Optional<Post> getPost(String postId) {
- return database.getPost(postId);
+ public Optional<Post> getPost(final String postId) {
+ Optional<Post> post = database.getPost(postId);
+ if (post.isPresent() || !isCompatibilityMode(CompatibilityMode.oldElementIds)) {
+ return post;
+ }
+ return FluentIterable.from(getSones()).transformAndConcat(Sone.toAllPosts).filter(new Predicate<Post>() {
+ @Override
+ public boolean apply(Post input) {
+ return (input != null) && input.getInternalId().equals(postId);
+ }
+ }).first();
}
/**
}
};
+ Function<Sone, Collection<Post>> toAllPosts = new Function<Sone, Collection<Post>>() {
+ @Override
+ public Collection<Post> apply(@Nullable Sone sone) {
+ return (sone != null) ? sone.getPosts() : Collections.<Post>emptyList();
+ }
+ };
+
/**
* Returns the identity of this Sone.
*