Skip to content

Commit

Permalink
Add support for not eq expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Dec 3, 2024
1 parent 4086718 commit 440d248
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,27 @@ class LocalEntitiesFilterStrategy(entitiesRepository: EntitiesRepository) :
val candidate = CompareToNodeExpression.parse(predicate)
return when (val original = candidate?.original) {
is XPathEqExpr -> {
if (original.isEqual) {
val child = candidate.nodeSide.steps[0].name.name
val value = candidate.evalContextSide(sourceInstance, evaluationContext)
val child = candidate.nodeSide.steps[0].name.name
val value = candidate.evalContextSide(sourceInstance, evaluationContext)

val results = instanceAdapter.queryEq(
val results = if (original.isEqual) {
instanceAdapter.queryEq(
sourceInstance.instanceId,
child,
value as String
)

sourceInstance.replacePartialElements(results)
results.map {
it.parent = sourceInstance.root
it.ref
}
} else {
next.get()
instanceAdapter.queryNotEq(
sourceInstance.instanceId,
child,
value as String
)
}

sourceInstance.replacePartialElements(results)
results.map {
it.parent = sourceInstance.root
it.ref
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ class LocalEntitiesInstanceAdapter(private val entitiesRepository: EntitiesRepos
}
}

fun queryNotEq(instanceId: String, child: String, value: String): List<TreeElement> {
return when (child) {
EntityItemElement.ID -> {
filterAndConvertEntities(instanceId) { it.id != value }
}

EntityItemElement.LABEL -> {
filterAndConvertEntities(instanceId) { it.label != value }
}

EntityItemElement.VERSION -> {
filterAndConvertEntities(instanceId) { it.version != value.toInt() }
}

EntityItemElement.TRUNK_VERSION -> {
filterAndConvertEntities(instanceId) { it.trunkVersion != value.toInt() }
}

EntityItemElement.BRANCH_ID -> {
filterAndConvertEntities(instanceId) { it.branchId != value }
}

else -> {
val allEntities = entitiesRepository.getEntities(instanceId)

val entities = entitiesRepository.getAllByProperty(
instanceId,
child,
value
)

allEntities
.filterNot { it in entities }
.map { convertToElement(it) }
}
}
}

private fun filterAndConvertEntities(
list: String,
filter: (Entity.Saved) -> Boolean
Expand Down

0 comments on commit 440d248

Please sign in to comment.