]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1573]
authorOlivier Lamy <olamy@apache.org>
Thu, 16 Feb 2012 23:31:40 +0000 (23:31 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 16 Feb 2012 23:31:40 +0000 (23:31 +0000)
refactor to have more generic REST model result.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1245254 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdEntry.java [deleted file]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdResult.java [deleted file]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseIdEntry.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseResult.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html

diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdEntry.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdEntry.java
deleted file mode 100644 (file)
index 32c64f7..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.apache.archiva.rest.api.model;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * 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.
- */
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * @author Olivier Lamy
- * @since 1.4-M3
- */
-@XmlRootElement( name = "browseGroupIdEntry" )
-public class BrowseGroupIdEntry
-    implements Comparable<BrowseGroupIdEntry>
-{
-
-    private String name;
-
-    private boolean project;
-
-    public BrowseGroupIdEntry()
-    {
-        // no op
-    }
-
-    public BrowseGroupIdEntry( String name, boolean project )
-    {
-        this.name = name;
-        this.project = project;
-    }
-
-    public String getName()
-    {
-        return name;
-    }
-
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-
-    public boolean isProject()
-    {
-        return project;
-    }
-
-    public void setProject( boolean project )
-    {
-        this.project = project;
-    }
-
-    public int compareTo( BrowseGroupIdEntry browseGroupIdEntry )
-    {
-        return this.name.compareTo( browseGroupIdEntry.name );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdResult.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdResult.java
deleted file mode 100644 (file)
index bafad96..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.archiva.rest.api.model;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * 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.
- */
-
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Olivier Lamy
- * @since 1.4-M3
- */
-@XmlRootElement( name = "browseGroupIdResult" )
-public class BrowseGroupIdResult
-{
-    private List<BrowseGroupIdEntry> browseGroupIdEntries;
-
-    public BrowseGroupIdResult()
-    {
-        // no op
-    }
-
-    public BrowseGroupIdResult( List<BrowseGroupIdEntry> browseGroupIdEntries )
-    {
-        this.browseGroupIdEntries = browseGroupIdEntries;
-    }
-
-    public List<BrowseGroupIdEntry> getBrowseGroupIdEntries()
-    {
-        return browseGroupIdEntries == null ? Collections.<BrowseGroupIdEntry>emptyList() : browseGroupIdEntries;
-    }
-
-    public void setBrowseGroupIdEntries( List<BrowseGroupIdEntry> browseGroupIdEntries )
-    {
-        this.browseGroupIdEntries = browseGroupIdEntries;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseIdEntry.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseIdEntry.java
new file mode 100644 (file)
index 0000000..598a4fd
--- /dev/null
@@ -0,0 +1,71 @@
+package org.apache.archiva.rest.api.model;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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.
+ */
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@XmlRootElement( name = "browseIdEntry" )
+public class BrowseIdEntry
+    implements Comparable<BrowseIdEntry>
+{
+
+    private String name;
+
+    private boolean project;
+
+    public BrowseIdEntry()
+    {
+        // no op
+    }
+
+    public BrowseIdEntry( String name, boolean project )
+    {
+        this.name = name;
+        this.project = project;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public boolean isProject()
+    {
+        return project;
+    }
+
+    public void setProject( boolean project )
+    {
+        this.project = project;
+    }
+
+    public int compareTo( BrowseIdEntry browseGroupIdEntry )
+    {
+        return this.name.compareTo( browseGroupIdEntry.name );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseResult.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseResult.java
new file mode 100644 (file)
index 0000000..b7a9cdd
--- /dev/null
@@ -0,0 +1,53 @@
+package org.apache.archiva.rest.api.model;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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.
+ */
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@XmlRootElement( name = "browseResult" )
+public class BrowseResult
+{
+    private List<BrowseIdEntry> browseIdEntries;
+
+    public BrowseResult()
+    {
+        // no op
+    }
+
+    public BrowseResult( List<BrowseIdEntry> browseIdEntries )
+    {
+        this.browseIdEntries = browseIdEntries;
+    }
+
+    public List<BrowseIdEntry> getBrowseIdEntries()
+    {
+        return browseIdEntries == null ? Collections.<BrowseIdEntry>emptyList() : browseIdEntries;
+    }
+
+    public void setBrowseIdEntries( List<BrowseIdEntry> browseIdEntries )
+    {
+        this.browseIdEntries = browseIdEntries;
+    }
+}
index a1fd181f678b6cad10f89282a945200ed6b8218d..1e7584a8a62e589428e8a2f3cfddac0c817a5a09 100644 (file)
@@ -18,7 +18,7 @@ package org.apache.archiva.rest.api.services;
  * under the License.
  */
 
-import org.apache.archiva.rest.api.model.BrowseGroupIdResult;
+import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.model.GroupIdList;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
@@ -39,13 +39,13 @@ public interface BrowseService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noRestriction = true, noPermission = false )
-    GroupIdList getRootGroups()
+    BrowseResult getRootGroups()
         throws ArchivaRestServiceException;
 
     @Path( "browseGroupId/{groupId}" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noRestriction = true, noPermission = false )
-    BrowseGroupIdResult browseGroupId(@PathParam( "groupId" ) String groupId )
+    BrowseResult browseGroupId(@PathParam( "groupId" ) String groupId )
         throws ArchivaRestServiceException;
 }
index 7bee58a43d884b6a5af4653a002ab1693f7d1f03..d30463ea451019cc68450b683a57653032d7586c 100644 (file)
@@ -21,9 +21,8 @@ package org.apache.archiva.rest.services;
 import org.apache.archiva.metadata.repository.MetadataResolutionException;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.rest.api.model.BrowseGroupIdEntry;
-import org.apache.archiva.rest.api.model.BrowseGroupIdResult;
-import org.apache.archiva.rest.api.model.GroupIdList;
+import org.apache.archiva.rest.api.model.BrowseIdEntry;
+import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.BrowseService;
 import org.apache.commons.collections.CollectionUtils;
@@ -47,14 +46,14 @@ public class DefaultBrowseService
     implements BrowseService
 {
 
-    public GroupIdList getRootGroups()
+    public BrowseResult getRootGroups()
         throws ArchivaRestServiceException
     {
         List<String> selectedRepos = getObservableRepos();
         if ( CollectionUtils.isEmpty( selectedRepos ) )
         {
             // FIXME 403 ???
-            return new GroupIdList( Collections.<String>emptyList() );
+            return new BrowseResult();
         }
 
         Set<String> namespaces = new LinkedHashSet<String>();
@@ -89,10 +88,17 @@ public class DefaultBrowseService
             repositorySession.close();
         }
 
-        return new GroupIdList( getSortedList( namespaces ) );
+        List<BrowseIdEntry> browseGroupIdEntries = new ArrayList<BrowseIdEntry>( namespaces.size() );
+        for ( String namespace : namespaces )
+        {
+            browseGroupIdEntries.add( new BrowseIdEntry( namespace, false ) );
+        }
+
+        Collections.sort( browseGroupIdEntries );
+        return new BrowseResult( browseGroupIdEntries );
     }
 
-    public BrowseGroupIdResult browseGroupId( String groupId )
+    public BrowseResult browseGroupId( String groupId )
         throws ArchivaRestServiceException
     {
 
@@ -100,7 +106,7 @@ public class DefaultBrowseService
         if ( CollectionUtils.isEmpty( selectedRepos ) )
         {
             // FIXME 403 ???
-            return new BrowseGroupIdResult();
+            return new BrowseResult();
         }
 
         Set<String> projects = new LinkedHashSet<String>();
@@ -139,22 +145,21 @@ public class DefaultBrowseService
         {
             repositorySession.close();
         }
-        List<BrowseGroupIdEntry> browseGroupIdEntries =
-            new ArrayList<BrowseGroupIdEntry>( namespaces.size() + projects.size() );
+        List<BrowseIdEntry> browseGroupIdEntries = new ArrayList<BrowseIdEntry>( namespaces.size() + projects.size() );
         for ( String namespace : namespaces )
         {
-            browseGroupIdEntries.add( new BrowseGroupIdEntry( namespace, false ) );
+            browseGroupIdEntries.add( new BrowseIdEntry( namespace, false ) );
         }
         for ( String project : projects )
         {
-            browseGroupIdEntries.add( new BrowseGroupIdEntry( project, true ) );
+            browseGroupIdEntries.add( new BrowseIdEntry( project, true ) );
         }
         Collections.sort( browseGroupIdEntries );
-        return new BrowseGroupIdResult( browseGroupIdEntries );
+        return new BrowseResult( browseGroupIdEntries );
 
     }
 
-//---------------------------
+    //---------------------------
     // internals
     //---------------------------
 
index ec021cf357e57efb35a0f5b1487f785b8f2c6dd6..cdcb8ac43094af87c61d706834d0071c7dca9b10 100644 (file)
  */
 $(function() {
 
-  BrowseTopViewModel=function(groupIds){
-    this.groupIds=groupIds;
-    var mainContent = $("#main-content");
-    var browseResult=mainContent.find("#browse_result");
-    displayGroupDetail=function(groupId){
-      browseResult.hide( "slide", {}, 500,
-        function(){
-          browseResult.html(mediumSpinnerImg());
-          browseResult.show();
-          $.ajax("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId), {
-            type: "GET",
-            dataType: 'json',
-            success: function(data) {
-              var browseGroupIdEntryies = $.isArray(data.browseGroupIdResult.browseGroupIdEntries) ?
-                   $.map(data.browseGroupIdResult.browseGroupIdEntries,function(item){
-                     return new BrowseGroupIdEntry(item.name, item.project);
-                   }): [data.browseGroupIdResult.browseGroupIdEntries];
-              browseResult.html($("#browse-groups-div-tmpl" ).tmpl());
-              var browseGroupsViewModel = new BrowseGroupsViewModel(browseGroupIdEntryies);
-
-              ko.applyBindings(browseGroupsViewModel,mainContent.find("#browse-groups-div" ).get(0));
-            }
-         });
-        }
-      );
-
+  BrowseTopViewModel=function(browseIdEntries){
+    this.browseIdEntries=browseIdEntries;
+    displayGroupId=function(groupId){
+      displayGroupDetail(groupId,"..");
     }
+
   }
 
-  BrowseGroupsViewModel=function(browseGroupIdEntryies){
-    this.browseGroupIdEntryies=browseGroupIdEntryies;
+  BrowseGroupsViewModel=function(browseIdEntries,parentGroupdId){
+    var self = this;
+    this.browseIdEntries=browseIdEntries;
+    this.parentGroupdId=parentGroupdId;
+    displayGroupId=function(groupId){
+      displayGroupDetail(groupId,self.parentGroupdId);
+    }
   }
 
   displayBrowse=function(){
@@ -59,23 +43,54 @@ $(function() {
         type: "GET",
         dataType: 'json',
         success: function(data) {
-          var groupdIds =
-              $.isArray(data.groupIdList.groupIds)? $.map(data.groupIdList.groupIds,function(item){
-                return item;
-              }): [data.groupIdList.groupIds];
-          $.log("size:"+groupdIds.length);
-          var browseTopViewModel = new BrowseTopViewModel(groupdIds);
+          var browseIdEntries = mapBrowseIdEntries(data);
+          $.log("size:"+browseIdEntries.length);
+          var browseTopViewModel = new BrowseTopViewModel(browseIdEntries);
 
           ko.applyBindings(browseTopViewModel,mainContent.find("#browse_result" ).get(0));
         }
     });
   }
 
+  displayGroupDetail=function(groupId,parentGroupdId){
+    var mainContent = $("#main-content");
+    var browseResult=mainContent.find("#browse_result");
+    browseResult.hide( "slide", {}, 500,
+      function(){
+        browseResult.html(mediumSpinnerImg());
+        browseResult.show();
+        var url = "restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId);
+        $.ajax(url, {
+          type: "GET",
+          dataType: 'json',
+          success: function(data) {
+            var browseIdEntries = mapBrowseIdEntries(data);
+            browseResult.html($("#browse-groups-div-tmpl" ).tmpl());
+            var browseGroupsViewModel = new BrowseGroupsViewModel(browseIdEntries,parentGroupdId);
+
+            ko.applyBindings(browseGroupsViewModel,mainContent.find("#browse-groups-div" ).get(0));
+          }
+       });
+      }
+    );
+
+  }
+
   displaySearch=function(){
     $("#main-content" ).html("coming soon :-)");
   }
 
-  BrowseGroupIdEntry=function(name,project){
+  mapBrowseIdEntries=function(data){
+    if (data.browseResult && data.browseResult.browseIdEntries) {
+      return $.isArray(data.browseResult.browseIdEntries) ?
+         $.map(data.browseResult.browseIdEntries,function(item){
+           return new BrowseIdEntry(item.name, item.project);
+         }): [data.browseResult.browseIdEntries];
+    }
+    return [];
+  }
+
+  BrowseIdEntry=function(name,project){
     this.name=name;
     this.project=project;
   }
index 3aa741654a98b5620569c20e6150ab5a3c1c708f..e065450fc14654b09389a328f3f980b9d73bdf9d 100644 (file)
@@ -22,6 +22,9 @@
     <div class="page-header">
       <h2>${$.i18n.prop('browse.groups')}</h2>
     </div>
+  </div>
+  <div id="browse_breadcrumb">
+
   </div>
   <div id="browse_result" class="well" data-bind='template:{name:"browse-top-tmpl"}'>
 
@@ -31,9 +34,9 @@
 <script id="browse-top-tmpl" type="text/html">
   <div>
     <ul>
-      {{each(i,groupId) groupIds}}
+      {{each(i,browseIdEntry) browseIdEntries}}
         <li class="browse-list">
-          <a href="#" data-bind="click: function(){displayGroupDetail(groupId)}">&nbsp;${groupId}</a>
+          <a href="#" data-bind="click: function(){displayGroupId(browseIdEntry.name)}">&nbsp;${browseIdEntry.name}</a>
         </li>
       {{/each}}
     </ul>
 <script id="browse-groups-tmpl" type="text/html">
   <div>
     <ul>
-      {{each(i,browseGroupIdEntry) browseGroupIdEntryies}}
+      <li class="browse-list"><a href="#" data-bind="click:function(){displayGroupId($root.parentGroupdId)}">..</a></li>
+      {{each(i,browseIdEntry) browseIdEntries}}
         <li class="browse-list">
-          <a href="#">&nbsp;${browseGroupIdEntry.name}-project: ${browseGroupIdEntry.project}</a>
+          <a href="#" data-bind="click:function(){displayGroupId(browseIdEntry.name)}">
+            &nbsp;${browseIdEntry.name}-project: ${browseIdEntry.project}
+          </a>
         </li>
       {{/each}}
     </ul>