}
private LocalSone loadLocalSone(OwnIdentity ownIdentity) {
- LocalSone localSone = newSoneBuilder().from(ownIdentity).using(
- new Client("Sone", SonePlugin.VERSION.toString())).buildLocal();
+ final SoneBuilder soneBuilder = newSoneBuilder().from(ownIdentity).using(
+ new Client("Sone", SonePlugin.VERSION.toString()));
+
+ loadElements(soneBuilder, ownIdentity.getId());
+
+ LocalSone localSone = soneBuilder.buildLocal();
+ loadSone(localSone);
+ localSone.setKnown(true);
localSone.setLatestEdition(
Optional.fromNullable(
Longs.tryParse(ownIdentity.getProperty(LATEST_EDITION_PROPERTY)))
.or(0L));
- localSone.setKnown(true);
-
- loadSone(localSone);
return localSone;
}
- private void loadSone(LocalSone sone) {
- long soneTime = configurationLoader.getLocalSoneTime(sone.getId());
- if (soneTime == -1) {
- return;
- }
+ private void loadElements(SoneBuilder soneBuilder, String soneId) {
+ ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, soneId);
- /* load profile. */
- ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone);
- Profile profile = configurationSoneParser.parseProfile();
-
- /* load posts. */
- Collection<Post> posts;
try {
- posts = configurationSoneParser.parsePosts(this);
+ Set<Post> posts = configurationSoneParser.parsePosts(this);
+ soneBuilder.withPosts(posts);
+ for (Post post : posts) {
+ post.setKnown(true);
+ }
} catch (InvalidPostFound ipf) {
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- /* load replies. */
- Collection<PostReply> postReplies;
try {
- postReplies = configurationSoneParser.parsePostReplies(this);
+ Set<PostReply> postReplies = configurationSoneParser.parsePostReplies(this);
+ soneBuilder.withPostReplies(postReplies);
+ for (PostReply reply : postReplies) {
+ reply.setKnown(true);
+ }
} catch (InvalidPostReplyFound iprf) {
logger.log(Level.WARNING, "Invalid reply found, aborting load!");
return;
}
+ }
+
+ private void loadSone(LocalSone sone) {
+ long soneTime = configurationLoader.getLocalSoneTime(sone.getId());
+ if (soneTime == -1) {
+ return;
+ }
+
+ /* load profile. */
+ ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone.getId());
+ Profile profile = configurationSoneParser.parseProfile(sone);
/* load post likes. */
Set<String> likedPostIds = configurationSoneParser.parseLikedPostIds();
/* load albums. */
List<Album> topLevelAlbums;
try {
- topLevelAlbums = configurationSoneParser.parseTopLevelAlbums(this);
+ topLevelAlbums = configurationSoneParser.parseTopLevelAlbums(this, sone);
} catch (InvalidAlbumFound iaf) {
logger.log(Level.WARNING, "Invalid album found, aborting load!");
return;
/* load images. */
try {
- configurationSoneParser.parseImages(this);
+ configurationSoneParser.parseImages(this, sone);
} catch (InvalidImageFound iif) {
logger.log(WARNING, "Invalid image found, aborting load!");
return;
lastInsertFingerprints.put(sone.getId(), lastInsertFingerprint);
allSones.put(sone.getId(), sone);
- storePosts(sone.getId(), posts);
- storePostReplies(sone.getId(), postReplies);
+ storePosts(sone.getId(), sone.getPosts());
+ storePostReplies(sone.getId(), sone.getReplies());
storeAlbums(sone.getId(), topLevelAlbums);
storeImages(sone.getId(), from(topLevelAlbums).transformAndConcat(Album.FLATTENER).transformAndConcat(Album.IMAGES).toList());
} finally {
lock.writeLock().unlock();
}
- for (Post post : posts) {
- post.setKnown(true);
- }
- for (PostReply reply : postReplies) {
- reply.setKnown(true);
- }
logger.info(String.format("Sone loaded successfully: %s", sone));
}
public ConfigurationSoneParserTest() {
when(sone.getId()).thenReturn("1");
configurationSoneParser =
- new ConfigurationSoneParser(configuration, sone);
+ new ConfigurationSoneParser(configuration, "1");
}
@Test
public void emptyProfileIsLoadedCorrectly() {
setupEmptyProfile();
- Profile profile = configurationSoneParser.parseProfile();
+ Profile profile = configurationSoneParser.parseProfile(sone);
assertThat(profile, notNullValue());
assertThat(profile.getFirstName(), nullValue());
assertThat(profile.getMiddleName(), nullValue());
@Test
public void filledProfileWithFieldsIsParsedCorrectly() {
setupFilledProfile();
- Profile profile = configurationSoneParser.parseProfile();
+ Profile profile = configurationSoneParser.parseProfile(sone);
assertThat(profile, notNullValue());
assertThat(profile.getFirstName(), is("First"));
assertThat(profile.getMiddleName(), is("M."));
AlbumBuilderFactory albumBuilderFactory = createAlbumBuilderFactory();
List<Album> topLevelAlbums =
configurationSoneParser.parseTopLevelAlbums(
- albumBuilderFactory);
+ albumBuilderFactory, sone);
assertThat(topLevelAlbums, hasSize(2));
Album firstAlbum = topLevelAlbums.get(0);
assertThat(firstAlbum, isAlbum("A1", null, "T1", "D1", "I1"));
public void albumWithInvalidTitleIsRecognized() {
setupAlbum(0, "A1", null, null, "D1", "I1");
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
}
@Test(expected = InvalidAlbumFound.class)
public void albumWithInvalidDescriptionIsRecognized() {
setupAlbum(0, "A1", null, "T1", null, "I1");
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
}
@Test(expected = InvalidParentAlbumFound.class)
public void albumWithInvalidParentIsRecognized() {
setupAlbum(0, "A1", "A0", "T1", "D1", "I1");
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
}
@Test
public void imagesAreParsedCorrectly() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImages();
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
Map<String, Album> albums = configurationSoneParser.getAlbums();
assertThat(albums.get("A1").getImages(),
contains(isImage("I1", 1000L, "K1", "T1", "D1", 16, 9)));
public void missingAlbumIdIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", null, 1000L, "K1", "T1", "D1", 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidParentAlbumFound.class)
public void invalidAlbumIdIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A4", 1000L, "K1", "T1", "D1", 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingCreationTimeIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", null, "K1", "T1", "D1", 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingKeyIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", 1000L, null, "T1", "D1", 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingTitleIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", 1000L, "K1", null, "D1", 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingDescriptionIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", 1000L, "K1", "T1", null, 16, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingWidthIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", 1000L, "K1", "T1", "D1", null, 9);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
@Test(expected = InvalidImageFound.class)
public void missingHeightIsRecognized() {
setupTopLevelAlbums();
configurationSoneParser.parseTopLevelAlbums(
- createAlbumBuilderFactory());
+ createAlbumBuilderFactory(), sone);
setupImage(0, "I1", "A1", 1000L, "K1", "T1", "D1", 16, null);
- configurationSoneParser.parseImages(createImageBuilderFactory());
+ configurationSoneParser.parseImages(createImageBuilderFactory(), sone);
}
}