Commit 04ca33b45903563b3a8bb9ad087de0399f7decec

Authored by Paulo Graça
1 parent bc6a818466
Exists in master

add method readFundingSummary

src/main/java/org/um/dsi/gavea/orcid/client/OrcidOAuthClient.java
... ... @@ -49,23 +49,23 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
49 49 private static final long serialVersionUID = -6655680509383446710L;
50 50  
51 51 private static final Logger _log = LoggerFactory.getLogger(OrcidOAuthClient.class);
52   -
  52 +
53 53 public OrcidOAuthClient(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri) {
54 54 this(null, loginUri, apiUri, clientId, clientSecret, redirectUri);
55 55 }
56   -
  56 +
57 57 public OrcidOAuthClient(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, boolean debugMode) {
58 58 this(null, loginUri, apiUri, clientId, clientSecret, redirectUri, debugMode);
59 59 }
60   -
  60 +
61 61 public OrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri) {
62 62 super(restClient, loginUri, apiUri, clientId, clientSecret, redirectUri);
63 63 }
64   -
  64 +
65 65 public OrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, boolean debugMode) {
66 66 super(restClient, loginUri, apiUri, clientId, clientSecret, redirectUri, debugMode);
67 67 }
68   -
  68 +
69 69 /**
70 70 *
71 71 * @param scopes
... ... @@ -100,7 +100,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
100 100 public String getAuthorizeUri(final List<ScopePathType> scopes, final String state, final String familyNames, final String givenNames) throws Exception {
101 101 return getAuthorizeUri(scopes, state, null, familyNames, givenNames, null, null, false);
102 102 }
103   -
  103 +
104 104 /**
105 105 *
106 106 * @param scopes
... ... @@ -131,10 +131,10 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
131 131 // Optional params
132 132 if (state != null && !"".equals(state))
133 133 builder.queryParam("state", state);
134   -
  134 +
135 135 if (orcidId != null && !"".equals(orcidId))
136 136 builder.queryParam("orcid", orcidId);
137   -
  137 +
138 138 if (familyNames != null && !"".equals(familyNames))
139 139 builder.queryParam("family_names", familyNames);
140 140  
... ... @@ -153,7 +153,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
153 153  
154 154 return builder.toString();
155 155 }
156   -
  156 +
157 157 /**
158 158 *
159 159 * @param authorizationCode
... ... @@ -169,60 +169,74 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
169 169  
170 170 return post(authorizationCode, formData).readEntity(OrcidAccessToken.class);
171 171 }
172   -
173   -
  172 +
  173 +
174 174 /* Activities */
175 175 public ActivitiesSummary readActivitiesSummary(final OrcidAccessToken token) throws OrcidClientException {
176 176 Response response = null;
177 177 try {
178 178 response = get(OrcidConstants.ENDPOINT_ACTIVITIES, token, null);
179   -
  179 +
180 180 return response.readEntity(ActivitiesSummary.class);
181 181 } finally {
182 182 if (response != null)
183 183 response.close();
184 184 }
185 185 }
186   -
  186 +
187 187 /* Activities - Works */
188 188 public org.um.dsi.gavea.orcid.model.activities.Works readWorksSummary(final OrcidAccessToken token) throws OrcidClientException {
189 189 Response response = null;
190 190 try {
191 191 response = get(OrcidConstants.ENDPOINT_WORKS, token, null);
192   -
  192 +
193 193 return response.readEntity(org.um.dsi.gavea.orcid.model.activities.Works.class);
194 194 } finally {
195 195 if (response != null)
196 196 response.close();
197 197 }
198 198 }
199   -
200   -
  199 +
  200 + /* Activities - Fundings */
  201 + public org.um.dsi.gavea.orcid.model.activities.Fundings readFundingSummary(final OrcidAccessToken token) throws OrcidClientException {
  202 + Response response = null;
  203 + try {
  204 + response = get(OrcidConstants.ENDPOINT_FUNDING, token, null);
  205 +
  206 + return response.readEntity(org.um.dsi.gavea.orcid.model.activities.Fundings.class);
  207 + } finally {
  208 + if (response != null)
  209 + response.close();
  210 + }
  211 + }
  212 +
  213 +
  214 +
201 215 /* Address */
202 216 public Addresses readAddresses(final OrcidAccessToken token) throws OrcidClientException {
203 217 Response response = null;
204 218 try {
205 219 response = get(OrcidConstants.ENDPOINT_ADDRESS, token, null);
206   -
  220 +
207 221 return response.readEntity(Addresses.class);
208 222 } finally {
209 223 if (response != null)
210 224 response.close();
211 225 }
212 226 }
213   -
  227 +
214 228 public Address readAddress(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
215 229 Response response = null;
216 230 try {
217 231 response = get(OrcidConstants.ENDPOINT_ADDRESS, token, putCode);
218   -
  232 +
219 233 return response.readEntity(Address.class);
220 234 } finally {
221 235 if (response != null)
222 236 response.close();
223 237 }
224 238 }
225   -
  239 +
226 240 public void addAddress(final OrcidAccessToken token, Address address) throws OrcidClientException {
227 241 Response response = null;
228 242 try {
... ... @@ -252,28 +266,28 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
252 266 response.close();
253 267 }
254 268 }
255   -
256   -
  269 +
  270 +
257 271 /* Biography */
258 272 public Biography readBiography(final OrcidAccessToken token) throws OrcidClientException {
259 273 Response response = null;
260 274 try {
261 275 response = get(OrcidConstants.ENDPOINT_BIOGRAPHY, token, null);
262   -
  276 +
263 277 return response.readEntity(Biography.class);
264 278 } finally {
265 279 if (response != null)
266 280 response.close();
267 281 }
268 282 }
269   -
270   -
  283 +
  284 +
271 285 /* Education */
272 286 public Education readEducation(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
273 287 Response response = null;
274 288 try {
275 289 response = get(OrcidConstants.ENDPOINT_EDUCATION, token, putCode);
276   -
  290 +
277 291 return response.readEntity(Education.class);
278 292 } finally {
279 293 if (response != null)
... ... @@ -285,19 +299,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
285 299 Response response = null;
286 300 try {
287 301 response = get(OrcidConstants.ENDPOINT_EDUCATION_SUMMARY, token, putCode);
288   -
  302 +
289 303 return response.readEntity(EducationSummary.class);
290 304 } finally {
291 305 if (response != null)
292 306 response.close();
293 307 }
294 308 }
295   -
  309 +
296 310 public String addEducation(final OrcidAccessToken token, final Education education) throws OrcidClientException {
297 311 Response response = null;
298 312 try {
299 313 response = post(OrcidConstants.ENDPOINT_EDUCATION, token, Entity.entity(education, MediaType.APPLICATION_XML_TYPE));
300   -
  314 +
301 315 return retrievePutCode(response);
302 316 } finally {
303 317 if (response != null)
... ... @@ -324,28 +338,28 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
324 338 response.close();
325 339 }
326 340 }
327   -
328   -
  341 +
  342 +
329 343 /* Email */
330 344 public Emails readEmails(final OrcidAccessToken token) throws OrcidClientException {
331 345 Response response = null;
332 346 try {
333 347 response = get(OrcidConstants.ENDPOINT_EMAIL, token, null);
334   -
  348 +
335 349 return response.readEntity(Emails.class);
336 350 } finally {
337 351 if (response != null)
338 352 response.close();
339 353 }
340 354 }
341   -
342   -
  355 +
  356 +
343 357 /* Employment */
344 358 public Employment readEmployment(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
345 359 Response response = null;
346 360 try {
347 361 response = get(OrcidConstants.ENDPOINT_EMPLOYMENT, token, putCode);
348   -
  362 +
349 363 return response.readEntity(Employment.class);
350 364 } finally {
351 365 if (response != null)
... ... @@ -357,19 +371,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
357 371 Response response = null;
358 372 try {
359 373 response = get(OrcidConstants.ENDPOINT_EMPLOYMENT_SUMMARY, token, putCode);
360   -
  374 +
361 375 return response.readEntity(EmploymentSummary.class);
362 376 } finally {
363 377 if (response != null)
364 378 response.close();
365 379 }
366 380 }
367   -
  381 +
368 382 public String addEmployment(final OrcidAccessToken token, final Employment employment) throws OrcidClientException {
369 383 Response response = null;
370 384 try {
371 385 response = post(OrcidConstants.ENDPOINT_EMPLOYMENT, token, Entity.entity(employment, MediaType.APPLICATION_XML_TYPE));
372   -
  386 +
373 387 return retrievePutCode(response);
374 388 } finally {
375 389 if (response != null)
... ... @@ -396,14 +410,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
396 410 response.close();
397 411 }
398 412 }
399   -
400   -
  413 +
  414 +
401 415 /* External Identifier */
402 416 public ExternalIdentifiers readExternalIdentifiers(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
403 417 Response response = null;
404 418 try {
405 419 response = get(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode);
406   -
  420 +
407 421 return response.readEntity(ExternalIdentifiers.class);
408 422 } finally {
409 423 if (response != null)
... ... @@ -415,19 +429,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
415 429 Response response = null;
416 430 try {
417 431 response = get(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode);
418   -
  432 +
419 433 return response.readEntity(ExternalIdentifier.class);
420 434 } finally {
421 435 if (response != null)
422 436 response.close();
423 437 }
424 438 }
425   -
  439 +
426 440 public String addExternalIdentifier(final OrcidAccessToken token, final ExternalIdentifier externalIdentifier) throws OrcidClientException {
427 441 Response response = null;
428 442 try {
429 443 response = post(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, Entity.entity(externalIdentifier, MediaType.APPLICATION_XML_TYPE));
430   -
  444 +
431 445 return retrievePutCode(response);
432 446 } finally {
433 447 if (response != null)
... ... @@ -454,14 +468,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
454 468 response.close();
455 469 }
456 470 }
457   -
458   -
  471 +
  472 +
459 473 /* Funding */
460 474 public Funding readFunding(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
461 475 Response response = null;
462 476 try {
463 477 response = get(OrcidConstants.ENDPOINT_FUNDING, token, putCode);
464   -
  478 +
465 479 return response.readEntity(Funding.class);
466 480 } finally {
467 481 if (response != null)
... ... @@ -472,7 +486,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
472 486 Response response = null;
473 487 try {
474 488 response = get(OrcidConstants.ENDPOINT_FUNDING_SUMMARY, token, putCode);
475   -
  489 +
476 490 return response.readEntity(FundingSummary.class);
477 491 } finally {
478 492 if (response != null)
... ... @@ -484,7 +498,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
484 498 Response response = null;
485 499 try {
486 500 response = post(OrcidConstants.ENDPOINT_FUNDING, token, Entity.entity(funding, MediaType.APPLICATION_XML_TYPE));
487   -
  501 +
488 502 return retrievePutCode(response);
489 503 } finally {
490 504 if (response != null)
... ... @@ -511,14 +525,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
511 525 response.close();
512 526 }
513 527 }
514   -
515   -
  528 +
  529 +
516 530 /* Keyword */
517 531 public Keywords readKeywords(final OrcidAccessToken token) throws OrcidClientException {
518 532 Response response = null;
519 533 try {
520 534 response = get(OrcidConstants.ENDPOINT_KEYWORDS, token, null);
521   -
  535 +
522 536 return response.readEntity(Keywords.class);
523 537 } finally {
524 538 if (response != null)
... ... @@ -530,19 +544,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
530 544 Response response = null;
531 545 try {
532 546 response = get(OrcidConstants.ENDPOINT_KEYWORDS, token, putCode);
533   -
  547 +
534 548 return response.readEntity(Keyword.class);
535 549 } finally {
536 550 if (response != null)
537 551 response.close();
538 552 }
539 553 }
540   -
  554 +
541 555 public String addKeyword(final OrcidAccessToken token, final Keyword keyword) throws OrcidClientException {
542 556 Response response = null;
543 557 try {
544 558 response = post(OrcidConstants.ENDPOINT_KEYWORDS, token, Entity.entity(keyword, MediaType.APPLICATION_XML_TYPE));
545   -
  559 +
546 560 return retrievePutCode(response);
547 561 } finally {
548 562 if (response != null)
... ... @@ -569,14 +583,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
569 583 response.close();
570 584 }
571 585 }
572   -
573   -
  586 +
  587 +
574 588 /* Other Name */
575 589 public OtherNames readOtherNames(final OrcidAccessToken token) throws OrcidClientException {
576 590 Response response = null;
577 591 try {
578 592 response = get(OrcidConstants.ENDPOINT_OTHER_NAMES, token, null);
579   -
  593 +
580 594 return response.readEntity(OtherNames.class);
581 595 } finally {
582 596 if (response != null)
... ... @@ -588,19 +602,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
588 602 Response response = null;
589 603 try {
590 604 response = get(OrcidConstants.ENDPOINT_OTHER_NAMES, token, putCode);
591   -
  605 +
592 606 return response.readEntity(OtherName.class);
593 607 } finally {
594 608 if (response != null)
595 609 response.close();
596 610 }
597 611 }
598   -
  612 +
599 613 public String addOtherName(final OrcidAccessToken token, final OtherName otherName) throws OrcidClientException {
600 614 Response response = null;
601 615 try {
602 616 response = post(OrcidConstants.ENDPOINT_OTHER_NAMES, token, Entity.entity(otherName, MediaType.APPLICATION_XML_TYPE));
603   -
  617 +
604 618 return retrievePutCode(response);
605 619 } finally {
606 620 if (response != null)
... ... @@ -627,14 +641,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
627 641 response.close();
628 642 }
629 643 }
630   -
631   -
  644 +
  645 +
632 646 /* Peer Review */
633 647 public PeerReview readPeerReview(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
634 648 Response response = null;
635 649 try {
636 650 response = get(OrcidConstants.ENDPOINT_PEERREVIEW, token, putCode);
637   -
  651 +
638 652 return response.readEntity(PeerReview.class);
639 653 } finally {
640 654 if (response != null)
... ... @@ -645,7 +659,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
645 659 Response response = null;
646 660 try {
647 661 response = get(OrcidConstants.ENDPOINT_PEERREVIEW_SUMMARY, token, putCode);
648   -
  662 +
649 663 return response.readEntity(PeerReviewSummary.class);
650 664 } finally {
651 665 if (response != null)
... ... @@ -657,7 +671,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
657 671 Response response = null;
658 672 try {
659 673 response = post(OrcidConstants.ENDPOINT_PEERREVIEW, token, Entity.entity(peerReview, MediaType.APPLICATION_XML_TYPE));
660   -
  674 +
661 675 return retrievePutCode(response);
662 676 } finally {
663 677 if (response != null)
... ... @@ -684,42 +698,42 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
684 698 response.close();
685 699 }
686 700 }
687   -
688   -
  701 +
  702 +
689 703 /* Person */
690 704 public Person readPerson(final OrcidAccessToken token) throws OrcidClientException {
691 705 Response response = null;
692 706 try {
693 707 response = get(OrcidConstants.ENDPOINT_PERSON, token, null);
694   -
  708 +
695 709 return response.readEntity(Person.class);
696 710 } finally {
697 711 if (response != null)
698 712 response.close();
699 713 }
700 714 }
701   -
702   -
  715 +
  716 +
703 717 /* Personal Details */
704 718 public PersonalDetails readPersonalDetails(final OrcidAccessToken token) throws OrcidClientException {
705 719 Response response = null;
706 720 try {
707 721 response = get(OrcidConstants.ENDPOINT_PERSONAL_DETAILS, token, null);
708   -
  722 +
709 723 return response.readEntity(PersonalDetails.class);
710 724 } finally {
711 725 if (response != null)
712 726 response.close();
713 727 }
714 728 }
715   -
716   -
  729 +
  730 +
717 731 /* Researcher Url */
718 732 public ResearcherUrls readResearcherUrls(final OrcidAccessToken token) throws OrcidClientException {
719 733 Response response = null;
720 734 try {
721 735 response = get(OrcidConstants.ENDPOINT_RESEARCHER_URLS, token, null);
722   -
  736 +
723 737 return response.readEntity(ResearcherUrls.class);
724 738 } finally {
725 739 if (response != null)
... ... @@ -731,19 +745,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
731 745 Response response = null;
732 746 try {
733 747 response = get(OrcidConstants.ENDPOINT_RESEARCHER_URLS, token, putCode);
734   -
  748 +
735 749 return response.readEntity(ResearcherUrl.class);
736 750 } finally {
737 751 if (response != null)
738 752 response.close();
739 753 }
740 754 }
741   -
  755 +
742 756 public String addResearcherUrl(final OrcidAccessToken token, final ResearcherUrl researcherUrl) throws OrcidClientException {
743 757 Response response = null;
744 758 try {
745 759 response = post(OrcidConstants.ENDPOINT_RESEARCHER_URLS, token, Entity.entity(researcherUrl, MediaType.APPLICATION_XML_TYPE));
746   -
  760 +
747 761 return retrievePutCode(response);
748 762 } finally {
749 763 if (response != null)
... ... @@ -770,40 +784,40 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
770 784 response.close();
771 785 }
772 786 }
773   -
774   -
  787 +
  788 +
775 789 /* Work */
776 790 public Work readWork(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
777 791 Response response = null;
778 792 try {
779 793 response = get(OrcidConstants.ENDPOINT_WORK, token, putCode);
780   -
  794 +
781 795 return response.readEntity(Work.class);
782 796 } finally {
783 797 if (response != null)
784 798 response.close();
785 799 }
786 800 }
787   -
  801 +
788 802 public Bulk readWorks(final OrcidAccessToken token, final List<String> putCodes) throws OrcidClientException {
789 803 Response response = null;
790 804 try {
791 805 response = get(OrcidConstants.ENDPOINT_WORKS, token, StringUtils.join(putCodes.iterator(), ","));
792   -
  806 +
793 807 return response.readEntity(Bulk.class);
794 808 } finally {
795 809 if (response != null)
796 810 response.close();
797 811 }
798 812 }
799   -
800   -
801   -
  813 +
  814 +
  815 +
802 816 public WorkSummary readWorkSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
803 817 Response response = null;
804 818 try {
805 819 response = get(OrcidConstants.ENDPOINT_WORK_SUMMARY, token, putCode);
806   -
  820 +
807 821 return response.readEntity(WorkSummary.class);
808 822 } finally {
809 823 if (response != null)
... ... @@ -815,14 +829,14 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
815 829 Response response = null;
816 830 try {
817 831 response = post(OrcidConstants.ENDPOINT_WORK, token, Entity.entity(work, MediaType.APPLICATION_XML_TYPE));
818   -
  832 +
819 833 return retrievePutCode(response);
820 834 } finally {
821 835 if (response != null)
822 836 response.close();
823 837 }
824 838 }
825   -
  839 +
826 840 /* Bulks */
827 841 public Bulk addWorks(final OrcidAccessToken token, final Bulk bulk) throws OrcidClientException {
828 842 Response response = null;
... ... @@ -854,8 +868,8 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
854 868 response.close();
855 869 }
856 870 }
857   -
858   -
  871 +
  872 +
859 873 /**
860 874 *
861 875 * @param response
... ... @@ -868,10 +882,10 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
868 882 if (putCode.matches("\\d+"))
869 883 return putCode;
870 884 }
871   -
  885 +
872 886 return null;
873 887 }
874   -
  888 +
875 889 /**
876 890 *
877 891 * @param value
... ...