]> source.dussan.org Git - archiva.git/commitdiff
simplify by reusing an existing class
authorOlivier Lamy <olamy@apache.org>
Tue, 29 May 2012 16:34:21 +0000 (16:34 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 29 May 2012 16:34:21 +0000 (16:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1343826 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactDownloadInfo.java [deleted file]
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-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html

index 2adeece4c0a0b51c4dcae7efae2cae39308929a8..027aca7de8e7a090dd6091544b5171ec22639975 100644 (file)
@@ -134,6 +134,12 @@ public class Artifact
      */
     private String fileExtension;
 
+    /**
+     * human readable size : not available for all services
+     * @since 1.4-M3
+     */
+    private String size;
+
 
     public Artifact()
     {
@@ -358,6 +364,16 @@ public class Artifact
         this.fileExtension = fileExtension;
     }
 
+    public String getSize()
+    {
+        return size;
+    }
+
+    public void setSize( String size )
+    {
+        this.size = size;
+    }
+
     @Override
     public String toString()
     {
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactDownloadInfo.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactDownloadInfo.java
deleted file mode 100644 (file)
index 612281a..0000000
+++ /dev/null
@@ -1,206 +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 org.apache.archiva.metadata.model.ArtifactMetadata;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.Locale;
-
-/**
- * @author Olivier Lamy
- * @since 1.4-M3
- */
-@XmlRootElement( name = "artifactDownloadInfo" )
-public class ArtifactDownloadInfo
-    implements Serializable
-{
-    private String type;
-
-    private String namespace;
-
-    private String project;
-
-    private String size;
-
-    private String id;
-
-    private String repositoryId;
-
-    private String version;
-
-    private String path;
-
-    private String classifier;
-
-    public ArtifactDownloadInfo()
-    {
-        // no op
-    }
-
-    public ArtifactDownloadInfo( ArtifactMetadata artifact, String path, String type, String classifier )
-    {
-        this.repositoryId = artifact.getRepositoryId();
-        this.path = path.substring( 0, path.lastIndexOf( "/" ) + 1 ) + artifact.getId();
-
-        this.type = type;
-        this.classifier = classifier;
-
-        this.namespace = artifact.getNamespace();
-        this.project = artifact.getProject();
-
-        // TODO: find a reusable formatter for this
-        double s = artifact.getSize();
-        String symbol = "b";
-        if ( s > 1024 )
-        {
-            symbol = "K";
-            s /= 1024;
-
-            if ( s > 1024 )
-            {
-                symbol = "M";
-                s /= 1024;
-
-                if ( s > 1024 )
-                {
-                    symbol = "G";
-                    s /= 1024;
-                }
-            }
-        }
-
-        DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) );
-        this.size = df.format( s ) + " " + symbol;
-        this.id = artifact.getId();
-        this.version = artifact.getVersion();
-    }
-
-    public String getType()
-    {
-        return type;
-    }
-
-    public void setType( String type )
-    {
-        this.type = type;
-    }
-
-    public String getNamespace()
-    {
-        return namespace;
-    }
-
-    public void setNamespace( String namespace )
-    {
-        this.namespace = namespace;
-    }
-
-    public String getProject()
-    {
-        return project;
-    }
-
-    public void setProject( String project )
-    {
-        this.project = project;
-    }
-
-    public String getSize()
-    {
-        return size;
-    }
-
-    public void setSize( String size )
-    {
-        this.size = size;
-    }
-
-    public String getId()
-    {
-        return id;
-    }
-
-    public void setId( String id )
-    {
-        this.id = id;
-    }
-
-    public String getRepositoryId()
-    {
-        return repositoryId;
-    }
-
-    public void setRepositoryId( String repositoryId )
-    {
-        this.repositoryId = repositoryId;
-    }
-
-    public String getVersion()
-    {
-        return version;
-    }
-
-    public void setVersion( String version )
-    {
-        this.version = version;
-    }
-
-    public String getPath()
-    {
-        return path;
-    }
-
-    public void setPath( String path )
-    {
-        this.path = path;
-    }
-
-    public String getClassifier()
-    {
-        return classifier;
-    }
-
-    public void setClassifier( String classifier )
-    {
-        this.classifier = classifier;
-    }
-
-    @Override
-    public String toString()
-    {
-        final StringBuilder sb = new StringBuilder();
-        sb.append( "ArtifactDownloadInfo" );
-        sb.append( "{type='" ).append( type ).append( '\'' );
-        sb.append( ", namespace='" ).append( namespace ).append( '\'' );
-        sb.append( ", project='" ).append( project ).append( '\'' );
-        sb.append( ", size='" ).append( size ).append( '\'' );
-        sb.append( ", id='" ).append( id ).append( '\'' );
-        sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
-        sb.append( ", version='" ).append( version ).append( '\'' );
-        sb.append( ", path='" ).append( path ).append( '\'' );
-        sb.append( ", classifier='" ).append( classifier ).append( '\'' );
-        sb.append( '}' );
-        return sb.toString();
-    }
-
-}
index 22028c4ab275c68197d6098374e42896e8199062..539a4f13577d9da3ab7d52ffa19adf352fff33b5 100644 (file)
@@ -24,7 +24,6 @@ import org.apache.archiva.redback.authorization.RedbackAuthorization;
 import org.apache.archiva.rest.api.model.Artifact;
 import org.apache.archiva.rest.api.model.ArtifactContent;
 import org.apache.archiva.rest.api.model.ArtifactContentEntry;
-import org.apache.archiva.rest.api.model.ArtifactDownloadInfo;
 import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.model.Entry;
 import org.apache.archiva.rest.api.model.TreeEntry;
@@ -165,7 +164,7 @@ public interface BrowseService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noPermission = true, noRestriction = true )
-    List<ArtifactDownloadInfo> getArtifactDownloadInfos( @PathParam( "g" ) String groupId,
+    List<Artifact> getArtifactDownloadInfos( @PathParam( "g" ) String groupId,
                                                          @PathParam( "a" ) String artifactId,
                                                          @PathParam( "v" ) String version,
                                                          @QueryParam( "repositoryId" ) String repositoryId )
index 1bad078d57c32debe4c4092b2de1d3fa29c39daf..290a9292a62e5a3fa51f9cfd41f3086d3f5c7b0a 100644 (file)
@@ -41,7 +41,6 @@ import org.apache.archiva.repository.RepositoryNotFoundException;
 import org.apache.archiva.rest.api.model.Artifact;
 import org.apache.archiva.rest.api.model.ArtifactContent;
 import org.apache.archiva.rest.api.model.ArtifactContentEntry;
-import org.apache.archiva.rest.api.model.ArtifactDownloadInfo;
 import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.model.BrowseResultEntry;
 import org.apache.archiva.rest.api.model.Entry;
@@ -661,13 +660,13 @@ public class DefaultBrowseService
         return Collections.emptyList();
     }
 
-    public List<ArtifactDownloadInfo> getArtifactDownloadInfos( String groupId, String artifactId, String version,
-                                                                String repositoryId )
+    public List<Artifact> getArtifactDownloadInfos( String groupId, String artifactId, String version,
+                                                    String repositoryId )
         throws ArchivaRestServiceException
     {
         List<String> selectedRepos = getSelectedRepos( repositoryId );
 
-        List<ArtifactDownloadInfo> artifactDownloadInfos = new ArrayList<ArtifactDownloadInfo>();
+        List<Artifact> artifactDownloadInfos = new ArrayList<Artifact>();
 
         RepositorySession session = repositorySessionFactory.createSession();
 
index 21d98e9063a5a3ae85771f20bee777874bf27100..5c550b6d954875111a8fdeffcf37468b03da19a3 100644 (file)
@@ -22,7 +22,11 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
 import org.apache.archiva.model.ArtifactReference;
 import org.apache.archiva.repository.ManagedRepositoryContent;
-import org.apache.archiva.rest.api.model.ArtifactDownloadInfo;
+import org.apache.archiva.rest.api.model.Artifact;
+
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
 
 /**
  * @author Olivier Lamy
@@ -53,14 +57,14 @@ public class ArtifactDownloadInfoBuilder
         return this;
     }
 
-    public ArtifactDownloadInfo build()
+    public Artifact build()
     {
         ArtifactReference ref = new ArtifactReference();
         ref.setArtifactId( artifactMetadata.getProject() );
         ref.setGroupId( artifactMetadata.getNamespace() );
         ref.setVersion( artifactMetadata.getVersion() );
         String path = managedRepositoryContent.toPath( ref );
-        path = path.substring( 0, path.lastIndexOf( "/" ) + 1 ) + artifactMetadata.getId();
+        //path = path.substring( 0, path.lastIndexOf( "/" ) + 1 ) + artifactMetadata.getId();
 
         String type = null, classifier = null;
 
@@ -71,8 +75,32 @@ public class ArtifactDownloadInfoBuilder
             classifier = facet.getClassifier();
         }
 
-        ArtifactDownloadInfo artifactDownloadInfo =
-            new ArtifactDownloadInfo( this.artifactMetadata, path, type, classifier );
+        Artifact artifactDownloadInfo = new Artifact( ref.getGroupId(), ref.getArtifactId(), ref.getVersion() );
+        artifactDownloadInfo.setClassifier( classifier );
+        artifactDownloadInfo.setPackaging( type );
+        // TODO: find a reusable formatter for this
+        double s = this.artifactMetadata.getSize();
+        String symbol = "b";
+        if ( s > 1024 )
+        {
+            symbol = "K";
+            s /= 1024;
+
+            if ( s > 1024 )
+            {
+                symbol = "M";
+                s /= 1024;
+
+                if ( s > 1024 )
+                {
+                    symbol = "G";
+                    s /= 1024;
+                }
+            }
+        }
+
+        DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) );
+        artifactDownloadInfo.setSize( df.format( s ) + " " + symbol );
         return artifactDownloadInfo;
 
     }
index 4e3e11369228cf94d4827bf2fca52fd388ce2cdb..db94da2fe98d9f39713b04e4a5f641470656c101 100644 (file)
         <div class="span5">
            <ul id="artifact-content-list-files">
            {{each artifactDownloadInfos}}
-             <li id="${$value.classifier}:${$value.version}:${$value.type}">
-               <a href="#">${$value.type}:${$value.version}&nbsp;-&nbsp;${$value.size}</a>
+             <li id="${$value.classifier}:${$value.version}:${$value.packaging}">
+               <a href="#">${$value.packaging}:${$value.version}&nbsp;-&nbsp;${$value.size}</a>
              </li>
            {{/each}}
            </ul>