use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method getProjectVersion.
@Override
public ProjectVersionMetadata getProjectVersion(RepositorySession repositorySession, final String repositoryId, final String namespaceId, final String projectId, final String projectVersion) throws MetadataResolutionException {
CqlSession session = cassandraArchivaManager.getSession();
{
String table = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
Select query = selectFrom(table).column(PROJECT_ID.toString()).all().whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(namespaceId)).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(projectId)).whereColumn(PROJECT_VERSION.toString()).isEqualTo(literal(projectVersion)).allowFiltering();
Row result = session.execute(query.build()).one();
if (result == null) {
return null;
}
String key = result.getString(DEFAULT_PRIMARY_KEY);
ProjectVersionMetadata projectVersionMetadata = new ProjectVersionMetadata();
projectVersionMetadata.setId(result.getString(PROJECT_VERSION.toString()));
projectVersionMetadata.setDescription(result.getString(DESCRIPTION.toString()));
projectVersionMetadata.setName(result.getString(NAME.toString()));
projectVersionMetadata.setIncomplete(result.getBoolean("incomplete"));
projectVersionMetadata.setUrl(result.getString(URL.toString()));
{
String ciUrl = result.getString("\"ciManagement.url\"");
String ciSystem = result.getString("\"ciManagement.system\"");
if (StringUtils.isNotEmpty(ciSystem) || StringUtils.isNotEmpty(ciUrl)) {
projectVersionMetadata.setCiManagement(new CiManagement(ciSystem, ciUrl));
}
}
{
String issueUrl = result.getString("\"issueManagement.url\"");
String issueSystem = result.getString("\"issueManagement.system\"");
if (StringUtils.isNotEmpty(issueSystem) || StringUtils.isNotEmpty(issueUrl)) {
projectVersionMetadata.setIssueManagement(new IssueManagement(issueSystem, issueUrl));
}
}
{
String organizationUrl = result.getString("\"organization.url\"");
String organizationName = result.getString("\"organization.name\"");
if (StringUtils.isNotEmpty(organizationUrl) || StringUtils.isNotEmpty(organizationName)) {
projectVersionMetadata.setOrganization(new Organization(organizationName, organizationUrl));
}
}
{
String devConn = result.getString("\"scm.developerConnection\"");
String conn = result.getString("\"scm.connection\"");
String url = result.getString("\"scm.url\"");
if (StringUtils.isNotEmpty(devConn) || StringUtils.isNotEmpty(conn) || StringUtils.isNotEmpty(url)) {
projectVersionMetadata.setScm(new Scm(conn, devConn, url));
}
}
projectVersionMetadata.setMailingLists(getMailingLists(key));
projectVersionMetadata.setLicenses(getLicenses(key));
projectVersionMetadata.setDependencies(getDependencies(key));
// Facets
table = cassandraArchivaManager.getMetadataFacetFamilyName();
query = selectFrom(table).column(PROJECT_ID.toString()).column(FACET_ID.toString()).column(KEY.toString()).column(VALUE.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(namespaceId)).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(projectId)).whereColumn(PROJECT_VERSION.toString()).isEqualTo(literal(projectVersion)).allowFiltering();
ResultSet rows = session.execute(query.build());
Map<String, Map<String, String>> metadataFacetsPerFacetIds = StreamSupport.stream(rows.spliterator(), false).collect(Collectors.groupingBy(row -> row.getString(FACET_ID.toString()), Collectors.toMap(row -> row.getString(KEY.toString()), row -> row.getString(VALUE.toString()))));
if (!metadataFacetsPerFacetIds.isEmpty()) {
for (Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet()) {
MetadataFacetFactory<?> metadataFacetFactory = getFacetFactory(entry.getKey());
if (metadataFacetFactory != null) {
MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
metadataFacet.fromProperties(entry.getValue());
projectVersionMetadata.addFacet(metadataFacet);
}
}
}
return projectVersionMetadata;
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method addMetadataFacet.
@Override
public void addMetadataFacet(RepositorySession repositorySession, String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException {
if (metadataFacet == null) {
return;
}
final String table = this.cassandraArchivaManager.getMetadataFacetFamilyName();
if (metadataFacet.toProperties().isEmpty()) {
String key = new MetadataFacetModel.KeyBuilder().withRepositoryId(repositoryId).withFacetId(metadataFacet.getFacetId()).withName(metadataFacet.getName()).build();
CqlSession session = cassandraArchivaManager.getSession();
{
Update update = update(table).setColumn(REPOSITORY_NAME.toString(), literal(repositoryId)).setColumn(FACET_ID.toString(), literal(metadataFacet.getFacetId())).setColumn(NAME.toString(), literal(metadataFacet.getName())).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(update.build());
}
} else {
CqlSession session = cassandraArchivaManager.getSession();
{
for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
String key = new MetadataFacetModel.KeyBuilder().withRepositoryId(repositoryId).withFacetId(metadataFacet.getFacetId()).withName(metadataFacet.getName()).withKey(entry.getKey()).build();
Update update = update(table).setColumn(REPOSITORY_NAME.toString(), literal(repositoryId)).setColumn(FACET_ID.toString(), literal(metadataFacet.getFacetId())).setColumn(NAME.toString(), literal(metadataFacet.getName())).setColumn(KEY.toString(), literal(entry.getKey())).setColumn(VALUE.toString(), literal(entry.getValue())).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(update.build());
}
}
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method removeArtifact.
@Override
public void removeArtifact(RepositorySession repositorySession, final String repositoryId, final String namespace, final String project, final String version, final String id) throws MetadataRepositoryException {
logger.debug("removeTimestampedArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'", repositoryId, namespace, project, version, id);
CqlSession session = cassandraArchivaManager.getSession();
{
String key = new ArtifactMetadataModel.KeyBuilder().withRepositoryId(repositoryId).withNamespace(namespace).withId(id).withProjectVersion(version).withProject(project).build();
String table = cassandraArchivaManager.getArtifactMetadataFamilyName();
Delete delete = deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(delete.build());
key = //
new ProjectVersionMetadataModel.KeyBuilder().withRepository(//
repositoryId).withNamespace(//
namespace).withProjectId(//
project).withProjectVersion(//
version).withId(//
id).build();
table = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
delete = deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(delete.build());
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method getArtifactsByChecksum.
@Override
public List<ArtifactMetadata> getArtifactsByChecksum(RepositorySession repositorySession, final String repositoryId, final String checksum) throws MetadataRepositoryException {
String table = cassandraArchivaManager.getChecksumFamilyName();
CqlSession session = cassandraArchivaManager.getSession();
{
Select query = selectFrom(table).column(ARTIFACT_METADATA_MODEL_KEY.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repositoryId)).whereColumn(CHECKSUM_VALUE.toString()).isEqualTo(literal(checksum)).allowFiltering();
ResultSet result = session.execute(query.build());
List<String> artifactKeys = StreamSupport.stream(result.spliterator(), false).map(row -> row.getString(ARTIFACT_METADATA_MODEL_KEY.toString())).distinct().collect(Collectors.toList());
List<ArtifactMetadata> metadataList = new ArrayList<>();
for (String key : artifactKeys) {
table = cassandraArchivaManager.getArtifactMetadataFamilyName();
query = selectFrom(table).all().whereColumn(DEFAULT_PRIMARY_KEY.toString()).isEqualTo(literal(key));
Row row = session.execute(query.build()).one();
if (row != null) {
metadataList.add(mapArtifactMetadata(row));
}
}
return metadataList;
}
}
use of com.datastax.oss.driver.api.core.CqlSession in project archiva by apache.
the class CassandraMetadataRepository method removeMetadataFacet.
@Override
public void removeMetadataFacet(RepositorySession repositorySession, final String repositoryId, final String facetId, final String name) 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)).whereColumn(NAME.toString()).isEqualTo(literal(name)).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()));
}
}
Aggregations