use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method removeProject.
@Override
public void removeProject(RepositorySession repositorySession, final String repositoryId, final String namespaceId, final String projectId) throws MetadataRepositoryException {
String key = //
new Project.KeyBuilder().withProjectId(//
projectId).withNamespace(//
new Namespace(namespaceId, new Repository(repositoryId))).build();
CqlSession session = cassandraArchivaManager.getSession();
{
String table = cassandraArchivaManager.getProjectFamilyName();
Delete delete = deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(delete.build());
table = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
Select query = selectFrom(table).columns(DEFAULT_PRIMARY_KEY, PROJECT_ID.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(namespaceId)).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(projectId)).allowFiltering();
ResultSet result = session.execute(query.build());
result.forEach(row -> removeMailingList(row.get(DEFAULT_PRIMARY_KEY, String.class)));
List<String> tables = Arrays.asList(cassandraArchivaManager.getProjectVersionMetadataFamilyName(), cassandraArchivaManager.getArtifactMetadataFamilyName());
for (String dTable : tables) {
Select deleteRows = selectFrom(dTable).column(DEFAULT_PRIMARY_KEY).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(namespaceId)).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(projectId)).allowFiltering();
result = session.execute(deleteRows.build());
StreamSupport.stream(result.spliterator(), false).map(row -> row.getString(DEFAULT_PRIMARY_KEY)).forEach(delKey -> session.execute(deleteFrom(dTable).column(PROJECT_ID.toString()).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(delKey)).build()));
}
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method recordLicenses.
protected void recordLicenses(String projectVersionMetadataKey, List<License> licenses) {
if (licenses == null || licenses.isEmpty()) {
return;
}
String table = cassandraArchivaManager.getLicenseFamilyName();
CqlSession session = cassandraArchivaManager.getSession();
{
for (License license : licenses) {
// we don't care about the key as the real used one with the projectVersionMetadata
String keyLicense = UUID.randomUUID().toString();
RegularInsert insert = insertInto(table).value(DEFAULT_PRIMARY_KEY, literal(keyLicense)).value("\"projectVersionMetadataModel.key\"", literal(projectVersionMetadataKey)).value(NAME.toString(), literal(license.getName())).value(URL.toString(), literal(license.getUrl()));
session.execute(insert.build());
}
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(RepositorySession repositorySession, final String repositoryId, final ZonedDateTime startTime, final ZonedDateTime endTime, QueryParameter queryParameter) throws MetadataRepositoryException {
final String table = cassandraArchivaManager.getArtifactMetadataFamilyName();
CqlSession session = cassandraArchivaManager.getSession();
{
long start = startTime == null ? Long.MIN_VALUE : startTime.toInstant().toEpochMilli();
long end = endTime == null ? Long.MAX_VALUE : endTime.toInstant().toEpochMilli();
Select query = selectFrom(table).all().whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(WHEN_GATHERED.toString()).isGreaterThanOrEqualTo(literal(start)).whereColumn(WHEN_GATHERED.toString()).isLessThanOrEqualTo(literal(end)).allowFiltering();
ResultSet result = session.execute(query.build());
return StreamSupport.stream(result.spliterator(), false).map(this::mapArtifactMetadata).collect(Collectors.toList());
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method removeMetadataFacets.
@Override
public void removeMetadataFacets(RepositorySession repositorySession, final String repositoryId, final String facetId) throws MetadataRepositoryException {
final String table = cassandraArchivaManager.getMetadataFacetFamilyName();
CqlSession session = cassandraArchivaManager.getSession();
{
Select deleteRows = selectFrom(table).column(DEFAULT_PRIMARY_KEY).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(FACET_ID.toString()).isEqualTo(literal(facetId)).allowFiltering();
ResultSet result = session.execute(deleteRows.build());
StreamSupport.stream(result.spliterator(), false).map(row -> row.getString(DEFAULT_PRIMARY_KEY)).distinct().forEach(delKey -> session.execute(deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(delKey)).build()));
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method getMetadataFacet.
@Override
public <T extends MetadataFacet> T getMetadataFacet(RepositorySession repositorySession, final String repositoryId, final Class<T> facetClazz, final String name) throws MetadataRepositoryException {
final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory(facetClazz);
if (metadataFacetFactory == null) {
return null;
}
final String facetId = metadataFacetFactory.getFacetId();
final String table = cassandraArchivaManager.getMetadataFacetFamilyName();
T metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
CqlSession session = cassandraArchivaManager.getSession();
{
Select query = selectFrom(table).column(KEY.toString()).column(VALUE.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(FACET_ID.toString()).isEqualTo(literal(facetId)).whereColumn(NAME.toString()).isEqualTo(literal(name)).allowFiltering();
ResultSet result = session.execute(query.build());
if (result.getAvailableWithoutFetching() == 0) {
return null;
}
Map<String, String> props = StreamSupport.stream(result.spliterator(), false).filter(row -> !row.isNull(KEY.toString())).collect(Collectors.toMap(row -> row.getString(KEY.toString()), row -> row.getString(VALUE.toString())));
metadataFacet.fromProperties(props);
return metadataFacet;
}
}
Aggregations