]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1573] start work on browse screen
authorOlivier Lamy <olamy@apache.org>
Thu, 16 Feb 2012 21:26:48 +0000 (21:26 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 16 Feb 2012 21:26:48 +0000 (21:26 +0000)
navigate on groupIds.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1245184 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 [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/BrowseGroupIdResult.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
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/BrowseAction.java

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
new file mode 100644 (file)
index 0000000..32c64f7
--- /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 = "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
new file mode 100644 (file)
index 0000000..309daf3
--- /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 = "browseGroupIdResult" )
+public class BrowseGroupIdResult
+{
+    private List<BrowseGroupIdEntry> browseGroupIdEntries;
+
+    public BrowseGroupIdResult()
+    {
+        // no op
+    }
+
+    public BrowseGroupIdResult( List<BrowseGroupIdEntry> browseGroupIdEntries )
+    {
+        // no op
+    }
+
+    public List<BrowseGroupIdEntry> getBrowseGroupIdEntries()
+    {
+        return browseGroupIdEntries == null ? Collections.<BrowseGroupIdEntry>emptyList() : browseGroupIdEntries;
+    }
+
+    public void setBrowseGroupIdEntries( List<BrowseGroupIdEntry> browseGroupIdEntries )
+    {
+        this.browseGroupIdEntries = browseGroupIdEntries;
+    }
+}
index 9e6b85423cfbfc4b9fb2e422eafa129af7659c82..a1fd181f678b6cad10f89282a945200ed6b8218d 100644 (file)
@@ -18,14 +18,15 @@ 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.GroupIdList;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
-import java.util.List;
 
 /**
  * @author Olivier Lamy
@@ -40,4 +41,11 @@ public interface BrowseService
     @RedbackAuthorization( noRestriction = true, noPermission = false )
     GroupIdList 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 )
+        throws ArchivaRestServiceException;
 }
index c83b9f19cc8aa0ec24e4b6010c29c4c54119232e..7bee58a43d884b6a5af4653a002ab1693f7d1f03 100644 (file)
@@ -21,6 +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.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.BrowseService;
@@ -90,7 +92,69 @@ public class DefaultBrowseService
         return new GroupIdList( getSortedList( namespaces ) );
     }
 
-    //---------------------------
+    public BrowseGroupIdResult browseGroupId( String groupId )
+        throws ArchivaRestServiceException
+    {
+
+        List<String> selectedRepos = getObservableRepos();
+        if ( CollectionUtils.isEmpty( selectedRepos ) )
+        {
+            // FIXME 403 ???
+            return new BrowseGroupIdResult();
+        }
+
+        Set<String> projects = new LinkedHashSet<String>();
+
+        RepositorySession repositorySession = repositorySessionFactory.createSession();
+        Set<String> namespaces;
+        try
+        {
+            MetadataResolver metadataResolver = repositorySession.getResolver();
+
+            Set<String> namespacesToCollapse = new LinkedHashSet<String>();
+            for ( String repoId : selectedRepos )
+            {
+                namespacesToCollapse.addAll( metadataResolver.resolveNamespaces( repositorySession, repoId, groupId ) );
+
+                projects.addAll( metadataResolver.resolveProjects( repositorySession, repoId, groupId ) );
+            }
+
+            // TODO: this logic should be optional, particularly remembering we want to keep this code simple
+            // it is located here to avoid the content repository implementation needing to do too much for what
+            // is essentially presentation code
+            namespaces = new LinkedHashSet<String>();
+            for ( String n : namespacesToCollapse )
+            {
+                // TODO: check performance of this
+                namespaces.add(
+                    collapseNamespaces( repositorySession, metadataResolver, selectedRepos, groupId + "." + n ) );
+            }
+        }
+        catch ( MetadataResolutionException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() );
+        }
+        finally
+        {
+            repositorySession.close();
+        }
+        List<BrowseGroupIdEntry> browseGroupIdEntries =
+            new ArrayList<BrowseGroupIdEntry>( namespaces.size() + projects.size() );
+        for ( String namespace : namespaces )
+        {
+            browseGroupIdEntries.add( new BrowseGroupIdEntry( namespace, false ) );
+        }
+        for ( String project : projects )
+        {
+            browseGroupIdEntries.add( new BrowseGroupIdEntry( project, true ) );
+        }
+        Collections.sort( browseGroupIdEntries );
+        return new BrowseGroupIdResult( browseGroupIdEntries );
+
+    }
+
+//---------------------------
     // internals
     //---------------------------
 
index 4d55519c41ae1d3302fcae13e4e3356b9da83f54..4a7744369c2719097502909cc2ae0ffe2af6ccad 100644 (file)
@@ -21,12 +21,28 @@ $(function() {
   BrowseTopViewModel=function(groupIds){
     this.groupIds=groupIds;
 
+    displayGroupDetail=function(groupId){
+      $.log("groupId:"+groupId);
+      $.ajax("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId), {
+          type: "GET",
+          dataType: 'json',
+          success: function(data) {
+            var groupdIds = $.map(data.groupIdList.groupIds,function(item){
+              return item;
+            });
+            $.log("size:"+groupdIds.length);
+            //var browseTopViewModel = new BrowseTopViewModel(groupdIds);
 
+            //ko.applyBindings(browseTopViewModel,mainContent.find("#browse_result" ).get(0));
+          }
+      });
+    }
   }
 
   displayBrowse=function(){
     var mainContent = $("#main-content");
-    mainContent.html(mediumSpinnerImg());
+    mainContent.html($("#browse-tmpl" ).tmpl());
+    mainContent.find("#browse_result").html(mediumSpinnerImg());
     $.ajax("restServices/archivaServices/browseService/rootGroups", {
         type: "GET",
         dataType: 'json',
@@ -36,7 +52,7 @@ $(function() {
           });
           $.log("size:"+groupdIds.length);
           var browseTopViewModel = new BrowseTopViewModel(groupdIds);
-          mainContent.html($("#browse-tmpl" ).tmpl());
+
           ko.applyBindings(browseTopViewModel,mainContent.find("#browse_result" ).get(0));
         }
     });
index 7443fcd20809299a1a10bd02891570a06f6a9c23..d6b050ad6c6fd401606973761f350272b55af544 100644 (file)
       <h2>${$.i18n.prop('browse.groups')}</h2>
     </div>
   </div>
-  <div id="browse_result" data-bind='template:{name:"browse-top-tmpl"}'>
+  <div id="browse_result" class="well" data-bind='template:{name:"browse-top-tmpl"}'>
 
   </div>
 </script>
 
 <script id="browse-top-tmpl" type="text/html">
-  <div class="well">
+  <div>
     <ul>
       {{each(i,groupId) groupIds}}
-        <li class="browse-list">&nbsp;${groupId}</li>
+        <li class="browse-list">
+          <a href="#" data-bind="click: function(){displayGroupDetail(groupId)}">&nbsp;${groupId}</a>
+        </li>
       {{/each}}
     </ul>
   </div>
index a0d18cd31e65a02e09e4ac2ff25ae9b84ab3c171..5c040c7290c64ef05f38db5d4566518c2c333489 100644 (file)
@@ -163,8 +163,8 @@ public class BrowseAction
             }
 
             // TODO: this logic should be optional, particularly remembering we want to keep this code simple
-            //       it is located here to avoid the content repository implementation needing to do too much for what
-            //       is essentially presentation code
+            // it is located here to avoid the content repository implementation needing to do too much for what
+            // is essentially presentation code
             namespaces = new LinkedHashSet<String>();
             for ( String n : namespacesToCollapse )
             {