diff --git a/legend-depot-artifacts-services/src/test/java/org/finos/legend/depot/services/artifacts/handlers/generations/TestGenerationsProvider.java b/legend-depot-artifacts-services/src/test/java/org/finos/legend/depot/services/artifacts/handlers/generations/TestGenerationsProvider.java index f41bfdbcb..8a836f85c 100644 --- a/legend-depot-artifacts-services/src/test/java/org/finos/legend/depot/services/artifacts/handlers/generations/TestGenerationsProvider.java +++ b/legend-depot-artifacts-services/src/test/java/org/finos/legend/depot/services/artifacts/handlers/generations/TestGenerationsProvider.java @@ -161,6 +161,14 @@ public void canGetTheRightElementPathFromGeneratedFile() StoredFileGeneration storedFileGeneration2 = fileGenerations.stream().filter(f -> f.getPath().equals("examples::metadata::snowFlakeApp2")).findFirst().get(); Assert.assertEquals(generatedFiles.get(0).getPath(), storedFileGeneration.getFile().getPath()); Assert.assertEquals(generatedFiles.get(1).getPath(), storedFileGeneration2.getFile().getPath()); + + List searchDocuments = generations.findByType(TEST_GROUP_ID,TEST_ARTIFACT_ID, "2.0.0", "searchDocuments"); + Assert.assertEquals(2, searchDocuments.size()); + List snowFlakeAppSearchDocuments = generations.findByType(TEST_GROUP_ID,TEST_ARTIFACT_ID, "2.0.0", "searchDocuments", "examples::metadata::snowFlakeApp"); + Assert.assertEquals(1, snowFlakeAppSearchDocuments.size()); + StoredFileGeneration storedFileGeneration1 = snowFlakeAppSearchDocuments.get(0); + Assert.assertEquals(storedFileGeneration1.getPath(),"examples::metadata::snowFlakeApp"); + Assert.assertEquals(storedFileGeneration1.getType(),"searchDocuments"); } @Test diff --git a/legend-depot-generations-api/src/main/java/org/finos/legend/depot/services/api/generations/FileGenerationsService.java b/legend-depot-generations-api/src/main/java/org/finos/legend/depot/services/api/generations/FileGenerationsService.java index 5ee8642e3..a7bf81c04 100644 --- a/legend-depot-generations-api/src/main/java/org/finos/legend/depot/services/api/generations/FileGenerationsService.java +++ b/legend-depot-generations-api/src/main/java/org/finos/legend/depot/services/api/generations/FileGenerationsService.java @@ -17,7 +17,6 @@ import org.finos.legend.depot.domain.generation.DepotGeneration; import org.finos.legend.depot.store.model.generations.StoredFileGeneration; -import org.finos.legend.sdlc.domain.model.entity.Entity; import java.util.List; import java.util.Optional; @@ -31,7 +30,12 @@ public interface FileGenerationsService Optional getFileGenerationsByFilePath(String groupId, String artifactId, String versionsId, String filePath); - List findByType(String groupId, String artifactId, String versionId, String type); + default List findByType(String groupId, String artifactId, String versionId, String type) + { + return findByType(groupId, artifactId, versionId, type, null); + } + + List findByType(String groupId, String artifactId, String versionId, String type, String elementPath); default Optional getFileGenerationContentByFilePath(String groupId, String artifactId, String versionsId, String filePath) { diff --git a/legend-depot-generations-api/src/main/java/org/finos/legend/depot/store/api/generations/FileGenerations.java b/legend-depot-generations-api/src/main/java/org/finos/legend/depot/store/api/generations/FileGenerations.java index 8bd5666b8..fd801e5b9 100644 --- a/legend-depot-generations-api/src/main/java/org/finos/legend/depot/store/api/generations/FileGenerations.java +++ b/legend-depot-generations-api/src/main/java/org/finos/legend/depot/store/api/generations/FileGenerations.java @@ -28,7 +28,9 @@ public interface FileGenerations List findByType(String groupId, String artifactId,String versionId, String type); - List findByElementPath(String groupId, String artifactId, String versionId, String generationPath); + List findByElementPath(String groupId, String artifactId, String versionId, String elementPath); + + List findByTypeAndElementPath(String groupId, String artifactId,String versionId, String type, String elementPath); Optional findByFilePath(String groupId, String artifactId, String versionId, String filePath); diff --git a/legend-depot-generations-services/src/main/java/org/finos/legend/depot/server/resources/generations/FileGenerationsResource.java b/legend-depot-generations-services/src/main/java/org/finos/legend/depot/server/resources/generations/FileGenerationsResource.java index 56f7af737..f71a77e47 100644 --- a/legend-depot-generations-services/src/main/java/org/finos/legend/depot/server/resources/generations/FileGenerationsResource.java +++ b/legend-depot-generations-services/src/main/java/org/finos/legend/depot/server/resources/generations/FileGenerationsResource.java @@ -29,6 +29,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Request; @@ -104,9 +105,9 @@ public Response getFileGenerationContentByFilePath(@PathParam("groupId") String @Path("/generations/{groupId}/{artifactId}/{versionId}/types/{type}") @ApiOperation(ResourceLoggingAndTracing.GET_VERSION_FILE_GENERATION_BY_TYPE) @Produces(MediaType.APPLICATION_JSON) - public Response getFileGenerations(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") @ApiParam("a valid version string: x.y.z, master-SNAPSHOT") String versionId, @PathParam("type") String type, @Context Request request) + public Response getFileGenerations(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId, @PathParam("versionId") @ApiParam("a valid version string: x.y.z, master-SNAPSHOT") String versionId, @PathParam("type") String type, @QueryParam("elementPath")@ApiParam("Element path that generated artifacts") String elementPath, @Context Request request) { - return handle(ResourceLoggingAndTracing.GET_VERSION_FILE_GENERATION_BY_TYPE, () -> this.generationsService.findByType(groupId, artifactId, versionId, type), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build()); + return handle(ResourceLoggingAndTracing.GET_VERSION_FILE_GENERATION_BY_TYPE, () -> this.generationsService.findByType(groupId, artifactId, versionId, type, elementPath), request, () -> EtagBuilder.create().withGAV(groupId, artifactId, versionId).build()); } } diff --git a/legend-depot-generations-services/src/main/java/org/finos/legend/depot/services/generations/impl/FileGenerationsServiceImpl.java b/legend-depot-generations-services/src/main/java/org/finos/legend/depot/services/generations/impl/FileGenerationsServiceImpl.java index e790ef70c..85ddc3f66 100644 --- a/legend-depot-generations-services/src/main/java/org/finos/legend/depot/services/generations/impl/FileGenerationsServiceImpl.java +++ b/legend-depot-generations-services/src/main/java/org/finos/legend/depot/services/generations/impl/FileGenerationsServiceImpl.java @@ -63,9 +63,13 @@ public Optional getFileGenerationsByFilePath(String groupId, St } @Override - public List findByType(String groupId, String artifactId, String versionId, String type) + public List findByType(String groupId, String artifactId, String versionId, String type, String elementPath) { versionId = this.projects.resolveAliasesAndCheckVersionExists(groupId, artifactId, versionId); - return fileGenerations.findByType(groupId, artifactId, versionId, type); + if (elementPath == null) + { + return fileGenerations.findByType(groupId, artifactId, versionId, type); + } + return fileGenerations.findByTypeAndElementPath(groupId, artifactId, versionId, type, elementPath); } } diff --git a/legend-depot-generations-services/src/test/java/org/finos/legend/depot/services/generations/TestFileGenerationsService.java b/legend-depot-generations-services/src/test/java/org/finos/legend/depot/services/generations/TestFileGenerationsService.java index 55b01fcf2..bf5ec6d1e 100644 --- a/legend-depot-generations-services/src/test/java/org/finos/legend/depot/services/generations/TestFileGenerationsService.java +++ b/legend-depot-generations-services/src/test/java/org/finos/legend/depot/services/generations/TestFileGenerationsService.java @@ -150,6 +150,15 @@ public void canQueryFileGenerationEntitiesByElementPath() Assert.assertEquals(2, service.getFileGenerationsByElementPath("group.test", "test", "1.0.0", "examples::metadata::test::ClientBasic").size()); } + @Test + public void canGetByType() + { + List fileGenerations = service.findByType("group.test", "test", "1.0.0", AVRO); + Assert.assertEquals(12, fileGenerations.size()); + Assert.assertEquals(0, service.findByType("group.test", "test", "1.0.0", AVRO, "element::NotFound").size()); + Assert.assertEquals(12, service.findByType("group.test", "test", "1.0.0", AVRO, "examples::avrogen").size()); + } + @Test public void canQueryFileGenerationEntitiesByFilePath() { diff --git a/legend-depot-generations-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generations/FileGenerationsMongo.java b/legend-depot-generations-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generations/FileGenerationsMongo.java index 2d5f48a07..d934c9c55 100644 --- a/legend-depot-generations-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generations/FileGenerationsMongo.java +++ b/legend-depot-generations-store-mongo/src/main/java/org/finos/legend/depot/store/mongo/generations/FileGenerationsMongo.java @@ -104,6 +104,12 @@ public List findByType(String groupId, String artifactId, return find(and(getArtifactAndVersionFilter(groupId, artifactId, versionId), eq(GENERATION_TYPE, type))); } + @Override + public List findByTypeAndElementPath(String groupId, String artifactId, String versionId, String type, String elementPath) + { + return find(and(getArtifactAndVersionFilter(groupId, artifactId, versionId), eq(GENERATION_TYPE, type), eq(GENERATION_PATH, elementPath))); + } + @Override public long delete(String groupId, String artifactId, String versionId) {