Search in sources :

Example 1 with DepotProjectId

use of org.finos.legend.sdlc.server.depot.model.DepotProjectId in project legend-sdlc by finos.

the class TestModelBuilder method buildEntitiesForTest.

public List<Entity> buildEntitiesForTest(String upstreamProjectId, VersionId upstreamVersionId, String downstreamProjectId, String downstreamVersionId) {
    DepotProjectId upstreamDepotProjectId = DepotProjectId.parseProjectId(upstreamProjectId);
    DepotProjectId downstreamDepotProjectId = DepotProjectId.parseProjectId(downstreamProjectId);
    Set<DepotProjectVersion> latestUpstreamLevel1Dependencies = this.metadataApi.getProjectDependencies(upstreamDepotProjectId, upstreamVersionId.toVersionIdString(), false);
    Set<DepotProjectVersion> dependencies = processDependencies(upstreamDepotProjectId, downstreamDepotProjectId, downstreamVersionId, latestUpstreamLevel1Dependencies);
    List<Entity> upstreamProjectWorkspaceEntities = this.metadataApi.getEntities(upstreamDepotProjectId, upstreamVersionId.toVersionIdString());
    return getEntities(downstreamDepotProjectId, downstreamVersionId, dependencies, upstreamProjectWorkspaceEntities);
}
Also used : DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) Entity(org.finos.legend.sdlc.domain.model.entity.Entity)

Example 2 with DepotProjectId

use of org.finos.legend.sdlc.server.depot.model.DepotProjectId in project legend-sdlc by finos.

the class TestModelBuilderTest method findEntitiesInMetadata.

private List<Entity> findEntitiesInMetadata(String projectId, String versionId) {
    DepotProjectId depotProjectId = DepotProjectId.parseProjectId(projectId);
    Set<DepotProjectVersion> dependencies = this.metadata.getMetadataApi().getProjectDependencies(depotProjectId, versionId, true);
    List<Entity> entities = Lists.mutable.withAll(this.metadata.getMetadataApi().getEntities(depotProjectId, versionId));
    dependencies.stream().map(d -> this.metadata.getMetadataApi().getEntities(d.getDepotProjectId(), d.getVersionId())).forEach(entities::addAll);
    return entities;
}
Also used : DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) VersionId(org.finos.legend.sdlc.domain.model.version.VersionId) InMemoryMetadataBackend(org.finos.legend.sdlc.server.inmemory.backend.metadata.InMemoryMetadataBackend) Lists(org.eclipse.collections.api.factory.Lists) Set(java.util.Set) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) TestModelBuilder(org.finos.legend.sdlc.server.domain.api.test.TestModelBuilder) WorkspaceType(org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType) MutableSet(org.eclipse.collections.api.set.MutableSet) TestTools(org.finos.legend.sdlc.domain.model.TestTools) List(java.util.List) DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) DependenciesApi(org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi) InMemoryBackend(org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend) Assert(org.junit.Assert) Collections(java.util.Collections) DependenciesApiImpl(org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApiImpl) Sets(org.eclipse.collections.api.factory.Sets) Before(org.junit.Before) Entity(org.finos.legend.sdlc.domain.model.entity.Entity)

Example 3 with DepotProjectId

use of org.finos.legend.sdlc.server.depot.model.DepotProjectId in project legend-sdlc by finos.

the class TestModelBuilder method processDependencies.

public Set<DepotProjectVersion> processDependencies(DepotProjectId upstreamProjectId, DepotProjectId downstreamProjectId, String downstreamVersionId, Set<DepotProjectVersion> latestUpstreamDependencies) {
    try {
        if (Iterate.anySatisfy(latestUpstreamDependencies, dependency -> downstreamProjectId.equals(dependency.getDepotProjectId()))) {
            throw new IllegalArgumentException("Project " + downstreamProjectId + " was specified as downstream but in fact it is a direct dependency for upstream project " + upstreamProjectId);
        }
        // get transitive dependencies for upstream project from metadata
        MutableSet<DepotProjectVersion> latestUpstreamTransitiveDependencies = Iterate.flatCollect(latestUpstreamDependencies, depotProjectVersion -> this.metadataApi.getProjectDependencies(depotProjectVersion.getDepotProjectId(), depotProjectVersion.getVersionId(), true), Sets.mutable.withAll(latestUpstreamDependencies));
        latestUpstreamTransitiveDependencies.removeIf(dependency -> upstreamProjectId.equals(dependency.getDepotProjectId()));
        Set<DepotProjectId> transitiveUpstreamDependenciesIds = SetAdapter.adapt(latestUpstreamDependencies).collect(DepotProjectVersion::getDepotProjectId);
        if (transitiveUpstreamDependenciesIds.contains(downstreamProjectId)) {
            throw new IllegalArgumentException("Project " + downstreamProjectId + " was specified as downstream but in fact it is an indirect dependency for upstream project " + upstreamProjectId);
        }
        Set<DepotProjectVersion> downstreamLevel1Dependencies = this.metadataApi.getProjectDependencies(downstreamProjectId, downstreamVersionId, false);
        Set<DepotProjectVersion> dependencies = Sets.mutable.empty();
        for (DepotProjectVersion dependency : downstreamLevel1Dependencies) {
            // remove the upstream project as it has changed
            if (dependency.getDepotProjectId().equals(upstreamProjectId)) {
                continue;
            }
            // remove common first level dependencies
            if (latestUpstreamDependencies.contains(dependency)) {
                continue;
            }
            // remove dependency if the upstream project has a different version of this dependency
            if (transitiveUpstreamDependenciesIds.contains(dependency.getDepotProjectId())) {
                continue;
            }
            // include this dependency
            dependencies.add(dependency);
            // and its transitive dependencies
            dependencies.addAll(this.metadataApi.getProjectDependencies(dependency.getDepotProjectId(), dependency.getVersionId(), true));
        }
        // finally add the new dependency tree of the upstream project
        dependencies.addAll(latestUpstreamTransitiveDependencies);
        // make sure that downstream or upstream projects were not included in dependencies list (it will cause entity duplication error)
        dependencies.removeIf(project -> project.getDepotProjectId().equals(downstreamProjectId) || project.getDepotProjectId().equals(upstreamProjectId));
        return dependencies;
    } catch (Exception ex) {
        throw new LegendSDLCServerException(StringTools.appendThrowableMessageIfPresent("Error processing dependencies", ex), ex);
    }
}
Also used : DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException)

Example 4 with DepotProjectId

use of org.finos.legend.sdlc.server.depot.model.DepotProjectId in project legend-sdlc by finos.

the class TestModelBuilder method buildEntitiesForTest.

public List<Entity> buildEntitiesForTest(String upstreamProjectId, String upstreamRevisionId, String downstreamProjectId, String downstreamVersionId) {
    DepotProjectId upstreamDepotProjectId = getDepotProjectId(upstreamProjectId);
    DepotProjectId downstreamDepotProjectId = DepotProjectId.parseProjectId(downstreamProjectId);
    Set<ProjectDependency> latestUpstreamLevel1Dependencies = this.dependenciesApi.getProjectRevisionUpstreamProjects(upstreamProjectId, upstreamRevisionId, false);
    Set<DepotProjectVersion> dependencies = processDependencies(upstreamDepotProjectId, downstreamDepotProjectId, downstreamVersionId, transformProjectDependencySet(latestUpstreamLevel1Dependencies));
    List<Entity> upstreamProjectWorkspaceEntities = this.entityApi.getProjectRevisionEntityAccessContext(upstreamProjectId, upstreamRevisionId).getEntities(null, null, null);
    return getEntities(downstreamDepotProjectId, downstreamVersionId, dependencies, upstreamProjectWorkspaceEntities);
}
Also used : DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency)

Example 5 with DepotProjectId

use of org.finos.legend.sdlc.server.depot.model.DepotProjectId in project legend-sdlc by finos.

the class TestModelBuilder method buildEntitiesForTest.

public List<Entity> buildEntitiesForTest(String upstreamProjectId, String upstreamWorkspaceId, WorkspaceType type, String upstreamRevisionId, String downstreamProjectId, String downstreamVersionId) {
    DepotProjectId upstreamDepotProjectId = getDepotProjectId(upstreamProjectId);
    DepotProjectId downstreamDepotProjectId = DepotProjectId.parseProjectId(downstreamProjectId);
    Set<ProjectDependency> latestUpstreamLevel1Dependencies = this.dependenciesApi.getWorkspaceRevisionUpstreamProjects(upstreamProjectId, upstreamWorkspaceId, type, upstreamRevisionId, false);
    Set<DepotProjectVersion> dependencies = processDependencies(upstreamDepotProjectId, downstreamDepotProjectId, downstreamVersionId, transformProjectDependencySet(latestUpstreamLevel1Dependencies));
    List<Entity> upstreamProjectWorkspaceEntities = this.entityApi.getWorkspaceRevisionEntityAccessContext(upstreamProjectId, upstreamWorkspaceId, type, upstreamRevisionId).getEntities(null, null, null);
    return getEntities(downstreamDepotProjectId, downstreamVersionId, dependencies, upstreamProjectWorkspaceEntities);
}
Also used : DepotProjectId(org.finos.legend.sdlc.server.depot.model.DepotProjectId) DepotProjectVersion(org.finos.legend.sdlc.server.depot.model.DepotProjectVersion) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency)

Aggregations

DepotProjectId (org.finos.legend.sdlc.server.depot.model.DepotProjectId)5 DepotProjectVersion (org.finos.legend.sdlc.server.depot.model.DepotProjectVersion)5 Entity (org.finos.legend.sdlc.domain.model.entity.Entity)4 ProjectDependency (org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency)2 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Lists (org.eclipse.collections.api.factory.Lists)1 Sets (org.eclipse.collections.api.factory.Sets)1 MutableSet (org.eclipse.collections.api.set.MutableSet)1 Iterate (org.eclipse.collections.impl.utility.Iterate)1 TestTools (org.finos.legend.sdlc.domain.model.TestTools)1 WorkspaceType (org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType)1 VersionId (org.finos.legend.sdlc.domain.model.version.VersionId)1 DependenciesApi (org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi)1 DependenciesApiImpl (org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApiImpl)1 TestModelBuilder (org.finos.legend.sdlc.server.domain.api.test.TestModelBuilder)1 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)1 InMemoryBackend (org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend)1 InMemoryMetadataBackend (org.finos.legend.sdlc.server.inmemory.backend.metadata.InMemoryMetadataBackend)1