[MRM-1362] [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic metadata" plugin

* 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
This commit is contained in:
Jevica Arianne B. Zurbano 2010-05-27 07:45:06 +00:00
parent a6063601a8
commit da6e920101
5 changed files with 179 additions and 3 deletions

View 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;
@ -103,6 +104,10 @@ public class ShowArtifactAction
private ProjectVersionMetadata projectMetadata;
private String deleteItem;
private String itemValue;
/**
* Show the versioned project information tab.
* TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
@ -296,6 +301,89 @@ 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

View File

@ -46,6 +46,12 @@ public class ProjectMetadataTag
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 );
}
@ -251,8 +271,35 @@ 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;
}
}

View File

@ -222,6 +222,13 @@
<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">

View File

@ -36,5 +36,5 @@
</p>
<div>
<archiva:project-metadata object="${projectMetadata}" />
<archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" />
</div>

View File

@ -125,6 +125,30 @@
<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>