Commit b0d3432ab90f9ccc162a21c0373863e43517a27f

Authored by Paulo Graça
1 parent 958d8db3c4

Complete with code examples

Showing 1 changed file with 85 additions and 7 deletions   Show diff stats
README.md
... ... @@ -57,8 +57,7 @@ You should import:
57 57 e.printStackTrace();
58 58 }
59 59  
60   -Then you should have a landing page in your project, configured in redirectUri to get the Authentication Code
61   -This method will
  60 +Then you should have a landing page in your project, configured in redirectUri to get the Authentication Code.
62 61  
63 62 OrcidAccessToken orcidToken;
64 63  
... ... @@ -71,17 +70,96 @@ This method will
71 70 // TODO Auto-generated catch block
72 71 e.printStackTrace();
73 72 }
74   -
  73 +
  74 +if you already have a token, you could simply use setAccess_token method in the OrcidAccessToken object:
  75 +
  76 + orcidToken.setAccess_token("d3c1edb9-5385-4b76-af77-e3cd9889c5ec");
  77 +
75 78 ## Get activities
76 79  
77   -## Get a Work
  80 +To access Activities the token must be associated with the scope ORCID_PROFILE_READ_LIMITED
78 81  
  82 + try {
  83 + ActivitiesSummary activities = orcidClient.readActivitiesSummary(orcidToken);
  84 + List<WorkGroup> workGroupList = activities.getWorks().getGroup();
  85 +
  86 + for (WorkGroup workGroup : workGroupList) {
  87 + System.out.print("PUTCODE: " + workGroup.getWorkSummary().get(0).getPutCode() + " - ");
  88 + System.out.println(workGroup.getWorkSummary().get(0).getTitle().getTitle());
  89 +
  90 + List<Identifier> identifiersList = workGroup.getIdentifiers().getIdentifier();
  91 + for (Identifier identifier: identifiersList) {
  92 + //print ID_TYPE: ID_VALUE
  93 + System.out.print(identifier.getExternalIdentifierType() +": " + identifier.getExternalIdentifierId()+"\n");
  94 + }
  95 + }
  96 + } catch (OrcidClientException e) {
  97 + // TODO Auto-generated catch block
  98 + e.printStackTrace();
  99 + }
  100 +
  101 +## Get a Work by PUTCODE
  102 +
  103 + try {
  104 + String putCode = "477804";
  105 +
  106 + Work work = orcidClient.readWork(orcidToken, putCode);
  107 + } catch (OrcidClientException e) {
  108 + // TODO Auto-generated catch block
  109 + e.printStackTrace();
  110 + }
  111 +
79 112 ## Update a Work
80 113  
  114 + try {
  115 + String putCode = "477804";
  116 +
  117 + Work work = orcidClient.readWork(orcidToken, putCode);
  118 + WorkTitle workTitle = new WorkTitle("Changed title regarding PTCRISSync",null,null);
  119 + work.setTitle(workTitle);
  120 +
  121 + //Save work with changed title
  122 + orcidClient.updateWork(orcidToken2, putCode, work);
  123 + System.out.println("\n\nSaved with title: " + workTitle.getTitle());
  124 +
  125 + } catch (OrcidClientException e) {
  126 + // TODO Auto-generated catch block
  127 + e.printStackTrace();
  128 + }
  129 +
81 130 ## Create a new Work
82 131  
  132 + try {
  133 + Work newWork = new Work();
  134 +
  135 + // Set the title
  136 + WorkTitle workTitle2 = new WorkTitle("new item PTCRISSync",null,null);
  137 + newWork.setTitle(workTitle2);
  138 +
  139 + // Set the type
  140 + newWork.setType(WorkType.JOURNAL_ARTICLE);
  141 +
  142 + // Set External ID (ORCID API requires at least one)
  143 + ExternalIdentifier internalId = new ExternalIdentifier();
  144 + internalId.setExternalIdentifierType(ExternalIdentifierType.SOURCE_WORK_ID);
  145 + internalId.setExternalIdentifierId("PTCRIS_01");
  146 + // You must indicate the Relationship or the External URL
  147 + internalId.setRelationship(RelationshipType.SELF);
  148 +
  149 + // Set the External Identifiers
  150 + WorkExternalIdentifiers externalIdentifiers = new WorkExternalIdentifiers();
  151 + externalIdentifiers.getWorkExternalIdentifier().add(internalId);
  152 + newWork.setExternalIdentifiers(externalIdentifiers);
  153 +
  154 + //The method addWork will retrieve the PUTCODE
  155 + String newPutCode = orcidClient.addWork(orcidToken2, newWork);
  156 + System.out.println("New item with PUTCODE: " + newPutCode);
  157 +
  158 + } catch (OrcidClientException e) {
  159 + // TODO Auto-generated catch block
  160 + e.printStackTrace();
  161 + }
83 162  
84 163  
85   -
86   -#License
87   -See [LICENSE.md](https://github.com/ORCID/ORCID-Work-in-Progress/blob/master/LICENSE.md)
  164 +# License
  165 +Please contact us.
88 166 \ No newline at end of file
... ...