Commit 42f98e9ac0bbd7a09ad04be37b9a6698d991cb9a

Authored by Ricardo Pereira
1 parent 2d531180c3
Exists in master and in 1 other branch API_v3.0

markdown files

Showing 2 changed files with 220 additions and 0 deletions   Show diff stats
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +The MIT License (MIT)
  2 +Copyright (c) 2017 PTCRIS - FCT|FCCN (http://ptcris.pt)
  3 +
  4 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  5 +
  6 +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  7 +
  8 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 \ No newline at end of file 9 \ No newline at end of file
@@ -0,0 +1,212 @@ @@ -0,0 +1,212 @@
  1 +# JAVA-ORCID-CLIENT
  2 +
  3 +Simple, easy to use ORCiD client written in Java. Supports the public and Tier2 API with OAuth. Natural object mapping - The entire ORCiD message schema is represented as a hirearchical graph of POJOs with JAXB support for serialisation.
  4 +This work is based on Tom Demeranville Orcid Java Client that is available at [GitHub](https://github.com/TomDemeranville/orcid-java-client)
  5 +
  6 +
  7 +
  8 +# Requirements to use this client in your project
  9 +
  10 +## Maven dependencies you will require
  11 +```xml
  12 + <dependency>
  13 + <groupId>org.um.dsi.gavea</groupId>
  14 + <artifactId>degois-orcid-client</artifactId>
  15 + <version>2.0</version>
  16 + <type>pom</type>
  17 + </dependency>
  18 +```
  19 +for now you can use the jfrog repository:
  20 +```xml
  21 + <repositories>
  22 + <repository>
  23 + <id>RCAAP artifactory</id>
  24 + <name>RCAAP Artifacts-releases</name>
  25 + <url>https://rcaap.jfrog.io/rcaap/libs-release/</url>
  26 + </repository>
  27 + </repositories>
  28 +```
  29 +
  30 +
  31 +## Java imports in your project
  32 +
  33 +You should import:
  34 +
  35 + // Import the client
  36 + import org.um.dsi.gavea.orcid.client.OrcidOAuthClient;
  37 + import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
  38 + import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  39 +
  40 + // Import activities
  41 + import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
  42 + import org.um.dsi.gavea.orcid.model.activities.Identifier;
  43 + import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
  44 +
  45 + // Import Works
  46 + import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
  47 + import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType;
  48 + import org.um.dsi.gavea.orcid.model.work.Work;
  49 + import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
  50 + import org.um.dsi.gavea.orcid.model.work.WorkTitle;
  51 + import org.um.dsi.gavea.orcid.model.work.WorkType;
  52 +
  53 + // Import Enum types
  54 + import org.um.dsi.gavea.orcid.model.common.RelationshipType;
  55 + import org.um.dsi.gavea.orcid.model.common.ScopePathType;
  56 +
  57 +
  58 +# Usage Examples
  59 +
  60 +## Generate an Access Token, using the sandbox
  61 + String loginUri = "https://sandbox.orcid.org";
  62 + String clientSecret = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
  63 + String clientId = "XXXX-XXXX-XXXX-XXXX";
  64 + String apiUri = "https://api.sandbox.orcid.org";
  65 + //Use google OAUTH playground, this should be the landing page used to receive the Authorization Code
  66 + String redirectUri = "https://developers.google.com/oauthplayground";
  67 +
  68 + // This scopes will allow you to do almost anything to the user profile
  69 + // You should limit the scopes you want to use
  70 + List<ScopePathType> scopes = new ArrayList<ScopePathType>();
  71 + scopes.add(ScopePathType.AUTHENTICATE);
  72 + scopes.add(ScopePathType.ORCID_PROFILE_READ_LIMITED);
  73 + scopes.add(ScopePathType.ACTIVITIES_UPDATE);
  74 + scopes.add(ScopePathType.ORCID_BIO_UPDATE);
  75 +
  76 + // Instantiate the Orcid Client
  77 + OrcidOAuthClient orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri);
  78 +
  79 + try {
  80 + String authorizationURI = orcidClient.getAuthorizeUriLogin(scopes,state,orcid);
  81 + System.out.println(authorizationURI);
  82 + } catch (Exception e) {
  83 + // TODO Auto-generated catch block
  84 + e.printStackTrace();
  85 + }
  86 +
  87 +Then you should have a landing page in your project, configured in redirectUri to get the Authentication Code.
  88 +
  89 + OrcidAccessToken orcidToken;
  90 +
  91 + try {
  92 + orcidToken = orcidClient.getAccessTokens(authorizationCode);
  93 + accessToken = orcidToken.getAccess_token();
  94 + System.out.println(accessToken);
  95 +
  96 + } catch (OrcidClientException e) {
  97 + // TODO Auto-generated catch block
  98 + e.printStackTrace();
  99 + }
  100 +
  101 +if you already have a token, you could simply use setAccess_token method in the OrcidAccessToken object:
  102 +
  103 + OrcidAccessToken orcidToken = new OrcidAccessToken();
  104 + orcidToken.setAccess_token("d3c1edb9-5385-4b76-af77-e3cd9889c5ec");
  105 +
  106 +## Get activities
  107 +
  108 +To access Activities the token must be associated with the scope /orcid-profile/read-limited
  109 +
  110 + try {
  111 + ActivitiesSummary activities = orcidClient.readActivitiesSummary(orcidToken);
  112 + List<WorkGroup> workGroupList = activities.getWorks().getGroup();
  113 +
  114 + for (WorkGroup workGroup : workGroupList) {
  115 + System.out.print("PUTCODE: " + workGroup.getWorkSummary().get(0).getPutCode() + " - ");
  116 + System.out.println(workGroup.getWorkSummary().get(0).getTitle().getTitle());
  117 +
  118 + List<Identifier> identifiersList = workGroup.getIdentifiers().getIdentifier();
  119 + for (Identifier identifier: identifiersList) {
  120 + //print ID_TYPE: ID_VALUE
  121 + System.out.print(identifier.getExternalIdentifierType() +": " + identifier.getExternalIdentifierId()+"\n");
  122 + }
  123 + }
  124 + } catch (OrcidClientException e) {
  125 + // TODO Auto-generated catch block
  126 + e.printStackTrace();
  127 + }
  128 +
  129 +The output will be:
  130 +
  131 + PUTCODE: 465120 - Organic matter composition and macrofaunal diversity in sediments of the Condor Seamount (Azores, {NE} Atlantic)
  132 + doi: http://dx.doi.org/10.1016/j.dsr2.2013.08.006
  133 + PUTCODE: 468006 - A complex picture of associations between two host mussels and symbiotic bacteria in the Northeast Atlantic
  134 + uri: http://hdl.handle.net/123456789/1154
  135 + PUTCODE: 477773 - Shape analysis of an adaptive elastic rod model
  136 + uri: http://hdl.handle.net/10400.19/2601
  137 + doi: 10.1137/040604443
  138 + PUTCODE: 477774 - Early skin immunological disturbance after Plasmodium-infected mosquito bites
  139 + uri: http://hdl.handle.net/10400.7/254
  140 +
  141 +
  142 +## Get a Work by PUTCODE
  143 +
  144 + try {
  145 + String putCode = "477804";
  146 +
  147 + Work work = orcidClient.readWork(orcidToken, putCode);
  148 + } catch (OrcidClientException e) {
  149 + // TODO Auto-generated catch block
  150 + e.printStackTrace();
  151 + }
  152 +
  153 +## Update a Work
  154 +
  155 +To update a work the token used must be associated with one of the scopes: /activities/update or /orcid-works/update
  156 +
  157 + try {
  158 + String putCode = "477804";
  159 +
  160 + Work work = orcidClient.readWork(orcidToken, putCode);
  161 + WorkTitle workTitle = new WorkTitle("Changed title regarding PTCRISSync",null,null);
  162 + work.setTitle(workTitle);
  163 +
  164 + //Save work with changed title
  165 + orcidClient.updateWork(orcidToken2, putCode, work);
  166 + System.out.println("\n\nSaved with title: " + workTitle.getTitle());
  167 +
  168 + } catch (OrcidClientException e) {
  169 + // TODO Auto-generated catch block
  170 + e.printStackTrace();
  171 + }
  172 +
  173 +## Create a new Work
  174 +
  175 +To create a new work the token used must be associated with one of the scopes: /activities/update or /orcid-works/create
  176 +
  177 + Work newWork = new Work();
  178 +
  179 + // Set the title
  180 + WorkTitle workTitle2 = new WorkTitle("new item PTCRISSync",null,null);
  181 + newWork.setTitle(workTitle2);
  182 +
  183 + // Set the type
  184 + newWork.setType(WorkType.JOURNAL_ARTICLE);
  185 +
  186 + // Set External ID (ORCID API requires at least one)
  187 + ExternalIdentifier internalId = new ExternalIdentifier();
  188 + internalId.setExternalIdentifierType(ExternalIdentifierType.SOURCE_WORK_ID);
  189 + internalId.setExternalIdentifierId("PTCRIS_01");
  190 + // You must indicate the Relationship or the External URL
  191 + internalId.setRelationship(RelationshipType.SELF);
  192 +
  193 + // Set the External Identifiers
  194 + WorkExternalIdentifiers externalIdentifiers = new WorkExternalIdentifiers();
  195 + externalIdentifiers.getWorkExternalIdentifier().add(internalId);
  196 + newWork.setExternalIdentifiers(externalIdentifiers);
  197 +
  198 + try {
  199 +
  200 + //The method addWork will retrieve the PUTCODE
  201 + String newPutCode = orcidClient.addWork(orcidToken2, newWork);
  202 + System.out.println("New item with PUTCODE: " + newPutCode);
  203 +
  204 + } catch (OrcidClientException e) {
  205 + // TODO Auto-generated catch block
  206 + e.printStackTrace();
  207 + }
  208 +
  209 +
  210 +# License
  211 +
  212 +Please contact us.
0 \ No newline at end of file 213 \ No newline at end of file