From: <pa...@us...> - 2010-06-23 16:04:23
|
Revision: 20974 http://gallery.svn.sourceforge.net/gallery/?rev=20974&view=rev Author: paour Date: 2010-06-23 16:04:16 +0000 (Wed, 23 Jun 2010) Log Message: ----------- Added creating albums. Modified Paths: -------------- trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm.java trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm3.java trunk/gallery_remote/com/gallery/GalleryRemote/GalleryCommTest.java trunk/gallery_remote/com/gallery/GalleryRemote/MainFrame.java trunk/gallery_remote/com/gallery/GalleryRemote/model/Gallery.java Modified: trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm.java =================================================================== --- trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm.java 2010-06-23 12:41:35 UTC (rev 20973) +++ trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm.java 2010-06-23 16:04:16 UTC (rev 20974) @@ -149,12 +149,8 @@ * the specified album (or at the root if album is null) * * @param su an instance that implements the StatusUpdate interface. - * @param parentAlbum if null, create the album in the root of the gallery; otherwise - * create as a child of the given album */ - public String newAlbum(StatusUpdate su, Album parentAlbum, - String newAlbumName, String newAlbumTitle, - String newAlbumDesc, boolean async) { + public void newAlbum(StatusUpdate su, Album album, boolean async) { throw new RuntimeException("This method is not available on this protocol"); } Modified: trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm3.java =================================================================== --- trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm3.java 2010-06-23 12:41:35 UTC (rev 20973) +++ trunk/gallery_remote/com/gallery/GalleryRemote/GalleryComm3.java 2010-06-23 16:04:16 UTC (rev 20974) @@ -54,6 +54,11 @@ doTask(uploadTask, async); } + public void newAlbum(StatusUpdate su, Album album, boolean async) { + NewAlbumTask newAlbumTask = new NewAlbumTask(su, album); + doTask(newAlbumTask, async); + } + public boolean checkAuth() { try { sendRequest(g.getUrlString() + api + "item/1", "get", (HttpEntity) null); @@ -508,9 +513,9 @@ ContentBody body = new FileBody(p.getUploadSource()); entity.addPart("file", body); - BufferedReader r = sendRequest(p.getParentAlbum().getUrl(), "post", entity); + BufferedReader entityReader = sendRequest(p.getParentAlbum().getUrl(), "post", entity); - String url = ((JSONObject) JSONValue.parse(r)).get("url").toString(); + String url = ((JSONObject) JSONValue.parse(entityReader)).get("url").toString(); status(su, StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "upSucc")); p.setUrl(url); @@ -566,6 +571,44 @@ } } + class NewAlbumTask extends GalleryTask { + Album album; + + NewAlbumTask(StatusUpdate su, Album album) { + super(su); + this.album = album; + } + + void runTask() { + status(su, StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "newAlbm", new Object[] { album.getName(), g.toString() })); + + try { + List<NameValuePair> formparams = new ArrayList<NameValuePair>(); + JSONObject jsonEntity = new JSONObject(); + jsonEntity.put("type", "album"); + if (album.getName() != null) + jsonEntity.put("name", album.getName()); + if (album.getTitle() != null) + jsonEntity.put("title", album.getTitle()); + if (album.getDescription() != null) + jsonEntity.put("description", album.getDescription()); + formparams.add(new BasicNameValuePair("entity", jsonEntity.toJSONString())); + + BufferedReader entityReader = sendRequest(album.getParentAlbum().getUrl(), "post", formparams); + + String url = ((JSONObject) JSONValue.parse(entityReader)).get("url").toString(); + status(su, StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "crateAlbmOk")); + album.setUrl(url); + + Log.log(Log.LEVEL_INFO, "Created album " + album.toString()); + } catch (IOException ioe) { + Log.logException(Log.LEVEL_ERROR, MODULE, ioe); + Object[] params2 = {ioe.toString()}; + error(su, GRI18n.getString(MODULE, "error", params2)); + } + } + } + /** * This class serves as the base class for each GalleryComm task. */ Modified: trunk/gallery_remote/com/gallery/GalleryRemote/GalleryCommTest.java =================================================================== --- trunk/gallery_remote/com/gallery/GalleryRemote/GalleryCommTest.java 2010-06-23 12:41:35 UTC (rev 20973) +++ trunk/gallery_remote/com/gallery/GalleryRemote/GalleryCommTest.java 2010-06-23 16:04:16 UTC (rev 20974) @@ -84,6 +84,21 @@ assertNotNull(p.getUrl()); } + @Test + public void testCreateAlbumToRoot() { + Album a = new Album(g); + a.setUrl(g.getUrlString() + "index.php/rest/item/1"); + Album na = new Album(g); + a.add(na); + g.setRoot(a); + na.setName("New Album"); + na.setTitle("New Album Title"); + na.setDescription("Created by testCreateNewAlbum"); + assertNull(na.getUrl()); + comm.newAlbum(su, na, false); + assertNotNull(na.getUrl()); + } + @BeforeClass public static void setupAll() { GalleryRemote.createInstance("com.gallery.GalleryRemote.GalleryRemoteMainFrame", null); Modified: trunk/gallery_remote/com/gallery/GalleryRemote/MainFrame.java =================================================================== --- trunk/gallery_remote/com/gallery/GalleryRemote/MainFrame.java 2010-06-23 12:41:35 UTC (rev 20973) +++ trunk/gallery_remote/com/gallery/GalleryRemote/MainFrame.java 2010-06-23 16:04:16 UTC (rev 20974) @@ -819,10 +819,10 @@ return; } - String newAlbumName = getCurrentGallery().doNewAlbum(newAlbum, GalleryRemote._().getCore().getMainStatusUpdate()); - if (!newAlbumName.equals(newAlbum.getName())) { - newAlbum.setName(newAlbumName); - } + getCurrentGallery().doNewAlbum(newAlbum, GalleryRemote._().getCore().getMainStatusUpdate()); +// if (!newAlbumName.equals(newAlbum.getName())) { +// newAlbum.setName(newAlbumName); +// } newAlbum.fetchAlbumProperties(GalleryRemote._().getCore().getMainStatusUpdate()); Modified: trunk/gallery_remote/com/gallery/GalleryRemote/model/Gallery.java =================================================================== --- trunk/gallery_remote/com/gallery/GalleryRemote/model/Gallery.java 2010-06-23 12:41:35 UTC (rev 20973) +++ trunk/gallery_remote/com/gallery/GalleryRemote/model/Gallery.java 2010-06-23 16:04:16 UTC (rev 20974) @@ -133,25 +133,24 @@ } } - public String doNewAlbum(Album a, StatusUpdate su) { + public void doNewAlbum(Album a, StatusUpdate su) { Log.log(Log.LEVEL_INFO, MODULE, "Creating new album " + a.toString()); // create album synchronously - String newAlbumName = getComm(su).newAlbum(su, a.getParentAlbum(), a.getName(), - a.getTitle(), a.getDescription(), false); + getComm(su).newAlbum(su, a, false); // refresh album list asynchronously //fetchAlbums(su); - if (!newAlbumName.equals(a.getName())) { - //Log.log(Log.LEVEL_INFO, MODULE, "Album name probably conflicted on the server, need to reload album list"); - //getComm(su).fetchAlbums(su, false); - a.setName(newAlbumName); - } +// if (!newAlbumName.equals(a.getName())) { +// //Log.log(Log.LEVEL_INFO, MODULE, "Album name probably conflicted on the server, need to reload album list"); +// //getComm(su).fetchAlbums(su, false); +// a.setName(newAlbumName); +// } //addAlbum(a); - return newAlbumName; + //return newAlbumName; } public void incrementViewCount(Picture p, StatusUpdate su) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |