Skip to content

Commit

Permalink
refactor and decompose classifier APIs functionally (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-gunjan authored Mar 7, 2024
1 parent 25d8d2f commit ff0e4b7
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@
package org.finos.legend.depot.services.api.entities;

import org.finos.legend.depot.domain.entity.DepotEntity;
import org.finos.legend.depot.domain.entity.DepotEntityOverview;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.depot.domain.version.Scope;

import java.util.List;

public interface EntityClassifierService
{
List<DepotEntity> getEntitiesByClassifierPath(String classifierPath, String search, Integer limit, Scope scope, boolean summary);
List<DepotEntity> getEntitiesByClassifierPath(String classifierPath, String search, Integer limit, Scope scope, boolean latestVersion);

List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, String search, List<ProjectVersion> projectVersions, Integer limit, boolean summary);
List<DepotEntity> findClassifierEntities(String classifier, Scope scope);

List<DepotEntity> findLatestEntitiesByClassifier(String classifier, String search, Integer limit, boolean summary);
List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions);

List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, boolean summary);
List<DepotEntityOverview> findClassifierSummaries(String classifier, Scope scope);

List<DepotEntity> findLatestEntitiesByClassifier(String classifier, boolean summary);
List<DepotEntityOverview> findClassifierSummariesByVersions(String classifier, List<ProjectVersion> projectVersions);

List<DepotEntity> findClassifierEntities(String classifier, Scope scope, String search, Integer limit);

List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions, String search, Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package org.finos.legend.depot.store.api.entities;

import org.finos.legend.depot.domain.entity.DepotEntity;
import org.finos.legend.depot.domain.entity.DepotEntityOverview;
import org.finos.legend.depot.store.model.entities.StoredEntity;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.sdlc.domain.model.entity.Entity;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -34,15 +36,28 @@ public interface Entities<T extends StoredEntity>

List<Entity> getEntitiesByPackage(String groupId, String artifactId, String versionId, String packageName, Set<String> classifierPaths, boolean includeSubPackages);

List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, String search, List<ProjectVersion> projectVersions, Integer limit, boolean summary);
default List<DepotEntity> findEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier)
{
return findClassifierEntitiesByVersions(classifier, Arrays.asList(new ProjectVersion(groupId, artifactId, versionId)));
}

List<DepotEntity> findLatestEntitiesByClassifier(String classifier, String search, Integer limit, boolean summary);
List<DepotEntity> findReleasedClassifierEntities(String classifier);

List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, boolean summary);
List<DepotEntity> findLatestClassifierEntities(String classifier);

List<DepotEntity> findLatestEntitiesByClassifier(String classifier, boolean summary);
List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions);

List<Entity> findEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier);
List<DepotEntityOverview> findReleasedClassifierSummaries(String classifier);

List<DepotEntityOverview> findLatestClassifierSummaries(String classifier);

List<DepotEntityOverview> findClassifierSummariesByVersions(String classifier, List<ProjectVersion> projectVersions);

List<DepotEntity> findReleasedClassifierEntities(String classifier, String search, Integer limit);

List<DepotEntity> findLatestClassifierEntities(String classifier, String search, Integer limit);

List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions, String search, Integer limit);

List<T> getStoredEntities(String groupId, String artifactId, String versionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public EntityClassifierResource(EntityClassifierService graphService)
public Response getEntities(@PathParam("classifierPath") @ApiParam("The classifier path of the entities") String classifierPath,
@QueryParam("search") @ApiParam("The search string that the entity path contains") String search,
@QueryParam("scope") @ApiParam("Whether to return entities for the latest released version or snapshot") @DefaultValue("RELEASES") Scope scope,
@QueryParam("limit") @ApiParam("Limit the number of entities returned") Integer limit,
@QueryParam("summary") @DefaultValue("false") @ApiParam("Whether to return the summary view of the ENTITIES or the full entity") boolean summary)
@QueryParam("limit") @ApiParam("Limit the number of entities returned") Integer limit)
{
return handleResponse(GET_ENTITIES_BY_CLASSIFIER_PATH, () -> this.graphService.getEntitiesByClassifierPath(classifierPath, search, limit, scope, summary));
return handleResponse(GET_ENTITIES_BY_CLASSIFIER_PATH, () -> this.graphService.getEntitiesByClassifierPath(classifierPath, search, limit, scope, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
package org.finos.legend.depot.services.entities;

import org.finos.legend.depot.domain.entity.DepotEntity;
import org.finos.legend.depot.domain.entity.DepotEntityOverview;
import org.finos.legend.depot.domain.project.ProjectVersion;
import org.finos.legend.depot.domain.version.Scope;
import org.finos.legend.depot.services.api.entities.EntityClassifierService;
import org.finos.legend.depot.services.api.projects.ProjectsService;
import org.finos.legend.depot.store.api.entities.Entities;
import org.finos.legend.depot.store.model.projects.StoreProjectData;
import org.slf4j.Logger;

import javax.inject.Inject;
import java.util.ArrayList;
Expand All @@ -32,7 +32,6 @@

public class EntityClassifierServiceImpl implements EntityClassifierService
{
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(EntityClassifierServiceImpl.class);
private final Entities entities;
private final ProjectsService projects;
private static final int PAGE_SIZE = 100;
Expand Down Expand Up @@ -63,19 +62,19 @@ else if (lastIndex >= allProjects.size())
}

@Override
public List<DepotEntity> getEntitiesByClassifierPath(String classifierPath, String search, Integer limit, Scope scope, boolean summary)
public List<DepotEntity> getEntitiesByClassifierPath(String classifierPath, String search, Integer limit, Scope scope, boolean latestVersion)
{
if (Scope.SNAPSHOT.equals(scope))
{
return this.findLatestEntitiesByClassifier(classifierPath, search, limit, summary);
return this.findClassifierEntities(classifierPath, scope, search, limit);
}
List<DepotEntity> result = new ArrayList<>();
int currentPage = 1;
List<StoreProjectData> allProjects = projects.getAllProjectCoordinates();
List<ProjectVersion> projectVersions = this.getLatestProjectVersionByPage(currentPage, PAGE_SIZE, allProjects);
while (!projectVersions.isEmpty())
{
List<DepotEntity> entities = this.findReleasedEntitiesByClassifier(classifierPath, search, projectVersions, limit, summary);
List<DepotEntity> entities = this.findClassifierEntitiesByVersions(classifierPath, projectVersions, search, limit);
result.addAll(entities);
if (limit != null && result.size() >= limit)
{
Expand All @@ -92,26 +91,50 @@ public List<DepotEntity> getEntitiesByClassifierPath(String classifierPath, Stri
}

@Override
public List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, String search, List<ProjectVersion> projectVersions, Integer limit, boolean summary)
public List<DepotEntity> findClassifierEntities(String classifier, Scope scope)
{
return entities.findReleasedEntitiesByClassifier(classifier, search, projectVersions, limit, summary);
if (scope.equals(Scope.SNAPSHOT))
{
return entities.findLatestClassifierEntities(classifier);
}
return entities.findReleasedClassifierEntities(classifier);
}

@Override
public List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions)
{
return entities.findClassifierEntitiesByVersions(classifier, projectVersions);
}

@Override
public List<DepotEntityOverview> findClassifierSummaries(String classifier, Scope scope)
{
if (scope.equals(Scope.SNAPSHOT))
{
return entities.findLatestClassifierSummaries(classifier);
}
return entities.findReleasedClassifierSummaries(classifier);
}

@Override
public List<DepotEntity> findLatestEntitiesByClassifier(String classifier, String search, Integer limit, boolean summary)
public List<DepotEntityOverview> findClassifierSummariesByVersions(String classifier, List<ProjectVersion> projectVersions)
{
return entities.findLatestEntitiesByClassifier(classifier, search, limit, summary);
return entities.findClassifierSummariesByVersions(classifier, projectVersions);
}

@Override
public List<DepotEntity> findReleasedEntitiesByClassifier(String classifier, boolean summary)
public List<DepotEntity> findClassifierEntities(String classifier, Scope scope, String search, Integer limit)
{
return entities.findReleasedEntitiesByClassifier(classifier, summary);
if (scope.equals(Scope.SNAPSHOT))
{
return entities.findLatestClassifierEntities(classifier, search, limit);
}
return entities.findReleasedClassifierEntities(classifier, search, limit);
}

@Override
public List<DepotEntity> findLatestEntitiesByClassifier(String classifier, boolean summary)
public List<DepotEntity> findClassifierEntitiesByVersions(String classifier, List<ProjectVersion> projectVersions, String search, Integer limit)
{
return entities.findLatestEntitiesByClassifier(classifier, summary);
return entities.findClassifierEntitiesByVersions(classifier, projectVersions, search, limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,6 @@ protected Bson getArtifactVersionedFilter(String groupId, String artifactId)

protected abstract Entity resolvedToEntityDefinition(T storedEntity);

public FindIterable findReleasedEntitiesByClassifier(String classifier, String search, List<ProjectVersion> projectVersions)
{
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
if (projectVersions != null && !projectVersions.isEmpty())
{
filters.add(or(ListIterate.collect(projectVersions, projectVersion -> getArtifactAndVersionFilter(projectVersion.getGroupId(), projectVersion.getArtifactId(), projectVersion.getVersionId()))));
}
else
{
filters.add(Filters.not(Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT(""))));
}
if (search != null)
{
filters.add(Filters.regex(ENTITY_PATH, Pattern.quote(search), "i"));
}
return executeFind(and(filters));
}

public FindIterable findLatestEntitiesByClassifier(String classifier, String search)
{
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
filters.add(Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT("")));
if (search != null)
{
filters.add(Filters.regex(ENTITY_PATH, Pattern.quote(search), "i"));
}
return executeFind(and(filters));
}

public Optional<Entity> getEntity(String groupId, String artifactId, String versionId, String path)
{
Bson filterByKey = getEntityPathFilter(groupId, artifactId, versionId, path);
Expand Down Expand Up @@ -210,9 +179,58 @@ public FindIterable findLatestEntitiesByClassifier(String classifier)
return executeFind(and(eq(ENTITY_CLASSIFIER_PATH, classifier), Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT(""))));
}

public List<Entity> findEntitiesByClassifier(String groupId, String artifactId, String versionId, String classifier)
public FindIterable findEntitiesByClassifierAndVersions(String classifier, List<ProjectVersion> projectVersions)
{
return find(and(getArtifactAndVersionVersionedFilter(groupId, artifactId, versionId), eq(ENTITY_CLASSIFIER_PATH, classifier))).parallelStream().map(this::resolvedToEntityDefinition).collect(Collectors.toList());
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
if (projectVersions != null && !projectVersions.isEmpty())
{
filters.add(or(ListIterate.collect(projectVersions, projectVersion -> getArtifactAndVersionFilter(projectVersion.getGroupId(), projectVersion.getArtifactId(), projectVersion.getVersionId()))));
}
return executeFind(and(filters));
}

public FindIterable findReleasedEntitiesByClassifier(String classifier, String search)
{
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
filters.add(Filters.not(Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT(""))));
if (search != null)
{
filters.add(Filters.regex(ENTITY_PATH, Pattern.quote(search), "i"));
}
return executeFind(and(filters));
}

public FindIterable findLatestEntitiesByClassifier(String classifier, String search)
{
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
filters.add(Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT("")));
if (search != null)
{
filters.add(Filters.regex(ENTITY_PATH, Pattern.quote(search), "i"));
}
return executeFind(and(filters));
}

public FindIterable findEntitiesByClassifierAndVersions(String classifier, String search, List<ProjectVersion> projectVersions)
{
List<Bson> filters = new ArrayList<>();
filters.add(eq(ENTITY_CLASSIFIER_PATH, classifier));
if (projectVersions != null && !projectVersions.isEmpty())
{
filters.add(or(ListIterate.collect(projectVersions, projectVersion -> getArtifactAndVersionFilter(projectVersion.getGroupId(), projectVersion.getArtifactId(), projectVersion.getVersionId()))));
}
else
{
filters.add(Filters.not(Filters.regex(BaseMongo.VERSION_ID, BRANCH_SNAPSHOT(""))));
}
if (search != null)
{
filters.add(Filters.regex(ENTITY_PATH, Pattern.quote(search), "i"));
}
return executeFind(and(filters));
}

public long delete(String groupId, String artifactId, String versionId)
Expand Down
Loading

0 comments on commit ff0e4b7

Please sign in to comment.