[MRM-1327] fix 'used by' to work under JCR store. This will still have problems under the file store at the moment

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1085722 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2011-03-26 14:00:06 +00:00
parent 1a95fa3b64
commit bed7aa1b59
2 changed files with 23 additions and 52 deletions

View File

@ -30,7 +30,6 @@ import org.apache.archiva.metadata.model.MetadataFacetFactory;
import org.apache.archiva.metadata.model.Organization; import org.apache.archiva.metadata.model.Organization;
import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.model.Scm;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
@ -307,29 +306,6 @@ public abstract class AbstractMetadataRepositoryTest
assertTrue( d.isOptional() ); assertTrue( d.isOptional() );
} }
public void testUpdateProjectReference()
throws Exception
{
ProjectVersionReference reference = new ProjectVersionReference();
reference.setNamespace( "another.namespace" );
reference.setProjectId( "another-project-id" );
reference.setProjectVersion( "1.1" );
reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
repository.updateProjectReference( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
reference );
Collection<ProjectVersionReference> references = repository.getProjectReferences( TEST_REPO_ID, TEST_NAMESPACE,
TEST_PROJECT,
TEST_PROJECT_VERSION );
assertEquals( 1, references.size() );
reference = references.iterator().next();
assertEquals( "another.namespace", reference.getNamespace() );
assertEquals( "another-project-id", reference.getProjectId() );
assertEquals( "1.1", reference.getProjectVersion() );
assertEquals( ProjectVersionReference.ReferenceType.DEPENDENCY, reference.getReferenceType() );
}
public void testGetRepositories() public void testGetRepositories()
throws Exception throws Exception
{ {

View File

@ -943,42 +943,37 @@ public class JcrMetadataRepository
{ {
List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>(); List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
// TODO: bind variables instead
String q = "SELECT * FROM [archiva:dependency] WHERE ISDESCENDANTNODE([/repositories/" + repositoryId +
"/content]) AND [groupId]='" + namespace + "' AND [artifactId]='" + projectId + "'";
if ( projectVersion != null )
{
q += " AND [version]='" + projectVersion + "'";
}
try try
{ {
Node root = session.getRootNode(); Query query = session.getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
QueryResult result = query.execute();
String path = getProjectVersionPath( repositoryId, namespace, projectId, projectVersion ) + "/references"; for ( Node n : JcrUtils.getNodes( result ) )
if ( root.hasNode( path ) )
{ {
Node node = root.getNode( path ); n = n.getParent(); // dependencies grouping element
NodeIterator i = node.getNodes(); n = n.getParent(); // project version
while ( i.hasNext() ) String usedByProjectVersion = n.getName();
{
Node ns = i.nextNode();
NodeIterator j = ns.getNodes(); n = n.getParent(); // project
String usedByProject = n.getName();
while ( j.hasNext() ) n = n.getParent(); // namespace
{ String usedByNamespace = n.getProperty( "namespace" ).getString();
Node project = j.nextNode();
NodeIterator k = project.getNodes(); ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace( usedByNamespace );
while ( k.hasNext() ) ref.setProjectId( usedByProject );
{ ref.setProjectVersion( usedByProjectVersion );
Node version = k.nextNode(); ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
references.add( ref );
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace( ns.getName() );
ref.setProjectId( project.getName() );
ref.setProjectVersion( version.getName() );
String type = version.getProperty( "type" ).getString();
ref.setReferenceType( ProjectVersionReference.ReferenceType.valueOf( type ) );
references.add( ref );
}
}
}
} }
} }
catch ( RepositoryException e ) catch ( RepositoryException e )