Skip to content

Commit 69a96fd

Browse files
Merge branch 'main' into papi_exceeded_limit_cleanup
2 parents ba65957 + c067eff commit 69a96fd

File tree

8 files changed

+118
-0
lines changed

8 files changed

+118
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.76.7 - 2025-03-27
2+
3+
[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.76.6...v2.76.7)
4+
15
## v2.76.6 - 2025-03-27
26

37
[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.76.5...v2.76.6)

orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileInterstitialFlagManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
*/
1111
public interface ProfileInterstitialFlagManager extends ProfileInterstitialFlagManagerReadOnly {
1212
ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName);
13+
1314
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.orcid.core.manager.v3.read_only;
22

3+
import java.util.List;
4+
35
/**
46
*
57
* @author Andrej Romanov
68
*
79
*/
810
public interface ProfileInterstitialFlagManagerReadOnly {
911
boolean hasInterstitialFlag(String orcid, String interstitialName);
12+
13+
List<String> findByOrcid(String orcid);
1014
}

orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileInterstitialFlagManagerReadOnlyImpl.java

+11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl;
55
import org.orcid.core.manager.v3.read_only.ProfileInterstitialFlagManagerReadOnly;
66
import org.orcid.persistence.dao.ProfileInterstitialFlagDao;
7+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
78

89
import javax.annotation.Resource;
10+
import java.util.ArrayList;
911
import java.util.List;
1012

1113
/**
@@ -24,4 +26,13 @@ public void setProfileInterstitialFlagDao(ProfileInterstitialFlagDao profileInte
2426
public boolean hasInterstitialFlag(String orcid, String interstitialName) {
2527
return profileInterstitialFlagDaoReadOnly.hasInterstitialFlag(orcid, interstitialName);
2628
};
29+
30+
public List<String> findByOrcid(String orcid) {
31+
List<ProfileInterstitialFlagEntity> entities = profileInterstitialFlagDaoReadOnly.findByOrcid(orcid);
32+
List<String> interstitialNames = new ArrayList<String>();
33+
for (ProfileInterstitialFlagEntity entity : entities) {
34+
interstitialNames.add(entity.getInterstitialName());
35+
}
36+
return interstitialNames;
37+
}
2738
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.orcid.core.manager.v3;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.mockito.Mock;
6+
import org.mockito.MockitoAnnotations;
7+
import org.orcid.core.manager.v3.impl.ProfileInterstitialFlagManagerImpl;
8+
import org.orcid.persistence.dao.ProfileInterstitialFlagDao;
9+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
10+
import org.orcid.test.TargetProxyHelper;
11+
12+
import java.util.List;
13+
14+
import static org.junit.Assert.assertEquals;
15+
import static org.mockito.ArgumentMatchers.eq;
16+
import static org.mockito.Mockito.*;
17+
18+
public class ProfileInterstitialFlagManagerTest {
19+
@Mock
20+
private ProfileInterstitialFlagDao profileInterstitialFlagDao;
21+
22+
@Mock
23+
private ProfileInterstitialFlagDao profileInterstitialFlagDaoReadOnly;
24+
25+
ProfileInterstitialFlagManager pifm = new ProfileInterstitialFlagManagerImpl();
26+
27+
28+
private static final String ORCID = "0000-0000-0000-0001";
29+
private static final String ORCID_TWO = "0000-0000-0000-0002";
30+
private static final String INTERSTITIAL_FLAG = "DOMAIN_INTERSTITIAL";
31+
private static final String INTERSTITIAL_FLAG_TWO = "AFFILIATION_INTERSTITIAL";
32+
33+
34+
@Before
35+
public void before() {
36+
MockitoAnnotations.initMocks(this);
37+
TargetProxyHelper.injectIntoProxy(pifm, "profileInterstitialFlagDao", profileInterstitialFlagDao);
38+
TargetProxyHelper.injectIntoProxy(pifm, "profileInterstitialFlagDaoReadOnly", profileInterstitialFlagDaoReadOnly);
39+
40+
ProfileInterstitialFlagEntity pif1 = new ProfileInterstitialFlagEntity();
41+
ProfileInterstitialFlagEntity pif2 = new ProfileInterstitialFlagEntity();
42+
43+
pif1.setInterstitialName(INTERSTITIAL_FLAG);
44+
pif1.setOrcid(ORCID);
45+
46+
pif2.setInterstitialName(INTERSTITIAL_FLAG_TWO);
47+
pif2.setOrcid(ORCID);
48+
49+
when(profileInterstitialFlagDaoReadOnly.findByOrcid(eq(ORCID))).thenReturn(List.of(pif1, pif2));
50+
when(profileInterstitialFlagDaoReadOnly.findByOrcid(eq(ORCID_TWO))).thenReturn(List.of(pif2));
51+
}
52+
53+
@Test(expected = IllegalArgumentException.class)
54+
public void addFlag_nullOrcid() {
55+
pifm.addInterstitialFlag(null, INTERSTITIAL_FLAG);
56+
}
57+
58+
@Test(expected = IllegalArgumentException.class)
59+
public void addFlag_nullInterstitialName() {
60+
pifm.addInterstitialFlag(ORCID, null);
61+
}
62+
63+
@Test
64+
public void addFlag_success() {
65+
pifm.addInterstitialFlag(ORCID, INTERSTITIAL_FLAG);
66+
verify(profileInterstitialFlagDao, times(1)).addInterstitialFlag(eq(ORCID), eq(INTERSTITIAL_FLAG));
67+
}
68+
69+
@Test
70+
public void findByOrcid() {
71+
List<String> flags = pifm.findByOrcid(ORCID);
72+
assertEquals(flags.size(), 2);
73+
assertEquals(flags.get(0), INTERSTITIAL_FLAG);
74+
assertEquals(flags.get(1), INTERSTITIAL_FLAG_TWO);
75+
76+
List<String> flags2 = pifm.findByOrcid(ORCID_TWO);
77+
assertEquals(flags2.size(), 1);
78+
assertEquals(flags2.get(0), INTERSTITIAL_FLAG_TWO);
79+
}
80+
}

orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileInterstitialFlagDao.java

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface ProfileInterstitialFlagDao extends GenericDao<ProfileInterstiti
99
ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName);
1010

1111
boolean hasInterstitialFlag(String orcid, String interstitialName);
12+
13+
List<ProfileInterstitialFlagEntity> findByOrcid(String orcid);
1214
}

orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileInterstitialFlagDaoImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import org.springframework.transaction.annotation.Transactional;
77

88
import javax.persistence.Query;
9+
import javax.persistence.TypedQuery;
910
import java.math.BigInteger;
11+
import java.util.List;
1012

1113
public class ProfileInterstitialFlagDaoImpl extends GenericDaoImpl<ProfileInterstitialFlagEntity, Long> implements ProfileInterstitialFlagDao {
1214

@@ -32,4 +34,12 @@ public boolean hasInterstitialFlag(String orcid, String interstitialName) {
3234
long result = ((BigInteger)query.getSingleResult()).longValue();
3335
return result > 0;
3436
}
37+
38+
@Override
39+
public List<ProfileInterstitialFlagEntity> findByOrcid(String orcid) {
40+
TypedQuery<ProfileInterstitialFlagEntity> query = entityManager.createQuery("from ProfileInterstitialFlagEntity where orcid = :orcid", ProfileInterstitialFlagEntity.class);
41+
query.setParameter("orcid", orcid);
42+
List<ProfileInterstitialFlagEntity> results = query.getResultList();
43+
return results.isEmpty() ? null : results;
44+
}
3545
}

orcid-web/src/main/java/org/orcid/frontend/web/controllers/ManageProfileController.java

+6
Original file line numberDiff line numberDiff line change
@@ -1068,4 +1068,10 @@ private void verifyPrimaryEmailIfNeeded(String orcid) {
10681068
String orcid = getCurrentUserOrcid();
10691069
return profileInterstitialFlagManager.addInterstitialFlag(orcid, interstitialName);
10701070
}
1071+
1072+
@RequestMapping(value = "/getInterstitialFlags")
1073+
public @ResponseBody List<String> getInterstitialFlags() {
1074+
String orcid = getCurrentUserOrcid();
1075+
return profileInterstitialFlagManagerReadOnly.findByOrcid(orcid);
1076+
}
10711077
}

0 commit comments

Comments
 (0)