]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1362] [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with...
authorJevica Arianne B. Zurbano <jzurbano@apache.org>
Thu, 27 May 2010 07:45:06 +0000 (07:45 +0000)
committerJevica Arianne B. Zurbano <jzurbano@apache.org>
Thu, 27 May 2010 07:45:06 +0000 (07:45 +0000)
* added delete of mailing list, dependency, and license entries

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

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld

index d148be496da3ae0fe4a8e7cfeccba743ec476c6d..077dcad61a96d072f253d629f8672497d94fd56e 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action;
 import com.opensymphony.xwork2.Validateable;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.Dependency;
+import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionReference;
@@ -102,6 +103,10 @@ public class ShowArtifactAction
     private boolean dependencyTree = false;
 
     private ProjectVersionMetadata projectMetadata;
+    
+    private String deleteItem;
+    
+    private String itemValue;
    
     /**
      * Show the versioned project information tab.
@@ -295,7 +300,90 @@ public class ShowArtifactAction
 
         return SUCCESS;
     }
-
+    
+    public String deleteMetadataEntry()
+    {   
+        projectMetadata = getProjectVersionMetadata();
+        
+        if ( !StringUtils.isEmpty( deleteItem ) && !StringUtils.isEmpty( itemValue ) )
+        {
+            if ( "dependency".equals( deleteItem ) )
+            {
+                removeDependency();
+            }
+            else if ( "mailingList".equals( deleteItem ) )
+            {
+                removeMailingList();
+            }
+            else if ( "license".equals( deleteItem ) )
+            {
+                removeLicense();
+            }
+            
+            deleteItem = "";
+            itemValue = "";
+        }
+        
+        return updateProjectMetadata();
+    }
+    
+    private void removeDependency()
+    {
+        List<Dependency> dependencies = projectMetadata.getDependencies();
+        List<Dependency> newDependencies = new ArrayList<Dependency>();
+        
+        if ( dependencies != null )
+        {
+            for ( Dependency dependency : dependencies )
+            {
+                if ( !StringUtils.equals( itemValue, dependency.getArtifactId() ) )
+                {
+                    newDependencies.add( dependency );
+                }
+            }
+        }
+        
+        projectMetadata.setDependencies( newDependencies );
+    }
+    
+    private void removeMailingList()
+    {
+        List<MailingList> mailingLists = projectMetadata.getMailingLists();
+        List<MailingList> newMailingLists = new ArrayList<MailingList>();
+        
+        if ( mailingLists != null )
+        {
+            for ( MailingList mailingList : mailingLists )
+            {
+                if ( !StringUtils.equals( itemValue, mailingList.getName() ) )
+                {
+                    newMailingLists.add( mailingList );
+                }
+            }
+        }
+        
+        projectMetadata.setMailingLists( newMailingLists );
+    }
+    
+    private void removeLicense()
+    {
+        List<License> licenses = projectMetadata.getLicenses();
+        List<License> newLicenses = new ArrayList<License>();
+        
+        if ( licenses != null )
+        {
+            for ( License license : licenses )
+            {
+                if ( !StringUtils.equals( itemValue, license.getName() ) )
+                {
+                    newLicenses.add( license );
+                }
+            }
+        }
+        
+        projectMetadata.setLicenses( newLicenses );
+    }
+    
     @Override
     public void validate()
     {
@@ -410,6 +498,16 @@ public class ShowArtifactAction
         this.projectMetadata = projectMetadata;
     }
 
+    public void setDeleteItem( String deleteItem )
+    {
+        this.deleteItem = deleteItem; 
+    }
+    
+    public void setItemValue( String itemValue )
+    {
+        this.itemValue = itemValue;
+    }
+
     // TODO: move this into the artifact metadata itself via facets where necessary
 
     public class ArtifactDownloadInfo
index d005446d38beea218b85478da5d07907a87730b8..73653c67bd30e1a29c6d37436bc80ae89432119a 100644 (file)
@@ -45,6 +45,12 @@ public class ProjectMetadataTag
     private Logger log = LoggerFactory.getLogger( ProjectMetadataTag.class );
 
     private Object object;
+    
+    private String groupId;
+
+    private String artifactId;
+
+    private String version;
 
     @Override
     public void release()
@@ -152,8 +158,12 @@ public class ProjectMetadataTag
             startList( metadataEntries );
             for ( License license : licenses )
             {
+                createDeleteLink( "license", license.getName(), metadataEntries );
+                startList( metadataEntries );
                 addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries );
                 addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries );
+                endList( metadataEntries );
+                endListItem( metadataEntries );
                 ctr++;
             }
             endList( metadataEntries );
@@ -171,6 +181,8 @@ public class ProjectMetadataTag
             startList( metadataEntries );
             for ( MailingList list : lists )
             {
+                createDeleteLink( "mailingList", list.getName(), metadataEntries );
+                startList( metadataEntries );
                 addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries );
                 addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries );
                 addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries );
@@ -194,6 +206,8 @@ public class ProjectMetadataTag
                     endList( metadataEntries );
                 }
                 endListItem( metadataEntries );
+                endList( metadataEntries );
+                endListItem( metadataEntries );
                 ctr++;
             }
             endList( metadataEntries );
@@ -207,8 +221,11 @@ public class ProjectMetadataTag
             int ctr = 0;
 
             startList( metadataEntries );
+            
             for ( Dependency dependency : dependencies )
             {
+                createDeleteLink( "dependency", dependency.getArtifactId(), metadataEntries );
+                startList( metadataEntries );
                 addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries );
                 addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries );
                 addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries );
@@ -216,9 +233,12 @@ public class ProjectMetadataTag
                 addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries );
                 addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries );
                 addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries );
+                endList( metadataEntries );
+                endListItem( metadataEntries );
                 ctr++;
             }
             endList( metadataEntries );
+            
             endListItem( metadataEntries );
         }
 
@@ -250,9 +270,36 @@ public class ProjectMetadataTag
     {
         metadataEntries.append( "\n</li>" );
     }
+    
+    private void createDeleteLink( String name, String value, StringBuffer metadataEntries )
+    {
+        metadataEntries.append( "\n<li>" ).append( value )
+                       .append( "\n<a href=\"showProjectMetadata!deleteMetadataEntry.action?" )
+                       .append( "groupId=" ).append( groupId )
+                       .append( "&artifactId=" ).append( artifactId )
+                       .append( "&version=" ).append( version )
+                       .append( "&deleteItem=" ).append( name )
+                       .append( "&itemValue=").append( value ).append( "\" >" )
+                       .append( "<img src=\"images/icons/delete.gif\"/>" ).append( "</a>" );
+    }
 
     public void setObject( Object object )
     {
         this.object = object;
     }
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
 }
index 10ad88add5560cfcd499d57d82b9d28ae9ff9f8b..a93499d44e0c66ac2d5fd620c0121496c6b4d906 100644 (file)
       <result>/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
 
+    <action name="deleteMetadataEntry" class="showArtifactAction" method="deleteMetadataEntry">
+      <result name="success" type="redirect-action">
+        <param name="actionName">showProjectMetadata</param>
+        <param name="namespace">/</param>
+      </result>
+    </action>
+
   </package>
 
   <package name="components" namespace="/components" extends="struts-default">
index 498fdabb0cd1c9ba31fb782e8fae2f55ee127e41..6e5202a7a840f95c94c6f5cbe471531b7781f7b8 100644 (file)
@@ -36,5 +36,5 @@
 </p>
 
 <div>
-  <archiva:project-metadata object="${projectMetadata}" />
+  <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" />
 </div>
index fc83554e0939f810ea3c9fcc8d5c12f9a32051e4..d5572f2768a096608f26b1b0637c32ae0bc7175b 100644 (file)
         
         <description><![CDATA[The Object to Render]]></description>
       </attribute>
+
+      <attribute>
+        <name>groupId</name>
+        <required>true</required>
+        <rtexprvalue>true</rtexprvalue>
+        
+        <description><![CDATA[The groupId]]></description>
+      </attribute>
+      
+      <attribute>
+        <name>artifactId</name>
+        <required>true</required>
+        <rtexprvalue>true</rtexprvalue>
+        
+        <description><![CDATA[The artifactId]]></description>
+      </attribute>
+
+      <attribute>
+        <name>version</name>
+        <required>true</required>
+        <rtexprvalue>true</rtexprvalue>
+        
+        <description><![CDATA[The version]]></description>
+      </attribute>
    
    </tag>
    
-</taglib>
\ No newline at end of file
+</taglib>