-
Notifications
You must be signed in to change notification settings - Fork 3
/
dspace_6x.patch
8485 lines (8460 loc) · 321 KB
/
dspace_6x.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg
index d17993d4d6386dadc22d72d7432d8a8324278c86..2564bab92b5c1717aa0e29d1f7558ddf92ad62c8 100644
--- a/dspace/config/dspace.cfg
+++ b/dspace/config/dspace.cfg
@@ -648,7 +648,7 @@ event.dispatcher.default.class = org.dspace.event.BasicDispatcher
# Add doi here if you are using org.dspace.identifier.DOIIdentifierProvider to generate DOIs.
# Adding doi here makes DSpace send metadata updates to your doi registration agency.
# Add rdf here, if you are using dspace-rdf to export your repository content as RDF.
-event.dispatcher.default.consumers = versioning, discovery, eperson
+event.dispatcher.default.consumers = authority, versioning, discovery, eperson
# The noindex dispatcher will not create search or browse indexes (useful for batch item imports)
event.dispatcher.noindex.class = org.dspace.event.BasicDispatcher
@@ -682,7 +682,7 @@ event.consumer.versioning.filters = Item+Install
# authority consumer
event.consumer.authority.class = org.dspace.authority.indexer.AuthorityConsumer
-event.consumer.authority.filters = Item+Modify|Modify_Metadata
+event.consumer.authority.filters = Item+Modify|Modify_Metadata|Install
# ...set to true to enable testConsumer messages to standard output
#testConsumer.verbose = true
@@ -950,7 +950,7 @@ webui.strengths.show = false
###### ItemCounter Configuration ######
#
# Define the DAO class to use. This must correspond to your choice of
-# storage for the browse system (Solr is only option at this time).
+# storage for the browse system (Solr is only option at this time).
# By default, the Solr implementation is used.
#
# Solr:
@@ -1426,16 +1426,16 @@ sherpa.romeo.url = http://www.sherpa.ac.uk/romeo/api29.php
# sherpa.romeo.apikey = YOUR-API-KEY
##### Authority Control Settings #####
-#plugin.named.org.dspace.content.authority.ChoiceAuthority = \
+;plugin.named.org.dspace.content.authority.ChoiceAuthority = \
# org.dspace.content.authority.SampleAuthority = Sample, \
# org.dspace.content.authority.LCNameAuthority = LCNameAuthority, \
# org.dspace.content.authority.SHERPARoMEOPublisher = SRPublisher, \
# org.dspace.content.authority.SHERPARoMEOJournalTitle = SRJournalTitle, \
-# org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority
+; org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority
#Uncomment to enable ORCID authority control
-#plugin.named.org.dspace.content.authority.ChoiceAuthority = \
-# org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority
+plugin.named.org.dspace.content.authority.ChoiceAuthority = \
+ org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority
# URL of ORCID API
# Defaults to using the Public API (pub.orcid.org)
@@ -1478,13 +1478,19 @@ orcid.api.url = https://pub.orcid.org/v2.1
## See manual or org.dspace.content.authority.Choices source for descriptions.
authority.minconfidence = ambiguous
+# Uncomment to disable allowing updates of person authority values through the REST api.
+# authority.allow-rest-updates.person = false
+
+# Uncomment to disable allowing updates of ORCIDS authority values through the REST api.
+# authority.allow-rest-updates.orcid = false
+
# Configuration settings for ORCID based authority control, uncomment the lines below to enable configuration
-#solr.authority.server=${solr.server}/authority
-#choices.plugin.dc.contributor.author = SolrAuthorAuthority
-#choices.presentation.dc.contributor.author = authorLookup
-#authority.controlled.dc.contributor.author = true
+solr.authority.server=${solr.server}/authority
+choices.plugin.dc.contributor.author = SolrAuthorAuthority
+choices.presentation.dc.contributor.author = authorLookup
+authority.controlled.dc.contributor.author = true
#
-#authority.author.indexer.field.1=dc.contributor.author
+authority.author.indexer.field.1=dc.contributor.author
## demo: use LC plugin for author
#choices.plugin.dc.contributor.author = LCNameAuthority
@@ -1525,6 +1531,10 @@ authority.minconfidence = ambiguous
# Change number of choices shown in the select in Choices lookup popup
#xmlui.lookup.select.size = 12
+# Putting orcid.connector.url in the config.
+# This property is not only used in the spring config, but also in actual code, so the config is used to link it as well.
+orcid.connector.url =https://orcid.org/
+
#### Ordering of bitstreams ####
diff --git a/dspace/config/spring/api/core-services.xml b/dspace/config/spring/api/core-services.xml
index 2c6160f55fd8eea66dcf52ef82b4874223307538..a5fe7c13e656a556dca4bef9e61d2af4353fb386 100644
--- a/dspace/config/spring/api/core-services.xml
+++ b/dspace/config/spring/api/core-services.xml
@@ -28,7 +28,7 @@
<bean class="org.dspace.authorize.AuthorizeServiceImpl"/>
<bean class="org.dspace.authorize.ResourcePolicyServiceImpl"/>
- <bean class="org.dspace.authority.AuthorityValueServiceImpl"/>
+ <bean class="com.atmire.dspace.authority.OrcidAuthorityValueServiceImpl"/>
<bean class="org.dspace.authority.AuthorityServiceImpl"/>
<bean class="org.dspace.checker.ChecksumHistoryServiceImpl"/>
diff --git a/dspace/config/spring/api/discovery.xml b/dspace/config/spring/api/discovery.xml
index d9c377e45ed017dd09904072eb3e76fd0f5347a1..4e3751e0794ec485a164f34b01e56ced94d09135 100644
--- a/dspace/config/spring/api/discovery.xml
+++ b/dspace/config/spring/api/discovery.xml
@@ -25,9 +25,10 @@
<bean id="solrServiceResourceIndexPlugin" class="org.dspace.discovery.SolrServiceResourceRestrictionPlugin" scope="prototype"/>
<bean id="SolrServiceSpellIndexingPlugin" class="org.dspace.discovery.SolrServiceSpellIndexingPlugin" scope="prototype"/>
<bean id="solrServiceMetadataBrowseIndexingPlugin" class="org.dspace.discovery.SolrServiceMetadataBrowseIndexingPlugin" scope="prototype"/>
+ <bean id="orcidIdIndexingPlugin" class="com.atmire.dspace.discovery.ORCIDIdIndexingPlugin"/>
<alias name="solrServiceResourceIndexPlugin" alias="org.dspace.discovery.SolrServiceResourceRestrictionPlugin"/>
-
+
<!-- Additional indexing plugin make filtering by has content in original bundle (like pdf's, images) posible via SOLR -->
<bean id="hasContentInOriginalBundle" class="org.dspace.discovery.SolrServiceContentInOriginalBundleFilterPlugin"/>
@@ -115,6 +116,7 @@
<ref bean="searchFilterContentInOriginalBundle"/>
<ref bean="searchFilterFileNameInOriginalBundle" />
<ref bean="searchFilterFileDescriptionInOriginalBundle" />
+ <ref bean="searchFilterOrcidFromAuthority" />
</list>
</property>
<!--The sort filters for the discovery search-->
@@ -227,6 +229,7 @@
<ref bean="searchFilterContentInOriginalBundle"/>
<ref bean="searchFilterFileNameInOriginalBundle" />
<ref bean="searchFilterFileDescriptionInOriginalBundle" />
+ <ref bean="searchFilterOrcidFromAuthority" />
</list>
</property>
<!--The sort filters for the discovery search (same as defaultConfiguration above)-->
@@ -423,7 +426,7 @@
<property name="sortOrderSidebar" value="COUNT"/>
<property name="sortOrderFilterPage" value="COUNT"/>
</bean>
-
+
<bean id="searchFilterContentInOriginalBundle" class="org.dspace.discovery.configuration.DiscoverySearchFilterFacet">
<property name="indexFieldName" value="has_content_in_original_bundle"/>
<property name="metadataFields">
@@ -449,6 +452,16 @@
</property>
</bean>
+ <bean class="org.dspace.discovery.configuration.DiscoverySearchFilter" id="searchFilterOrcidFromAuthority">
+ <property name="indexFieldName" value="orcidid" />
+ <property name="metadataFields">
+ <list>
+ <value>dc.identifier.orcid</value>
+ <value>orcid_id</value>
+ </list>
+ </property>
+ </bean>
+
<!--Sort properties-->
<bean id="sortTitle" class="org.dspace.discovery.configuration.DiscoverySortFieldConfiguration">
<property name="metadataField" value="dc.title"/>
diff --git a/dspace/config/spring/api/orcid-authority-services.xml b/dspace/config/spring/api/orcid-authority-services.xml
index 1efc8f51bd9e15e60f5766f45a1af15d1dd498ff..70e3058b78cc5b893c50110ca02b1638c9fd9fc2 100644
--- a/dspace/config/spring/api/orcid-authority-services.xml
+++ b/dspace/config/spring/api/orcid-authority-services.xml
@@ -44,6 +44,9 @@
<alias name="OrcidSource" alias="AuthoritySource"/>
<bean name="OrcidSource" class="org.dspace.authority.orcid.Orcidv2" init-method="init">
<constructor-arg value="${orcid.api.url}"/>
+ <constructor-arg value="https://api.orcid.org/oauth/token"/>
+ <constructor-arg value=""/>
+ <constructor-arg value=""/>
</bean>
diff --git a/dspace/modules/additions/src/main/java/com/atmire/dspace/authority/OrcidAuthorityValueServiceImpl.java b/dspace/modules/additions/src/main/java/com/atmire/dspace/authority/OrcidAuthorityValueServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd65afcef882ee758c7d5494bacde6ef97c6698e
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/com/atmire/dspace/authority/OrcidAuthorityValueServiceImpl.java
@@ -0,0 +1,53 @@
+package com.atmire.dspace.authority;
+
+import org.apache.log4j.Logger;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.dspace.authority.AuthorityUtil;
+import org.dspace.authority.AuthorityValue;
+import org.dspace.authority.AuthorityValueServiceImpl;
+import org.dspace.authority.PersonAuthorityValue;
+import org.dspace.authority.orcid.Orcidv2AuthorityValue;
+import org.dspace.content.authority.SolrAuthority;
+import org.dspace.core.Context;
+import org.dspace.core.LogManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.log4j.Logger.getLogger;
+
+public class OrcidAuthorityValueServiceImpl extends AuthorityValueServiceImpl {
+
+ private Logger log = getLogger(OrcidAuthorityValueServiceImpl.class);
+
+ protected List<AuthorityValue> find(Context context, String queryString) {
+ List<AuthorityValue> findings = new ArrayList<AuthorityValue>();
+ try {
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(filtered(queryString));
+ log.debug("AuthorityValueFinder makes the query: " + queryString);
+ QueryResponse queryResponse = SolrAuthority.getSearchService().search(solrQuery);
+ if (queryResponse != null && queryResponse.getResults() != null && 0 < queryResponse.getResults().getNumFound()) {
+ for (SolrDocument document : queryResponse.getResults()) {
+ AuthorityValue authorityValue;
+ if ("orcid".equals(document.getFieldValue("authority_type"))) {
+ authorityValue = new Orcidv2AuthorityValue(document);
+ ((Orcidv2AuthorityValue) authorityValue).setOrcid_id((String) document.getFieldValue("orcid_id"));
+ } else if (new AuthorityUtil().isPersonAuthority(document.getFieldValue("field") + "")) {
+ authorityValue = new PersonAuthorityValue(document);
+ } else {
+ authorityValue = new AuthorityValue(document);
+ }
+ findings.add(authorityValue);
+ log.debug("AuthorityValueFinder found: " + authorityValue.getValue());
+ }
+ }
+ } catch (Exception e) {
+ log.error(LogManager.getHeader(context, "Error while retrieving AuthorityValue from solr", "query: " + queryString),e);
+ }
+
+ return findings;
+ }
+}
diff --git a/dspace/modules/additions/src/main/java/com/atmire/dspace/discovery/ORCIDIdIndexingPlugin.java b/dspace/modules/additions/src/main/java/com/atmire/dspace/discovery/ORCIDIdIndexingPlugin.java
new file mode 100644
index 0000000000000000000000000000000000000000..a5b043113b2aab420a8006d53a4ad11270130012
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/com/atmire/dspace/discovery/ORCIDIdIndexingPlugin.java
@@ -0,0 +1,67 @@
+package com.atmire.dspace.discovery;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.solr.common.SolrInputDocument;
+import org.dspace.authority.AuthorityValue;
+import org.dspace.authority.PersonAuthorityValue;
+import org.dspace.authority.factory.AuthorityServiceFactory;
+import org.dspace.content.DSpaceObject;
+import org.dspace.content.Item;
+import org.dspace.content.MetadataValue;
+import org.dspace.content.factory.ContentServiceFactory;
+import org.dspace.core.Constants;
+import org.dspace.core.Context;
+import org.dspace.discovery.SolrServiceIndexPlugin;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by jonas - jonas@atmire.com on 07/06/2018.
+ */
+public class ORCIDIdIndexingPlugin implements SolrServiceIndexPlugin {
+
+ private static final String ORCID_ID_FIELD = "orcid_id";
+
+ @Override
+ public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) {
+ if (dso != null && dso.getType() == Constants.ITEM) {
+ Item item = (Item) dso;
+
+ List<String> personAuthorityFields = new ArrayList<>();
+ for (Map.Entry<String, AuthorityValue> fieldDefaults : AuthorityServiceFactory.getInstance().getAuthorTypes().getFieldDefaults().entrySet()) {
+ if (fieldDefaults.getValue() instanceof PersonAuthorityValue) {
+ personAuthorityFields.add(fieldDefaults.getKey());
+ }
+ }
+
+ for (String personAuthorityFieldKey : personAuthorityFields) {
+ String[] split = personAuthorityFieldKey.split("_");
+ List<MetadataValue> metadata = ContentServiceFactory.getInstance().getItemService().getMetadata(item, split[0], split[1], (split.length > 2) ? split[2] : null, Item.ANY);
+ for (MetadataValue metadataValue : metadata) {
+ checkAndIndexMetadata(context, document, metadataValue);
+ }
+ }
+
+ }
+ }
+
+ private void checkAndIndexMetadata(Context context, SolrInputDocument document, MetadataValue metadatum) {
+ String authority = metadatum.getAuthority();
+ if (StringUtils.isNotBlank(authority)) {
+
+ AuthorityValue value = AuthorityServiceFactory.getInstance().getAuthorityValueService().findByUID(context, authority);
+ if (value != null) {
+ String orcidId = (String) value.getSolrInputDocument().getFieldValue(ORCID_ID_FIELD);
+ if (StringUtils.isNotBlank(orcidId)) {
+ Collection<Object> fieldValues = document.getFieldValues(ORCID_ID_FIELD);
+ if (fieldValues == null || !fieldValues.contains(orcidId)) {
+ document.addField(ORCID_ID_FIELD, orcidId);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityUtil.java b/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..8ebc28a1875be7f1632856ca22ae58b1d782a40a
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityUtil.java
@@ -0,0 +1,173 @@
+package org.dspace.authority;
+
+import org.apache.log4j.Logger;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.dspace.authority.factory.AuthorityServiceFactory;
+import org.dspace.authority.indexer.AuthorityIndexingService;
+import org.dspace.authority.orcid.Orcidv2AuthorityValue;
+import org.dspace.authority.service.AuthorityValueService;
+import org.dspace.content.Item;
+import org.dspace.content.MetadataField;
+import org.dspace.content.authority.Choice;
+import org.dspace.content.authority.Choices;
+import org.dspace.content.authority.factory.ContentAuthorityServiceFactory;
+import org.dspace.content.authority.service.MetadataAuthorityService;
+import org.dspace.content.factory.ContentServiceFactory;
+import org.dspace.content.service.ItemService;
+import org.dspace.core.Constants;
+import org.dspace.core.Context;
+import org.dspace.utils.DSpace;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Date;
+
+import static java.util.Collections.singletonList;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.apache.log4j.Logger.getLogger;
+import static org.dspace.content.authority.Choices.CF_ACCEPTED;
+
+public class AuthorityUtil {
+
+ protected static final Logger log = getLogger(AuthorityUtil.class);
+
+ private AuthorityIndexingService indexingService = new DSpace().getServiceManager()
+ .getServiceByName(AuthorityIndexingService.class.getName(), AuthorityIndexingService.class);
+ private AuthorityValueService authorityValueService =
+ AuthorityServiceFactory.getInstance().getAuthorityValueService();
+ private ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+
+ public void addMetadataWithOrcid(Context context, Item item, MetadataField metadataField, String value, String authority, String language) throws SQLException {
+
+ String orcidAuthorityID = null;
+
+ if (isOrcidFormat(authority)) {
+
+ AuthorityValue orcidAuthority = authorityValueService.findByOrcidID(context, authority);
+ if (orcidAuthority == null) {
+
+ orcidAuthorityID = createSolrOrcidAuthority(authority, value, metadataField);
+ } else {
+ orcidAuthorityID = orcidAuthority.getId();
+ }
+ }
+
+ if (orcidAuthorityID != null) {
+ itemService.addMetadata(context, item, metadataField, language, value, orcidAuthorityID, CF_ACCEPTED);
+
+ } else {
+ itemService.addMetadata(context, item, metadataField, language, value);
+ }
+ }
+
+ private String createSolrOrcidAuthority(final String orcidID, String value, MetadataField metadataField) {
+
+ Orcidv2AuthorityValue authorityValue = Orcidv2AuthorityValue.create();
+ authorityValue.setValue(value);
+ authorityValue.setField(metadataField.toString());
+
+ return updateOrcidAuthorityValue(orcidID, authorityValue);
+ }
+
+ public boolean isOrcidFormat(final String authority) {
+
+ return isNotBlank(authority) && authority.matches("\\d{4}-\\d{4}-\\d{4}-(\\d{3}X|\\d{4})");
+ }
+
+ private String updateOrcidAuthorityValue(String orcidID, Orcidv2AuthorityValue value) {
+
+ if (value == null) {
+ return null;
+ }
+
+ value.setOrcid_id(orcidID);
+ Date now = new Date();
+ value.setLastModified(now);
+ value.setCreationDate(now);
+ indexingService.indexContent(value);
+ indexingService.commit();
+ return value.getId();
+ }
+
+ public void addMetadata(Context context, Item dspaceItem, String[] field, String value, String language) throws SQLException {
+
+ MetadataField metadataField = ContentServiceFactory.getInstance().getMetadataFieldService()
+ .findByElement(context, field[0], field[1], field[2]);
+
+ String[] splitAuthority = splitAuthority(value);
+ if (splitAuthority.length > 1) {
+
+ String authority = splitAuthority[1];
+ if (isOrcidFormat(authority)) {
+ addMetadataWithOrcid(context, dspaceItem, metadataField, splitAuthority[0], authority, language);
+ } else {
+ addMetadataWithAuthority(context, dspaceItem, metadataField, splitAuthority[0], authority, language);
+ }
+ } else {
+ addMetadataWhenNoAuthorityIsProvided(context, dspaceItem, metadataField, splitAuthority[0], language);
+ }
+ }
+
+ private String[] splitAuthority(final String value) {
+ return value.split("::");
+ }
+
+ public void addMetadataWithAuthority(Context context, Item item, MetadataField metadataField, String value, String authority, String language) throws SQLException {
+
+ AuthorityValue authorityValue = authorityValueService.findByUID(context, authority);
+
+ if (authorityValue != null) {
+ itemService.addMetadata(context, item, metadataField, language,
+ authorityValue.getValue(), authority, CF_ACCEPTED);
+ } else {
+ itemService.addMetadata(context, item, metadataField, language, value);
+ }
+ }
+
+ public void addMetadataWhenNoAuthorityIsProvided(Context context, Item item, MetadataField metadataField, String value, String language) throws SQLException {
+ MetadataAuthorityService mam = ContentAuthorityServiceFactory.getInstance().getMetadataAuthorityService();
+ String fieldKey = mam.makeFieldKey(metadataField);
+
+ boolean fieldAdded = false;
+
+ if (mam.isAuthorityControlled(fieldKey)) {
+ if (isPersonAuthority(metadataField)) {
+
+ Choices c = ContentAuthorityServiceFactory.getInstance().getChoiceAuthorityService()
+ .getMatches(fieldKey, value, null, 0, 0, null);
+
+ for (Choice choice : c.values) {
+ AuthorityValue matchedAuthority = authorityValueService.findByUID(context, choice.authority);
+ if (!(matchedAuthority instanceof Orcidv2AuthorityValue)) {
+ itemService.addMetadata(context, item, metadataField, language, value,
+ c.values[0].authority, c.confidence);
+
+ fieldAdded = true;
+ break;
+ }
+ }
+ }
+ }
+
+ // make sure the field is always added to the metadata
+ if (!fieldAdded){
+ itemService.addMetadata(context, item, metadataField, language, singletonList(value), null, null);
+ }
+ }
+
+ public boolean isPersonAuthority(MetadataField metadataField) {
+
+ return isPersonAuthority(metadataField.toString());
+ }
+
+ public boolean isPersonAuthority(String metadataField) {
+
+ return AuthorityServiceFactory.getInstance().getAuthorTypes().getFieldDefaults()
+ .get(metadataField) instanceof PersonAuthorityValue;
+ }
+
+ public void deleteAuthorityValueById(String id) throws IOException, SolrServerException {
+ ((AuthoritySolrServiceImpl) indexingService).getSolr().deleteByQuery("id:\"" + id + "\"");
+ indexingService.commit();
+ }
+}
diff --git a/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityValueFinder.java b/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityValueFinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..ed4a9b4491670004043d5ab7bc9d64228c056cf0
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/org/dspace/authority/AuthorityValueFinder.java
@@ -0,0 +1,133 @@
+/**
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.authority;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.dspace.authority.orcid.Orcidv2AuthorityValue;
+import org.dspace.content.authority.SolrAuthority;
+import org.dspace.core.Context;
+import org.dspace.core.LogManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ *
+ * @author Antoine Snyers (antoine at atmire.com)
+ * @author Kevin Van de Velde (kevin at atmire dot com)
+ * @author Ben Bosman (ben at atmire dot com)
+ * @author Mark Diggory (markd at atmire dot com)
+ */
+public class AuthorityValueFinder {
+
+ /**
+ * log4j logger
+ */
+ private static Logger log = Logger.getLogger(AuthorityValueFinder.class);
+
+ /**
+ * Item.ANY does not work here.
+ */
+ public AuthorityValue findByUID(Context context, String authorityID) {
+ //Ensure that if we use the full identifier to match on
+ String queryString = "id:\"" + authorityID + "\"";
+ List<AuthorityValue> findings = find(context, queryString);
+ return findings.size() > 0 ? findings.get(0) : null;
+ }
+
+ public List<AuthorityValue> findByExactValue(Context context, String field, String value) {
+ String queryString = "value:\"" + value + "\" AND field:" + field;
+ return find(context, queryString);
+ }
+
+ public List<AuthorityValue> findByValue(Context context, String field, String value) {
+ String queryString = "value:" + value + " AND field:" + field;
+ return find(context, queryString);
+ }
+
+ public List<AuthorityValue> findByValue(Context context, String schema, String element, String qualifier, String value) {
+ String field = fieldParameter(schema, element, qualifier);
+ return findByValue(context, field, qualifier);
+ }
+
+ public AuthorityValue findByOrcidID(Context context, String orcid_id) {
+ String queryString = "orcid_id:" + orcid_id;
+ List<AuthorityValue> findings = find(context, queryString);
+ return findings.size() > 0 ? findings.get(0) : null;
+ }
+
+ public List<AuthorityValue> findByName(Context context, String schema, String element, String qualifier, String name) {
+ String field = fieldParameter(schema, element, qualifier);
+ String queryString = "first_name:" + name + " OR last_name:" + name + " OR name_variant:" + name + " AND field:" + field;
+ return find(context, queryString);
+ }
+
+ public List<AuthorityValue> findByAuthorityMetadata(Context context, String schema, String element, String qualifier, String value) {
+ String field = fieldParameter(schema, element, qualifier);
+ String queryString = "all_Labels:" + value + " AND field:" + field;
+ return find(context, queryString);
+ }
+
+ public List<AuthorityValue> findOrcidHolders(Context context) {
+ String queryString = "orcid_id:*";
+ return find(context, queryString);
+ }
+
+ public List<AuthorityValue> findAll(Context context) {
+ String queryString = "*:*";
+ return find(context, queryString);
+ }
+
+ private List<AuthorityValue> find(Context context, String queryString) {
+ List<AuthorityValue> findings = new ArrayList<AuthorityValue>();
+ try {
+ SolrQuery solrQuery = new SolrQuery();
+ solrQuery.setQuery(filtered(queryString));
+ log.debug("AuthorityValueFinder makes the query: " + queryString);
+ QueryResponse queryResponse = SolrAuthority.getSearchService().search(solrQuery);
+ if (queryResponse != null && queryResponse.getResults() != null && 0 < queryResponse.getResults().getNumFound()) {
+ for (SolrDocument document : queryResponse.getResults()) {
+ AuthorityValue authorityValue;
+ if ("orcid".equals(document.getFieldValue("authority_type"))) {
+ authorityValue = new Orcidv2AuthorityValue(document);
+ ((Orcidv2AuthorityValue) authorityValue).setOrcid_id((String) document.getFieldValue("orcid_id"));
+ } else if (new AuthorityUtil().isPersonAuthority(document.getFieldValue("field") + "")) {
+ authorityValue = new PersonAuthorityValue(document);
+ } else {
+ authorityValue = new AuthorityValue(document);
+ }
+ findings.add(authorityValue);
+ log.debug("AuthorityValueFinder found: " + authorityValue.getValue());
+ }
+ }
+ } catch (Exception e) {
+ log.error(LogManager.getHeader(context, "Error while retrieving AuthorityValue from solr", "query: " + queryString),e);
+ }
+
+ return findings;
+ }
+
+ private String filtered(String queryString) throws InstantiationException, IllegalAccessException {
+ String instanceFilter = "-deleted:true";
+ if (StringUtils.isNotBlank(instanceFilter)) {
+ queryString += " AND " + instanceFilter;
+ }
+ return queryString;
+ }
+
+ private String fieldParameter(String schema, String element, String qualifier) {
+ return schema + "_" + element + ((qualifier != null) ? "_" + qualifier : "");
+ }
+
+
+}
diff --git a/dspace/modules/additions/src/main/java/org/dspace/authority/PersonAuthorityValue.java b/dspace/modules/additions/src/main/java/org/dspace/authority/PersonAuthorityValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..476b227f216174ea07bcb862e6d3a4ba04905389
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/org/dspace/authority/PersonAuthorityValue.java
@@ -0,0 +1,277 @@
+/**
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.authority;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrInputDocument;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @author Antoine Snyers (antoine at atmire.com)
+ * @author Kevin Van de Velde (kevin at atmire dot com)
+ * @author Ben Bosman (ben at atmire dot com)
+ * @author Mark Diggory (markd at atmire dot com)
+ */
+public class PersonAuthorityValue extends AuthorityValue {
+
+ private String firstName;
+ private String lastName;
+ private List<String> nameVariants = new ArrayList<String>();
+ private String institution;
+ private List<String> emails = new ArrayList<String>();
+
+ public PersonAuthorityValue() {
+ }
+
+ public PersonAuthorityValue(SolrDocument document) {
+ super(document);
+ }
+
+ @Override
+ public String getId() {
+ // A PersonValue is considered unique with the first & last name.
+ String nonDigestedIdentifier;
+ if(StringUtils.isNotBlank(firstName)) {
+ nonDigestedIdentifier = org.dspace.authority.PersonAuthorityValue.class.toString() + "field: Person " + "lastName: " + lastName + ", firstName: " + firstName;
+ }
+ else {
+ nonDigestedIdentifier = org.dspace.authority.PersonAuthorityValue.class.toString() + "field: Person " + "lastName: " + lastName ;
+ }
+ // We return an md5 digest of the toString, this will ensure a unique identifier for the same value each time
+ return DigestUtils.md5Hex(nonDigestedIdentifier);
+ }
+
+ public String getName() {
+ String name = "";
+ if (StringUtils.isNotBlank(lastName)) {
+ name = lastName;
+ if (StringUtils.isNotBlank(firstName)) {
+ name += ", ";
+ }
+ }
+ if (StringUtils.isNotBlank(firstName)) {
+ name += firstName;
+ }
+ return name;
+ }
+
+ public void setName(String name) {
+ if (StringUtils.isNotBlank(name)) {
+ String[] split = name.split(",");
+ if (split.length > 0) {
+ setLastName(split[0].trim());
+ if (split.length > 1) {
+ setFirstName(split[1].trim());
+ } else {
+ setFirstName(null);
+ }
+ }
+ }
+ if (!StringUtils.equals(getValue(), name)) {
+ setValue(name);
+ }
+ }
+
+ @Override
+ public void setValue(String value) {
+ super.setValue(value);
+ setName(value);
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public List<String> getNameVariants() {
+ return nameVariants;
+ }
+
+ public void addNameVariant(String name) {
+ if (StringUtils.isNotBlank(name)) {
+ nameVariants.add(name);
+ }
+ }
+
+ public String getInstitution() {
+ return institution;
+ }
+
+ public void setInstitution(String institution) {
+ this.institution = institution;
+ }
+
+ public List<String> getEmails() {
+ return emails;
+ }
+
+ public void addEmail(String email) {
+ if (StringUtils.isNotBlank(email)) {
+ emails.add(email);
+ }
+ }
+
+ @Override
+ public SolrInputDocument getSolrInputDocument() {
+ SolrInputDocument doc = super.getSolrInputDocument();
+ if (StringUtils.isNotBlank(getFirstName())) {
+ doc.addField("first_name", getFirstName());
+ }
+ if (StringUtils.isNotBlank(getLastName())) {
+ doc.addField("last_name", getLastName());
+ }
+ for (String nameVariant : getNameVariants()) {
+ doc.addField("name_variant", nameVariant);
+ }
+
+ for (String email : emails) {
+ doc.addField("email", email);
+ }
+ doc.addField("institution", getInstitution());
+ return doc;
+ }
+
+ @Override
+ public void setValues(SolrDocument document) {
+ super.setValues(document);
+ this.firstName = ObjectUtils.toString(document.getFieldValue("first_name"));
+ this.lastName = ObjectUtils.toString(document.getFieldValue("last_name"));
+ nameVariants = new ArrayList<String>();
+ Collection<Object> document_name_variant = document.getFieldValues("name_variant");
+ if (document_name_variant != null) {
+ for (Object name_variants : document_name_variant) {
+ addNameVariant(String.valueOf(name_variants));
+ }
+ }
+ if (document.getFieldValue("institution") != null) {
+ this.institution = String.valueOf(document.getFieldValue("institution"));
+ }
+
+ Collection<Object> emails = document.getFieldValues("email");
+ if (emails != null) {
+ for (Object email : emails) {
+ addEmail(String.valueOf(email));
+ }
+ }
+ }
+
+
+ @Override
+ public Map<String, String> choiceSelectMap() {
+
+ Map<String, String> map = super.choiceSelectMap();
+
+ if (StringUtils.isNotBlank(getFirstName())) {
+ map.put("first-name", getFirstName());
+ } else {
+ map.put("first-name", "/");
+ }
+
+ if (StringUtils.isNotBlank(getLastName())) {
+ map.put("last-name", getLastName());
+ } else {
+ map.put("last-name", "/");
+ }
+
+ if (!getEmails().isEmpty()) {
+ boolean added = false;
+ for (String email : getEmails()) {
+ if (!added && StringUtils.isNotBlank(email)) {
+ map.put("email",email);
+ added = true;
+ }
+ }
+ }
+ if (StringUtils.isNotBlank(getInstitution())) {
+ map.put("institution", getInstitution());
+ }
+
+ return map;
+ }
+
+ @Override
+ public String getAuthorityType() {
+ return "person";
+ }
+
+ @Override
+ public String generateString() {
+ return AuthorityValueServiceImpl.GENERATE + getAuthorityType() + AuthorityValueServiceImpl.SPLIT + getName();
+ // the part after "AuthorityValueGenerator.GENERATE + getAuthorityType() + AuthorityValueGenerator.SPLIT" is the value of the "info" parameter in public AuthorityValue newInstance(String info)
+ }
+
+ @Override
+ public AuthorityValue newInstance(String info) {
+ PersonAuthorityValue authorityValue = new PersonAuthorityValue();
+ authorityValue.setValue(info);
+ return authorityValue;
+ }
+
+ @Override
+ public String toString() {
+ return "PersonAuthorityValue{" +
+ "firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ ", nameVariants=" + nameVariants +
+ ", institution='" + institution + '\'' +
+ ", emails=" + emails +
+ "} " + super.toString();
+ }
+
+ @Override
+ public boolean hasTheSameInformationAs(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if(!super.hasTheSameInformationAs(o)){
+ return false;
+ }
+
+ PersonAuthorityValue that = (PersonAuthorityValue) o;
+
+ if (emails != null ? !emails.equals(that.emails) : that.emails != null) {
+ return false;
+ }
+ if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) {
+ return false;
+ }
+ if (institution != null ? !institution.equals(that.institution) : that.institution != null) {
+ return false;
+ }
+ if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) {
+ return false;
+ }
+ if (nameVariants != null ? !nameVariants.equals(that.nameVariants) : that.nameVariants != null) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/dspace/modules/additions/src/main/java/org/dspace/authority/orcid/Orcidv2AuthorityValue.java b/dspace/modules/additions/src/main/java/org/dspace/authority/orcid/Orcidv2AuthorityValue.java
new file mode 100644
index 0000000000000000000000000000000000000000..55eed1d62a23322ecbf53041e4bf6ddffd95c8f9
--- /dev/null
+++ b/dspace/modules/additions/src/main/java/org/dspace/authority/orcid/Orcidv2AuthorityValue.java
@@ -0,0 +1,355 @@
+/*
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.authority.orcid;
+
+import java.util.*;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrInputDocument;
+import org.dspace.authority.AuthorityValue;
+import org.dspace.authority.AuthorityValueServiceImpl;
+import org.dspace.authority.PersonAuthorityValue;
+import org.dspace.utils.DSpace;
+import org.orcid.jaxb.model.common_v2.ExternalId;
+import org.orcid.jaxb.model.record_v2.ExternalIdentifiers;
+import org.orcid.jaxb.model.record_v2.KeywordType;
+import org.orcid.jaxb.model.record_v2.NameType;
+import org.orcid.jaxb.model.record_v2.Person;
+import org.orcid.jaxb.model.record_v2.ResearcherUrlType;
+
+/**
+ * @author Jonas Van Goolen (jonas at atmire dot com)
+ */
+public class Orcidv2AuthorityValue extends PersonAuthorityValue {
+
+ /*
+ * The ORCID identifier
+ */
+ private String orcid_id;
+
+ /*
+ * Map containing key-value pairs filled in by "setValues(Person person)".
+ * This represents all dynamic information of the object.
+ */
+ private Map<String, List<String>> otherMetadata = new HashMap<String, List<String>>();
+
+ /**
+ * The syntax that the ORCID id needs to conform to
+ */
+ public static final String ORCID_ID_SYNTAX = "\\d{4}-\\d{4}-\\d{4}-(\\d{3}X|\\d{4})";
+
+ @Override
+ public String getId() {
+ // A PersonValue is considered unique with the first & last name.
+ String nonDigestedIdentifier;
+ if(StringUtils.isNotBlank(getFirstName())) {
+ nonDigestedIdentifier = Orcidv2AuthorityValue.class.toString() + "field: Person " + "lastName: " + getLastName() + ", firstName: " + getFirstName()+ ", OrcidIdentifier: " + getOrcid_id();
+ }
+ else {
+ nonDigestedIdentifier = Orcidv2AuthorityValue.class.toString() + "field: Person " + "lastName: " + getLastName()+", OrcidIdentifier: " + getOrcid_id() ;
+ }
+ // We return an md5 digest of the toString, this will ensure a unique identifier for the same value each time
+ return DigestUtils.md5Hex(nonDigestedIdentifier);
+ }
+
+ /**
+ * Creates an instance of Orcidv2AuthorityValue with only uninitialized fields.
+ * This is meant to be filled in with values from an existing record.
+ * To create a brand new Orcidv2AuthorityValue, use create()
+ */
+ public Orcidv2AuthorityValue() {
+ }
+
+ public Orcidv2AuthorityValue(SolrDocument document) {
+ super(document);
+ }
+
+
+ public String getOrcid_id() {
+ return orcid_id;
+ }
+
+ public void setOrcid_id(String orcid_id) {
+ this.orcid_id = orcid_id;
+ }
+
+ /**
+ * Create an empty authority.
+ * @return OrcidAuthorityValue
+ */
+ public static Orcidv2AuthorityValue create() {