Search in sources :

Example 1 with DEFAULT_PRIMARY_KEY

use of org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY 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()));
    }
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 2 with DEFAULT_PRIMARY_KEY

use of org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY in project archiva by apache.

the class CassandraMetadataRepository method updateFacets.

/*
     * iterate over available facets to remove/add from the artifactMetadata
     *
     * @param facetedMetadata
     * @param artifactMetadataModel only use for the key
     */
private void updateFacets(final FacetedMetadata facetedMetadata, final ArtifactMetadataModel artifactMetadataModel) {
    String table = cassandraArchivaManager.getMetadataFacetFamilyName();
    CqlSession session = cassandraArchivaManager.getSession();
    {
        for (final String facetId : getSupportedFacets()) {
            MetadataFacet metadataFacet = facetedMetadata.getFacet(facetId);
            if (metadataFacet != null) {
                Select deleteRows = selectFrom(table).column(DEFAULT_PRIMARY_KEY).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(artifactMetadataModel.getRepositoryId())).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(artifactMetadataModel.getNamespace())).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(artifactMetadataModel.getProject())).whereColumn(PROJECT_VERSION.toString()).isEqualTo(literal(artifactMetadataModel.getProjectVersion())).whereColumn(FACET_ID.toString()).isEqualTo(literal(facetId)).allowFiltering();
                ResultSet resultSet = session.execute(deleteRows.build());
                StreamSupport.stream(resultSet.spliterator(), false).map(row -> row.getString(DEFAULT_PRIMARY_KEY)).distinct().forEach(key -> {
                    Delete delete = deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
                    session.execute(delete.build());
                });
                Map<String, String> properties = metadataFacet.toProperties();
                for (Map.Entry<String, String> entry : properties.entrySet()) {
                    String key = new MetadataFacetModel.KeyBuilder().withKey(entry.getKey()).withArtifactMetadataModel(artifactMetadataModel).withFacetId(facetId).withName(metadataFacet.getName()).build();
                    Update update = update(table).setColumn(REPOSITORY_NAME.toString(), literal(artifactMetadataModel.getRepositoryId())).setColumn(NAMESPACE_ID.toString(), literal(artifactMetadataModel.getNamespace())).setColumn(PROJECT_ID.toString(), literal(artifactMetadataModel.getProject())).setColumn(PROJECT_VERSION.toString(), literal(artifactMetadataModel.getProjectVersion())).setColumn(FACET_ID.toString(), literal(facetId)).setColumn(KEY.toString(), literal(entry.getKey())).setColumn(VALUE.toString(), literal(entry.getValue())).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
                    session.execute(update.build());
                }
            }
        }
    }
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DEFAULT_PRIMARY_KEY

use of org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY 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()));
    }
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 4 with DEFAULT_PRIMARY_KEY

use of org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY 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()));
        }
    }
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) MailingList(org.apache.archiva.metadata.model.MailingList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 5 with DEFAULT_PRIMARY_KEY

use of org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY 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;
    }
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Organization(org.apache.archiva.metadata.model.Organization) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) CqlSession(com.datastax.oss.driver.api.core.CqlSession) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) CiManagement(org.apache.archiva.metadata.model.CiManagement) Row(com.datastax.oss.driver.api.core.cql.Row) Scm(org.apache.archiva.metadata.model.Scm) Map(java.util.Map) HashMap(java.util.HashMap) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Aggregations

CqlSession (com.datastax.oss.driver.api.core.CqlSession)8 ColumnDefinition (com.datastax.oss.driver.api.core.cql.ColumnDefinition)8 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)8 Row (com.datastax.oss.driver.api.core.cql.Row)8 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)8 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)8 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)8 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)8 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)8 Select (com.datastax.oss.driver.api.querybuilder.select.Select)8 Update (com.datastax.oss.driver.api.querybuilder.update.Update)8 UpdateStart (com.datastax.oss.driver.api.querybuilder.update.UpdateStart)8 UpdateWithAssignments (com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments)8 Instant (java.time.Instant)8 ZonedDateTime (java.time.ZonedDateTime)8 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Comparator (java.util.Comparator)8 HashMap (java.util.HashMap)8 Iterator (java.util.Iterator)8