31
31
import org .dspace .builder .ItemBuilder ;
32
32
import org .dspace .content .Collection ;
33
33
import org .dspace .content .Item ;
34
+ import org .dspace .content .authority .ItemAuthority ;
34
35
import org .dspace .content .authority .OrcidAuthority ;
35
36
import org .dspace .orcid .client .OrcidClient ;
36
37
import org .dspace .orcid .client .OrcidConfiguration ;
@@ -712,6 +713,101 @@ public void testWithAffiliationExtra() throws Exception {
712
713
verifyNoMoreInteractions (orcidClientMock );
713
714
}
714
715
716
+ @ Test
717
+ public void testSourceReference () throws Exception {
718
+
719
+ List <ExpandedResult > orcidSearchResults = List .of (
720
+ expandedResult ("Author" , "From Orcid 1" , "0000-1111-2222-3333" ),
721
+ expandedResult ("AUTHOR" , "FROM ORCID 2" , "0000-2222-3333-4444" ));
722
+
723
+ String expectedQuery = "(given-names:author+OR+family-name:author+OR+other-names:author)" ;
724
+
725
+ when (orcidClientMock .expandedSearch (READ_PUBLIC_TOKEN , expectedQuery , 0 , 20 ))
726
+ .thenReturn (expandedSearch (2 , orcidSearchResults ));
727
+
728
+ String token = getAuthToken (eperson .getEmail (), password );
729
+ getClient (token ).perform (get ("/api/submission/vocabularies/AuthorAuthority/entries" )
730
+ .param ("filter" , "author" ))
731
+ .andExpect (status ().isOk ())
732
+ .andExpect (jsonPath ("$._embedded.entries" , containsInAnyOrder (
733
+ orcidEntry ("From Orcid 1 Author" , REFERENCE , "0000-1111-2222-3333" , getSource ()),
734
+ orcidEntry ("From Orcid 2 Author" , REFERENCE , "0000-2222-3333-4444" , getSource ()))))
735
+ .andExpect (jsonPath ("$.page.size" , Matchers .is (20 )))
736
+ .andExpect (jsonPath ("$.page.totalPages" , Matchers .is (1 )))
737
+ .andExpect (jsonPath ("$.page.totalElements" , Matchers .is (2 )));
738
+
739
+ verify (orcidClientMock ).getReadPublicAccessToken ();
740
+ verify (orcidClientMock ).expandedSearch (READ_PUBLIC_TOKEN , expectedQuery , 0 , 20 );
741
+ verifyNoMoreInteractions (orcidClientMock );
742
+ }
743
+
744
+ @ Test
745
+ public void testMultipleSourcesReferences () throws Exception {
746
+ context .turnOffAuthorisationSystem ();
747
+
748
+ List <ExpandedResult > orcidSearchResults = List .of (
749
+ expandedResult ("Author" , "From Orcid 1" , "0000-1111-2222-3333" ),
750
+ expandedResult ("AUTHOR" , "FROM ORCID 2" , "0000-2222-3333-4444" ));
751
+
752
+ String expectedQuery = "(given-names:author+OR+family-name:author+OR+other-names:author)" ;
753
+
754
+ when (orcidClientMock .expandedSearch (READ_PUBLIC_TOKEN , expectedQuery , 0 , 18 ))
755
+ .thenReturn (expandedSearch (2 , orcidSearchResults ));
756
+
757
+ parentCommunity = CommunityBuilder .createCommunity (context ).build ();
758
+ Collection col1 = CollectionBuilder .createCollection (context , parentCommunity ).build ();
759
+
760
+ Item orgUnit_1 = ItemBuilder .createItem (context , col1 )
761
+ .withTitle ("OrgUnit_1" )
762
+ .withEntityType ("orgunit" )
763
+ .build ();
764
+
765
+ Item orgUnit_2 = ItemBuilder .createItem (context , col1 )
766
+ .withTitle ("OrgUnit_2" )
767
+ .withEntityType ("orgunit" )
768
+ .build ();
769
+
770
+ Item author_1 = ItemBuilder .createItem (context , col1 )
771
+ .withTitle ("Author 1" )
772
+ .withPersonMainAffiliation (orgUnit_1 .getName (), orgUnit_1 .getID ().toString ())
773
+ .withEntityType ("person" )
774
+ .build ();
775
+
776
+ Item author_2 = ItemBuilder .createItem (context , col1 )
777
+ .withTitle ("Author 2" )
778
+ .withPersonMainAffiliation (orgUnit_2 .getName (), orgUnit_2 .getID ().toString ())
779
+ .withEntityType ("person" )
780
+ .build ();
781
+
782
+ context .restoreAuthSystemState ();
783
+
784
+ String token = getAuthToken (eperson .getEmail (), password );
785
+ getClient (token ).perform (get ("/api/submission/vocabularies/AuthorAuthority/entries" )
786
+ .param ("filter" , "author" ))
787
+ .andExpect (status ().isOk ())
788
+ .andExpect (jsonPath ("$._embedded.entries" , Matchers .containsInAnyOrder (
789
+ // source should be local
790
+ ItemAuthorityMatcher .matchItemAuthorityWithOtherInformations (author_1 .getID ().toString (),
791
+ "Author 1" , "Author 1" , "vocabularyEntry" ,
792
+ Map .of ("data-oairecerif_author_affiliation" , "OrgUnit_1::" + orgUnit_1 .getID (),
793
+ "oairecerif_author_affiliation" , "OrgUnit_1::" + orgUnit_1 .getID (),
794
+ "data-person_identifier_orcid" , "" ,
795
+ "person_identifier_orcid" , "" ),
796
+ ItemAuthority .DEFAULT ),
797
+ ItemAuthorityMatcher .matchItemAuthorityWithOtherInformations (author_2 .getID ().toString (),
798
+ "Author 2" , "Author 2" , "vocabularyEntry" ,
799
+ Map .of ("data-oairecerif_author_affiliation" , "OrgUnit_2::" + orgUnit_2 .getID (),
800
+ "oairecerif_author_affiliation" , "OrgUnit_2::" + orgUnit_2 .getID (),
801
+ "data-person_identifier_orcid" , "" ,
802
+ "person_identifier_orcid" , "" ),
803
+ ItemAuthority .DEFAULT ),
804
+ // source should be orcid as configured
805
+ orcidEntry ("From Orcid 1 Author" , REFERENCE , "0000-1111-2222-3333" , getSource ()),
806
+ orcidEntry ("From Orcid 2 Author" , REFERENCE , "0000-2222-3333-4444" , getSource ())
807
+ )))
808
+ .andExpect (jsonPath ("$.page.totalElements" , Matchers .is (4 )));
809
+ }
810
+
715
811
private ExpandedSearch buildExpandedSearchFromSublist (List <ExpandedResult > totalResults , int start , int rows ) {
716
812
int total = totalResults .size ();
717
813
if (start > total ) {
@@ -783,6 +879,12 @@ private Matcher<? super Object> orcidEntry(String title, String authorityPrefix,
783
879
title , "vocabularyEntry" , ORCID_INFO , orcid );
784
880
}
785
881
882
+ private Matcher <? super Object > orcidEntry (String title , String authorityPrefix , String orcid , String source ) {
883
+ String authority = authorityPrefix + "ORCID::" + orcid ;
884
+ return ItemAuthorityMatcher .matchItemAuthorityWithOtherInformations (authority , title ,
885
+ title , "vocabularyEntry" , ORCID_INFO , orcid , source );
886
+ }
887
+
786
888
private Matcher <? super Object > orcidEntryWithAffiliation (String title , String authorityPrefix ,
787
889
String orcid , String affiliation ) {
788
890
String authority = authorityPrefix + "ORCID::" + orcid ;
@@ -800,4 +902,9 @@ private Matcher<? super Object> orcidEntryWithAffiliation(String title, String a
800
902
private String id (Item item ) {
801
903
return item .getID ().toString ();
802
904
}
905
+
906
+ private String getSource () {
907
+ return configurationService .getProperty (
908
+ "cris.ItemAuthority.AuthorAuthority.source" , ItemAuthority .DEFAULT );
909
+ }
803
910
}
0 commit comments