Search in sources :

Example 1 with Namespace

use of org.apache.archiva.metadata.repository.cassandra.model.Namespace 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)

Example 2 with Namespace

use of org.apache.archiva.metadata.repository.cassandra.model.Namespace in project archiva by apache.

the class RepositoriesNamespaceTest method testMetadataRepo.

@Test
public void testMetadataRepo() throws Exception {
    Repository r = null;
    Namespace n = null;
    try {
        cmr.updateNamespace("release", "org");
        r = cmr.getRepository("release");
        assertThat(r).isNotNull();
        assertThat(cmr.getRepositories()).isNotEmpty().hasSize(1);
        assertThat(cmr.getNamespaces("release")).isNotEmpty().hasSize(1);
        n = cmr.getNamespace("release", "org");
        assertThat(n).isNotNull();
        assertThat(n.getRepository()).isNotNull();
        cmr.updateNamespace("release", "org.apache");
        r = cmr.getRepository("release");
        assertThat(r).isNotNull();
        assertThat(cmr.getNamespaces("release")).isNotEmpty().hasSize(2);
        cmr.removeNamespace("release", "org.apache");
        assertThat(cmr.getNamespaces("release")).isNotEmpty().hasSize(1);
        assertThat(cmr.getNamespaces("release")).containsExactly("org");
        ProjectMetadata projectMetadata = new ProjectMetadata();
        projectMetadata.setId("theproject");
        projectMetadata.setNamespace("org");
        cmr.updateProject("release", projectMetadata);
        assertThat(cmr.getProjects("release", "org")).isNotEmpty().hasSize(1).containsExactly("theproject");
        cmr.removeProject("release", "org", "theproject");
        assertThat(cmr.getProjects("release", "org")).isEmpty();
        cmr.removeRepository("release");
        r = cmr.getRepository("release");
        assertThat(r).isNull();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw e;
    } finally {
        CassandraMetadataRepositoryTest.clearReposAndNamespace(cassandraArchivaManager);
    }
}
Also used : Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) Test(org.junit.Test)

Example 3 with Namespace

use of org.apache.archiva.metadata.repository.cassandra.model.Namespace in project archiva by apache.

the class CassandraMetadataRepository method mapProjectVersionMetadataModel.

protected ProjectVersionMetadataModel mapProjectVersionMetadataModel(ColumnSlice<String, String> columnSlice) {
    ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
    projectVersionMetadataModel.setId(getStringValue(columnSlice, ID.toString()));
    projectVersionMetadataModel.setDescription(getStringValue(columnSlice, DESCRIPTION.toString()));
    projectVersionMetadataModel.setName(getStringValue(columnSlice, NAME.toString()));
    Namespace namespace = new // 
    Namespace(// 
    getStringValue(columnSlice, NAMESPACE_ID.toString()), new Repository(getStringValue(columnSlice, REPOSITORY_NAME.toString())));
    projectVersionMetadataModel.setNamespace(namespace);
    projectVersionMetadataModel.setIncomplete(Boolean.parseBoolean(getStringValue(columnSlice, "incomplete")));
    projectVersionMetadataModel.setProjectId(getStringValue(columnSlice, PROJECT_ID.toString()));
    projectVersionMetadataModel.setUrl(getStringValue(columnSlice, URL.toString()));
    return projectVersionMetadataModel;
}
Also used : MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 4 with Namespace

use of org.apache.archiva.metadata.repository.cassandra.model.Namespace in project archiva by apache.

the class CassandraMetadataRepository method updateOrAddNamespace.

private Namespace updateOrAddNamespace(String repositoryId, String namespaceId) throws MetadataRepositoryException {
    try {
        Repository repository = getOrCreateRepository(repositoryId);
        String key = new Namespace.KeyBuilder().withNamespace(namespaceId).withRepositoryId(repositoryId).build();
        Namespace namespace = getNamespace(repositoryId, namespaceId);
        if (namespace == null) {
            String cf = cassandraArchivaManager.getNamespaceFamilyName();
            namespace = new Namespace(namespaceId, repository);
            HFactory.createMutator(keyspace, StringSerializer.get()).addInsertion(key, cf, // 
            CassandraUtils.column(NAME.toString(), namespace.getName())).addInsertion(key, cf, // 
            CassandraUtils.column(REPOSITORY_NAME.toString(), repository.getName())).execute();
        }
        return namespace;
    } catch (HInvalidRequestException e) {
        logger.error(e.getMessage(), e);
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 5 with Namespace

use of org.apache.archiva.metadata.repository.cassandra.model.Namespace in project archiva by apache.

the class CassandraMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repositoryId, String namespaceId, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
    try {
        Namespace namespace = getNamespace(repositoryId, namespaceId);
        if (namespace == null) {
            updateOrAddNamespace(repositoryId, namespaceId);
        }
        if (getProject(repositoryId, namespaceId, projectId) == null) {
            ProjectMetadata projectMetadata = new ProjectMetadata();
            projectMetadata.setNamespace(namespaceId);
            projectMetadata.setId(projectId);
            updateProject(repositoryId, projectMetadata);
        }
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    versionMetadata.getId()).execute();
    ProjectVersionMetadataModel projectVersionMetadataModel = null;
    boolean creation = true;
    if (result.get().getCount() > 0) {
        projectVersionMetadataModel = mapProjectVersionMetadataModel(result.get().getList().get(0).getColumnSlice());
        creation = false;
    } else {
        projectVersionMetadataModel = getModelMapper().map(versionMetadata, ProjectVersionMetadataModel.class);
    }
    projectVersionMetadataModel.setProjectId(projectId);
    projectVersionMetadataModel.setNamespace(new Namespace(namespaceId, new Repository(repositoryId)));
    projectVersionMetadataModel.setCiManagement(versionMetadata.getCiManagement());
    projectVersionMetadataModel.setIssueManagement(versionMetadata.getIssueManagement());
    projectVersionMetadataModel.setOrganization(versionMetadata.getOrganization());
    projectVersionMetadataModel.setScm(versionMetadata.getScm());
    projectVersionMetadataModel.setMailingLists(versionMetadata.getMailingLists());
    projectVersionMetadataModel.setDependencies(versionMetadata.getDependencies());
    projectVersionMetadataModel.setLicenses(versionMetadata.getLicenses());
    // we don't test of repository and namespace really exist !
    String key = // 
    new ProjectVersionMetadataModel.KeyBuilder().withRepository(// 
    repositoryId).withNamespace(// 
    namespaceId).withProjectId(// 
    projectId).withProjectVersion(// 
    versionMetadata.getVersion()).withId(// 
    versionMetadata.getId()).build();
    // FIXME nested objects to store!!!
    if (creation) {
        String cf = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
        Mutator<String> mutator = projectVersionMetadataTemplate.createMutator().addInsertion(key, cf, // 
        column(PROJECT_ID.toString(), projectId)).addInsertion(key, cf, // 
        column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        column(NAMESPACE_ID.toString(), namespaceId)).addInsertion(key, cf, // 
        column(PROJECT_VERSION.toString(), versionMetadata.getVersion()));
        addInsertion(mutator, key, cf, DESCRIPTION.toString(), versionMetadata.getDescription());
        addInsertion(mutator, key, cf, NAME.toString(), versionMetadata.getName());
        addInsertion(mutator, key, cf, "incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addInsertion(mutator, key, cf, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addInsertion(mutator, key, cf, "ciManagement.system", ci.getSystem());
                addInsertion(mutator, key, cf, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addInsertion(mutator, key, cf, "issueManagement.system", issueManagement.getSystem());
                addInsertion(mutator, key, cf, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addInsertion(mutator, key, cf, "organization.name", organization.getName());
                addInsertion(mutator, key, cf, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addInsertion(mutator, key, cf, "scm.url", scm.getUrl());
                addInsertion(mutator, key, cf, "scm.connection", scm.getConnection());
                addInsertion(mutator, key, cf, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        recordMailingList(key, versionMetadata.getMailingLists());
        recordLicenses(key, versionMetadata.getLicenses());
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        MutationResult mutationResult = mutator.execute();
    } else {
        ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater(key);
        addUpdateStringValue(updater, PROJECT_ID.toString(), projectId);
        addUpdateStringValue(updater, REPOSITORY_NAME.toString(), repositoryId);
        addUpdateStringValue(updater, NAMESPACE_ID.toString(), namespaceId);
        addUpdateStringValue(updater, PROJECT_VERSION.toString(), versionMetadata.getVersion());
        addUpdateStringValue(updater, DESCRIPTION.toString(), versionMetadata.getDescription());
        addUpdateStringValue(updater, NAME.toString(), versionMetadata.getName());
        updater.setString("incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addUpdateStringValue(updater, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addUpdateStringValue(updater, "ciManagement.system", ci.getSystem());
                addUpdateStringValue(updater, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addUpdateStringValue(updater, "issueManagement.system", issueManagement.getSystem());
                addUpdateStringValue(updater, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addUpdateStringValue(updater, "organization.name", organization.getName());
                addUpdateStringValue(updater, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addUpdateStringValue(updater, "scm.url", scm.getUrl());
                addUpdateStringValue(updater, "scm.connection", scm.getConnection());
                addUpdateStringValue(updater, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        // update is a delete record
        removeMailingList(key);
        recordMailingList(key, versionMetadata.getMailingLists());
        removeLicenses(key);
        recordLicenses(key, versionMetadata.getLicenses());
        removeDependencies(key);
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        projectVersionMetadataTemplate.update(updater);
    }
    ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
    artifactMetadataModel.setRepositoryId(repositoryId);
    artifactMetadataModel.setNamespace(namespaceId);
    artifactMetadataModel.setProject(projectId);
    artifactMetadataModel.setProjectVersion(versionMetadata.getVersion());
    artifactMetadataModel.setVersion(versionMetadata.getVersion());
    updateFacets(versionMetadata, artifactMetadataModel);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) Organization(org.apache.archiva.metadata.model.Organization) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) MutationResult(me.prettyprint.hector.api.mutation.MutationResult)

Aggregations

Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)7 Repository (org.apache.archiva.metadata.repository.cassandra.model.Repository)5 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)4 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)4 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)3 ProjectVersionMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 ArtifactMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel)2 Project (org.apache.archiva.metadata.repository.cassandra.model.Project)2 Date (java.util.Date)1 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)1 MutationResult (me.prettyprint.hector.api.mutation.MutationResult)1 CiManagement (org.apache.archiva.metadata.model.CiManagement)1 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)1 Organization (org.apache.archiva.metadata.model.Organization)1 Scm (org.apache.archiva.metadata.model.Scm)1 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)1 Test (org.junit.Test)1