Search in sources :

Example 11 with OrderedRows

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

the class CassandraMetadataRepository method getMailingLists.

protected List<MailingList> getMailingLists(String projectVersionMetadataKey) {
    List<MailingList> mailingLists = new ArrayList<>();
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss).setColumnFamily(// 
    cassandraArchivaManager.getMailingListFamilyName()).setColumnNames(// 
    NAME.toString()).setRowCount(// 
    Integer.MAX_VALUE).addEqualsExpression("projectVersionMetadataModel.key", // 
    projectVersionMetadataKey).execute();
    for (Row<String, String, String> row : result.get()) {
        ColumnFamilyResult<String, String> columnFamilyResult = this.mailingListTemplate.queryColumns(row.getKey());
        MailingList mailingList = new MailingList();
        mailingList.setName(columnFamilyResult.getString(NAME.toString()));
        mailingList.setMainArchiveUrl(columnFamilyResult.getString("mainArchiveUrl"));
        mailingList.setPostAddress(columnFamilyResult.getString("postAddress"));
        mailingList.setSubscribeAddress(columnFamilyResult.getString("subscribeAddress"));
        mailingList.setUnsubscribeAddress(columnFamilyResult.getString("unsubscribeAddress"));
        List<String> otherArchives = new ArrayList<>();
        for (String columnName : columnFamilyResult.getColumnNames()) {
            if (StringUtils.startsWith(columnName, "otherArchive.")) {
                otherArchives.add(columnFamilyResult.getString(columnName));
            }
        }
        mailingList.setOtherArchives(otherArchives);
        mailingLists.add(mailingList);
    }
    return mailingLists;
}
Also used : OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) MailingList(org.apache.archiva.metadata.model.MailingList) ArrayList(java.util.ArrayList)

Example 12 with OrderedRows

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

the class CassandraMetadataRepository method updateArtifact.

@Override
public void updateArtifact(String repositoryId, String namespaceId, String projectId, String projectVersion, ArtifactMetadata artifactMeta) throws MetadataRepositoryException {
    Namespace namespace = getNamespace(repositoryId, namespaceId);
    if (namespace == null) {
        namespace = updateOrAddNamespace(repositoryId, namespaceId);
    }
    ProjectMetadata projectMetadata = new ProjectMetadata();
    projectMetadata.setId(projectId);
    projectMetadata.setNamespace(namespaceId);
    updateProject(repositoryId, projectMetadata);
    String key = new ArtifactMetadataModel.KeyBuilder().withNamespace(namespace).withProject(projectId).withId(artifactMeta.getId()).withProjectVersion(projectVersion).build();
    // exists?
    boolean exists = this.artifactMetadataTemplate.isColumnsExist(key);
    if (exists) {
        // updater
        ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater(key);
        updater.setLong(FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime());
        updater.setLong(WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime());
        updater.setLong(SIZE.toString(), artifactMeta.getSize());
        addUpdateStringValue(updater, MD5.toString(), artifactMeta.getMd5());
        addUpdateStringValue(updater, SHA1.toString(), artifactMeta.getSha1());
        addUpdateStringValue(updater, VERSION.toString(), artifactMeta.getVersion());
        this.artifactMetadataTemplate.update(updater);
    } else {
        String cf = this.cassandraArchivaManager.getArtifactMetadataFamilyName();
        // create
        // 
        this.artifactMetadataTemplate.createMutator().addInsertion(key, cf, // 
        column(ID.toString(), artifactMeta.getId())).addInsertion(key, cf, // 
        column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        column(NAMESPACE_ID.toString(), namespaceId)).addInsertion(key, cf, // 
        column(PROJECT.toString(), artifactMeta.getProject())).addInsertion(key, cf, // 
        column(PROJECT_VERSION.toString(), projectVersion)).addInsertion(key, cf, // 
        column(VERSION.toString(), artifactMeta.getVersion())).addInsertion(key, cf, // 
        column(FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime())).addInsertion(key, cf, // 
        column(SIZE.toString(), artifactMeta.getSize())).addInsertion(key, cf, // 
        column(MD5.toString(), artifactMeta.getMd5())).addInsertion(key, cf, // 
        column(SHA1.toString(), artifactMeta.getSha1())).addInsertion(key, cf, // 
        column(WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime())).execute();
    }
    key = // 
    new ProjectVersionMetadataModel.KeyBuilder().withRepository(// 
    repositoryId).withNamespace(// 
    namespace).withProjectId(// 
    projectId).withProjectVersion(// 
    projectVersion).withId(// 
    artifactMeta.getId()).build();
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    projectVersion).addEqualsExpression(VERSION.toString(), // 
    artifactMeta.getVersion()).execute();
    exists = result.get().getCount() > 0;
    if (!exists) {
        String cf = this.cassandraArchivaManager.getProjectVersionMetadataFamilyName();
        // 
        projectVersionMetadataTemplate.createMutator().addInsertion(key, cf, // 
        column(NAMESPACE_ID.toString(), namespace.getName())).addInsertion(key, cf, // 
        column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        column(PROJECT_VERSION.toString(), projectVersion)).addInsertion(key, cf, // 
        column(PROJECT_ID.toString(), projectId)).addInsertion(key, cf, // 
        column(VERSION.toString(), artifactMeta.getVersion())).execute();
    }
    ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
    artifactMetadataModel.setRepositoryId(repositoryId);
    artifactMetadataModel.setNamespace(namespaceId);
    artifactMetadataModel.setProject(projectId);
    artifactMetadataModel.setProjectVersion(projectVersion);
    artifactMetadataModel.setVersion(artifactMeta.getVersion());
    artifactMetadataModel.setFileLastModified(artifactMeta.getFileLastModified() == null ? new Date().getTime() : artifactMeta.getFileLastModified().getTime());
    // now facets
    updateFacets(artifactMeta, artifactMetadataModel);
}
Also used : ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) Date(java.util.Date)

Example 13 with OrderedRows

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

the class CassandraMetadataRepository method removeProject.

@Override
public void removeProject(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();
    this.projectTemplate.deleteRow(key);
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    ID.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).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(// 
    PROJECT_ID.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).execute();
    for (Row<String, String, String> row : result.get()) {
        this.artifactMetadataTemplate.deleteRow(row.getKey());
    }
}
Also used : 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) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 14 with OrderedRows

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

the class CassandraMetadataRepository method getLicenses.

protected List<License> getLicenses(String projectVersionMetadataKey) {
    List<License> licenses = new ArrayList<>();
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss).setColumnFamily(// 
    cassandraArchivaManager.getLicenseFamilyName()).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.licenseTemplate.queryColumns(row.getKey());
        licenses.add(new License(columnFamilyResult.getString(NAME.toString()), columnFamilyResult.getString(URL.toString())));
    }
    return licenses;
}
Also used : OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) License(org.apache.archiva.metadata.model.License) ArrayList(java.util.ArrayList)

Example 15 with OrderedRows

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

the class CassandraMetadataRepository method getProject.

@Override
public ProjectMetadata getProject(final String repoId, final String namespace, final String id) throws MetadataResolutionException {
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectFamilyName()).setColumnNames(// 
    PROJECT_ID.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repoId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespace).addEqualsExpression(PROJECT_ID.toString(), // 
    id).execute();
    int count = result.get().getCount();
    if (count < 1) {
        return null;
    }
    ProjectMetadata projectMetadata = new ProjectMetadata();
    projectMetadata.setId(id);
    projectMetadata.setNamespace(namespace);
    logger.debug("getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id, projectMetadata);
    return projectMetadata;
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows)

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