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);
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations