Skip to content

Commit

Permalink
Merge pull request #6812 from ORCID/8660-prod-refactor-the-trusted-or…
Browse files Browse the repository at this point in the history
…gs-endpoint

feature: Refactor `get-trusted-orgs.json` endpoint and remove unneces…
  • Loading branch information
amontenegro authored Jun 12, 2023
2 parents 0d00874 + d862dd5 commit 05f0cde
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,27 +344,17 @@ private void addApplicationToMap(OrcidOauth2TokenDetail token, Map<String, Appli
applicationSummary = new ApplicationSummary();
distinctApplications.put(client.getId(), applicationSummary);
applicationSummary.setScopePaths(new HashMap<String, String>());
applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
applicationSummary.setOrcidUri(orcidUrlManager.getBaseUrl() + "/" + client.getId());
applicationSummary.setOrcidPath(client.getId());
applicationSummary.setName(client.getClientName());
applicationSummary.setWebsiteValue(client.getClientWebsite());
applicationSummary.setApprovalDate(token.getDateCreated());
applicationSummary.setTokenId(String.valueOf(token.getId()));

if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
applicationSummary.setGroupOrcidPath(member.getId());
applicationSummary.setGroupName(getMemberDisplayName(member));
}
}

Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
String scopeFullPath = ScopePathType.class.getName() + ".";
for (ScopePathType tempScope : scopesGrantedToClient) {
try {
String label = localeManager.resolveMessage(scopeFullPath + tempScope.toString());
applicationSummary.getScopePaths().put(label, label);
applicationSummary.getScopePaths().put(tempScope.toString(), label);
} catch (NoSuchMessageException e) {
LOGGER.warn("No message to display for scope " + tempScope.toString());
}
Expand Down
79 changes: 0 additions & 79 deletions orcid-core/src/main/java/org/orcid/pojo/ApplicationSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,14 @@

public class ApplicationSummary {

private String orcidUri;

private String orcidPath;

private String orcidHost;

private String name;

private String groupOrcidUri;

private String groupOrcidPath;

private String groupOrcidHost;

private String groupName;

private String websiteValue;

private Date approvalDate;

private Map<String, String> scopePaths;

private String tokenId;

public String getOrcidUri() {
return orcidUri;
}

public void setOrcidUri(String orcidUri) {
this.orcidUri = orcidUri;
}

public String getOrcidPath() {
return orcidPath;
}

public void setOrcidPath(String orcidPath) {
this.orcidPath = orcidPath;
}

public String getOrcidHost() {
return orcidHost;
}

public void setOrcidHost(String orcidHost) {
this.orcidHost = orcidHost;
}

public String getName() {
return name;
}
Expand All @@ -61,38 +21,6 @@ public void setName(String name) {
this.name = name;
}

public String getGroupOrcidUri() {
return groupOrcidUri;
}

public void setGroupOrcidUri(String groupOrcidUri) {
this.groupOrcidUri = groupOrcidUri;
}

public String getGroupOrcidPath() {
return groupOrcidPath;
}

public void setGroupOrcidPath(String groupOrcidPath) {
this.groupOrcidPath = groupOrcidPath;
}

public String getGroupOrcidHost() {
return groupOrcidHost;
}

public void setGroupOrcidHost(String groupOrcidHost) {
this.groupOrcidHost = groupOrcidHost;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

public String getWebsiteValue() {
return websiteValue;
}
Expand All @@ -117,11 +45,4 @@ public void setScopePaths(Map<String, String> scopePaths) {
this.scopePaths = scopePaths;
}

public String getTokenId() {
return tokenId;
}

public void setTokenId(String tokenId) {
this.tokenId = tokenId;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package org.orcid.core.manager.v3.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -38,6 +26,7 @@
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
import org.orcid.core.profile.history.ProfileHistoryEventType;
import org.orcid.jaxb.model.common.AvailableLocales;
import org.orcid.jaxb.model.message.ScopePathType;
import org.orcid.jaxb.model.v3.release.common.Visibility;
import org.orcid.jaxb.model.v3.release.record.Address;
import org.orcid.jaxb.model.v3.release.record.Addresses;
Expand Down Expand Up @@ -68,6 +57,17 @@
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* @author: Declan Newman (declan) Date: 10/02/2012
*/
Expand Down Expand Up @@ -326,12 +326,17 @@ public void testGetApplications() {
List<ApplicationSummary> applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertEquals(2, applications.size());
assertEquals(4, applications.get(0).getScopePaths().keySet().size());
assertEquals(2, applications.get(1).getScopePaths().keySet().size());
assertEquals(5, applications.get(0).getScopePaths().keySet().size());
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_READ_LIMITED.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_WORKS_READ_LIMITED.toString()));

// test ordering based on name
assertEquals(CLIENT_ID_1, applications.get(0).getOrcidPath());
assertEquals(CLIENT_ID_2, applications.get(1).getOrcidPath());
assertEquals(3, applications.get(1).getScopePaths().keySet().size());
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
assertTrue(applications.get(1).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));

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

// 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)
assertEquals(3, applications.get(0).getScopePaths().keySet().size());
assertEquals(4, applications.get(0).getScopePaths().keySet().size());
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.READ_LIMITED.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ORCID_PROFILE_READ_LIMITED.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.ACTIVITIES_UPDATE.toString()));
assertTrue(applications.get(0).getScopePaths().keySet().contains(ScopePathType.PERSON_READ_LIMITED.toString()));

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

0 comments on commit 05f0cde

Please sign in to comment.