Blame view

README.md 7.38 KB
958d8db3c   Paulo Graça   Initial documenta...
1
  # JAVA-ORCID-CLIENT
75cef0137   Paulo Graça   Changes in introd...
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.
  This work is based on Tom Demeranville Orcid Java Client that is available at [GitHub](https://github.com/TomDemeranville/orcid-java-client)
b2cfa1538   Paulo Graça   Changing build text
4
4b327300c   Paulo Graça   Change doc structure
5
bf0a167bf   Paulo Graça   Change text
6
  # Requirements to use this client in your project
958d8db3c   Paulo Graça   Initial documenta...
7
bf0a167bf   Paulo Graça   Change text
8
  ## Maven dependencies you will require
7b5c03333   Paulo Graça   update readme.md
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  ```xml
    <dependency>
      <groupId>org.um.dsi.gavea</groupId>
      <artifactId>degois-orcid-client</artifactId>
      <version>2.0</version>
      <type>pom</type>
    </dependency>
  ```
  for now you can use the jfrog repository:
  ```xml
    <repositories>
      <repository>
         <id>RCAAP artifactory</id>
         <name>RCAAP Artifacts-releases</name>
         <url>https://rcaap.jfrog.io/rcaap/libs-release/</url>
      </repository>
    </repositories>
  ```
9c05b8720   Paulo Graça   deploy section
27
      
939e12287   Paulo Graça   Add the dependencies
28
4b327300c   Paulo Graça   Change doc structure
29
  ## Java imports in your project
958d8db3c   Paulo Graça   Initial documenta...
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
  
  You should import:
  
      // Import the client
      import org.um.dsi.gavea.orcid.client.OrcidOAuthClient;
      import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
      import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
      
      // Import activities
      import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
      import org.um.dsi.gavea.orcid.model.activities.Identifier;
      import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
      
      // Import Works
      import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
      import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType;
      import org.um.dsi.gavea.orcid.model.work.Work;
      import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
      import org.um.dsi.gavea.orcid.model.work.WorkTitle;
      import org.um.dsi.gavea.orcid.model.work.WorkType;
      
      // Import Enum types
      import org.um.dsi.gavea.orcid.model.common.RelationshipType;
      import org.um.dsi.gavea.orcid.model.common.ScopePathType;
      
4b327300c   Paulo Graça   Change doc structure
55
  # Usage Examples
958d8db3c   Paulo Graça   Initial documenta...
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
  
  ## Generate an Access Token, using the sandbox
      String loginUri = "https://sandbox.orcid.org";
  	String clientSecret = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
  	String clientId = "XXXX-XXXX-XXXX-XXXX";
  	String apiUri = "https://api.sandbox.orcid.org";
  	//Use google OAUTH playground, this should be the landing page used to receive the Authorization Code
  	String redirectUri = "https://developers.google.com/oauthplayground";
  	
  	// This scopes will allow you to do almost anything to the user profile	
  	// You should limit the scopes you want to use
  	List<ScopePathType> scopes = new ArrayList<ScopePathType>();
  	scopes.add(ScopePathType.AUTHENTICATE);
  	scopes.add(ScopePathType.ORCID_PROFILE_READ_LIMITED);
  	scopes.add(ScopePathType.ACTIVITIES_UPDATE);
  	scopes.add(ScopePathType.ORCID_BIO_UPDATE);
  
      // Instantiate the Orcid Client
  	OrcidOAuthClient orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri);	
  	
  	try {
  			String authorizationURI = orcidClient.getAuthorizeUriLogin(scopes,state,orcid);
  			System.out.println(authorizationURI);
  	} catch (Exception e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  	}
  	
b0d3432ab   Paulo Graça   Complete with cod...
84
  Then you should have a landing page in your project, configured in redirectUri to get the Authentication Code.
958d8db3c   Paulo Graça   Initial documenta...
85
86
87
88
89
90
91
92
93
94
95
96
  
      OrcidAccessToken orcidToken;
      
      try {
  			orcidToken = orcidClient.getAccessTokens(authorizationCode);
  			accessToken = orcidToken.getAccess_token(); 
  			System.out.println(accessToken);
  
  	} catch (OrcidClientException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  	}
b0d3432ab   Paulo Graça   Complete with cod...
97
98
  
  if you already have a token, you could simply use setAccess_token method in the OrcidAccessToken object:
be412ccf3   Paulo Graça   changes in text
99
  	OrcidAccessToken orcidToken = new OrcidAccessToken();
b0d3432ab   Paulo Graça   Complete with cod...
100
  	orcidToken.setAccess_token("d3c1edb9-5385-4b76-af77-e3cd9889c5ec");
958d8db3c   Paulo Graça   Initial documenta...
101
  ## Get activities
be412ccf3   Paulo Graça   changes in text
102
  To access Activities the token must be associated with the scope /orcid-profile/read-limited
958d8db3c   Paulo Graça   Initial documenta...
103
b0d3432ab   Paulo Graça   Complete with cod...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
      try {
  		ActivitiesSummary activities = orcidClient.readActivitiesSummary(orcidToken);
  		List<WorkGroup> workGroupList = activities.getWorks().getGroup();
  			
  		for (WorkGroup workGroup : workGroupList) {				
  			System.out.print("PUTCODE: " + workGroup.getWorkSummary().get(0).getPutCode() + " - ");
  			System.out.println(workGroup.getWorkSummary().get(0).getTitle().getTitle());	
  				
  			List<Identifier> identifiersList = workGroup.getIdentifiers().getIdentifier();
  			for (Identifier identifier: identifiersList) {	
  				//print ID_TYPE: ID_VALUE
  				System.out.print(identifier.getExternalIdentifierType() +": " + identifier.getExternalIdentifierId()+"
  ");
  			}
          }
      } catch (OrcidClientException e) {
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	}
a31a6e269   Paulo Graça   Add example output
123
124
125
126
127
128
129
130
131
132
133
134
  	
  The output will be:
  
      PUTCODE: 465120 - Organic matter composition and macrofaunal diversity in sediments of the Condor Seamount (Azores, {NE} Atlantic)
      doi: http://dx.doi.org/10.1016/j.dsr2.2013.08.006
      PUTCODE: 468006 - A complex picture of associations between two host mussels and symbiotic bacteria in the Northeast Atlantic
      uri: http://hdl.handle.net/123456789/1154
      PUTCODE: 477773 - Shape analysis of an adaptive elastic rod model
      uri: http://hdl.handle.net/10400.19/2601
      doi: 10.1137/040604443
      PUTCODE: 477774 - Early skin immunological disturbance after Plasmodium-infected mosquito bites
      uri: http://hdl.handle.net/10400.7/254
b0d3432ab   Paulo Graça   Complete with cod...
135
136
137
138
139
140
141
142
143
144
145
146
  
  ## Get a Work by PUTCODE
  
      try {
  		String putCode = "477804";
  		
  		Work work = orcidClient.readWork(orcidToken, putCode);
      } catch (OrcidClientException e) {
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	}
  	
958d8db3c   Paulo Graça   Initial documenta...
147
  ## Update a Work
be412ccf3   Paulo Graça   changes in text
148
  To update a work the token used must be associated with one of the scopes: /activities/update  or /orcid-works/update
b0d3432ab   Paulo Graça   Complete with cod...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
      try {
          String putCode = "477804";
          
          Work work = orcidClient.readWork(orcidToken, putCode);
  		WorkTitle workTitle = new WorkTitle("Changed title regarding PTCRISSync",null,null); 
  		work.setTitle(workTitle);
  		
  		//Save work with changed title
  		orcidClient.updateWork(orcidToken2, putCode, work);			
  		System.out.println("
  
  Saved with title: " + workTitle.getTitle());
  		
      } catch (OrcidClientException e) {
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	}
  	
958d8db3c   Paulo Graça   Initial documenta...
167
  ## Create a new Work
be412ccf3   Paulo Graça   changes in text
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  To create a new work the token used must be associated with one of the scopes: /activities/update  or /orcid-works/create
  
  	Work newWork = new Work();
  	
  	// Set the title
  	WorkTitle workTitle2 = new WorkTitle("new item PTCRISSync",null,null);
  	newWork.setTitle(workTitle2);			
  	
  	// Set the type		
  	newWork.setType(WorkType.JOURNAL_ARTICLE);
  	
  	// Set External ID (ORCID API requires at least one)
  	ExternalIdentifier internalId = new ExternalIdentifier();
  	internalId.setExternalIdentifierType(ExternalIdentifierType.SOURCE_WORK_ID);
  	internalId.setExternalIdentifierId("PTCRIS_01");
  	// You must indicate the Relationship or the External URL
  	internalId.setRelationship(RelationshipType.SELF);
  								
  	// Set the External Identifiers	
  	WorkExternalIdentifiers externalIdentifiers = new WorkExternalIdentifiers();
  	externalIdentifiers.getWorkExternalIdentifier().add(internalId);
  	newWork.setExternalIdentifiers(externalIdentifiers);
b0d3432ab   Paulo Graça   Complete with cod...
190
      try {
b0d3432ab   Paulo Graça   Complete with cod...
191
192
193
194
195
196
197
198
199
  
          //The method addWork will retrieve the PUTCODE
  		String newPutCode = orcidClient.addWork(orcidToken2, newWork);			
  		System.out.println("New item with PUTCODE: " + newPutCode);
  		
      } catch (OrcidClientException e) {
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	}    
958d8db3c   Paulo Graça   Initial documenta...
200
b0d3432ab   Paulo Graça   Complete with cod...
201
  # License
be412ccf3   Paulo Graça   changes in text
202
b0d3432ab   Paulo Graça   Complete with cod...
203
  Please contact us.