Search in sources :

Example 6 with ProjectVersionReference

use of org.apache.archiva.metadata.model.ProjectVersionReference in project archiva by apache.

the class JcrMetadataRepository method getProjectReferences.

@Override
public Collection<ProjectVersionReference> getProjectReferences(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    List<ProjectVersionReference> references = new ArrayList<>();
    // 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 {
        Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
        QueryResult result = query.execute();
        for (Node n : JcrUtils.getNodes(result)) {
            // dependencies grouping element
            n = n.getParent();
            // project version
            n = n.getParent();
            String usedByProjectVersion = n.getName();
            // project
            n = n.getParent();
            String usedByProject = n.getName();
            // namespace
            n = n.getParent();
            String usedByNamespace = n.getProperty("namespace").getString();
            ProjectVersionReference ref = new ProjectVersionReference();
            ref.setNamespace(usedByNamespace);
            ref.setProjectId(usedByProject);
            ref.setProjectVersion(usedByProjectVersion);
            ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
            references.add(ref);
        }
    } catch (RepositoryException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
    return references;
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Aggregations

ProjectVersionReference (org.apache.archiva.metadata.model.ProjectVersionReference)6 ArrayList (java.util.ArrayList)4 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 Dependency (org.apache.archiva.metadata.model.Dependency)2 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)2 LinkedHashSet (java.util.LinkedHashSet)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Query (javax.jcr.query.Query)1 QueryResult (javax.jcr.query.QueryResult)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 License (org.apache.archiva.metadata.model.License)1 MailingList (org.apache.archiva.metadata.model.MailingList)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)1 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)1 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)1