Search in sources :

Example 31 with ProjectVersionMetadata

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

the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved.

@Test
public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved() throws Exception {
    ProjectVersionMetadata metadata = new ProjectVersionMetadata();
    metadata.setId(TEST_PROJECT_VERSION);
    Map<String, String> additionalProps = new HashMap<>();
    additionalProps.put("deleteKey", "deleteValue");
    MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
    metadata.addFacet(facet);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
    TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
    Map<String, String> facetProperties = testFacet.toProperties();
    assertEquals("deleteValue", facetProperties.get("deleteKey"));
    facetProperties.remove("deleteKey");
    TestMetadataFacet newTestFacet = new TestMetadataFacet(TEST_FACET_ID, testFacet.getValue(), facetProperties);
    metadata.addFacet(newTestFacet);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
    testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
    assertFalse(testFacet.toProperties().containsKey("deleteKey"));
}
Also used : HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) Test(org.junit.Test)

Example 32 with ProjectVersionMetadata

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

the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithAllElements.

@Test
public void testUpdateProjectVersionMetadataWithAllElements() throws Exception {
    ProjectVersionMetadata metadata = new ProjectVersionMetadata();
    metadata.setId(TEST_PROJECT_VERSION);
    metadata.setName("project name");
    metadata.setDescription("project description");
    metadata.setUrl("the url");
    MailingList mailingList = new MailingList();
    mailingList.setName("Foo List");
    mailingList.setUnsubscribeAddress("UnsubscribeAddress");
    mailingList.setSubscribeAddress("SubscribeAddress");
    mailingList.setPostAddress("PostAddress");
    mailingList.setMainArchiveUrl("MainArchiveUrl");
    mailingList.setOtherArchives(Arrays.asList("other archive"));
    metadata.setMailingLists(Arrays.asList(mailingList));
    Scm scm = new Scm();
    scm.setConnection("connection");
    scm.setDeveloperConnection("dev conn");
    scm.setUrl("url");
    metadata.setScm(scm);
    CiManagement ci = new CiManagement();
    ci.setSystem("system");
    ci.setUrl("ci url");
    metadata.setCiManagement(ci);
    IssueManagement tracker = new IssueManagement();
    tracker.setSystem("system");
    tracker.setUrl("issue tracker url");
    metadata.setIssueManagement(tracker);
    metadata.setOrganization(TEST_ORGANIZATION);
    License l = new License();
    l.setName("license name");
    l.setUrl("license url");
    metadata.addLicense(l);
    Dependency d = new Dependency();
    d.setArtifactId("artifactId");
    d.setClassifier("classifier");
    d.setGroupId("groupId");
    d.setScope("scope");
    d.setSystemPath("system path");
    d.setType("type");
    d.setVersion("version");
    d.setOptional(true);
    metadata.addDependency(d);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertEquals(TEST_PROJECT_VERSION, metadata.getId());
    assertEquals(TEST_PROJECT_VERSION, metadata.getVersion());
    assertEquals("project name", metadata.getName());
    assertEquals("project description", metadata.getDescription());
    assertEquals("the url", metadata.getUrl());
    assertEquals("connection", metadata.getScm().getConnection());
    assertEquals("dev conn", metadata.getScm().getDeveloperConnection());
    assertEquals("url", metadata.getScm().getUrl());
    assertEquals("system", metadata.getCiManagement().getSystem());
    assertEquals("ci url", metadata.getCiManagement().getUrl());
    assertEquals("system", metadata.getIssueManagement().getSystem());
    assertEquals("issue tracker url", metadata.getIssueManagement().getUrl());
    assertEquals(TEST_ORGANIZATION.getName(), metadata.getOrganization().getName());
    assertEquals(TEST_ORGANIZATION.getUrl(), metadata.getOrganization().getUrl());
    assertEquals(1, metadata.getMailingLists().size());
    MailingList retrievedMailingList = metadata.getMailingLists().get(0);
    assertEquals(mailingList.getName(), retrievedMailingList.getName());
    assertEquals(mailingList.getMainArchiveUrl(), retrievedMailingList.getMainArchiveUrl());
    assertEquals(mailingList.getPostAddress(), retrievedMailingList.getPostAddress());
    assertEquals(mailingList.getSubscribeAddress(), retrievedMailingList.getSubscribeAddress());
    assertEquals(mailingList.getUnsubscribeAddress(), retrievedMailingList.getUnsubscribeAddress());
    // 
    assertThat(retrievedMailingList.getOtherArchives()).isNotNull().isNotEmpty().hasSize(// 
    1).contains("other archive");
    assertEquals(1, metadata.getLicenses().size());
    l = metadata.getLicenses().get(0);
    assertEquals("license name", l.getName());
    assertEquals("license url", l.getUrl());
    assertEquals(1, metadata.getDependencies().size());
    d = metadata.getDependencies().get(0);
    assertEquals("artifactId", d.getArtifactId());
    assertEquals("classifier", d.getClassifier());
    assertEquals("groupId", d.getGroupId());
    assertEquals("scope", d.getScope());
    assertEquals("system path", d.getSystemPath());
    assertEquals("type", d.getType());
    assertEquals("version", d.getVersion());
    assertTrue(d.isOptional());
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MailingList(org.apache.archiva.metadata.model.MailingList) License(org.apache.archiva.metadata.model.License) CiManagement(org.apache.archiva.metadata.model.CiManagement) Dependency(org.apache.archiva.metadata.model.Dependency) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Test(org.junit.Test)

Example 33 with ProjectVersionMetadata

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

the class DefaultMetadataResolver method resolveProjectVersion.

@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    MetadataRepository metadataRepository = session.getRepository();
    ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
    // may then work here and be more efficient than always trying again)
    if (metadata == null || metadata.isIncomplete()) {
        try {
            ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
            metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
            log.debug("Resolved project version metadata from storage: {}", metadata);
            // eg. maven projects should be able to process parent here
            if (!metadata.getDependencies().isEmpty()) {
                ProjectVersionReference ref = new ProjectVersionReference();
                ref.setNamespace(namespace);
                ref.setProjectId(projectId);
                ref.setProjectVersion(projectVersion);
                ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
            }
            try {
                for (RepositoryListener listener : listeners) {
                    listener.addArtifact(session, repoId, namespace, projectId, metadata);
                }
                metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
            } catch (MetadataRepositoryException e) {
                log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
            }
            session.markDirty();
        } catch (RepositoryStorageMetadataInvalidException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
            throw new MetadataResolutionException(e.getMessage(), e);
        } catch (RepositoryStorageMetadataNotFoundException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
        // no need to rethrow - return null
        } catch (RepositoryStorageRuntimeException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
            throw new MetadataResolutionException(e.getMessage(), e);
        }
    }
    return metadata;
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)

Example 34 with ProjectVersionMetadata

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

the class DefaultMetadataResolver method resolveProjectVersions.

@Override
public Collection<String> resolveProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException {
    try {
        MetadataRepository metadataRepository = session.getRepository();
        Collection<String> projectVersions = metadataRepository.getProjectVersions(repoId, namespace, projectId);
        Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions(repoId, namespace, projectId, new ExcludesFilter<String>(projectVersions));
        if (storageProjectVersions != null && !storageProjectVersions.isEmpty()) {
            log.debug("Resolved project versions from storage: {}", storageProjectVersions);
            for (String projectVersion : storageProjectVersions) {
                try {
                    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion);
                    ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifact(session, repoId, namespace, projectId, versionMetadata);
                    }
                    metadataRepository.updateProjectVersion(repoId, namespace, projectId, versionMetadata);
                } catch (MetadataRepositoryException e) {
                    log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
                } catch (RepositoryStorageMetadataInvalidException e) {
                    log.warn("Not update project in metadata repository due to an error resolving it from storage: {}", e.getMessage());
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
                    }
                } catch (RepositoryStorageMetadataNotFoundException e) {
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
                    }
                }
            }
            session.markDirty();
            projectVersions = new ArrayList<>(projectVersions);
            projectVersions.addAll(storageProjectVersions);
        }
        return projectVersions;
    } catch (RepositoryStorageRuntimeException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)

Example 35 with ProjectVersionMetadata

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

the class CassandraMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(final String repoId, final String namespace, final String projectId, final String projectVersion) throws MetadataResolutionException {
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repoId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespace).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    projectVersion).execute();
    if (result.get().getCount() < 1) {
        return null;
    }
    String key = result.get().iterator().next().getKey();
    ColumnFamilyResult<String, String> columnFamilyResult = this.projectVersionMetadataTemplate.queryColumns(key);
    if (!columnFamilyResult.hasResults()) {
        return null;
    }
    ProjectVersionMetadata projectVersionMetadata = new ProjectVersionMetadata();
    projectVersionMetadata.setId(columnFamilyResult.getString(PROJECT_VERSION.toString()));
    projectVersionMetadata.setDescription(columnFamilyResult.getString(DESCRIPTION.toString()));
    projectVersionMetadata.setName(columnFamilyResult.getString(NAME.toString()));
    projectVersionMetadata.setIncomplete(Boolean.parseBoolean(columnFamilyResult.getString("incomplete")));
    projectVersionMetadata.setUrl(columnFamilyResult.getString(URL.toString()));
    {
        String ciUrl = columnFamilyResult.getString("ciManagement.url");
        String ciSystem = columnFamilyResult.getString("ciManagement.system");
        if (StringUtils.isNotEmpty(ciSystem) || StringUtils.isNotEmpty(ciUrl)) {
            projectVersionMetadata.setCiManagement(new CiManagement(ciSystem, ciUrl));
        }
    }
    {
        String issueUrl = columnFamilyResult.getString("issueManagement.url");
        String issueSystem = columnFamilyResult.getString("issueManagement.system");
        if (StringUtils.isNotEmpty(issueSystem) || StringUtils.isNotEmpty(issueUrl)) {
            projectVersionMetadata.setIssueManagement(new IssueManagement(issueSystem, issueUrl));
        }
    }
    {
        String organizationUrl = columnFamilyResult.getString("organization.url");
        String organizationName = columnFamilyResult.getString("organization.name");
        if (StringUtils.isNotEmpty(organizationUrl) || StringUtils.isNotEmpty(organizationName)) {
            projectVersionMetadata.setOrganization(new Organization(organizationName, organizationUrl));
        }
    }
    {
        String devConn = columnFamilyResult.getString("scm.developerConnection");
        String conn = columnFamilyResult.getString("scm.connection");
        String url = columnFamilyResult.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
    result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(FACET_ID.toString(), KEY.toString(), VALUE.toString(), // 
    NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repoId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespace).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    projectVersion).execute();
    Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<>();
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        String facetId = getStringValue(columnSlice, FACET_ID.toString());
        Map<String, String> metaValues = metadataFacetsPerFacetIds.get(facetId);
        if (metaValues == null) {
            metaValues = new HashMap<>();
            metadataFacetsPerFacetIds.put(facetId, metaValues);
        }
        metaValues.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
    }
    if (!metadataFacetsPerFacetIds.isEmpty()) {
        for (Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet()) {
            MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(entry.getKey());
            if (metadataFacetFactory != null) {
                MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
                metadataFacet.fromProperties(entry.getValue());
                projectVersionMetadata.addFacet(metadataFacet);
            }
        }
    }
    return projectVersionMetadata;
}
Also used : Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) Map(java.util.Map) HashMap(java.util.HashMap) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Aggregations

ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)44 Test (org.junit.Test)29 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)19 ArrayList (java.util.ArrayList)14 Dependency (org.apache.archiva.metadata.model.Dependency)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)8 HashMap (java.util.HashMap)7 GenericMetadataFacet (org.apache.archiva.metadata.generic.GenericMetadataFacet)6 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)5 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)5 RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)5 CiManagement (org.apache.archiva.metadata.model.CiManagement)4 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)4 MailingList (org.apache.archiva.metadata.model.MailingList)4 Scm (org.apache.archiva.metadata.model.Scm)4 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)4 RepositoryStorageMetadataInvalidException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)4 RepositoryStorageMetadataNotFoundException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)4 Path (java.nio.file.Path)3 License (org.apache.archiva.metadata.model.License)3