Skip to content

Commit

Permalink
add a new API for pulling invalid entities
Browse files Browse the repository at this point in the history
  • Loading branch information
YannanGao-gs committed Oct 4, 2022
1 parent 0b56633 commit 5700899
Show file tree
Hide file tree
Showing 19 changed files with 441 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public interface EntityAccessContext

List<Entity> getEntities(Predicate<String> entityPathPredicate, Predicate<String> classifierPathPredicate, Predicate<? super Map<String, ?>> entityContentPredicate);

List<Entity> getInvalidEntities(Predicate<String> entityPathPredicate, Predicate<String> classifierPathPredicate, Predicate<? super Map<String, ?>> entityContentPredicate);

List<String> getEntityPaths(Predicate<String> entityPathPredicate, Predicate<String> classifierPathPredicate, Predicate<? super Map<String, ?>> entityContentPredicate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@ public List<Entity> getEntities(Predicate<String> entityPathPredicate, Predicate
}
}

@Override
public List<Entity> getInvalidEntities(Predicate<String> entityPathPredicate, Predicate<String> classifierPathPredicate, Predicate<? super Map<String, ?>> entityContentPredicate)
{
try (Stream<EntityProjectFile> stream = getEntityProjectFiles(getFileAccessContext(getProjectFileAccessProvider()), entityPathPredicate, classifierPathPredicate, entityContentPredicate))
{
return stream.map(EntityProjectFile::getInvalidEntity).filter(Objects::nonNull).collect(Collectors.toList());
}
catch (Exception e)
{
throw buildException(e,
() -> "User " + getCurrentUser() + " is not allowed to get entities for " + getInfoForException(),
() -> "Unknown entities for " + getInfoForException(),
() -> "Failed to get entities for " + getInfoForException());
}
}

@Override
public List<String> getEntityPaths(Predicate<String> entityPathPredicate, Predicate<String> classifierPathPredicate, Predicate<? super Map<String, ?>> entityContentPredicate)
{
Expand Down Expand Up @@ -923,5 +939,18 @@ synchronized Entity getEntity()
}
return this.entity;
}

synchronized Entity getInvalidEntity()
{
if (this.entity == null)
{
Entity localEntity = this.sourceDirectory.deserialize(this.file);
if (!Objects.equals(localEntity.getPath(), getEntityPath()))
{
return localEntity;
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ public List<Entity> getAllEntities(@PathParam("projectId") String projectId,
);
}

@GET
@Path("invalidEntities")
@ApiOperation("Get invalid entities of the backup user workspace")
public List<Entity> getInvalidEntities(@PathParam("projectId") String projectId,
@PathParam("workspaceId") String workspaceId,
@QueryParam("classifierPath")
@ApiParam("Only include entities with one of these classifier paths.") Set<String> classifierPaths,
@QueryParam("package")
@ApiParam("Only include entities in one of these packages. If includeSubPackages is true (which it is by default), then entities in subpackages are also included. Otherwise, only entities directly in one of the packages are included.") Set<String> packages,
@QueryParam("includeSubPackages")
@DefaultValue("true")
@ApiParam("Whether to include entities from subpackages or only directly in one of the given packages. This is ignored if no packages are supplied.") boolean includeSubPackages,
@QueryParam("name")
@ApiParam("Only include entities with a name matching this regular expression.") String nameRegex,
@QueryParam("stereotype")
@ApiParam("Only include entities with one of these stereotypes. The syntax is PROFILE.NAME, where PROFILE is the full path of the Profile that owns the Stereotype.") Set<String> stereotypes,
@QueryParam("taggedValue")
@ApiParam("Only include entities with a matching tagged value. The syntax is PROFILE.NAME/REGEX, where PROFILE is the full path of the Profile that owns the Tag, NAME is the name of the Tag, and REGEX is a regular expression to match against the value.") List<String> taggedValueRegexes)
{
return executeWithLogging(
"getting invalid entities in backup user workspace " + workspaceId + " for project " + projectId,
() -> getInvalidEntities(this.entityApi.getBackupUserWorkspaceEntityAccessContext(projectId, workspaceId), classifierPaths, packages, includeSubPackages, nameRegex, stereotypes, taggedValueRegexes)
);
}

@GET
@Path("{path}")
@ApiOperation("Get an entity of the backup user workspace by its path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ public List<Entity> getAllEntities(@PathParam("projectId") String projectId,
);
}

@GET
@Path("invalidEntities")
@ApiOperation("Get invalid entities of the backup user workspace at the revision")
public List<Entity> getInvalidEntities(@PathParam("projectId") String projectId,
@PathParam("workspaceId") String workspaceId,
@PathParam("revisionId") @ApiParam("Including aliases: head, latest, current, base") String revisionId,
@QueryParam("classifierPath")
@ApiParam("Only include entities with one of these classifier paths.") Set<String> classifierPaths,
@QueryParam("package")
@ApiParam("Only include entities in one of these packages. If includeSubPackages is true (which it is by default), then entities in subpackages are also included. Otherwise, only entities directly in one of the packages are included.") Set<String> packages,
@QueryParam("includeSubPackages")
@DefaultValue("true")
@ApiParam("Whether to include entities from subpackages or only directly in one of the given packages. This is ignored if no packages are supplied.") boolean includeSubPackages,
@QueryParam("name")
@ApiParam("Only include entities with a name matching this regular expression.") String nameRegex,
@QueryParam("stereotype")
@ApiParam("Only include entities with one of these stereotypes. The syntax is PROFILE.NAME, where PROFILE is the full path of the Profile that owns the Stereotype.") Set<String> stereotypes,
@QueryParam("taggedValue")
@ApiParam("Only include entities with a matching tagged value. The syntax is PROFILE.NAME/REGEX, where PROFILE is the full path of the Profile that owns the Tag, NAME is the name of the Tag, and REGEX is a regular expression to match against the value.") List<String> taggedValueRegexes)
{
return executeWithLogging(
"getting invalid entities in revision " + revisionId + " of backup user workspace " + workspaceId + " for project " + projectId,
() -> getInvalidEntities(this.entityApi.getBackupUserWorkspaceRevisionEntityAccessContext(projectId, workspaceId, revisionId), classifierPaths, packages, includeSubPackages, nameRegex, stereotypes, taggedValueRegexes)
);
}

@GET
@Path("{path}")
@ApiOperation("Get an entity of the backup user workspace at the revision by its path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ public List<Entity> getAllEntities(@PathParam("projectId") String projectId,
);
}

@GET
@Path("invalidEntities")
@ApiOperation("Get invalid entities of the user workspace with conflict resolution")
public List<Entity> getInvalidEntities(@PathParam("projectId") String projectId,
@PathParam("workspaceId") String workspaceId,
@QueryParam("classifierPath")
@ApiParam("Only include entities with one of these classifier paths.") Set<String> classifierPaths,
@QueryParam("package")
@ApiParam("Only include entities in one of these packages. If includeSubPackages is true (which it is by default), then entities in subpackages are also included. Otherwise, only entities directly in one of the packages are included.") Set<String> packages,
@QueryParam("includeSubPackages")
@DefaultValue("true")
@ApiParam("Whether to include entities from subpackages or only directly in one of the given packages. This is ignored if no packages are supplied.") boolean includeSubPackages,
@QueryParam("name")
@ApiParam("Only include entities with a name matching this regular expression.") String nameRegex,
@QueryParam("stereotype")
@ApiParam("Only include entities with one of these stereotypes. The syntax is PROFILE.NAME, where PROFILE is the full path of the Profile that owns the Stereotype.") Set<String> stereotypes,
@QueryParam("taggedValue")
@ApiParam("Only include entities with a matching tagged value. The syntax is PROFILE.NAME/REGEX, where PROFILE is the full path of the Profile that owns the Tag, NAME is the name of the Tag, and REGEX is a regular expression to match against the value.") List<String> taggedValueRegexes)
{
return executeWithLogging(
"getting invalid entities in user workspace with conflict resolution " + workspaceId + " for project " + projectId,
() -> getInvalidEntities(this.entityApi.getUserWorkspaceWithConflictResolutionEntityAccessContext(projectId, workspaceId), classifierPaths, packages, includeSubPackages, nameRegex, stereotypes, taggedValueRegexes)
);
}

@GET
@Path("{path}")
@ApiOperation("Get an entity of the user workspace with conflict resolution by its path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ public List<Entity> getAllEntities(@PathParam("projectId") String projectId,
);
}

@GET
@Path("invalidEntities")
@ApiOperation("Get invalid entities of the user workspace with conflict resolution at the revision")
public List<Entity> getInvalidEntities(@PathParam("projectId") String projectId,
@PathParam("workspaceId") String workspaceId,
@PathParam("revisionId") @ApiParam("Including aliases: head, latest, current, base") String revisionId,
@QueryParam("classifierPath")
@ApiParam("Only include entities with one of these classifier paths.") Set<String> classifierPaths,
@QueryParam("package")
@ApiParam("Only include entities in one of these packages. If includeSubPackages is true (which it is by default), then entities in subpackages are also included. Otherwise, only entities directly in one of the packages are included.") Set<String> packages,
@QueryParam("includeSubPackages")
@DefaultValue("true")
@ApiParam("Whether to include entities from subpackages or only directly in one of the given packages. This is ignored if no packages are supplied.") boolean includeSubPackages,
@QueryParam("name")
@ApiParam("Only include entities with a name matching this regular expression.") String nameRegex,
@QueryParam("stereotype")
@ApiParam("Only include entities with one of these stereotypes. The syntax is PROFILE.NAME, where PROFILE is the full path of the Profile that owns the Stereotype.") Set<String> stereotypes,
@QueryParam("taggedValue")
@ApiParam("Only include entities with a matching tagged value. The syntax is PROFILE.NAME/REGEX, where PROFILE is the full path of the Profile that owns the Tag, NAME is the name of the Tag, and REGEX is a regular expression to match against the value.") List<String> taggedValueRegexes)
{
return executeWithLogging(
"getting invalid entities in revision " + revisionId + " of user workspace with conflict resolution " + workspaceId + " for project " + projectId,
() -> getInvalidEntities(this.entityApi.getUserWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, workspaceId, revisionId), classifierPaths, packages, includeSubPackages, nameRegex, stereotypes, taggedValueRegexes)
);
}

@GET
@Path("{path}")
@ApiOperation("Get an entity of the user workspace with conflict resolution at the revision by its path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ protected List<Entity> getEntities(EntityAccessContext entityAccessContext, Set<
return entityAccessContext.getEntities(entityPathPredicate, classifierPathPredicate, contentPredicate);
}

protected List<Entity> getInvalidEntities(EntityAccessContext entityAccessContext, Set<String> classifierPaths, Set<String> packages, boolean includeSubPackages, String nameRegex, Set<String> stereotypes, Collection<String> taggedValueRegexes)
{
Predicate<String> entityPathPredicate = getEntityPathPredicate(packages, includeSubPackages, nameRegex);
Predicate<String> classifierPathPredicate = getClassifierPathPredicate(classifierPaths);
Predicate<Map<String, ?>> contentPredicate = getContentPredicate(stereotypes, taggedValueRegexes);
return entityAccessContext.getInvalidEntities(entityPathPredicate, classifierPathPredicate, contentPredicate);
}

private Predicate<String> getEntityPathPredicate(Set<String> packages, boolean includeSubPackages, String nameRegex)
{
Pattern namePattern = compileRegex(nameRegex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ public List<Entity> getAllEntities(@PathParam("projectId") String projectId,
);
}

@GET
@ApiOperation("Get invalid entities of the backup group workspace")
public List<Entity> getInvalidEntities(@PathParam("projectId") String projectId,
@PathParam("workspaceId") String workspaceId,
@QueryParam("classifierPath")
@ApiParam("Only include entities with one of these classifier paths.") Set<String> classifierPaths,
@QueryParam("package")
@ApiParam("Only include entities in one of these packages. If includeSubPackages is true (which it is by default), then entities in subpackages are also included. Otherwise, only entities directly in one of the packages are included.") Set<String> packages,
@QueryParam("includeSubPackages")
@DefaultValue("true")
@ApiParam("Whether to include entities from subpackages or only directly in one of the given packages. This is ignored if no packages are supplied.") boolean includeSubPackages,
@QueryParam("name")
@ApiParam("Only include entities with a name matching this regular expression.") String nameRegex,
@QueryParam("stereotype")
@ApiParam("Only include entities with one of these stereotypes. The syntax is PROFILE.NAME, where PROFILE is the full path of the Profile that owns the Stereotype.") Set<String> stereotypes,
@QueryParam("taggedValue")
@ApiParam("Only include entities with a matching tagged value. The syntax is PROFILE.NAME/REGEX, where PROFILE is the full path of the Profile that owns the Tag, NAME is the name of the Tag, and REGEX is a regular expression to match against the value.") List<String> taggedValueRegexes)
{
return executeWithLogging(
"getting invalid entities in backup group workspace " + workspaceId + " for project " + projectId,
() -> getInvalidEntities(this.entityApi.getBackupGroupWorkspaceEntityAccessContext(projectId, workspaceId), classifierPaths, packages, includeSubPackages, nameRegex, stereotypes, taggedValueRegexes)
);
}

@GET
@Path("{path}")
@ApiOperation("Get an entity of the backup group workspace by its path")
Expand Down
Loading

0 comments on commit 5700899

Please sign in to comment.