Skip to content

Commit

Permalink
add element path as query param to get by type in generations api
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Nov 18, 2024
1 parent 4490620 commit 01729da
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoredFileGeneration> searchDocuments = generations.findByType(TEST_GROUP_ID,TEST_ARTIFACT_ID, "2.0.0", "searchDocuments");
Assert.assertEquals(2, searchDocuments.size());
List<StoredFileGeneration> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +30,12 @@ public interface FileGenerationsService

Optional<DepotGeneration> getFileGenerationsByFilePath(String groupId, String artifactId, String versionsId, String filePath);

List<StoredFileGeneration> findByType(String groupId, String artifactId, String versionId, String type);
default List<StoredFileGeneration> findByType(String groupId, String artifactId, String versionId, String type)
{
return findByType(groupId, artifactId, versionId, type, null);
}

List<StoredFileGeneration> findByType(String groupId, String artifactId, String versionId, String type, String elementPath);

default Optional<String> getFileGenerationContentByFilePath(String groupId, String artifactId, String versionsId, String filePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public interface FileGenerations

List<StoredFileGeneration> findByType(String groupId, String artifactId,String versionId, String type);

List<StoredFileGeneration> findByElementPath(String groupId, String artifactId, String versionId, String generationPath);
List<StoredFileGeneration> findByElementPath(String groupId, String artifactId, String versionId, String elementPath);

List<StoredFileGeneration> findByTypeAndElementPath(String groupId, String artifactId,String versionId, String type, String elementPath);

Optional<StoredFileGeneration> findByFilePath(String groupId, String artifactId, String versionId, String filePath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ public Optional<DepotGeneration> getFileGenerationsByFilePath(String groupId, St
}

@Override
public List<StoredFileGeneration> findByType(String groupId, String artifactId, String versionId, String type)
public List<StoredFileGeneration> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoredFileGeneration> 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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public List<StoredFileGeneration> findByType(String groupId, String artifactId,
return find(and(getArtifactAndVersionFilter(groupId, artifactId, versionId), eq(GENERATION_TYPE, type)));
}

@Override
public List<StoredFileGeneration> 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)
{
Expand Down

0 comments on commit 01729da

Please sign in to comment.