@@ -745,36 +745,159 @@ public void shouldPerformComplexOperationWithPathWildcard() {
745
745
}
746
746
747
747
@ Test
748
- public void shouldDoListAs () {
748
+ public void shouldDoListAsWithSingleList () {
749
749
MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
750
750
"set_array('sourceOrga[]')" ,
751
- "do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]')" ,
751
+ "do list_as(orgId: 'ccm:university[]')" ,
752
+ " copy_field(orgId, 'sourceOrga[].$append.id')" ,
753
+ "end"
754
+ ),
755
+ i -> {
756
+ i .startRecord ("1" );
757
+ i .startEntity ("ccm:university[]" );
758
+ i .literal ("1" , "https://ror.org/0304hq317" );
759
+ i .literal ("2" , "https://ror.org/014nnvj65" );
760
+ i .endEntity ();
761
+ i .endRecord ();
762
+ },
763
+ (o , f ) -> {
764
+ o .get ().startRecord ("1" );
765
+ o .get ().startEntity ("ccm:university[]" );
766
+ o .get ().literal ("1" , "https://ror.org/0304hq317" );
767
+ o .get ().literal ("2" , "https://ror.org/014nnvj65" );
768
+ o .get ().endEntity ();
769
+ o .get ().startEntity ("sourceOrga[]" );
770
+ o .get ().startEntity ("1" );
771
+ o .get ().literal ("id" , "https://ror.org/0304hq317" );
772
+ o .get ().endEntity ();
773
+ o .get ().startEntity ("2" );
774
+ o .get ().literal ("id" , "https://ror.org/014nnvj65" );
775
+ f .apply (2 ).endEntity ();
776
+ o .get ().endRecord ();
777
+ }
778
+ );
779
+ }
780
+
781
+ @ Test
782
+ public void shouldDoListAsWithMultipleLists () {
783
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
784
+ "set_array('sourceOrga[]')" ,
785
+ "do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')" ,
752
786
" copy_field(orgId, 'sourceOrga[].$append.id')" ,
753
787
" copy_field(orgName, 'sourceOrga[].$last.name')" ,
788
+ " copy_field(orgLoc, 'sourceOrga[].$last.location')" ,
754
789
"end"
755
790
),
756
791
i -> {
757
792
i .startRecord ("1" );
758
793
i .startEntity ("ccm:university[]" );
759
794
i .literal ("1" , "https://ror.org/0304hq317" );
795
+ i .literal ("2" , "https://ror.org/014nnvj65" );
760
796
i .endEntity ();
761
797
i .startEntity ("ccm:university_DISPLAYNAME[]" );
762
798
i .literal ("1" , "Gottfried Wilhelm Leibniz Universität Hannover" );
799
+ i .literal ("2" , "Technische Hochschule Köln" );
800
+ i .endEntity ();
801
+ i .startEntity ("ccm:university_LOCATION[]" );
802
+ i .literal ("1" , "Hannover" );
803
+ i .literal ("2" , "Köln" );
763
804
i .endEntity ();
764
805
i .endRecord ();
765
806
},
766
807
(o , f ) -> {
767
808
o .get ().startRecord ("1" );
768
809
o .get ().startEntity ("ccm:university[]" );
769
810
o .get ().literal ("1" , "https://ror.org/0304hq317" );
811
+ o .get ().literal ("2" , "https://ror.org/014nnvj65" );
770
812
o .get ().endEntity ();
771
813
o .get ().startEntity ("ccm:university_DISPLAYNAME[]" );
772
814
o .get ().literal ("1" , "Gottfried Wilhelm Leibniz Universität Hannover" );
815
+ o .get ().literal ("2" , "Technische Hochschule Köln" );
816
+ o .get ().endEntity ();
817
+ o .get ().startEntity ("ccm:university_LOCATION[]" );
818
+ o .get ().literal ("1" , "Hannover" );
819
+ o .get ().literal ("2" , "Köln" );
773
820
o .get ().endEntity ();
774
821
o .get ().startEntity ("sourceOrga[]" );
775
822
o .get ().startEntity ("1" );
776
823
o .get ().literal ("id" , "https://ror.org/0304hq317" );
777
824
o .get ().literal ("name" , "Gottfried Wilhelm Leibniz Universität Hannover" );
825
+ o .get ().literal ("location" , "Hannover" );
826
+ o .get ().endEntity ();
827
+ o .get ().startEntity ("2" );
828
+ o .get ().literal ("id" , "https://ror.org/014nnvj65" );
829
+ o .get ().literal ("name" , "Technische Hochschule Köln" );
830
+ o .get ().literal ("location" , "Köln" );
831
+ f .apply (2 ).endEntity ();
832
+ o .get ().endRecord ();
833
+ }
834
+ );
835
+ }
836
+
837
+ @ Test // checkstyle-disable-line JavaNCSS
838
+ public void shouldDoListAsWithMultipleListsOfDifferentSizes () {
839
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
840
+ "set_array('sourceOrga[]')" ,
841
+ "do list_as(orgId: 'ccm:university[]', orgName: 'ccm:university_DISPLAYNAME[]', orgLoc: 'ccm:university_LOCATION[]')" ,
842
+ " set_hash('sourceOrga[].$append')" ,
843
+ " copy_field(orgId, 'sourceOrga[].$last.id')" ,
844
+ " copy_field(orgName, 'sourceOrga[].$last.name')" ,
845
+ " copy_field(orgLoc, 'sourceOrga[].$last.location')" ,
846
+ "end"
847
+ ),
848
+ i -> {
849
+ i .startRecord ("1" );
850
+ i .startEntity ("ccm:university[]" );
851
+ i .literal ("1" , "https://ror.org/0304hq317" );
852
+ i .literal ("2" , "https://ror.org/014nnvj65" );
853
+ i .endEntity ();
854
+ i .startEntity ("ccm:university_DISPLAYNAME[]" );
855
+ i .literal ("1" , "Gottfried Wilhelm Leibniz Universität Hannover" );
856
+ i .literal ("2" , "Technische Hochschule Köln" );
857
+ i .literal ("3" , "Universität zu Köln" );
858
+ i .literal ("4" , "Stadtbibliothek Köln" );
859
+ i .endEntity ();
860
+ i .startEntity ("ccm:university_LOCATION[]" );
861
+ i .literal ("1" , "Hannover" );
862
+ i .literal ("2" , "Köln" );
863
+ i .literal ("3" , "Köln" );
864
+ i .endEntity ();
865
+ i .endRecord ();
866
+ },
867
+ (o , f ) -> {
868
+ o .get ().startRecord ("1" );
869
+ o .get ().startEntity ("ccm:university[]" );
870
+ o .get ().literal ("1" , "https://ror.org/0304hq317" );
871
+ o .get ().literal ("2" , "https://ror.org/014nnvj65" );
872
+ o .get ().endEntity ();
873
+ o .get ().startEntity ("ccm:university_DISPLAYNAME[]" );
874
+ o .get ().literal ("1" , "Gottfried Wilhelm Leibniz Universität Hannover" );
875
+ o .get ().literal ("2" , "Technische Hochschule Köln" );
876
+ o .get ().literal ("3" , "Universität zu Köln" );
877
+ o .get ().literal ("4" , "Stadtbibliothek Köln" );
878
+ o .get ().endEntity ();
879
+ o .get ().startEntity ("ccm:university_LOCATION[]" );
880
+ o .get ().literal ("1" , "Hannover" );
881
+ o .get ().literal ("2" , "Köln" );
882
+ o .get ().literal ("3" , "Köln" );
883
+ o .get ().endEntity ();
884
+ o .get ().startEntity ("sourceOrga[]" );
885
+ o .get ().startEntity ("1" );
886
+ o .get ().literal ("id" , "https://ror.org/0304hq317" );
887
+ o .get ().literal ("name" , "Gottfried Wilhelm Leibniz Universität Hannover" );
888
+ o .get ().literal ("location" , "Hannover" );
889
+ o .get ().endEntity ();
890
+ o .get ().startEntity ("2" );
891
+ o .get ().literal ("id" , "https://ror.org/014nnvj65" );
892
+ o .get ().literal ("name" , "Technische Hochschule Köln" );
893
+ o .get ().literal ("location" , "Köln" );
894
+ o .get ().endEntity ();
895
+ o .get ().startEntity ("3" );
896
+ o .get ().literal ("name" , "Universität zu Köln" );
897
+ o .get ().literal ("location" , "Köln" );
898
+ o .get ().endEntity ();
899
+ o .get ().startEntity ("4" );
900
+ o .get ().literal ("name" , "Stadtbibliothek Köln" );
778
901
f .apply (2 ).endEntity ();
779
902
o .get ().endRecord ();
780
903
}
0 commit comments