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;
}
Aggregations