Skip to content

Commit 38269cc

Browse files
willr3stalep
authored andcommitted
fix findMatchingFingerprint sorting when not preceeding values
1 parent 3132a52 commit 38269cc

3 files changed

Lines changed: 95 additions & 36 deletions

File tree

src/main/java/io/hyperfoil/tools/h5m/entity/ValueEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public ValueEntity(FolderEntity folder, NodeEntity node,JsonNode data){
7979
this.node = node;
8080
this.data = data;
8181
}
82+
public ValueEntity(FolderEntity folder, NodeEntity node,JsonNode data,List<ValueEntity> sources){
83+
this.sources = new ArrayList<>(sources);
84+
this.folder = folder;
85+
this.node = node;
86+
this.data = data;
87+
}
8288

8389
@RegisterForReflection
8490
public record DataProjection(JsonNode data) {} // field names must match with entity

src/main/java/io/hyperfoil/tools/h5m/svc/ValueService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ ANCESTOR_PREFIX ancestor(vid) as (
387387
List<ValueEntity> rtrn = query
388388
.getResultList();
389389
//reversed
390-
return rtrn.reversed();
390+
if(preceedingValues){
391+
rtrn = rtrn.reversed();
392+
}
393+
return rtrn;
391394
}
392395

393396
public List<ValueEntity> getAncestor(ValueEntity value, NodeEntity node){

src/test/java/io/hyperfoil/tools/h5m/svc/ValueServiceTest.java

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.hyperfoil.tools.h5m.entity.ValueEntity;
1313
import io.hyperfoil.tools.h5m.entity.mapper.ApiMapper;
1414
import io.hyperfoil.tools.h5m.entity.mapper.CycleAvoidingContext;
15+
import io.hyperfoil.tools.h5m.entity.node.FingerprintNode;
1516
import io.hyperfoil.tools.h5m.entity.node.JqNode;
1617
import io.hyperfoil.tools.h5m.entity.node.RootNode;
1718
import io.quarkus.test.junit.QuarkusTest;
@@ -672,57 +673,106 @@ public void findMatchingFingerprint_sibling() throws SystemException, NotSupport
672673

673674
}
674675
@Test
675-
public void findMatchingFingerprint_sorting_cousin() throws SystemException, NotSupportedException, JsonProcessingException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
676+
public void findMatchingFingerprint_sorting_cousin_reverse() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException, JsonProcessingException {
676677
tm.begin();
677678
NodeEntity rootNode = new RootNode();
678-
rootNode.persist(rootNode);
679-
NodeEntity aNode = new JqNode("a");
680-
aNode.sources=List.of(rootNode);
681-
aNode.persist(aNode);
682-
NodeEntity bNode = new JqNode("b");
683-
bNode.sources=List.of(rootNode);
679+
rootNode.persist();
680+
NodeEntity aNode = new JqNode("a",".a",rootNode);
681+
aNode.persist();
682+
NodeEntity bNode = new JqNode("b",".b",rootNode);
684683
bNode.persist();
685-
NodeEntity cNode = new JqNode("c");
686-
cNode.sources=List.of(rootNode);
684+
NodeEntity cNode = new JqNode("c",".c",rootNode);
687685
cNode.persist();
688-
NodeEntity caNode = new JqNode("ca");
689-
caNode.sources=List.of(cNode);
686+
NodeEntity caNode = new JqNode("c",".ca",List.of(cNode,aNode));
690687
caNode.persist();
691-
ObjectMapper objectMapper = new ObjectMapper();
692688

693-
ValueEntity rootValue01 = new ValueEntity(null,rootNode,new TextNode("root1"));
689+
ObjectMapper objectMapper = new ObjectMapper();
690+
ValueEntity rootValue01 = new ValueEntity(null,rootNode,
691+
objectMapper.readTree("""
692+
{ "a" : "a", "b" : "b1", "c" : "c1", "ca" : "ca1" }
693+
"""));
694+
ValueEntity rootValue02 = new ValueEntity(null,rootNode,
695+
objectMapper.readTree("""
696+
{ "a" : "a", "b" : "b2", "c" : "c1", "ca" : "ca2" }
697+
"""));
694698
rootValue01.persist();
695-
ValueEntity rootValue02 = new ValueEntity(null,rootNode,new TextNode("root2"));
696-
rootValue02.persist();
697-
698-
ValueEntity aValue01 = new ValueEntity(null,aNode,new TextNode("a"));
699-
aValue01.sources=List.of(rootValue01);
699+
// a values
700+
ValueEntity aValue01 = new ValueEntity(null,aNode,rootValue01.data.get("a"),List.of(rootValue01));
700701
aValue01.persist();
701-
702-
ValueEntity aValue02 = new ValueEntity(null,aNode,new TextNode("a"));
703-
aValue02.sources=List.of(rootValue02);
702+
ValueEntity aValue02 = new ValueEntity(null,aNode,rootValue02.data.get("a"),List.of(rootValue02));
704703
aValue02.persist();
705-
706-
ValueEntity bValue01 = new ValueEntity(null,bNode,new TextNode("b1"));
707-
bValue01.sources=List.of(rootValue01);
704+
// b values
705+
ValueEntity bValue01 = new ValueEntity(null,bNode,rootValue01.data.get("b"),List.of(rootValue01));
708706
bValue01.persist();
709-
ValueEntity bValue02 = new ValueEntity(null,bNode,new TextNode("b2"));
710-
bValue02.sources=List.of(rootValue02);
707+
ValueEntity bValue02 = new ValueEntity(null,bNode,rootValue02.data.get("b"),List.of(rootValue02));
711708
bValue02.persist();
709+
// c values
710+
ValueEntity cValue01 = new ValueEntity(null,cNode,rootValue01.data.get("c"),List.of(rootValue01));
711+
cValue01.persist();
712+
ValueEntity cValue02 = new ValueEntity(null,cNode,rootValue02.data.get("c"),List.of(rootValue02));
713+
cValue02.persist();
714+
// ca values
715+
ValueEntity caValue01 = new ValueEntity(null,caNode,rootValue01.data.get("ca"),List.of(rootValue01));
716+
caValue01.persist();
717+
ValueEntity caValue02 = new ValueEntity(null,caNode,rootValue02.data.get("ca"),List.of(rootValue02));
718+
caValue02.persist();
712719

720+
tm.commit();
713721

714-
ValueEntity cValue01 = new ValueEntity(null,cNode,new TextNode("c1"));
715-
cValue01.sources=List.of(rootValue01);
722+
List<ValueEntity> found = valueService.findMatchingFingerprint(caNode,rootNode,aValue01,bNode,null,-1,-1,false);
723+
724+
assertNotNull(found);
725+
assertEquals(2,found.size(),found.toString());
726+
assertTrue(found.contains(caValue01),found.toString());
727+
assertTrue(found.contains(caValue02),found.toString());
728+
729+
assertEquals(caValue01,found.get(0),found.toString());
730+
assertEquals(caValue02,found.get(1),found.toString());
731+
732+
}
733+
@Test
734+
public void findMatchingFingerprint_sorting_cousin() throws SystemException, NotSupportedException, JsonProcessingException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
735+
tm.begin();
736+
NodeEntity rootNode = new RootNode();
737+
rootNode.persist();
738+
NodeEntity aNode = new JqNode("a",".a",rootNode);
739+
aNode.persist();
740+
NodeEntity bNode = new JqNode("b",".b",rootNode);
741+
bNode.persist();
742+
NodeEntity cNode = new JqNode("c",".c",rootNode);
743+
cNode.persist();
744+
NodeEntity caNode = new JqNode("c",".ca",List.of(cNode,aNode));
745+
caNode.persist();
746+
747+
ObjectMapper objectMapper = new ObjectMapper();
748+
ValueEntity rootValue01 = new ValueEntity(null,rootNode,
749+
objectMapper.readTree("""
750+
{ "a" : "a", "b" : "b1", "c" : "c1", "ca" : "ca1" }
751+
"""));
752+
ValueEntity rootValue02 = new ValueEntity(null,rootNode,
753+
objectMapper.readTree("""
754+
{ "a" : "a", "b" : "b2", "c" : "c1", "ca" : "ca2" }
755+
"""));
756+
rootValue01.persist();
757+
// a values
758+
ValueEntity aValue01 = new ValueEntity(null,aNode,rootValue01.data.get("a"),List.of(rootValue01));
759+
aValue01.persist();
760+
ValueEntity aValue02 = new ValueEntity(null,aNode,rootValue02.data.get("a"),List.of(rootValue02));
761+
aValue02.persist();
762+
// b values
763+
ValueEntity bValue01 = new ValueEntity(null,bNode,rootValue01.data.get("b"),List.of(rootValue01));
764+
bValue01.persist();
765+
ValueEntity bValue02 = new ValueEntity(null,bNode,rootValue02.data.get("b"),List.of(rootValue02));
766+
bValue02.persist();
767+
// c values
768+
ValueEntity cValue01 = new ValueEntity(null,cNode,rootValue01.data.get("c"),List.of(rootValue01));
716769
cValue01.persist();
717-
ValueEntity cValue02 = new ValueEntity(null,cNode,new TextNode("c2"));
718-
cValue02.sources=List.of(rootValue02);
770+
ValueEntity cValue02 = new ValueEntity(null,cNode,rootValue02.data.get("c"),List.of(rootValue02));
719771
cValue02.persist();
720-
721-
ValueEntity caValue01 = new ValueEntity(null,caNode,new TextNode("ca1"));
722-
caValue01.sources=List.of(cValue01);
772+
// ca values
773+
ValueEntity caValue01 = new ValueEntity(null,caNode,rootValue01.data.get("ca"),List.of(rootValue01));
723774
caValue01.persist();
724-
ValueEntity caValue02 = new ValueEntity(null,caNode,new TextNode("ca2"));
725-
caValue02.sources=List.of(cValue02);
775+
ValueEntity caValue02 = new ValueEntity(null,caNode,rootValue02.data.get("ca"),List.of(rootValue02));
726776
caValue02.persist();
727777

728778
tm.commit();

0 commit comments

Comments
 (0)