Commits

Sebastian Sdorra committed 566bb4e

use repositorymanager in repositoryresource

Comments (0)

Files changed (7)

scm-webapp/src/main/java/sonia/scm/api/rest/JsonJaxbContextResolver.java

   {
     this.context = new JSONJAXBContext(
         JSONConfiguration.mapped().rootUnwrapping(true).arrays(
-          "member", "groups", "permissions", "repositoryTypes").nonStrings(
-          "readable", "writeable", "groupPermission").build(), types.toArray(
-          new Class[0]));
+          "member", "groups", "permissions", "repositories",
+          "repositoryTypes").nonStrings(
+            "readable", "writeable", "groupPermission").build(), types.toArray(
+            new Class[0]));
   }
 
   //~--- get methods ----------------------------------------------------------

scm-webapp/src/main/java/sonia/scm/api/rest/resources/AbstractResource.java

    *
    *
    * @param item
+   *
+   * @throws Exception
    */
-  protected abstract void addItem(T item);
+  protected abstract void addItem(T item) throws Exception;
 
   /**
    * Method description
    *
    *
    * @param item
+   *
+   * @throws Exception
    */
-  protected abstract void removeItem(T item);
+  protected abstract void removeItem(T item) throws Exception;
 
   /**
    * Method description
    *
    * @param name
    * @param item
+   *
+   * @throws Exception
    */
-  protected abstract void updateItem(String name, T item);
+  protected abstract void updateItem(String name, T item) throws Exception;
 
   //~--- get methods ----------------------------------------------------------
 
   @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
   public Response add(@Context UriInfo uriInfo, T item)
   {
-    addItem(item);
+    try
+    {
+      addItem(item);
+    }
+    catch (Exception ex)
+    {
+      throw new WebApplicationException(ex);
+    }
 
     return Response.created(
         uriInfo.getAbsolutePath().resolve(
       throw new WebApplicationException(Response.Status.NOT_FOUND);
     }
 
-    removeItem(item);
+    try
+    {
+      removeItem(item);
+    }
+    catch (Exception ex)
+    {
+      throw new WebApplicationException(ex);
+    }
 
     return Response.noContent().build();
   }
   public Response update(@Context UriInfo uriInfo,
                          @PathParam("name") String name, T item)
   {
-    T updateItem = getItem(name);
-
-    if (updateItem == null)
+    try
     {
-      throw new WebApplicationException(Response.Status.NOT_FOUND);
+      updateItem(name, item);
     }
-
-    updateItem(name, item);
+    catch (Exception ex)
+    {
+      throw new WebApplicationException(ex);
+    }
 
     return Response.created(
         uriInfo.getAbsolutePath().resolve(getId(item))).build();

scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java

 //~--- non-JDK imports --------------------------------------------------------
 
 import com.google.inject.Inject;
+import com.google.inject.Singleton;
 
-import sonia.scm.SCMContext;
 import sonia.scm.ScmState;
 import sonia.scm.User;
 import sonia.scm.repository.RepositoryManager;
  * @author Sebastian Sdorra
  */
 @Path("authentication")
+@Singleton
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class AuthenticationResource
 {

scm-webapp/src/main/java/sonia/scm/api/rest/resources/GroupResource.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.inject.Singleton;
+
 import sonia.scm.group.Group;
 
 //~--- JDK imports ------------------------------------------------------------
  * @author Sebastian Sdorra
  */
 @Path("groups")
+@Singleton
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class GroupResource extends AbstractResource<Group>
 {

scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
-import sonia.scm.repository.Permission;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
 import sonia.scm.repository.Repository;
+import sonia.scm.repository.RepositoryException;
+import sonia.scm.repository.RepositoryManager;
 
 //~--- JDK imports ------------------------------------------------------------
 
+import java.io.IOException;
+
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.UUID;
 
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
  * @author Sebastian Sdorra
  */
 @Path("repositories")
+@Singleton
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class RepositoryResource extends AbstractResource<Repository>
 {
   /** Field description */
   public static final String PATH_PART = "repositories";
 
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   */
-  public RepositoryResource()
-  {
-    repositoryStore = new LinkedHashMap<String, Repository>();
-    repositoryStore.put("sonia.lib",
-                        new Repository(createId(), "hg", "sonia.lib",
-                                       "csit@ostfalia.de", "SONIA Library",
-                                       new Permission("csit", true, true,
-                                         true)));
-    repositoryStore.put("sonia.misc",
-                        new Repository(createId(), "hg", "sonia.misc",
-                                       "csit@ostfalia.de",
-                                       "SONIA Miscelanious",
-                                       new Permission("csit", true, true,
-                                         true)));
-    repositoryStore.put("PWA",
-                        new Repository(createId(), "svn", "PWA",
-                                       "csit@fh-wolfenbuettel.de", "PWA",
-                                       new Permission("th", true, true),
-                                       new Permission("sdorra", true, true),
-                                       new Permission("oelkersd", true,
-                                         false)));
-    repositoryStore.put("sonia.app",
-                        new Repository(createId(), "hg", "sonia.app",
-                                       "csit@ostfalia.de",
-                                       "SONIA Applications",
-                                       new Permission("csit", true, true,
-                                         true)));
-    repositoryStore.put("sonia.webapps",
-                        new Repository(createId(), "hg", "sonia.webapps",
-                                       "csit@ostfalia.de",
-                                       "SONIA WebApplications",
-                                       new Permission("csit", true, true,
-                                         true)));
-  }
-
   //~--- methods --------------------------------------------------------------
 
   /**
    *
    *
    * @param item
+   *
+   * @throws IOException
+   * @throws RepositoryException
    */
   @Override
   protected void addItem(Repository item)
+          throws RepositoryException, IOException
   {
-    repositoryStore.put(item.getName(), item);
+    repositoryManager.create(item);
   }
 
   /**
    *
    *
    * @param item
+   *
+   * @throws IOException
+   * @throws RepositoryException
    */
   @Override
   protected void removeItem(Repository item)
+          throws RepositoryException, IOException
   {
-    repositoryStore.remove(item.getName());
+    repositoryManager.delete(item);
   }
 
   /**
    *
    * @param name
    * @param item
+   *
+   * @throws IOException
+   * @throws RepositoryException
    */
   @Override
   protected void updateItem(String name, Repository item)
+          throws RepositoryException, IOException
   {
-    Repository repository = repositoryStore.get(name);
-
-    repository.setContact(item.getContact());
-    repository.setDescription(item.getDescription());
+    repositoryManager.modify(item);
   }
 
   //~--- get methods ----------------------------------------------------------
   @Override
   protected Repository[] getAllItems()
   {
-    Collection<Repository> repositoryCollection = repositoryStore.values();
+    Collection<Repository> repositoryCollection = repositoryManager.getAll();
 
     return repositoryCollection.toArray(
         new Repository[repositoryCollection.size()]);
   @Override
   protected String getId(Repository item)
   {
-    return item.getName();
+    return item.getId();
   }
 
   /**
    * Method description
    *
    *
-   * @param name
+   *
+   * @param id
    *
    * @return
    */
   @Override
-  protected Repository getItem(String name)
+  protected Repository getItem(String id)
   {
-    return repositoryStore.get(name);
+    return repositoryManager.get(id);
   }
 
   /**
     return PATH_PART;
   }
 
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  private String createId()
-  {
-    return UUID.randomUUID().toString();
-  }
-
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */
-  private HashMap<String, Repository> repositoryStore;
+  @Inject
+  private RepositoryManager repositoryManager;
 }

scm-webapp/src/main/webapp/resources/js/sonia.repository.js

     var repositoryStore = new Sonia.rest.JsonStore({
       url: restUrl + 'repositories.json',
       root: 'repositories',
-      fields: [ 'name', 'type', 'contact', 'description' ],
+      fields: [ 'id', 'name', 'type', 'contact', 'description' ],
       sortInfo: {
         field: 'name'
       }
     var config = {
       store: repositoryStore,
       colModel: repositoryColModel,
-      idField: 'name',
+      idField: 'id',
       searchField: 'name',
       editForm: 'repositoryEditForm',
       restAddUrl: restUrl + 'repositories.json',

scm-webapp/src/main/webapp/resources/js/sonia.rest.js

               fn: function(item){
 
                 var store = this.store;
-                var id = item[this.idField];
+                var id = data[this.idField];
+                item[this.idField] = id;
                 var url = String.format(this.restEditUrlPattern, id);
 
                 if ( debug ){
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.