Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Refactor get-trusted-orgs.json endpoint and remove unneces… #6812

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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