use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method getMetadataFacets.
@Override
public List<String> getMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
List<String> facets = new ArrayList<>();
try {
// no need to construct node-by-node here, as we'll find in the next instance, the facet names have / and
// are paths themselves
Node node = getJcrSession().getRootNode().getNode(getFacetPath(repositoryId, facetId));
// TODO: this is a bit awkward. Might be better to review the purpose of this function - why is the list of
// paths helpful?
recurse(facets, "", node);
} catch (PathNotFoundException e) {
// ignored - the facet doesn't exist, so return the empty list
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return facets;
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method populateStatistics.
@Override
public void populateStatistics(MetadataRepository repository, String repositoryId, RepositoryStatistics repositoryStatistics) throws MetadataRepositoryException {
if (!(repository instanceof JcrMetadataRepository)) {
throw new MetadataRepositoryException("The statistics population is only possible for JcrMetdataRepository implementations");
}
Session session = (Session) repository.obtainAccess(Session.class);
try {
QueryManager queryManager = session.getWorkspace().getQueryManager();
// TODO: Check, if this is still the case - Switched to Jackrabbit OAK with archiva 3.0
// Former statement: JCR-SQL2 query will not complete on a large repo in Jackrabbit 2.2.0 - see JCR-2835
// Using the JCR-SQL2 variants gives
// "org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024"
// String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])";
// Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause,
// Query.JCR_SQL2 );
String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])";
Query query = queryManager.createQuery("SELECT size FROM [archiva:artifact] " + whereClause, Query.JCR_SQL2);
QueryResult queryResult = query.execute();
Map<String, Integer> totalByType = new HashMap<>();
long totalSize = 0, totalArtifacts = 0;
for (Row row : JcrUtils.getRows(queryResult)) {
Node n = row.getNode();
totalSize += row.getValue("size").getLong();
String type;
if (n.hasNode(MavenArtifactFacet.FACET_ID)) {
Node facetNode = n.getNode(MavenArtifactFacet.FACET_ID);
type = facetNode.getProperty("type").getString();
} else {
type = "Other";
}
Integer prev = totalByType.get(type);
totalByType.put(type, prev != null ? prev + 1 : 1);
totalArtifacts++;
}
repositoryStatistics.setTotalArtifactCount(totalArtifacts);
repositoryStatistics.setTotalArtifactFileSize(totalSize);
for (Map.Entry<String, Integer> entry : totalByType.entrySet()) {
log.info("Setting count for type: {} = {}", entry.getKey(), entry.getValue());
repositoryStatistics.setTotalCountForType(entry.getKey(), entry.getValue());
}
// The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1
// query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 );
query = queryManager.createQuery("SELECT * FROM [archiva:project] " + whereClause + " ORDER BY [jcr:score]", Query.JCR_SQL2);
repositoryStatistics.setTotalProjectCount(query.execute().getRows().getSize());
// query = queryManager.createQuery(
// "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 );
query = queryManager.createQuery("SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL ORDER BY [jcr:score]", Query.JCR_SQL2);
repositoryStatistics.setTotalGroupCount(query.execute().getRows().getSize());
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method updateArtifact.
@Override
public void updateArtifact(String repositoryId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifactMeta) throws MetadataRepositoryException {
updateNamespace(repositoryId, namespace);
try {
Node node = getOrAddArtifactNode(repositoryId, namespace, projectId, projectVersion, artifactMeta.getId());
Calendar cal = Calendar.getInstance();
cal.setTime(artifactMeta.getFileLastModified());
node.setProperty(JCR_LAST_MODIFIED, cal);
cal = Calendar.getInstance();
cal.setTime(artifactMeta.getWhenGathered());
node.setProperty("whenGathered", cal);
node.setProperty("size", artifactMeta.getSize());
node.setProperty("md5", artifactMeta.getMd5());
node.setProperty("sha1", artifactMeta.getSha1());
node.setProperty("version", artifactMeta.getVersion());
// iterate over available facets to update/add/remove from the artifactMetadata
for (String facetId : metadataFacetFactories.keySet()) {
MetadataFacet metadataFacet = artifactMeta.getFacet(facetId);
if (metadataFacet == null) {
continue;
}
if (node.hasNode(facetId)) {
node.getNode(facetId).remove();
}
if (metadataFacet != null) {
// recreate, to ensure properties are removed
Node n = node.addNode(facetId);
n.addMixin(FACET_NODE_TYPE);
for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
n.setProperty(entry.getKey(), entry.getValue());
}
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeProjectVersion.
@Override
public void removeProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataRepositoryException {
try {
String path = getProjectPath(repoId, namespace, projectId);
Node root = getJcrSession().getRootNode();
Node nodeAtPath = root.getNode(path);
for (Node node : JcrUtils.getChildNodes(nodeAtPath)) {
if (node.isNodeType(PROJECT_VERSION_NODE_TYPE) && StringUtils.equals(projectVersion, node.getName())) {
node.remove();
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method addMetadataFacet.
@Override
public void addMetadataFacet(String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException {
try {
Node repo = getOrAddRepositoryNode(repositoryId);
Node facets = JcrUtils.getOrAddNode(repo, "facets");
String id = metadataFacet.getFacetId();
Node facetNode = JcrUtils.getOrAddNode(facets, id);
Node node = getOrAddNodeByPath(facetNode, metadataFacet.getName());
for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
node.setProperty(entry.getKey(), entry.getValue());
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
Aggregations