Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get project entities by classifier API #476

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface EntitiesService<T extends StoredEntity>

List<Entity> getEntities(String groupId, String artifactId, String versionId);

List<Entity> getEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier);

Optional<Entity> getEntity(String groupId, String artifactId, String versionId, String entityPath);

List<Entity> getEntityFromDependencies(String groupId, String artifactId, String versionId, List<String> entityPaths, boolean includeOrigin);
Expand All @@ -39,8 +41,15 @@ public interface EntitiesService<T extends StoredEntity>

List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion> projectDependencies, boolean transitive, boolean includeOrigin);

List<ProjectVersionEntities> getDependenciesEntitiesByClassifier(List<ProjectVersion> projectDependencies, String classifier, boolean transitive, boolean includeOrigin);

default List<ProjectVersionEntities> getDependenciesEntities(String groupId, String artifactId, String versionId, boolean transitive, boolean includeOrigin)
{
return getDependenciesEntities(Arrays.asList(new ProjectVersion(groupId, artifactId, versionId)), transitive, includeOrigin);
}

default List<ProjectVersionEntities> getDependenciesEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier, boolean transitive, boolean includeOrigin)
{
return getDependenciesEntitiesByClassifier(Arrays.asList(new ProjectVersion(groupId, artifactId, versionId)), classifier, transitive, includeOrigin);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ public Response getEntitiesFromDependencies(@PathParam("groupId") String groupId
return handle(GET_VERSION_DEPENDENCY_ENTITIES, () -> this.entitiesService.getDependenciesEntities(groupId, artifactId, versionId, transitive, includeOrigin), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build());
}

@GET
YannanGao-gs marked this conversation as resolved.
Show resolved Hide resolved
@Path("/projects/{groupId}/{artifactId}/versions/{versionId}/classifier/{classifier}/dependencies")
@ApiOperation(value = GET_VERSION_DEPENDENCY_ENTITIES, hidden = true)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getEntitiesFromDependenciesByClassifier(@PathParam("groupId") String groupId,
@PathParam("artifactId") String artifactId,
@PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId,
@PathParam("classifier") String classifier,
@QueryParam("transitive") @DefaultValue("false")
@ApiParam("Whether to return transitive dependencies") boolean transitive,
@QueryParam("includeOrigin") @DefaultValue("false")
@ApiParam("Whether to return start of dependency tree") boolean includeOrigin,
@Context Request request)
{
if (classifier == null)
{
Response.status(Response.Status.BAD_REQUEST).entity("Classifier is not valid").build();
}
return handle(GET_VERSION_DEPENDENCY_ENTITIES, () -> this.entitiesService.getDependenciesEntitiesByClassifier(groupId, artifactId, versionId, classifier, transitive, includeOrigin), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build());
}

@POST
@Path("/projects/{groupId}/{artifactId}/versions/{versionId}/dependencies/paths")
@ApiOperation(value = GET_VERSION_ENTITY_FROM_DEPENDENCIES, hidden = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,23 @@ public Response getEntities(@PathParam("groupId") String groupId,
return handle(GET_VERSION_ENTITIES, () -> this.entitiesService.getEntities(groupId, artifactId, versionId), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build());
}


@GET
@Path("/projects/{groupId}/{artifactId}/versions/{versionId}/classifier/{classifier}")
@ApiOperation(value = GET_VERSION_ENTITIES, hidden = true)
@Produces(MediaType.APPLICATION_JSON)
public Response getEntitiesByClassifier(@PathParam("groupId") String groupId,
@PathParam("artifactId") String artifactId,
@PathParam("versionId") @ApiParam(value = VersionValidator.VALID_VERSION_ID_TXT) String versionId,
@PathParam("classifier") String classifier,
@Context Request request)
{
if (classifier == null)
{
Response.status(Response.Status.BAD_REQUEST).entity("Classifier is not valid").build();
}
return handle(GET_VERSION_ENTITIES, () -> this.entitiesService.getEntitiesByClassifier(groupId, artifactId, versionId, classifier), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build());
}

@GET
@Path("/projects/{groupId}/{artifactId}/versions/{versionId}/entities/{path}")
@ApiOperation(GET_VERSION_ENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public List<Entity> getEntities(String groupId, String artifactId, String versio
return entities.getAllEntities(groupId, artifactId, version);
}

@Override
public List<Entity> getEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier)
{
String version = this.projects.resolveAliasesAndCheckVersionExists(groupId, artifactId, versionId);
return entities.findEntitiesByClassifier(groupId, artifactId, version, classifier);
}

@Override
public Optional<Entity> getEntity(String groupId, String artifactId, String versionId, String entityPath)
{
Expand All @@ -87,8 +94,7 @@ public List<Entity> getEntitiesByPackage(String groupId, String artifactId, Stri
return entities.getEntitiesByPackage(groupId, artifactId, version, packageName, classifierPaths, includeSubPackages);
}

@Override
public List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion> projectDependencies, boolean transitive, boolean includeOrigin)
public List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion> projectDependencies, String classifier, boolean transitive, boolean includeOrigin)
{
Set<ProjectVersion> dependencies = (Set<ProjectVersion>) executeWithTrace(CALCULATE_PROJECT_DEPENDENCIES, () ->
{
Expand All @@ -110,7 +116,15 @@ public List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion>
ParallelIterate.forEach(dependencies, dep ->
{
String version = this.projects.resolveAliasesAndCheckVersionExists(dep.getGroupId(), dep.getArtifactId(), dep.getVersionId());
List<Entity> deps = (List<Entity>) entities.getAllEntities(dep.getGroupId(), dep.getArtifactId(), version).stream().collect(Collectors.toList());
List<Entity> deps;
if (classifier != null)
{
deps = (List<Entity>) entities.findEntitiesByClassifier(dep.getGroupId(), dep.getArtifactId(), version, classifier).stream().collect(Collectors.toList());
}
else
{
deps = (List<Entity>) entities.getAllEntities(dep.getGroupId(), dep.getArtifactId(), version).stream().collect(Collectors.toList());
}
depEntities.add(new ProjectVersionEntities(dep.getGroupId(), dep.getArtifactId(), version, deps));
totalEntities.addAndGet(deps.size());
TracerFactory.get().log(String.format("Total [%s-%s-%s]: [%s] entities",dep.getGroupId(), dep.getArtifactId(), dep.getVersionId(),deps.size()));
Expand All @@ -120,6 +134,18 @@ public List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion>
});
}

@Override
public List<ProjectVersionEntities> getDependenciesEntities(List<ProjectVersion> projectDependencies, boolean transitive, boolean includeOrigin)
{
return getDependenciesEntities(projectDependencies, null, transitive, includeOrigin);
}

@Override
public List<ProjectVersionEntities> getDependenciesEntitiesByClassifier(List<ProjectVersion> projectDependencies, String classifier, boolean transitive, boolean includeOrigin)
{
return getDependenciesEntities(projectDependencies, classifier, transitive, includeOrigin);
}

private Object executeWithTrace(String label, Supplier<Object> functionToExecute)
{
return TracerFactory.get().executeWithTrace(label, () -> functionToExecute.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;

import static org.finos.legend.depot.domain.version.VersionValidator.BRANCH_SNAPSHOT;
Expand Down Expand Up @@ -244,6 +243,35 @@ public void canGetClassifiers()
Assert.assertEquals(entities.size(), 3);
}

@Test
public void canGetEntitiesForProjectAndVersionByClassifier()
{
projectsVersionsStore.createOrUpdate(new StoreProjectVersionData("example.services.test","test","2.0.2"));
entityUtils.loadEntities("PROD-C", "2.0.2");
List<Entity> entity = entitiesService.getEntitiesByClassifier("example.services.test", "test", "2.0.2", "meta::pure::metamodel::function::ConcreteFunctionDefinition");
Assert.assertNotNull(entity);
Assert.assertEquals(1, entity.size());
}

@Test
public void canGetDependencyEntitiesForProjectAndVersionByClassifier()
{
StoreProjectVersionData project = new StoreProjectVersionData("examples.metadata", "test-dependencies", "1.0.1");
ProjectVersion pv = new ProjectVersion("example.services.test", "test", "2.0.2");
project.getVersionData().addDependency(pv);
projectsVersionsStore.createOrUpdate(project);
projectsVersionsStore.createOrUpdate(new StoreProjectVersionData("example.services.test","test","2.0.2"));
entityUtils.loadEntities("PROD-B", "1.0.1");
entityUtils.loadEntities("PROD-C", "2.0.2");
List<Entity> entity = entitiesService.getDependenciesEntitiesByClassifier("examples.metadata", "test-dependencies", "1.0.1", "meta::pure::metamodel::function::ConcreteFunctionDefinition", true, true);
Assert.assertNotNull(entity);
Assert.assertEquals(2, entity.size());

List<Entity> entity1 = entitiesService.getDependenciesEntitiesByClassifier("examples.metadata", "test-dependencies", "1.0.1", "meta::pure::metamodel::function::ConcreteFunctionDefinition", true, false);
Assert.assertNotNull(entity1);
Assert.assertEquals(1, entity1.size());
}

@Test
public void canGetEntityFromDependencies()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"_type": "entityData",
"versionId": "1.0.1",
"groupId": "examples.metadata",
"artifactId": "test-dependencies",
"versionedEntity": false,
"entityAttributes": {
"path": "test::testFunction__String_1_",
"classifierPath": "meta::pure::metamodel::function::ConcreteFunctionDefinition",
"package": "test"
},
"entity": {
"classifierPath": "meta::pure::metamodel::function::ConcreteFunctionDefinition",
"path": "test::testFunction__String_1_",
"content": {
"_type": "function",
"body": [
{
"_type": "string",
"value": ""
}
],
"name": "testFunction__String_1_",
"package": "test",
"parameters": [],
"postConstraints": [],
"preConstraints": [],
"returnMultiplicity": {
"lowerBound": 1,
"upperBound": 1
},
"returnType": "String"
}
},
"id": ""
}
]
Loading
Loading