[MRM-378]: Clicking on the tabs in the artifact detail page doesn't change the view

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@542881 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-05-30 17:20:20 +00:00
parent 4d8738d248
commit f457d052ae
12 changed files with 415 additions and 41 deletions

View File

@ -45,6 +45,15 @@ public interface DeclarativeConstraint extends Constraint
*/
public abstract String[] getDeclaredParameters();
/**
* The JDOQL filter to apply to the query. (optional)
*
* NOTE: This is DAO implementation specific.
*
* @return the filter to apply. (can be null)
*/
public abstract String getFilter();
/**
* Get the parameters used for this query. (required if using {@link #getDeclaredParameters()} )
*
@ -68,6 +77,15 @@ public interface DeclarativeConstraint extends Constraint
*/
public abstract String getSortColumn();
/**
* Get the variables used within the query.
*
* NOTE: This is DAO implementation specific.
*
* @return the variables used within the query.
*/
public abstract String[] getVariables();
/**
* Get the SELECT WHERE (condition) value for the constraint.
*

View File

@ -22,6 +22,7 @@ package org.apache.maven.archiva.database.browsing;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.constraints.ProjectsByArtifactUsageConstraint;
import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint;
import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
@ -30,6 +31,7 @@ import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.Collections;
import java.util.List;
/**
@ -131,8 +133,8 @@ public class DefaultRepositoryBrowsing
if ( model == null )
{
throw new ObjectNotFoundException( "Unable to find project model for [" + groupId + ":" + artifactId + ":"
+ version + "]" );
throw new ObjectNotFoundException( "Unable to find project model for [" + groupId + ":" + artifactId
+ ":" + version + "]" );
}
return model;
@ -142,4 +144,19 @@ public class DefaultRepositoryBrowsing
throw e;
}
}
public List getUsedBy( String groupId, String artifactId, String version )
throws ArchivaDatabaseException
{
ProjectsByArtifactUsageConstraint constraint = new ProjectsByArtifactUsageConstraint( groupId, artifactId,
version );
List results = dao.getProjectModelDAO().queryProjectModels( constraint );
if ( results == null )
{
// defensive. to honor contract as specified. never null.
return Collections.EMPTY_LIST;
}
return results;
}
}

View File

@ -23,20 +23,63 @@ import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import java.util.List;
/**
* RepositoryBrowsing
* Repository Browsing component
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface RepositoryBrowsing
{
/**
* Get the {@link BrowsingResults} for the root of the repository.
*
* @return the root browsing results.
*/
public BrowsingResults getRoot();
/**
* Get the {@link BrowsingResults} for the selected groupId.
*
* @param groupId the groupId to select.
* @return the {@link BrowsingResults} for the specified groupId.
*/
public BrowsingResults selectGroupId( String groupId );
/**
* Get the {@link BrowsingResults} for the selected groupId & artifactId.
*
* @param groupId the groupId selected
* @param artifactId the artifactId selected
* @return the {@link BrowsingResults} for the specified groupId / artifactId combo.
*/
public BrowsingResults selectArtifactId( String groupId, String artifactId );
/**
* Get the {@link ArchivaProjectModel} for the selected groupId / artifactId / version combo.
*
* @param groupId the groupId selected
* @param artifactId the artifactId selected
* @param version the version selected
* @return the {@link ArchivaProjectModel} for the selected groupId / artifactId / version combo.
* @throws ObjectNotFoundException if the artifact object or project object isn't found in the database.
* @throws ArchivaDatabaseException if there is a fundamental database error.
*/
public ArchivaProjectModel selectVersion( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException;
/**
* Get the {@link List} of {@link ArchivaProjectModel} that are used by the provided
* groupId, artifactId, and version specified.
*
* @param groupId the groupId selected
* @param artifactId the artifactId selected
* @param version the version selected
* @return the {@link List} of {@link ArchivaProjectModel} objects. (never null, but can be empty)
* @throws ArchivaDatabaseException if there is a fundamental database error.
*/
public List getUsedBy( String groupId, String artifactId, String version )
throws ArchivaDatabaseException;
}

View File

@ -35,8 +35,15 @@ public abstract class AbstractDeclarativeConstraint
protected String[] declParams;
protected String[] variables;
protected Object[] params;
public String getFilter()
{
return null;
}
public String getFetchLimits()
{
return null;
@ -61,4 +68,9 @@ public abstract class AbstractDeclarativeConstraint
{
return Constraint.ASCENDING;
}
public String[] getVariables()
{
return variables;
}
}

View File

@ -0,0 +1,81 @@
package org.apache.maven.archiva.database.constraints;
/*
* 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.maven.archiva.database.DeclarativeConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.Dependency;
/**
* ProjectsByArtifactUsageConstraint
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class ProjectsByArtifactUsageConstraint
extends AbstractDeclarativeConstraint
implements DeclarativeConstraint
{
private String filter;
public ProjectsByArtifactUsageConstraint( ArchivaArtifact artifact )
{
this( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion() );
}
public ProjectsByArtifactUsageConstraint( String groupId, String artifactId, String version )
{
super.declImports = new String[] {
"import " + Dependency.class.getName()
};
super.variables = new String[] {
"Dependency dep"
};
super.declParams = new String[] {
"String selectedGroupId",
"String selectedArtifactId",
"String selectedVersion"
};
filter = "dependencies.contains( dep ) && " +
"dep.groupId == selectedGroupId && " +
"dep.artifactId == selectedArtifactId && " +
"dep.version == selectedVersion";
super.params = new Object[] { groupId, artifactId, version };
}
public String getSortColumn()
{
return "groupId";
}
public String getWhereCondition()
{
return null;
}
public String getFilter()
{
return filter;
}
}

View File

@ -31,12 +31,8 @@ import org.codehaus.plexus.jdo.JdoFactory;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.jpox.PMFConfiguration;
import org.jpox.SchemaTool;
import java.io.File;
import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -324,6 +320,16 @@ public class JdoAccess
Extent extent = pm.getExtent( clazz, true );
Query query = pm.newQuery( extent );
if ( constraint.getFilter() != null )
{
query.setFilter( constraint.getFilter() );
}
if ( constraint.getVariables() != null )
{
query.declareVariables( StringUtils.join( constraint.getVariables(), "; " ) );
}
if ( constraint.getSortColumn() != null )
{
String ordering = constraint.getSortColumn();

View File

@ -19,10 +19,13 @@ package org.apache.maven.archiva.database;
* under the License.
*/
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
import org.apache.maven.archiva.database.updater.TestDatabaseCleanupConsumer;
import org.apache.maven.archiva.database.updater.TestDatabaseUnprocessedConsumer;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.VersionedReference;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
import org.codehaus.plexus.jdo.JdoFactory;
@ -163,4 +166,43 @@ public class AbstractArchivaDatabaseTestCase
SimpleDateFormat sdf = new SimpleDateFormat( TIMESTAMP );
return sdf.format( date );
}
protected VersionedReference toVersionedReference( String id )
{
String parts[] = StringUtils.splitPreserveAllTokens( id, ':' );
assertEquals( "Should have 3 parts [" + id + "]", 3, parts.length );
VersionedReference ref = new VersionedReference();
ref.setGroupId( parts[0] );
ref.setArtifactId( parts[1] );
ref.setVersion( parts[2] );
assertTrue( "Group ID should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getGroupId() ) );
assertTrue( "Artifact ID should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getArtifactId() ) );
assertTrue( "Version should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getVersion() ) );
return ref;
}
protected ArtifactReference toArtifactReference( String id )
{
String parts[] = StringUtils.splitPreserveAllTokens( id, ':' );
assertEquals( "Should have 5 parts [" + id + "]", 5, parts.length );
ArtifactReference ref = new ArtifactReference();
ref.setGroupId( parts[0] );
ref.setArtifactId( parts[1] );
ref.setVersion( parts[2] );
ref.setClassifier( parts[3] );
ref.setType( parts[4] );
assertTrue( "Group ID should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getGroupId() ) );
assertTrue( "Artifact ID should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getArtifactId() ) );
assertTrue( "Version should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getVersion() ) );
// Blank string is ok for classifier, NULL is not.
assertNotNull( "Classifier should not be null [" + id + "]", ref.getClassifier() );
assertTrue( "Type should not be blank [" + id + "]", StringUtils.isNotBlank( ref.getType() ) );
return ref;
}
}

View File

@ -0,0 +1,115 @@
package org.apache.maven.archiva.database.constraints;
/*
* 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.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.DeclarativeConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.VersionedReference;
import java.util.Date;
import java.util.List;
/**
* ProjectsByArtifactUsageConstraintTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class ProjectsByArtifactUsageConstraintTest
extends AbstractArchivaDatabaseTestCase
{
protected void setUp()
throws Exception
{
super.setUp();
}
private void saveModel( String modelId, String deps[] )
throws Exception
{
ArchivaProjectModel model = new ArchivaProjectModel();
// Piece together a simple model.
VersionedReference ref = toVersionedReference( modelId );
model.setGroupId( ref.getGroupId() );
model.setArtifactId( ref.getArtifactId() );
model.setVersion( ref.getVersion() );
model.setPackaging( "jar" );
model.setOrigin( "testcase" );
if ( deps != null )
{
for ( int i = 0; i < deps.length; i++ )
{
ArtifactReference artiref = toArtifactReference( deps[i] );
Dependency dep = new Dependency();
dep.setGroupId( artiref.getGroupId() );
dep.setArtifactId( artiref.getArtifactId() );
dep.setVersion( artiref.getVersion() );
dep.setClassifier( artiref.getClassifier() );
dep.setClassifier( artiref.getType() );
model.addDependency( dep );
}
}
dao.getProjectModelDAO().saveProjectModel( model );
}
public ArchivaArtifact toArtifact( String id )
{
ArtifactReference ref = toArtifactReference( id );
ArchivaArtifact artifact = new ArchivaArtifact( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref
.getClassifier(), ref.getType() );
artifact.getModel().setLastModified( new Date() );
artifact.getModel().setRepositoryId( "testable_repo" );
return artifact;
}
public void testContraint()
throws Exception
{
saveModel( "org.apache.maven.archiva:archiva-configuration:1.0",
new String[] { "org.codehaus.plexus:plexus-digest:1.0::jar" } );
saveModel( "org.apache.maven.archiva:archiva-common:1.0", new String[] {
"org.codehaus.plexus:plexus-digest:1.0::jar",
"junit:junit:3.8.1::jar" } );
ArchivaArtifact artifact;
artifact = toArtifact( "org.foo:bar:4.0::jar" );
assertConstraint( 0, new ProjectsByArtifactUsageConstraint( artifact ) );
artifact = toArtifact( "org.codehaus.plexus:plexus-digest:1.0::jar" );
assertConstraint( 2, new ProjectsByArtifactUsageConstraint( artifact ) );
}
private void assertConstraint( int expectedHits, DeclarativeConstraint constraint )
throws Exception
{
List results = dao.getProjectModelDAO().queryProjectModels( constraint );
assertNotNull( "Projects By Artifact Usage: Not Null", results );
assertEquals( "Projects By Artifact Usage: Results.size", expectedHits, results.size() );
}
}

View File

@ -26,13 +26,10 @@ import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ProjectRepository;
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Iterator;
/**
* Browse the repository.
@ -144,8 +141,7 @@ public class ShowArtifactAction
{
this.model = repoBrowsing.selectVersion( groupId, artifactId, version );
// TODO: create depends on collector.
this.dependees = Collections.EMPTY_LIST;
this.dependees = repoBrowsing.getUsedBy( groupId, artifactId, version );
return SUCCESS;
}
@ -158,7 +154,7 @@ public class ShowArtifactAction
{
this.model = repoBrowsing.selectVersion( groupId, artifactId, version );
this.dependencyTree = new ArrayList();
this.dependencyTree = Collections.EMPTY_LIST;
return SUCCESS;
}
@ -231,6 +227,7 @@ public class ShowArtifactAction
return dependencies;
}
public List getDependees()
{
return dependees;

View File

@ -0,0 +1,39 @@
<%--
~ 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.
--%>
<%@ taglib prefix="ww" uri="/webwork" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%-- TODO: paginate! --%>
<c:forEach items="${dependees}" var="project">
<h3 class="artifact-title">
<my:showArtifactTitle groupId="${project.groupId}" artifactId="${project.artifactId}"
version="${project.version}"/>
</h3>
<p>
<my:showArtifactLink groupId="${project.groupId}" artifactId="${project.artifactId}"
version="${project.version}"/>
</p>
</c:forEach>
<c:if test="${empty(dependees)}">
<strong>No results</strong>
</c:if>

View File

@ -146,6 +146,9 @@
<c:when test="${dependencyTree != null}">
<%@ include file="/WEB-INF/jsp/include/dependencyTree.jspf" %>
</c:when>
<c:when test="${dependees != null}">
<%@ include file="/WEB-INF/jsp/include/projectDependees.jspf" %>
</c:when>
<c:when test="${mailingLists != null}">
<%@ include file="/WEB-INF/jsp/include/mailingLists.jspf" %>
</c:when>

View File

@ -20,6 +20,7 @@
<%@ taglib prefix="ww" uri="/webwork" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="archiva" uri="http://maven.apache.org/archiva" %>
<%@ attribute name="groupId" required="true" %>
<%@ attribute name="artifactId" %>
<%@ attribute name="version" %>
@ -28,7 +29,7 @@
<%@ attribute name="versions" type="java.util.List" %>
<span class="artifact-link">
<archiva:groupIdLink var="${model.groupId}" includeTop="true" />
<archiva:groupIdLink var="${groupId}" includeTop="false" />
<c:if test="${!empty(artifactId)}">
<c:set var="url">
@ -37,7 +38,7 @@
<ww:param name="artifactId" value="%{'${artifactId}'}"/>
</ww:url>
</c:set>
/ <a href="${url}">${artifactId}</a>
<a href="${url}">${artifactId}</a>
</c:if>
| <strong>Version(s):</strong>
<c:choose>