- * Saves the given Sone. This will persist all local settings for the given
- * Sone, such as the friends list and similar, private options.
- *
- * @param sone
- * The Sone to save
- */
- private synchronized void saveSone(Sone sone) {
- if (!sone.isLocal()) {
- logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
- return;
- }
- if (!(sone.getIdentity() instanceof OwnIdentity)) {
- logger.log(Level.WARNING, String.format("Local Sone without OwnIdentity found, refusing to save: %s", sone));
- return;
- }
-
- logger.log(Level.INFO, String.format("Saving Sone: %s", sone));
- try {
- /* save Sone into configuration. */
- String sonePrefix = "Sone/" + sone.getId();
- configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
- configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());
-
- /* save profile. */
- Profile profile = sone.getProfile();
- configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
- configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
- configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
- configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
- configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
- configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
- configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());
-
- /* save profile fields. */
- int fieldCounter = 0;
- for (Field profileField : profile.getFields()) {
- String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
- configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
- configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
- }
- configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
-
- /* save posts. */
- int postCounter = 0;
- for (Post post : sone.getPosts()) {
- String postPrefix = sonePrefix + "/Posts/" + postCounter++;
- configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
- configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
- configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
- configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
- }
- configuration.getStringValue(sonePrefix + "/Posts/" + postCounter + "/ID").setValue(null);
-
- /* save replies. */
- int replyCounter = 0;
- for (PostReply reply : sone.getReplies()) {
- String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
- configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
- configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
- configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
- configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
- }
- configuration.getStringValue(sonePrefix + "/Replies/" + replyCounter + "/ID").setValue(null);
-
- /* save post likes. */
- int postLikeCounter = 0;
- for (String postId : sone.getLikedPostIds()) {
- configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter++ + "/ID").setValue(postId);
- }
- configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter + "/ID").setValue(null);
-
- /* save reply likes. */
- int replyLikeCounter = 0;
- for (String replyId : sone.getLikedReplyIds()) {
- configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter++ + "/ID").setValue(replyId);
- }
- configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
-
- /* save friends. */
- int friendCounter = 0;
- for (String friendId : sone.getFriends()) {
- configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter++ + "/ID").setValue(friendId);
- }
- configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null);
-
- /* save albums. first, collect in a flat structure, top-level first. */
- List<Album> albums = FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).toList();
-
- int albumCounter = 0;
- for (Album album : albums) {
- String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
- configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId());
- configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
- configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
- configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
- configuration.getStringValue(albumPrefix + "/AlbumImage").setValue(album.getAlbumImage() == null ? null : album.getAlbumImage().getId());
- }
- configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
-
- /* save images. */
- int imageCounter = 0;
- for (Album album : albums) {
- for (Image image : album.getImages()) {
- if (!image.isInserted()) {
- continue;
- }
- String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
- configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
- configuration.getStringValue(imagePrefix + "/Album").setValue(album.getId());
- configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
- configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());
- configuration.getStringValue(imagePrefix + "/Description").setValue(image.getDescription());
- configuration.getLongValue(imagePrefix + "/CreationTime").setValue(image.getCreationTime());
- configuration.getIntValue(imagePrefix + "/Width").setValue(image.getWidth());
- configuration.getIntValue(imagePrefix + "/Height").setValue(image.getHeight());
- }
- }
- configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
-
- /* save options. */
- configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
- configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
- configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
- configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
-
- configuration.save();
-
- webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
-
- logger.log(Level.INFO, String.format("Sone %s saved.", sone));
- } catch (ConfigurationException ce1) {
- logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1);
- }
- }
-
- /**