]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic...
authorMaria Odea B. Ching <oching@apache.org>
Fri, 4 Jun 2010 02:11:25 +0000 (02:11 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 4 Jun 2010 02:11:25 +0000 (02:11 +0000)
o added new facet for generic properties
o display correct metadata in Metadata tab
o add new properties to metadata from UI

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

13 files changed:
archiva-modules/archiva-web/archiva-webapp/pom.xml
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/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/jsp/showArtifact.jsp
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/plugins/generic-metadata-support/pom.xml [new file with mode: 0644]
archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java [new file with mode: 0644]
archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java [new file with mode: 0644]
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/pom.xml
pom.xml

index e27a14479b0fdbf65a931f8b531bdb3e1fbf74e7..ee89fe97c989687c28012c4fb7f34a0ad03dd054 100644 (file)
   <packaging>war</packaging>
   <name>Archiva Web :: Application</name>
   <dependencies>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>generic-metadata-support</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>npanday-support</artifactId>
index 077dcad61a96d072f253d629f8672497d94fd56e..eed67d57171f1f6e163f46ba369b2e890c9f4e2e 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action;
  */
 
 import com.opensymphony.xwork2.Validateable;
+
+import org.apache.archiva.metadata.generic.GenericMetadataFacet;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.Dependency;
 import org.apache.archiva.metadata.model.License;
@@ -42,9 +44,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * Browse the repository.
@@ -107,7 +111,14 @@ public class ShowArtifactAction
     private String deleteItem;
     
     private String itemValue;
+    
+    private Map<String, String> genericMetadata;
+    
+    private String propertyName;
+
+    private String propertyValue;
    
+    
     /**
      * Show the versioned project information tab.
      * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
@@ -141,7 +152,7 @@ public class ShowArtifactAction
     {
         ProjectVersionMetadata versionMetadata = null;
         artifacts = new LinkedHashMap<String, List<ArtifactDownloadInfo>>();
-
+        
         List<String> repos = getObservableRepos();
 
         for ( String repoId : repos )
@@ -277,20 +288,60 @@ public class ShowArtifactAction
 
     public String projectMetadata()
     {
-        projectMetadata = getProjectVersionMetadata();
-        String errorMsg = null;
+        String result = artifact();
+        
+        if( model.getFacet( GenericMetadataFacet.FACET_ID ) != null )
+        {
+            genericMetadata = model.getFacet( GenericMetadataFacet.FACET_ID ).toProperties();
+        }
+        
+        if( genericMetadata == null )
+        {
+            genericMetadata = new HashMap<String, String>();
+        }
 
-        if ( projectMetadata == null )
+        return result;
+    }
+    
+    public String addMetadataProperty()
+    {
+        ProjectVersionMetadata projectMetadata = getProjectVersionMetadata();
+        String errorMsg = null;      
+        
+        if( projectMetadata == null )
         {
             addActionError( errorMsg != null ? errorMsg : "Artifact not found" );
             return ERROR;
         }
-
-        if ( projectMetadata.isIncomplete() )
+        
+        if( projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ) == null )
         {
-            addIncompleteModelWarning();
+            genericMetadata = new HashMap<String, String>();
         }
-
+        else
+        {
+            genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties();
+        }
+        
+        genericMetadata.put( propertyName, propertyValue );
+        
+        GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet();
+        genericMetadataFacet.fromProperties( genericMetadata );
+                
+        // add updated facet
+        projectMetadata.addFacet( genericMetadataFacet );
+                
+        metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata );
+         
+        projectMetadata = getProjectVersionMetadata();
+        
+        genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties();
+        
+        model = projectMetadata;
+        
+        propertyName = "";
+        propertyValue = "";
+        
         return SUCCESS;
     }
     
@@ -507,6 +558,36 @@ public class ShowArtifactAction
     {
         this.itemValue = itemValue;
     }
+    
+    public Map<String, String> getGenericMetadata()
+    {
+        return genericMetadata;
+    }
+
+    public void setGenericMetadata( Map<String, String> genericMetadata )
+    {
+        this.genericMetadata = genericMetadata;
+    }
+    
+    public String getPropertyName()
+    {
+        return propertyName;
+    }
+
+    public void setPropertyName( String propertyName )
+    {
+        this.propertyName = propertyName;
+    }
+
+    public String getPropertyValue()
+    {
+        return propertyValue;
+    }
+
+    public void setPropertyValue( String propertyValue )
+    {
+        this.propertyValue = propertyValue;
+    }
 
     // TODO: move this into the artifact metadata itself via facets where necessary
 
@@ -629,7 +710,5 @@ public class ShowArtifactAction
         {
             return path;
         }
-
-
     }
 }
index a93499d44e0c66ac2d5fd620c0121496c6b4d906..1da4912a894ba4b196ad537610a8bf5877d5f07b 100644 (file)
       <result>/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
 
+    <action name="addMetadataProperty" class="showArtifactAction" method="addMetadataProperty">      
+      <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>
index 6e5202a7a840f95c94c6f5cbe471531b7781f7b8..65f3be1f7f63724bcd96adecb13b4c3a23b45336 100644 (file)
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="archiva"   uri="/WEB-INF/taglib.tld" %>
 
-<p>
-  <archiva:groupIdLink var="${groupId}" includeTop="true" />
+<div> 
 
-  <c:set var="url">
-    <s:url action="browseArtifact" namespace="/">
-      <s:param name="groupId" value="%{#attr.groupId}"/>
-      <s:param name="artifactId" value="%{#attr.artifactId}"/>
-    </s:url>
-  </c:set>
-  <a href="${url}">${artifactId}</a> /
-  <strong>${version}</strong>
-</p>
-
-<div>
-  <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" />
+  <div>
+    <s:form action="addMetadataProperty" namespace="/" method="post" validate="true" theme="simple">    
+      <s:hidden name="groupId" value="%{groupId}" />
+      <s:hidden name="artifactId" value="%{artifactId}" />
+      <s:hidden name="version" value="%{version}" />
+      <s:hidden name="repositoryId" value="%{repositoryId}" />
+      <table>
+        <tr>
+          <td align="center"><strong>Property Name</strong></td>
+          <td align="center"><strong>Property Value</strong></td>
+          <td/>
+        </tr>
+        <tr>
+          <td>
+            <s:textfield name="propertyName" size="30" required="true"/>
+          </td>
+          <td>
+            <s:textfield name="propertyValue" size="30" required="true"/>
+          </td>
+          <td align="right">
+            <s:submit value="Add"/>
+          </td>
+        </tr>
+      </table>
+    </s:form>  
+  </div>
+   
+  <div>
+    <c:if test="${empty genericMetadata}">
+      <p>
+        <strong>No metadata content.</strong>
+      </p>
+    </c:if>
+  
+    <c:if test="${!empty genericMetadata}">
+      <ul>
+        <c:forEach var="prop" items="${genericMetadata}">
+         <li>${prop.key}=${prop.value}</li> 
+        </c:forEach> 
+      </ul>
+    </c:if>  
+  </div>
+  
+  <%-- <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" /> --%>
 </div>
index d54e7346276992383b592d4f58a979efac026f4e..24b7cf49ae5c7b93c5eb4a62cc032c11e0281991 100644 (file)
   <%-- TODO: panels? this is ugly as is --%>
   <div id="tabArea">
     <c:choose>
-      <c:when test="${projectMetadata != null}">
+      <c:when test="${genericMetadata != null}">
         <%@ include file="/WEB-INF/jsp/include/projectMetadata.jspf" %>
       </c:when>
       <c:when test="${dependencies != null}">
     </s:if>
   </div>
 </div>
-
 </body>
 </html>
index 73ba58bca91bcc6e666d43d5f41f49c343e4e05c..a95cebf525e1cc4f30ad53c3f3efd12b49ab711d 100644 (file)
@@ -19,8 +19,11 @@ package org.apache.maven.archiva.web.action;
  * under the License.
  */
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.archiva.metadata.generic.GenericMetadataFacet;
 import org.apache.archiva.metadata.model.CiManagement;
 import org.apache.archiva.metadata.model.IssueManagement;
 import org.apache.archiva.metadata.model.License;
@@ -84,7 +87,11 @@ public abstract class AbstractActionTestCase
     protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
 
     protected static final String TEST_SCM_URL = "scmUrl";
-
+    
+    protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating";
+    
+    protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars";
+    
     protected void setObservableRepos( List<String> repoIds )
     {
         UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class );
@@ -176,6 +183,13 @@ public abstract class AbstractActionTestCase
         parent.setVersion( TEST_PARENT_VERSION );
         mavenProjectFacet.setParent( parent );
         model.addFacet( mavenProjectFacet );
+        
+        GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet();
+        Map<String, String> props = new HashMap<String,String>();
+        props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE );        
+        genericMetadataFacet.setAdditionalProperties( props );
+        model.addFacet( genericMetadataFacet );
+        
         return model;
     }
 }
index aa00d21ac1991fd9c05d88c35616024916431d6e..cb56754fffbd27b2ca7751696be40245a872a0c4 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action;
  */
 
 import com.opensymphony.xwork2.Action;
+
+import org.apache.archiva.metadata.generic.GenericMetadataFacet;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.Dependency;
 import org.apache.archiva.metadata.model.MailingList;
@@ -371,14 +373,7 @@ public class ShowArtifactActionTest
     public void testGetProjectMetadata()
     {
         ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
-        Dependency dependency1 = createDependencyBasic( "artifactId1" );
-        Dependency dependency2 = createDependencyExtended( "artifactId2" );
-        versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
-
-        MailingList ml1 = createMailingList( "Users List", "users" );
-        MailingList ml2 = createMailingList( "Developers List", "dev" );
-        versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
-
+        
         metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
 
         setActionParameters();
@@ -388,15 +383,13 @@ public class ShowArtifactActionTest
         assertActionSuccess( action, result );
 
         assertActionParameters( action );
-        ProjectVersionMetadata projectMetadata = action.getProjectMetadata();
-        assertDefaultModel( projectMetadata );
-
-        assertNotNull( projectMetadata.getDependencies() );
-        assertDependencyBasic( projectMetadata.getDependencies().get( 0 ), "artifactId1" );
-        assertDependencyExtended( projectMetadata.getDependencies().get( 1 ), "artifactId2" );
-
+        
+        Map<String, String> genericMetadata = action.getGenericMetadata();
+        assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
+        assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE );
+        
         assertEquals( TEST_REPO, action.getRepositoryId() );
-        assertNull( action.getModel() );
+        assertNotNull( action.getModel() );
         assertNull( action.getDependees() );
         assertNull( action.getDependencies() );
         assertNull( action.getMailingLists() );
diff --git a/archiva-modules/plugins/generic-metadata-support/pom.xml b/archiva-modules/plugins/generic-metadata-support/pom.xml
new file mode 100644 (file)
index 0000000..c8b34ce
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>plugins</artifactId>
+    <groupId>org.apache.archiva</groupId>
+    <version>1.4-SNAPSHOT</version>
+  </parent>
+  <artifactId>generic-metadata-support</artifactId>
+  <name>Generic Metadata Support</name>
+  <url>http://maven.apache.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-model</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java
new file mode 100644 (file)
index 0000000..8bbe945
--- /dev/null
@@ -0,0 +1,83 @@
+package org.apache.archiva.metadata.generic;
+
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.archiva.metadata.model.MetadataFacet;
+
+public class GenericMetadataFacet
+    implements MetadataFacet
+{   
+    private Map<String, String> additionalProperties;
+    
+    public static final String FACET_ID = "org.apache.archiva.metadata.generic";
+    
+    public String getFacetId()
+    {
+        return FACET_ID;
+    }
+
+    public String getName()
+    {
+        return "";
+    }
+
+    public void fromProperties( Map<String, String> properties )
+    {           
+        if( additionalProperties == null )
+        {
+            additionalProperties = new TreeMap<String, String>();            
+        }
+        
+        for( String key : properties.keySet() )
+        {
+            additionalProperties.put( key, properties.get( key ) );
+        }
+    }
+
+    public Map<String, String> toProperties()
+    {
+        Map<String, String> properties = new TreeMap<String, String>();
+                
+        if( additionalProperties != null )
+        {
+            for( String key : additionalProperties.keySet() )
+            {
+                properties.put( key, additionalProperties.get( key ) );
+            }
+        }
+        
+        return properties;
+    }
+        
+    public Map<String, String> getAdditionalProperties()
+    {
+        return additionalProperties;
+    }
+
+    public void setAdditionalProperties( Map<String, String> additionalProperties )
+    {
+        this.additionalProperties = additionalProperties;
+    }
+
+}
diff --git a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java
new file mode 100644 (file)
index 0000000..e8e9a7d
--- /dev/null
@@ -0,0 +1,42 @@
+package org.apache.archiva.metadata.generic;
+
+/*
+ * 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.MetadataFacet;
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.generic"
+ */
+public class GenericMetadataFacetFactory
+    implements MetadataFacetFactory
+{
+
+    public MetadataFacet createMetadataFacet()
+    {
+        return new GenericMetadataFacet();
+    }
+
+    public MetadataFacet createMetadataFacet( String repositoryId, String name )
+    {
+        throw new UnsupportedOperationException( "There is no valid name for project version facets" );
+    }
+
+}
index b391173cfdd496659814c9457f56b30bdb4de3f6..d35f4607325764db4689b2d3e6a4990a42c2ea62 100644 (file)
@@ -618,7 +618,7 @@ public class FileMetadataRepository
 
     private String join( Collection<String> ids )
     {
-        if ( !ids.isEmpty() )
+        if ( ids != null && !ids.isEmpty() )
         {
             StringBuilder s = new StringBuilder();
             for ( String id : ids )
index 14e84fca5eca42bc9a4e376eb2fb8620fab8ea07..6f24b170f4463c65b59df86c4c81a0022e68e402 100644 (file)
@@ -35,5 +35,6 @@
     <!-- TODO: eventually not a core plugin, needs to be moved to a separate tree, with it's own Selenium tests -->
     <module>npanday-support</module>
     <module>maven1-repository</module>
+    <module>generic-metadata-support</module>
   </modules>
 </project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 363b1a491eb8d8c0a2b6217b2b5e2f4f1481cd28..883eda030902773ca58e58744326a55d534e1c8e 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>maven2-repository</artifactId>
         <version>1.4-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.archiva</groupId>
+        <artifactId>generic-metadata-support</artifactId>
+        <version>1.4-SNAPSHOT</version>
+      </dependency>
       <dependency>
         <groupId>org.apache.archiva</groupId>
         <artifactId>archiva-applet</artifactId>