Search in sources :

Example 11 with ProjectMetadata

use of org.apache.archiva.metadata.model.ProjectMetadata in project archiva by apache.

the class DefaultMetadataResolver method resolveProjects.

@Override
public Collection<String> resolveProjects(RepositorySession session, String repoId, String namespace) throws MetadataResolutionException {
    try {
        MetadataRepository metadataRepository = session.getRepository();
        Collection<String> projects = metadataRepository.getProjects(repoId, namespace);
        Collection<String> exclusions = new ArrayList<>(projects);
        String cacheKey = repoId + "-" + namespace;
        Collection<String> namespaces = namespacesCache.get(cacheKey);
        if (namespaces == null) {
            namespaces = metadataRepository.getNamespaces(repoId, namespace);
            namespacesCache.put(cacheKey, namespaces);
        }
        exclusions.addAll(namespaces);
        Collection<String> storageProjects = repositoryStorage.listProjects(repoId, namespace, new ExcludesFilter<>(exclusions));
        if (storageProjects != null && !storageProjects.isEmpty()) {
            log.debug("Resolved projects from storage: {}", storageProjects);
            for (String projectId : storageProjects) {
                ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata(repoId, namespace, projectId);
                if (projectMetadata != null) {
                    try {
                        metadataRepository.updateProject(repoId, projectMetadata);
                    } catch (MetadataRepositoryException e) {
                        log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
                    }
                }
            }
            session.markDirty();
            projects = new ArrayList<>(projects);
            projects.addAll(storageProjects);
        }
        return projects;
    } catch (RepositoryStorageRuntimeException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArrayList(java.util.ArrayList)

Example 12 with ProjectMetadata

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

Example 13 with ProjectMetadata

use of org.apache.archiva.metadata.model.ProjectMetadata 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 14 with ProjectMetadata

use of org.apache.archiva.metadata.model.ProjectMetadata 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

ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)14 Test (org.junit.Test)6 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)3 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)3 ArrayList (java.util.ArrayList)2 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)2 ArtifactMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel)2 ProjectVersionMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel)2 Repository (org.apache.archiva.metadata.repository.cassandra.model.Repository)2 RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1