Search in sources :

Example 1 with Organization

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

Example 2 with Organization

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

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

the class FileMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    try {
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        String id = properties.getProperty("id");
        ProjectVersionMetadata versionMetadata = null;
        if (id != null) {
            versionMetadata = new ProjectVersionMetadata();
            versionMetadata.setId(id);
            versionMetadata.setName(properties.getProperty("name"));
            versionMetadata.setDescription(properties.getProperty("description"));
            versionMetadata.setUrl(properties.getProperty("url"));
            versionMetadata.setIncomplete(Boolean.valueOf(properties.getProperty("incomplete", "false")));
            String scmConnection = properties.getProperty("scm.connection");
            String scmDeveloperConnection = properties.getProperty("scm.developerConnection");
            String scmUrl = properties.getProperty("scm.url");
            if (scmConnection != null || scmDeveloperConnection != null || scmUrl != null) {
                Scm scm = new Scm();
                scm.setConnection(scmConnection);
                scm.setDeveloperConnection(scmDeveloperConnection);
                scm.setUrl(scmUrl);
                versionMetadata.setScm(scm);
            }
            String ciSystem = properties.getProperty("ci.system");
            String ciUrl = properties.getProperty("ci.url");
            if (ciSystem != null || ciUrl != null) {
                CiManagement ci = new CiManagement();
                ci.setSystem(ciSystem);
                ci.setUrl(ciUrl);
                versionMetadata.setCiManagement(ci);
            }
            String issueSystem = properties.getProperty("issue.system");
            String issueUrl = properties.getProperty("issue.url");
            if (issueSystem != null || issueUrl != null) {
                IssueManagement issueManagement = new IssueManagement();
                issueManagement.setSystem(issueSystem);
                issueManagement.setUrl(issueUrl);
                versionMetadata.setIssueManagement(issueManagement);
            }
            String orgName = properties.getProperty("org.name");
            String orgUrl = properties.getProperty("org.url");
            if (orgName != null || orgUrl != null) {
                Organization org = new Organization();
                org.setName(orgName);
                org.setUrl(orgUrl);
                versionMetadata.setOrganization(org);
            }
            boolean done = false;
            int i = 0;
            while (!done) {
                String licenseName = properties.getProperty("license." + i + ".name");
                String licenseUrl = properties.getProperty("license." + i + ".url");
                if (licenseName != null || licenseUrl != null) {
                    License license = new License();
                    license.setName(licenseName);
                    license.setUrl(licenseUrl);
                    versionMetadata.addLicense(license);
                } else {
                    done = true;
                }
                i++;
            }
            done = false;
            i = 0;
            while (!done) {
                String mailingListName = properties.getProperty("mailingList." + i + ".name");
                if (mailingListName != null) {
                    MailingList mailingList = new MailingList();
                    mailingList.setName(mailingListName);
                    mailingList.setMainArchiveUrl(properties.getProperty("mailingList." + i + ".archive"));
                    String p = properties.getProperty("mailingList." + i + ".otherArchives");
                    if (p != null && p.length() > 0) {
                        mailingList.setOtherArchives(Arrays.asList(p.split(",")));
                    } else {
                        mailingList.setOtherArchives(Collections.emptyList());
                    }
                    mailingList.setPostAddress(properties.getProperty("mailingList." + i + ".post"));
                    mailingList.setSubscribeAddress(properties.getProperty("mailingList." + i + ".subscribe"));
                    mailingList.setUnsubscribeAddress(properties.getProperty("mailingList." + i + ".unsubscribe"));
                    versionMetadata.addMailingList(mailingList);
                } else {
                    done = true;
                }
                i++;
            }
            done = false;
            i = 0;
            while (!done) {
                String dependencyArtifactId = properties.getProperty("dependency." + i + ".artifactId");
                if (dependencyArtifactId != null) {
                    Dependency dependency = new Dependency();
                    dependency.setArtifactId(dependencyArtifactId);
                    dependency.setGroupId(properties.getProperty("dependency." + i + ".groupId"));
                    dependency.setClassifier(properties.getProperty("dependency." + i + ".classifier"));
                    dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
                    dependency.setScope(properties.getProperty("dependency." + i + ".scope"));
                    dependency.setSystemPath(properties.getProperty("dependency." + i + ".systemPath"));
                    dependency.setType(properties.getProperty("dependency." + i + ".type"));
                    dependency.setVersion(properties.getProperty("dependency." + i + ".version"));
                    dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
                    versionMetadata.addDependency(dependency);
                } else {
                    done = true;
                }
                i++;
            }
            String facetIds = properties.getProperty("facetIds", "");
            if (facetIds.length() > 0) {
                for (String facetId : facetIds.split(",")) {
                    MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
                    if (factory == null) {
                        log.error("Attempted to load unknown project version metadata facet: {}", facetId);
                    } else {
                        MetadataFacet facet = factory.createMetadataFacet();
                        Map<String, String> map = new HashMap<>();
                        for (Object key : new ArrayList<>(properties.keySet())) {
                            String property = (String) key;
                            if (property.startsWith(facet.getFacetId())) {
                                map.put(property.substring(facet.getFacetId().length() + 1), properties.getProperty(property));
                            }
                        }
                        facet.fromProperties(map);
                        versionMetadata.addFacet(facet);
                    }
                }
            }
            updateProjectVersionFacets(versionMetadata, properties);
        }
        return versionMetadata;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) Dependency(org.apache.archiva.metadata.model.Dependency) IOException(java.io.IOException) Properties(java.util.Properties) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Example 4 with Organization

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

the class JcrMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    ProjectVersionMetadata versionMetadata;
    try {
        Node root = getJcrSession().getRootNode();
        String path = getProjectVersionPath(repositoryId, namespace, projectId, projectVersion);
        if (!root.hasNode(path)) {
            return null;
        }
        Node node = root.getNode(path);
        versionMetadata = new ProjectVersionMetadata();
        versionMetadata.setId(projectVersion);
        versionMetadata.setName(getPropertyString(node, "name"));
        versionMetadata.setDescription(getPropertyString(node, "description"));
        versionMetadata.setUrl(getPropertyString(node, "url"));
        versionMetadata.setIncomplete(node.hasProperty("incomplete") && node.getProperty("incomplete").getBoolean());
        // FIXME: decide how to treat these in the content repo
        String scmConnection = getPropertyString(node, "scm.connection");
        String scmDeveloperConnection = getPropertyString(node, "scm.developerConnection");
        String scmUrl = getPropertyString(node, "scm.url");
        if (scmConnection != null || scmDeveloperConnection != null || scmUrl != null) {
            Scm scm = new Scm();
            scm.setConnection(scmConnection);
            scm.setDeveloperConnection(scmDeveloperConnection);
            scm.setUrl(scmUrl);
            versionMetadata.setScm(scm);
        }
        String ciSystem = getPropertyString(node, "ci.system");
        String ciUrl = getPropertyString(node, "ci.url");
        if (ciSystem != null || ciUrl != null) {
            CiManagement ci = new CiManagement();
            ci.setSystem(ciSystem);
            ci.setUrl(ciUrl);
            versionMetadata.setCiManagement(ci);
        }
        String issueSystem = getPropertyString(node, "issue.system");
        String issueUrl = getPropertyString(node, "issue.url");
        if (issueSystem != null || issueUrl != null) {
            IssueManagement issueManagement = new IssueManagement();
            issueManagement.setSystem(issueSystem);
            issueManagement.setUrl(issueUrl);
            versionMetadata.setIssueManagement(issueManagement);
        }
        String orgName = getPropertyString(node, "org.name");
        String orgUrl = getPropertyString(node, "org.url");
        if (orgName != null || orgUrl != null) {
            Organization org = new Organization();
            org.setName(orgName);
            org.setUrl(orgUrl);
            versionMetadata.setOrganization(org);
        }
        boolean done = false;
        int i = 0;
        while (!done) {
            String licenseName = getPropertyString(node, "license." + i + ".name");
            String licenseUrl = getPropertyString(node, "license." + i + ".url");
            if (licenseName != null || licenseUrl != null) {
                License license = new License();
                license.setName(licenseName);
                license.setUrl(licenseUrl);
                versionMetadata.addLicense(license);
            } else {
                done = true;
            }
            i++;
        }
        done = false;
        i = 0;
        while (!done) {
            String mailingListName = getPropertyString(node, "mailingList." + i + ".name");
            if (mailingListName != null) {
                MailingList mailingList = new MailingList();
                mailingList.setName(mailingListName);
                mailingList.setMainArchiveUrl(getPropertyString(node, "mailingList." + i + ".archive"));
                String n = "mailingList." + i + ".otherArchives";
                if (node.hasProperty(n)) {
                    mailingList.setOtherArchives(Arrays.asList(getPropertyString(node, n).split(",")));
                } else {
                    mailingList.setOtherArchives(Collections.<String>emptyList());
                }
                mailingList.setPostAddress(getPropertyString(node, "mailingList." + i + ".post"));
                mailingList.setSubscribeAddress(getPropertyString(node, "mailingList." + i + ".subscribe"));
                mailingList.setUnsubscribeAddress(getPropertyString(node, "mailingList." + i + ".unsubscribe"));
                versionMetadata.addMailingList(mailingList);
            } else {
                done = true;
            }
            i++;
        }
        if (node.hasNode("dependencies")) {
            Node dependenciesNode = node.getNode("dependencies");
            for (Node n : JcrUtils.getChildNodes(dependenciesNode)) {
                if (n.isNodeType(DEPENDENCY_NODE_TYPE)) {
                    Dependency dependency = new Dependency();
                    // FIXME: correct these properties
                    dependency.setArtifactId(getPropertyString(n, "artifactId"));
                    dependency.setGroupId(getPropertyString(n, "groupId"));
                    dependency.setClassifier(getPropertyString(n, "classifier"));
                    dependency.setOptional(Boolean.valueOf(getPropertyString(n, "optional")));
                    dependency.setScope(getPropertyString(n, "scope"));
                    dependency.setSystemPath(getPropertyString(n, "systemPath"));
                    dependency.setType(getPropertyString(n, "type"));
                    dependency.setVersion(getPropertyString(n, "version"));
                    versionMetadata.addDependency(dependency);
                }
            }
        }
        for (Node n : JcrUtils.getChildNodes(node)) {
            if (n.isNodeType(FACET_NODE_TYPE)) {
                String name = n.getName();
                MetadataFacetFactory factory = metadataFacetFactories.get(name);
                if (factory == null) {
                    log.error("Attempted to load unknown project version metadata facet: {}", name);
                } else {
                    MetadataFacet facet = factory.createMetadataFacet();
                    Map<String, String> map = new HashMap<>();
                    for (Property property : JcrUtils.getProperties(n)) {
                        String p = property.getName();
                        if (!p.startsWith("jcr:")) {
                            map.put(p, property.getString());
                        }
                    }
                    facet.fromProperties(map);
                    versionMetadata.addFacet(facet);
                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
    return versionMetadata;
}
Also used : Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) Node(javax.jcr.Node) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) Property(javax.jcr.Property) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Aggregations

CiManagement (org.apache.archiva.metadata.model.CiManagement)4 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)4 Organization (org.apache.archiva.metadata.model.Organization)4 Scm (org.apache.archiva.metadata.model.Scm)4 HashMap (java.util.HashMap)3 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)3 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)2 Dependency (org.apache.archiva.metadata.model.Dependency)2 License (org.apache.archiva.metadata.model.License)2 MailingList (org.apache.archiva.metadata.model.MailingList)2 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Node (javax.jcr.Node)1