use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class RepositoryProblemEventListener method addArtifactProblem.
@Override
public void addArtifactProblem(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion, RepositoryStorageMetadataException exception) {
RepositoryProblemFacet problem = new RepositoryProblemFacet();
problem.setMessage(exception.getMessage());
problem.setProject(projectId);
problem.setNamespace(namespace);
problem.setRepositoryId(repoId);
problem.setVersion(projectVersion);
problem.setProblem(exception.getId());
try {
session.getRepository().addMetadataFacet(repoId, problem);
session.markDirty();
} catch (MetadataRepositoryException e) {
log.warn("Unable to add repository problem facets for the version being removed: {}", e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class CassandraMetadataRepository method removeNamespace.
@Override
public void removeNamespace(String repositoryId, String namespaceId) throws MetadataRepositoryException {
try {
String key = //
new Namespace.KeyBuilder().withNamespace(//
namespaceId).withRepositoryId(//
repositoryId).build();
//
HFactory.createMutator(cassandraArchivaManager.getKeyspace(), new StringSerializer()).addDeletion(key, //
cassandraArchivaManager.getNamespaceFamilyName()).execute();
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.projectTemplate.deleteRow(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.projectVersionMetadataTemplate.deleteRow(row.getKey());
removeMailingList(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.artifactMetadataTemplate.deleteRow(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.metadataFacetTemplate.deleteRow(row.getKey());
}
} catch (HInvalidRequestException e) {
logger.error(e.getMessage(), e);
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method getArtifacts.
@Override
public List<ArtifactMetadata> getArtifacts(String repositoryId) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery(repositoryId);
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for (Node n : JcrUtils.getNodes(result)) {
if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
artifacts.add(getArtifactFromNode(repositoryId, n));
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return artifacts;
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeRepository.
@Override
public void removeRepository(String repositoryId) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String path = getRepositoryPath(repositoryId);
if (root.hasNode(path)) {
root.getNode(path).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 runJcrQuery.
private List<ArtifactMetadata> runJcrQuery(String repositoryId, String q, Map<String, String> bindings) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
if (repositoryId != null) {
q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath(repositoryId) + "')";
}
log.info("Running JCR Query: {}", q);
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
ValueFactory valueFactory = getJcrSession().getValueFactory();
for (Entry<String, String> entry : bindings.entrySet()) {
query.bindValue(entry.getKey(), valueFactory.createValue(entry.getValue()));
}
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
log.info("JCR Query ran in {} milliseconds: {}", end - start, q);
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
while (rows.hasNext()) {
Row row = rows.nextRow();
Node node = row.getNode("artifact");
artifacts.add(getArtifactFromNode(repositoryId, node));
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
log.info("Artifacts found {}", artifacts.size());
for (ArtifactMetadata meta : artifacts) {
log.info("Artifact: " + meta.getVersion() + " " + meta.getFacetList());
}
return artifacts;
}
Aggregations