Skip to content

Commit 05f0cde

Browse files
authored
Merge pull request #6812 from ORCID/8660-prod-refactor-the-trusted-orgs-endpoint
feature: Refactor `get-trusted-orgs.json` endpoint and remove unneces…
2 parents 0d00874 + d862dd5 commit 05f0cde

File tree

3 files changed

+28
-108
lines changed

3 files changed

+28
-108
lines changed

Diff for: orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEntityManagerImpl.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -344,27 +344,17 @@ private void addApplicationToMap(OrcidOauth2TokenDetail token, Map<String, Appli
344344
applicationSummary = new ApplicationSummary();
345345
distinctApplications.put(client.getId(), applicationSummary);
346346
applicationSummary.setScopePaths(new HashMap<String, String>());
347-
applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
348-
applicationSummary.setOrcidUri(orcidUrlManager.getBaseUrl() + "/" + client.getId());
349-
applicationSummary.setOrcidPath(client.getId());
350347
applicationSummary.setName(client.getClientName());
351348
applicationSummary.setWebsiteValue(client.getClientWebsite());
352349
applicationSummary.setApprovalDate(token.getDateCreated());
353-
applicationSummary.setTokenId(String.valueOf(token.getId()));
354-
355-
if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
356-
ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
357-
applicationSummary.setGroupOrcidPath(member.getId());
358-
applicationSummary.setGroupName(getMemberDisplayName(member));
359-
}
360350
}
361351

362352
Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
363353
String scopeFullPath = ScopePathType.class.getName() + ".";
364354
for (ScopePathType tempScope : scopesGrantedToClient) {
365355
try {
366356
String label = localeManager.resolveMessage(scopeFullPath + tempScope.toString());
367-
applicationSummary.getScopePaths().put(label, label);
357+
applicationSummary.getScopePaths().put(tempScope.toString(), label);
368358
} catch (NoSuchMessageException e) {
369359
LOGGER.warn("No message to display for scope " + tempScope.toString());
370360
}

Diff for: orcid-core/src/main/java/org/orcid/pojo/ApplicationSummary.java

-79
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,14 @@
55

66
public class ApplicationSummary {
77

8-
private String orcidUri;
9-
10-
private String orcidPath;
11-
12-
private String orcidHost;
13-
148
private String name;
159

16-
private String groupOrcidUri;
17-
18-
private String groupOrcidPath;
19-
20-
private String groupOrcidHost;
21-
22-
private String groupName;
23-
2410
private String websiteValue;
2511

2612
private Date approvalDate;
2713

2814
private Map<String, String> scopePaths;
2915

30-
private String tokenId;
31-
32-
public String getOrcidUri() {
33-
return orcidUri;
34-
}
35-
36-
public void setOrcidUri(String orcidUri) {
37-
this.orcidUri = orcidUri;
38-
}
39-
40-
public String getOrcidPath() {
41-
return orcidPath;
42-
}
43-
44-
public void setOrcidPath(String orcidPath) {
45-
this.orcidPath = orcidPath;
46-
}
47-
48-
public String getOrcidHost() {
49-
return orcidHost;
50-
}
51-
52-
public void setOrcidHost(String orcidHost) {
53-
this.orcidHost = orcidHost;
54-
}
55-
5616
public String getName() {
5717
return name;
5818
}
@@ -61,38 +21,6 @@ public void setName(String name) {
6121
this.name = name;
6222
}
6323

64-
public String getGroupOrcidUri() {
65-
return groupOrcidUri;
66-
}
67-
68-
public void setGroupOrcidUri(String groupOrcidUri) {
69-
this.groupOrcidUri = groupOrcidUri;
70-
}
71-
72-
public String getGroupOrcidPath() {
73-
return groupOrcidPath;
74-
}
75-
76-
public void setGroupOrcidPath(String groupOrcidPath) {
77-
this.groupOrcidPath = groupOrcidPath;
78-
}
79-
80-
public String getGroupOrcidHost() {
81-
return groupOrcidHost;
82-
}
83-
84-
public void setGroupOrcidHost(String groupOrcidHost) {
85-
this.groupOrcidHost = groupOrcidHost;
86-
}
87-
88-
public String getGroupName() {
89-
return groupName;
90-
}
91-
92-
public void setGroupName(String groupName) {
93-
this.groupName = groupName;
94-
}
95-
9624
public String getWebsiteValue() {
9725
return websiteValue;
9826
}
@@ -117,11 +45,4 @@ public void setScopePaths(Map<String, String> scopePaths) {
11745
this.scopePaths = scopePaths;
11846
}
11947

120-
public String getTokenId() {
121-
return tokenId;
122-
}
123-
124-
public void setTokenId(String tokenId) {
125-
this.tokenId = tokenId;
126-
}
12748
}

Diff for: orcid-core/src/test/java/org/orcid/core/manager/v3/impl/ProfileEntityManagerImplTest.java

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
package org.orcid.core.manager.v3.impl;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
5-
import static org.junit.Assert.assertNotNull;
6-
import static org.junit.Assert.assertNull;
7-
import static org.junit.Assert.assertTrue;
8-
9-
import java.util.Arrays;
10-
import java.util.Date;
11-
import java.util.List;
12-
13-
import javax.annotation.Resource;
14-
153
import org.junit.AfterClass;
164
import org.junit.Before;
175
import org.junit.BeforeClass;
@@ -38,6 +26,7 @@
3826
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
3927
import org.orcid.core.profile.history.ProfileHistoryEventType;
4028
import org.orcid.jaxb.model.common.AvailableLocales;
29+
import org.orcid.jaxb.model.message.ScopePathType;
4130
import org.orcid.jaxb.model.v3.release.common.Visibility;
4231
import org.orcid.jaxb.model.v3.release.record.Address;
4332
import org.orcid.jaxb.model.v3.release.record.Addresses;
@@ -68,6 +57,17 @@
6857
import org.springframework.test.util.ReflectionTestUtils;
6958
import org.springframework.transaction.annotation.Transactional;
7059

60+
import javax.annotation.Resource;
61+
import java.util.Arrays;
62+
import java.util.Date;
63+
import java.util.List;
64+
65+
import static org.junit.Assert.assertEquals;
66+
import static org.junit.Assert.assertFalse;
67+
import static org.junit.Assert.assertNotNull;
68+
import static org.junit.Assert.assertNull;
69+
import static org.junit.Assert.assertTrue;
70+
7171
/**
7272
* @author: Declan Newman (declan) Date: 10/02/2012
7373
*/
@@ -326,12 +326,17 @@ public void testGetApplications() {
326326
List<ApplicationSummary> applications = profileEntityManager.getApplications(USER_ORCID);
327327
assertNotNull(applications);
328328
assertEquals(2, applications.size());
329-
assertEquals(4, applications.get(0).getScopePaths().keySet().size());
330-
assertEquals(2, applications.get(1).getScopePaths().keySet().size());
329+
assertEquals(5, applications.get(0).getScopePaths().keySet().size());
330+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
331+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
332+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));
333+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_READ_LIMITED.toString()));
334+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_WORKS_READ_LIMITED.toString()));
331335

332-
// test ordering based on name
333-
assertEquals(CLIENT_ID_1, applications.get(0).getOrcidPath());
334-
assertEquals(CLIENT_ID_2, applications.get(1).getOrcidPath());
336+
assertEquals(3, applications.get(1).getScopePaths().keySet().size());
337+
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
338+
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
339+
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));
335340

336341
//Assert we can delete them
337342
profileEntityManager.disableClientAccess(CLIENT_ID_1, USER_ORCID);
@@ -364,7 +369,11 @@ public void testDontGetDuplicatedApplications() {
364369
assertEquals(1, applications.size());
365370

366371
// scopes grouped by label - Read limited information from your biography., Read your information with visibility set to Trusted Parties, Add/update your research activities (works, affiliations, etc)
367-
assertEquals(3, applications.get(0).getScopePaths().keySet().size());
372+
assertEquals(4, applications.get(0).getScopePaths().keySet().size());
373+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
374+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
375+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));
376+
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.PERSON_READ_LIMITED.toString()));
368377

369378
//Revoke them to check revoking one revokes all the ones with the same scopes
370379
profileEntityManager.disableClientAccess(CLIENT_ID_1, USER_ORCID);

0 commit comments

Comments
 (0)