Factor out some methods. working
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 14 Oct 2013 04:45:31 +0000 (06:45 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:25 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java

index 8473eb0..4f268ec 100644 (file)
@@ -62,15 +62,23 @@ public class CreateAlbumPage extends SoneTemplatePage {
                                templateContext.set("nameMissing", true);
                                return;
                        }
                                templateContext.set("nameMissing", true);
                                return;
                        }
-                       String description = request.getHttpRequest().getPartAsStringFailsafe("description", 256).trim();
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36);
-                       AlbumBuilderFactory parent = parentId.equals("") ? currentSone : webInterface.getCore().getAlbum(parentId).get();
-                       Album album = parent.newAlbumBuilder().randomId().build();
-                       album.modify().setTitle(name).setDescription(filter(request.getHttpRequest().getHeader("host"), description)).update();
+                       Album album = createAlbum(request, name);
                        webInterface.getCore().touchConfiguration();
                        throw new RedirectException("imageBrowser.html?album=" + album.getId());
                }
        }
 
                        webInterface.getCore().touchConfiguration();
                        throw new RedirectException("imageBrowser.html?album=" + album.getId());
                }
        }
 
+       private Album createAlbum(FreenetRequest request, String name) {
+               Sone currentSone = getCurrentSone(request.getToadletContext());
+               String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36);
+               AlbumBuilderFactory parent = parentId.equals("") ? currentSone : webInterface.getCore().getAlbum(parentId).get();
+               Album album = parent.newAlbumBuilder().randomId().build();
+               return setTitleAndDescription(request, name, album);
+       }
+
+       private Album setTitleAndDescription(FreenetRequest request, String name, Album album) {
+               String description = request.getHttpRequest().getPartAsStringFailsafe("description", 256).trim();
+               return album.modify().setTitle(name).setDescription(filter(request.getHttpRequest().getHeader("host"), description)).update();
+       }
+
 }
 }