You are viewing a plain text version of this content. The canonical link for it is here.
Posted to photark-commits@incubator.apache.org by lr...@apache.org on 2010/11/01 21:18:10 UTC

svn commit: r1029844 - in /incubator/photark/branches/photark-rest/photark-jcr: ./ src/main/java/org/apache/photark/jcr/services/ src/main/java/org/apache/photark/jcr/util/ src/main/java/org/apache/photark/services/jcr/ src/test/java/org/apache/photark...

Author: lresende
Date: Mon Nov  1 21:18:10 2010
New Revision: 1029844

URL: http://svn.apache.org/viewvc?rev=1029844&view=rev
Log:
JCR basic implementation of the PhotArk REST Apis

Removed:
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageCollectionImpl.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/jcr/util/ArchiveFileExtractor.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/AlbumCollection.java
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRAlbumCollection.java
    incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/album/jcr/GalleryTestCase.java
Modified:
    incubator/photark/branches/photark-rest/photark-jcr/pom.xml
    incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRGallery.java
    incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/jcr/JCRGalleryTestCase.java
    incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite

Modified: incubator/photark/branches/photark-rest/photark-jcr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-jcr/pom.xml?rev=1029844&r1=1029843&r2=1029844&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-jcr/pom.xml (original)
+++ incubator/photark/branches/photark-rest/photark-jcr/pom.xml Mon Nov  1 21:18:10 2010
@@ -7,15 +7,15 @@
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License.  You may obtain a copy of the License at
-    * 
+    *
     *   http://www.apache.org/licenses/LICENSE-2.0
-    * 
+    *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied.  See the License for the
     * specific language governing permissions and limitations
-    * under the License.    
+    * under the License.
 -->
 <project>
 	<modelVersion>4.0.0</modelVersion>
@@ -32,7 +32,7 @@
 		<dependency>
 			<groupId>org.apache.photark</groupId>
 			<artifactId>photark</artifactId>
-			<version>1.0-incubating-SNAPSHOT</version>
+			<version>${project.version}</version>
 		</dependency>
 
         <!-- Tuscany Dependencies -->
@@ -61,14 +61,6 @@
 			<groupId>org.apache.jackrabbit</groupId>
 			<artifactId>jackrabbit-core</artifactId>
 			<version>1.6.1</version>
-			<!-- 
-			<exclusions>
-				<exclusion>
-					<artifactId>jackrabbit-text-extractors</artifactId>
-					<groupId>org.apache.jackrabbit</groupId>
-				</exclusion>
-			</exclusions>
-		    -->
 		</dependency>
 
 		<!-- Use Log4J for logging -->
@@ -117,18 +109,32 @@
 			<version>${tuscany.version}</version>
 			<scope>test</scope>
 		</dependency>
-						
+
 		<dependency>
 			<groupId>org.apache.tuscany.sca</groupId>
 			<artifactId>tuscany-node-impl</artifactId>
 			<version>${tuscany.version}</version>
 			<scope>test</scope>
 		</dependency>
-				
+
+		<dependency>
+			<groupId>org.apache.tuscany.sca</groupId>
+			<artifactId>tuscany-host-jetty</artifactId>
+			<version>${tuscany.version}</version>
+			<scope>test</scope>
+		</dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
-			<version>4.5</version>
+			<version>4.8.1</version>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>httpunit</groupId>
+			<artifactId>httpunit</artifactId>
+			<version>1.7</version>
 			<scope>test</scope>
 		</dependency>
 	</dependencies>

Modified: incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRGallery.java
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRGallery.java?rev=1029844&r1=1029843&r2=1029844&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRGallery.java (original)
+++ incubator/photark/branches/photark-rest/photark-jcr/src/main/java/org/apache/photark/services/jcr/JCRGallery.java Mon Nov  1 21:18:10 2010
@@ -6,24 +6,30 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
  */
 
 package org.apache.photark.services.jcr;
 
 import java.security.InvalidParameterException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.jcr.LoginException;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -32,83 +38,221 @@ import org.apache.photark.AlbumList;
 import org.apache.photark.AlbumRef;
 import org.apache.photark.services.GalleryService;
 import org.apache.photark.services.PhotarkRuntimeException;
-import org.apache.tuscany.sca.data.collection.Entry;
+import org.oasisopen.sca.annotation.Init;
 import org.oasisopen.sca.annotation.Reference;
 import org.oasisopen.sca.annotation.Scope;
 
 /**
  * JCR based Gallery
- * 
+ *
  * @version $Rev$ $Date$
  */
 @Scope("COMPOSITE")
 public class JCRGallery implements GalleryService {
+    private static final String JCR_ALBUM_ROOT_NODE = "albums";
+
     private static final Logger logger = Logger.getLogger(JCRGallery.class.getName());
 
+    private Map<String, Album> albums = new HashMap<String, Album>();
+
     private JCRRepositoryManager repositoryManager;
-    
-    public JCRAlbumCollection albumCollection;
-    
+
     public JCRGallery(@Reference(name="repositoryManager") JCRRepositoryManager repositoryManager) {
         this.repositoryManager = repositoryManager;
     }
-    
+
+    @Init
+    public void init() {
+        try {
+            if(logger.isLoggable(Level.FINE)) {
+                logger.fine("Initializing JCR Gallery");
+            }
+
+            //get all albums from the repository
+            Node albumRootNode = getAlbumRoot(repositoryManager);
+            NodeIterator albumNodes = albumRootNode.getNodes();
+            while (albumNodes.hasNext()) {
+                Node albumNode = albumNodes.nextNode();
+                if(albumNode != null) {
+                    Album album = fromNode(albumNode);
+                    albums.put(album.getName(), album);
+                }
+            }
+
+            if(logger.isLoggable(Level.FINE)) {
+                logger.fine("Found '" + albums.size() + "' albums in the repository");
+            }
+
+        } catch (Exception e) {
+            logger.log(Level.SEVERE, "Error retrieving list of Albums :" + e.getMessage(), e);
+        }
+    }
+
     public AlbumList getAlbums() {
-        //get all albums from the repository
-        Entry<String, Album>[] albumEntries = albumCollection.getAll();
-        
-        AlbumList albums = new AlbumList();
+        AlbumList albumList = new AlbumList();
         //loop trough the entries and create a albumRef for each Album
-        for(Entry<String, Album> albumEntry : albumEntries) {
-            albums.getAlbums().add(AlbumRef.createAlbumRef(albumEntry.getData()));
+        Iterator<Entry<String, Album>> albumIterator = albums.entrySet().iterator();
+        while(albumIterator.hasNext()) {
+            Album album = (Album) albumIterator.next().getValue();
+            albumList.getAlbums().add(AlbumRef.createAlbumRef(album));
         }
-        return null;
+
+        return albumList;
     }
 
     public Album getAlbum(String albumId) {
         if(albumId == null || albumId.isEmpty()) {
             throw new InvalidParameterException("Invalid/Empty album id");
         }
-        
-        Album album = null;
-        try {
-            //find the album based on the albumId
-            Session session = repositoryManager.getSession();
-            Node root = session.getRootNode();
-            Node albumNode = root.getNode(albumId);
-            
-            //convert albumNode to a Album object
-            album = fromNode(albumNode);
-        } catch (Exception e) {
-            logger.log(Level.WARNING,"Error retrieving album '" + albumId + "' : " + e.getMessage(), e);
-        } 
 
-        return album;
+        if(! albums.containsKey(albumId)) {
+            throw new InvalidParameterException("Album '" + albumId + "' not found");
+        }
+
+        return albums.get(albumId);
     }
 
     public void addAlbum(Album newAlbum) throws PhotarkRuntimeException {
         if(newAlbum.getName() == null || newAlbum.getName().isEmpty()) {
             throw new InvalidParameterException("Album has no name");
         }
+
+        try {
+            Node albumRootNode = getAlbumRoot(repositoryManager);
+
+            if(albumRootNode.hasNode(newAlbum.getName())) {
+                throw new PhotarkRuntimeException("Error creating album. Album '" + newAlbum.getName() + "' already exists !");
+            }
+
+            Node albumNode = albumRootNode.addNode(newAlbum.getName());
+            if(albumNode != null) {
+                albumNode.setProperty("name", newAlbum.getName());
+                albumNode.setProperty("description", newAlbum.getDescription());
+                albumNode.setProperty("name", newAlbum.getLocation());
+                repositoryManager.getSession().save();
+            }
+
+            albums.put(newAlbum.getName(), newAlbum);
+
+        } catch(RepositoryException e) {
+            if(logger.isLoggable(Level.SEVERE)) {
+                logger.log(Level.SEVERE, "Error creating new album node '" + newAlbum.getName() + "'" );
+            }
+            throw new PhotarkRuntimeException("Error creating new album node '" + newAlbum.getName() + "'" );
+        }
     }
 
     public void updateAlbum(Album album) throws PhotarkRuntimeException {
         if(album.getName() == null || album.getName().isEmpty()) {
             throw new InvalidParameterException("Album has no name");
         }
+
+        if(! albums.containsKey(album.getName())) {
+            if(logger.isLoggable(Level.SEVERE)) {
+                logger.log(Level.SEVERE, "Album '" + album.getName() + "' not found");
+            }
+            throw new InvalidParameterException("Album '" + album.getName() + "' not found");
+        }
+
+        try {
+            Node albumRootNode = getAlbumRoot(repositoryManager);
+
+            if(! albumRootNode.hasNode(album.getName())) {
+                if(logger.isLoggable(Level.SEVERE)) {
+                    logger.log(Level.SEVERE, "Album node '" + album.getName() + "' not found in the JCR repository");
+                }
+
+                throw new PhotarkRuntimeException("Album node '" + album.getName()  + "' not found in the JCR repository");
+            }
+
+            Node albumNode = albumRootNode.getNode(album.getName());
+            albumNode.setProperty("name", album.getName());
+            albumNode.setProperty("description", album.getDescription());
+            albumNode.setProperty("name", album.getLocation());
+            repositoryManager.getSession().save();
+
+            albums.put(album.getName(), album);
+
+        } catch(RepositoryException e) {
+            if(logger.isLoggable(Level.SEVERE)) {
+                logger.log(Level.SEVERE, "Error updating album node '" + album.getName() + "'" );
+            }
+            throw new PhotarkRuntimeException("Error updating album node '" + album.getName() + "'" );
+        }
+
+
     }
 
     public void removeAlbum(String albumName) throws PhotarkRuntimeException {
         if(albumName == null || albumName.isEmpty()) {
-            throw new InvalidParameterException("Invalid/Empty album id");
+            throw new InvalidParameterException("Invalid/Empty album name");
+        }
+
+
+        if(! albums.containsKey(albumName)) {
+            if(logger.isLoggable(Level.SEVERE)) {
+                logger.log(Level.SEVERE, "Album '" + albumName + "' not found");
+            }
+            throw new InvalidParameterException("Album '" + albumName + "' not found");
+        }
+
+        try {
+            Node albumRootNode = getAlbumRoot(repositoryManager);
+
+            if(! albumRootNode.hasNode(albumName)) {
+                if(logger.isLoggable(Level.SEVERE)) {
+                    logger.log(Level.SEVERE, "Album node '" + albumName + "' not found in the JCR repository");
+                }
+
+                throw new PhotarkRuntimeException("Album node '" + albumName  + "' not found in the JCR repository");
+            }
+
+            Node albumNode = albumRootNode.getNode(albumName);
+            albumNode.remove();
+            repositoryManager.getSession().save();
+
+            albums.remove(albumName);
+
+        } catch(RepositoryException e) {
+            if(logger.isLoggable(Level.SEVERE)) {
+                logger.log(Level.SEVERE, "Error deleting album node '" + albumName + "'" );
+            }
+            throw new PhotarkRuntimeException("Error deleting album node '" + albumName + "'" );
         }
     }
-        
-    private Album fromNode(Node albumNode) throws RepositoryException {
+
+    private static Album fromNode(Node albumNode) throws RepositoryException {
         Album album = new Album();
         album.setName(albumNode.getName());
         album.setDescription(albumNode.getProperty("description").getString());
-        
+
         return album;
     }
+
+
+    private static Node getAlbumRoot(JCRRepositoryManager repositoryManager) throws PhotarkRuntimeException {
+        Session session = null;
+        Node root = null;
+        Node albumRoot = null;
+        try {
+            session = repositoryManager.getSession();
+            root = session.getRootNode();
+            if (root.hasNode(JCR_ALBUM_ROOT_NODE)) {
+                albumRoot = root.getNode(JCR_ALBUM_ROOT_NODE);
+            } else {
+                albumRoot = root.addNode(JCR_ALBUM_ROOT_NODE);
+                session.save();
+            }
+        } catch (LoginException e) {
+            logger.log(Level.SEVERE, "Error loging in to photark repository :" + e.getMessage(), e);
+            throw new PhotarkRuntimeException("Error loging in to photark repository  :" + e.getMessage(), e);
+        } catch (RepositoryException e) {
+            logger.log(Level.SEVERE, "Error retrieving albums from the repository :" + e.getMessage(), e);
+            throw new PhotarkRuntimeException("Error retrieving albums from the repository :" + e.getMessage(), e);
+        }
+
+        return albumRoot;
+    }
+
+
 }

Modified: incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/jcr/JCRGalleryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/jcr/JCRGalleryTestCase.java?rev=1029844&r1=1029843&r2=1029844&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/jcr/JCRGalleryTestCase.java (original)
+++ incubator/photark/branches/photark-rest/photark-jcr/src/test/java/org/apache/photark/services/jcr/JCRGalleryTestCase.java Mon Nov  1 21:18:10 2010
@@ -2,16 +2,19 @@ package org.apache.photark.services.jcr;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import junit.framework.Assert;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONException;
-import net.sf.json.JSONObject;
 
 import org.apache.tuscany.sca.node.Contribution;
 import org.apache.tuscany.sca.node.ContributionLocationHelper;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -23,106 +26,120 @@ import com.meterware.httpunit.WebRequest
 import com.meterware.httpunit.WebResponse;
 
 public class JCRGalleryTestCase {
-	private static final String GALLERY_SERVICE_URL = "http://localhost:8085/gallery";
+    private static final String GALLERY_SERVICE_URL = "http://localhost:8085/gallery";
 
-	private static Node node;
+    private static Node node;
 
-	@BeforeClass
-	public static void BeforeClass() {
-		try {
-			String contribution = ContributionLocationHelper
-					.getContributionLocation("gallery.composite");
-			node = NodeFactory.newInstance().createNode("gallery.composite",
-					new Contribution("gallery", contribution));
-			node.start();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-	
-	@AfterClass
+    @BeforeClass
+    public static void BeforeClass() {
+        try {
+            String contribution = ContributionLocationHelper.getContributionLocation("gallery.composite");
+            node = NodeFactory.newInstance().createNode("gallery.composite", new Contribution("gallery", contribution));
+            node.start();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @AfterClass
     public static void AfterClass() {
         node.stop();
     }
-    
-	
-	  @Test
-	    public void testGetAlbums() throws IOException, JSONException {
-	        JSONArray albums = readAlbums();
-
-	        //for debug purposes
-	        //System.out.println(">>>" + jsonResponse.toString());    
-	        
-	        Assert.assertNotNull(albums);
-	        
-	    }
-
-	    @Test
-	    public void testAddAlbums() throws IOException, JSONException {
-	        JSONArray albums = readAlbums();
-	        int albumSize = albums.size();
-	        
-	        //for debug purposes
-	        //System.out.println(">>>" + jsonResponse.toString());    
-	        
-	        addAlbum();
-
-	        albums = readAlbums();
-
-	        //for debug purposes
-	        //System.out.println(">>>" + jsonResponse.toString());    
-	        
-	        Assert.assertEquals(albumSize + 1, albums.size());
-	    }
-	    
-	    @Test
-	    public void testRemoveAlbums() throws IOException, JSONException {
-	        WebConversation wc = new WebConversation();
-	        WebRequest request = new GetMethodWebRequest(GALLERY_SERVICE_URL + "/" + getLastAlbumName());
-	        ((GetMethodWebRequest) request).setMethod("DELETE");
-	        WebResponse response = wc.getResource(request);
-	        
-	        Assert.assertEquals(200, response.getResponseCode());
-	    }
-
-
-	    private JSONArray readAlbums()  throws IOException, JSONException {
-	        WebConversation wc = new WebConversation();
-	        WebRequest request = new GetMethodWebRequest(GALLERY_SERVICE_URL);
-	        WebResponse response = wc.getResource(request);
-	        JSONObject jsonResponse = new JSONObject();
-	        //TODO initialize josonResponse
-	        JSONArray albums = (JSONArray) jsonResponse.get("albums");
-	        return albums;
-	    }
-	    
-	    private void addAlbum() throws IOException, JSONException {
-	        JSONObject jsonAlbum = new JSONObject();
-	        jsonAlbum.put("name", getNewAlbumName());
-	        
-	        WebConversation wc = new WebConversation();
-	        WebRequest request   = new PostMethodWebRequest(GALLERY_SERVICE_URL, new ByteArrayInputStream(jsonAlbum.toString().getBytes("UTF-8")),"application/json");
-	        request.setHeaderField("Content-Type", "application/json");
-	        WebResponse response = wc.getResource(request);
-	        
-	        Assert.assertEquals(204, response.getResponseCode());
-	    }
-	    
-	    private String getNewAlbumName() throws IOException, JSONException {
-	        JSONArray albums = readAlbums();
-	        JSONObject album = (JSONObject) albums.get(albums.size() -1);
-	        String albumName = album.getString("name");
-	        String[] tokens = albumName.split("-");
-	        albumName = tokens[0] + "-" + (Integer.parseInt(tokens[1]) + 1);
-	        
-	        return albumName;
-	    }
-	    
-	    private String getLastAlbumName() throws IOException, JSONException {
-	        JSONArray albums = readAlbums();
-	        JSONObject album = (JSONObject) albums.get(albums.size() -1);
-	        String albumName = album.getString("name");
-	        
-	        return albumName;
-	    }
+
+    @Test
+    public void testGetAlbums() throws IOException, JSONException {
+        String[] albums = readAlbums();
+
+        //for debug purposes
+        //System.out.println(">>>" + jsonResponse.toString());
+
+        Assert.assertNotNull(albums);
+    }
+
+    @Test
+    public void testAddAlbums() throws IOException, JSONException {
+        String[] albums = readAlbums();
+        int albumSize = albums.length;
+
+        //for debug purposes
+        //System.out.println(">>>" + jsonResponse.toString());
+
+        addAlbum();
+
+        albums = readAlbums();
+
+        //for debug purposes
+        //System.out.println(">>>" + jsonResponse.toString());
+
+        Assert.assertEquals(albumSize + 1, albums.length);
+    }
+
+    @Test
+    public void testRemoveAlbums() throws IOException, JSONException {
+        WebConversation wc = new WebConversation();
+        WebRequest request = new GetMethodWebRequest(GALLERY_SERVICE_URL + "/" + getLastAlbumName());
+        ((GetMethodWebRequest) request).setMethod("DELETE");
+        WebResponse response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+    }
+
+    private void addAlbum() throws IOException, JSONException {
+        JSONObject jsonAlbum = new JSONObject();
+        String albumName = getNewAlbumName();
+        jsonAlbum.put("name", albumName);
+        jsonAlbum.put("description", "Some description to my album : " + albumName);
+
+        WebConversation wc = new WebConversation();
+        WebRequest request   = new PostMethodWebRequest(GALLERY_SERVICE_URL, new ByteArrayInputStream(jsonAlbum.toString().getBytes("UTF-8")),"application/json");
+        request.setHeaderField("Content-Type", "application/json");
+        WebResponse response = wc.getResource(request);
+
+        Assert.assertEquals(204, response.getResponseCode());
+    }
+
+    private String[] readAlbums()  throws IOException, JSONException {
+        WebConversation wc = new WebConversation();
+        WebRequest request = new GetMethodWebRequest(GALLERY_SERVICE_URL);
+        WebResponse response = wc.getResource(request);
+
+        JSONObject jsonResponse = new JSONObject(response.getText());
+
+        //for debug purposes
+        System.out.println(">>>" + jsonResponse.toString());
+
+        JSONArray albums = (org.json.JSONArray) jsonResponse.get("albums");
+        List<String> albumNames = new ArrayList<String>();
+        for(int pos=0; pos<albums.length(); pos++) {
+            JSONObject album = (JSONObject) albums.get(pos);
+            albumNames.add( album.getString("name"));
+        }
+
+        String[] albumNameArray = new String[albumNames.size()];
+        albumNames.toArray(albumNameArray);
+        Arrays.sort(albumNameArray, String.CASE_INSENSITIVE_ORDER);
+
+        return albumNameArray;
+    }
+
+    private String getNewAlbumName() throws IOException, JSONException {
+        String[] albums = readAlbums();
+        String album = null;
+        if (albums.length == 0) {
+            album = "album-0";
+        } else {
+            album = albums[albums.length -1 ];
+            String[] tokens = album.split("-");
+            album = tokens[0] + "-" + (Integer.parseInt(tokens[1]) + 1);
+        }
+        return album;
+    }
+
+    private String getLastAlbumName() throws IOException, JSONException {
+        String[] albums = readAlbums();
+        String album = albums[albums.length -1];
+
+        return album;
+    }
+
 }

Modified: incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite?rev=1029844&r1=1029843&r2=1029844&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite (original)
+++ incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite Mon Nov  1 21:18:10 2010
@@ -7,15 +7,15 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
 -->
 <composite	xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
 		xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
@@ -25,23 +25,21 @@
     <!-- Component responsible for providing JCR Management Support -->
     <component name="RepositoryManager">
 		<implementation.java class="org.apache.photark.services.jcr.JCRRepositoryManager"/>
-		<property name="repositoryHome">photark</property>
-	</component> 	
-	
+		<property name="repositoryHome">target/photark</property>
+	</component>
+
 	<component name="SubscriptionComponent">
 		<implementation.java class="org.apache.photark.services.jcr.JCRSubscriptionCollection"/>
 		<reference name="repositoryManager" target="RepositoryManager"/>
 	</component>
 
-	<!--		
 	<component name="GalleryComponent">
 		<implementation.java class="org.apache.photark.services.jcr.JCRGallery"/>
-		<property name="galleryRoot">gallery-root</property> 
 		<service name="GalleryService">
 			<tuscany:binding.rest uri="http://localhost:8085/gallery">
 			    <tuscany:operationSelector.jaxrs />
     		</tuscany:binding.rest>
-   		</service>	
+   		</service>
+   		<reference name="repositoryManager" target="RepositoryManager" />
 	</component>
-	-->
 </composite>