Search in sources :

Example 1 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getMetadataFacet.

@Override
public MetadataFacet getMetadataFacet(final String repositoryId, final String facetId, final String name) throws MetadataRepositoryException {
    MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
    if (metadataFacetFactory == null) {
        return null;
    }
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(KEY.toString(), // 
    VALUE.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(FACET_ID.toString(), // 
    facetId).addEqualsExpression(NAME.toString(), // 
    name).execute();
    MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
    int size = result.get().getCount();
    if (size < 1) {
        return null;
    }
    Map<String, String> map = new HashMap<>(size);
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        map.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
    }
    metadataFacet.fromProperties(map);
    return metadataFacet;
}
Also used : HashMap(java.util.HashMap) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory)

Example 2 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getArtifactsByDateRange.

@Override
public List<ArtifactMetadata> getArtifactsByDateRange(final String repositoryId, final Date startTime, final Date endTime) throws MetadataRepositoryException {
    LongSerializer ls = LongSerializer.get();
    RangeSlicesQuery<String, String, Long> query = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ls).setColumnFamily(// 
    cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(// 
    ArtifactMetadataModel.COLUMNS);
    if (startTime != null) {
        query = query.addGteExpression(WHEN_GATHERED.toString(), startTime.getTime());
    }
    if (endTime != null) {
        query = query.addLteExpression(WHEN_GATHERED.toString(), endTime.getTime());
    }
    QueryResult<OrderedRows<String, String, Long>> result = query.execute();
    List<ArtifactMetadata> artifactMetadatas = new ArrayList<>(result.get().getCount());
    for (Row<String, String, Long> row : result.get()) {
        ColumnSlice<String, Long> columnSlice = row.getColumnSlice();
        String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString());
        if (StringUtils.equals(repositoryName, repositoryId)) {
            artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(columnSlice));
        }
    }
    return artifactMetadatas;
}
Also used : LongSerializer(me.prettyprint.cassandra.serializers.LongSerializer) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 3 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getDependencies.

protected List<Dependency> getDependencies(String projectVersionMetadataKey) {
    List<Dependency> dependencies = new ArrayList<>();
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss).setColumnFamily(// 
    cassandraArchivaManager.getDependencyFamilyName()).setColumnNames(// 
    "projectVersionMetadataModel.key").setRowCount(// 
    Integer.MAX_VALUE).addEqualsExpression("projectVersionMetadataModel.key", // 
    projectVersionMetadataKey).execute();
    for (Row<String, String, String> row : result.get()) {
        ColumnFamilyResult<String, String> columnFamilyResult = this.dependencyTemplate.queryColumns(row.getKey());
        Dependency dependency = new Dependency();
        dependency.setClassifier(columnFamilyResult.getString("classifier"));
        dependency.setOptional(Boolean.parseBoolean(columnFamilyResult.getString("optional")));
        dependency.setScope(columnFamilyResult.getString("scope"));
        dependency.setSystemPath(columnFamilyResult.getString("systemPath"));
        dependency.setType(columnFamilyResult.getString("type"));
        dependency.setArtifactId(columnFamilyResult.getString(ARTIFACT_ID.toString()));
        dependency.setGroupId(columnFamilyResult.getString(GROUP_ID.toString()));
        dependency.setVersion(columnFamilyResult.getString(VERSION.toString()));
        dependencies.add(dependency);
    }
    return dependencies;
}
Also used : OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ArrayList(java.util.ArrayList) Dependency(org.apache.archiva.metadata.model.Dependency)

Example 4 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows 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);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 5 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method updateProject.

@Override
public void updateProject(String repositoryId, ProjectMetadata projectMetadata) throws MetadataRepositoryException {
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectFamilyName()).setColumnNames(// 
    PROJECT_ID.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    projectMetadata.getNamespace()).addEqualsExpression(PROJECT_ID.toString(), // 
    projectMetadata.getId()).execute();
    // project exists ? if yes return nothing to update here
    if (result.get().getCount() > 0) {
        return;
    } else {
        Namespace namespace = updateOrAddNamespace(repositoryId, projectMetadata.getNamespace());
        String key = new Project.KeyBuilder().withProjectId(projectMetadata.getId()).withNamespace(namespace).build();
        String cf = cassandraArchivaManager.getProjectFamilyName();
        projectTemplate.createMutator().addInsertion(key, cf, // 
        CassandraUtils.column(PROJECT_ID.toString(), projectMetadata.getId())).addInsertion(key, cf, // 
        CassandraUtils.column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        CassandraUtils.column(NAMESPACE_ID.toString(), projectMetadata.getNamespace())).execute();
    }
}
Also used : Project(org.apache.archiva.metadata.repository.cassandra.model.Project) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Aggregations

OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)16 ArrayList (java.util.ArrayList)5 Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)5 HashMap (java.util.HashMap)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)3 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)3 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)3 Repository (org.apache.archiva.metadata.repository.cassandra.model.Repository)3 Map (java.util.Map)2 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)2 MutationResult (me.prettyprint.hector.api.mutation.MutationResult)2 CiManagement (org.apache.archiva.metadata.model.CiManagement)2 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)2 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)2 Organization (org.apache.archiva.metadata.model.Organization)2 Scm (org.apache.archiva.metadata.model.Scm)2 ArtifactMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel)2 Project (org.apache.archiva.metadata.repository.cassandra.model.Project)2 ProjectVersionMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel)2