import java.util.ArrayList;
import java.util.Collection;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
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;
/** The trust updater. */
private final WebOfTrustUpdater webOfTrustUpdater;
+ private final Set<CompatibilityMode> compatibilityModes = EnumSet.noneOf(CompatibilityMode.class);
+
/** The times Sones were followed. */
private final Map<String, Long> soneFollowingTimes = new HashMap<String, Long>();
return updateChecker;
}
+ public boolean isCompatibilityMode(CompatibilityMode compatibilityMode) {
+ return compatibilityModes.contains(compatibilityMode);
+ }
+
+ public void setCompatibilityMode(CompatibilityMode compatibilityMode) {
+ compatibilityModes.add(compatibilityMode);
+ }
+
+ public void clearCompatibilityMod(CompatibilityMode compatibilityMode) {
+ compatibilityModes.remove(compatibilityMode);
+ }
+
/**
* Returns the Sone rescuer for the given local Sone.
*
* {@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();
}
/**
int postCounter = 0;
for (Post post : sone.getPosts()) {
String postPrefix = sonePrefix + "/Posts/" + postCounter++;
- configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
+ configuration.getStringValue(postPrefix + "/ID").setValue(post.getInternalId());
configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
continue;
}
String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
- configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
+ configuration.getStringValue(imagePrefix + "/ID").setValue(image.getInternalId());
configuration.getStringValue(imagePrefix + "/Album").setValue(album.getInternalId());
configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());