Skip to content

Commit 195a256

Browse files
authored
Add interstitial flag logic (#7263)
* add interstitial flag liquibase change * add interstitial flag manager and dao * more interstitial flag logic and config * add orcid index to profile interstitial flag * do not update last modified and indexing status
1 parent 38bd03d commit 195a256

File tree

13 files changed

+290
-14
lines changed

13 files changed

+290
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.orcid.core.manager.v3;
2+
3+
import org.orcid.core.manager.v3.read_only.ProfileInterstitialFlagManagerReadOnly;
4+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
5+
6+
/**
7+
*
8+
* @author Andrej Romanov
9+
*
10+
*/
11+
public interface ProfileInterstitialFlagManager extends ProfileInterstitialFlagManagerReadOnly {
12+
ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.orcid.core.manager.v3.impl;
2+
3+
import org.orcid.core.manager.v3.ProfileInterstitialFlagManager;
4+
import org.orcid.core.manager.v3.read_only.impl.ProfileInterstitialFlagManagerReadOnlyImpl;
5+
import org.orcid.persistence.dao.ProfileInterstitialFlagDao;
6+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
7+
import org.springframework.transaction.annotation.Transactional;
8+
9+
import javax.annotation.Resource;
10+
11+
/**
12+
*
13+
* @author Andrej Romanov
14+
*
15+
*/
16+
public class ProfileInterstitialFlagManagerImpl extends ProfileInterstitialFlagManagerReadOnlyImpl implements ProfileInterstitialFlagManager {
17+
@Resource
18+
protected ProfileInterstitialFlagDao profileInterstitialFlagDao;
19+
20+
@Transactional
21+
public ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName) {
22+
if (orcid == null || orcid.isBlank()) {
23+
throw new IllegalArgumentException("ORCID must not be empty");
24+
}
25+
if (interstitialName == null || interstitialName.isBlank()) {
26+
throw new IllegalArgumentException("Interstitial flag must not be empty");
27+
}
28+
return profileInterstitialFlagDao.addInterstitialFlag(orcid, interstitialName);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.orcid.core.manager.v3.read_only;
2+
3+
/**
4+
*
5+
* @author Andrej Romanov
6+
*
7+
*/
8+
public interface ProfileInterstitialFlagManagerReadOnly {
9+
boolean hasInterstitialFlag(String orcid, String interstitialName);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.orcid.core.manager.v3.read_only.impl;
2+
3+
4+
import org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl;
5+
import org.orcid.core.manager.v3.read_only.ProfileInterstitialFlagManagerReadOnly;
6+
import org.orcid.persistence.dao.ProfileInterstitialFlagDao;
7+
8+
import javax.annotation.Resource;
9+
import java.util.List;
10+
11+
/**
12+
*
13+
* @author Andrej Romanov
14+
*
15+
*/
16+
public class ProfileInterstitialFlagManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements ProfileInterstitialFlagManagerReadOnly {
17+
@Resource
18+
protected ProfileInterstitialFlagDao profileInterstitialFlagDaoReadOnly;
19+
20+
public void setProfileInterstitialFlagDao(ProfileInterstitialFlagDao profileInterstitialFlagDaoReadOnly) {
21+
this.profileInterstitialFlagDaoReadOnly = profileInterstitialFlagDaoReadOnly;
22+
}
23+
24+
public boolean hasInterstitialFlag(String orcid, String interstitialName) {
25+
return profileInterstitialFlagDaoReadOnly.hasInterstitialFlag(orcid, interstitialName);
26+
};
27+
}

orcid-core/src/main/resources/orcid-core-context.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
</bean>
505505

506506
<bean id="profileEmailDomainManager" class="org.orcid.core.manager.v3.impl.ProfileEmailDomainManagerImpl">
507-
<property name="profileEmailDomainDao" ref="profileEmailDomainDaoReadOnly" />
507+
<property name="profileEmailDomainDao" ref="profileEmailDomainDao" />
508508
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
509509
</bean>
510510

@@ -513,6 +513,16 @@
513513
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
514514
</bean>
515515

516+
<bean id="profileInterstitialFlagManager" class="org.orcid.core.manager.v3.impl.ProfileInterstitialFlagManagerImpl">
517+
<property name="profileInterstitialFlagDao" ref="profileInterstitialFlagDao" />
518+
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
519+
</bean>
520+
521+
<bean id="profileInterstitialFlagManagerReadOnly" class="org.orcid.core.manager.v3.read_only.impl.ProfileInterstitialFlagManagerReadOnlyImpl">
522+
<property name="profileInterstitialFlagDao" ref="profileInterstitialFlagDaoReadOnly" />
523+
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
524+
</bean>
525+
516526
<bean id="externalIdentifierManagerV3" class="org.orcid.core.manager.v3.impl.ExternalIdentifierManagerImpl">
517527
<property name="externalIdentifierDao" ref="externalIdentifierDao" />
518528
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspect" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.orcid.persistence.dao;
2+
3+
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity;
4+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
5+
6+
import java.util.List;
7+
8+
public interface ProfileInterstitialFlagDao extends GenericDao<ProfileInterstitialFlagEntity, Long> {
9+
ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName);
10+
11+
boolean hasInterstitialFlag(String orcid, String interstitialName);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.orcid.persistence.dao.impl;
2+
3+
import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus;
4+
import org.orcid.persistence.dao.ProfileInterstitialFlagDao;
5+
import org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity;
6+
import org.springframework.transaction.annotation.Transactional;
7+
8+
import javax.persistence.Query;
9+
import java.math.BigInteger;
10+
11+
public class ProfileInterstitialFlagDaoImpl extends GenericDaoImpl<ProfileInterstitialFlagEntity, Long> implements ProfileInterstitialFlagDao {
12+
13+
public ProfileInterstitialFlagDaoImpl() {
14+
super(ProfileInterstitialFlagEntity.class);
15+
}
16+
17+
@Override
18+
@Transactional
19+
public ProfileInterstitialFlagEntity addInterstitialFlag(String orcid, String interstitialName) {
20+
ProfileInterstitialFlagEntity e = new ProfileInterstitialFlagEntity();
21+
e.setInterstitialName(interstitialName);
22+
e.setOrcid(orcid);
23+
entityManager.persist(e);
24+
return e;
25+
}
26+
27+
@Override
28+
public boolean hasInterstitialFlag(String orcid, String interstitialName) {
29+
Query query = entityManager.createNativeQuery("select count(*) from profile_interstitial_flag where orcid = :orcid and interstitial_name = :interstitialName");
30+
query.setParameter("orcid", orcid);
31+
query.setParameter("interstitialName", interstitialName);
32+
long result = ((BigInteger)query.getSingleResult()).longValue();
33+
return result > 0;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.orcid.persistence.jpa.entities;
2+
3+
import javax.persistence.*;
4+
import java.util.Objects;
5+
6+
/**
7+
*
8+
* @author Andrej Romanov
9+
*
10+
*/
11+
@Entity
12+
@Table(name = "profile_interstitial_flag")
13+
public class ProfileInterstitialFlagEntity extends BaseEntity<Long> {
14+
private static final long serialVersionUID = 1L;
15+
private Long id;
16+
private String orcid;
17+
private String interstitialName;
18+
19+
@Id
20+
@Column(name = "id")
21+
@GeneratedValue(strategy = GenerationType.AUTO, generator = "profile_interstitial_flag_seq")
22+
@SequenceGenerator(name = "profile_interstitial_flag_seq", sequenceName = "profile_interstitial_flag_seq", allocationSize = 1)
23+
public Long getId() {
24+
return id;
25+
}
26+
27+
public void setId(Long id) {
28+
this.id = id;
29+
}
30+
31+
@Column(name = "orcid")
32+
public String getOrcid() {
33+
return orcid;
34+
}
35+
36+
public void setOrcid(String orcid) {
37+
this.orcid = orcid;
38+
}
39+
40+
@Column(name = "interstitial_name")
41+
public String getInterstitialName() {
42+
return interstitialName;
43+
}
44+
45+
public void setInterstitialName(String interstitialName) {
46+
this.interstitialName = interstitialName;
47+
}
48+
49+
@Override
50+
public boolean equals(Object obj) {
51+
if (this == obj)
52+
return true;
53+
if (obj == null)
54+
return false;
55+
if (getClass() != obj.getClass())
56+
return false;
57+
ProfileInterstitialFlagEntity other = (ProfileInterstitialFlagEntity) obj;
58+
return Objects.equals(interstitialName, other.interstitialName) && Objects.equals(orcid, other.orcid);
59+
}
60+
61+
}

orcid-persistence/src/main/resources/META-INF/persistence.xml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<class>org.orcid.persistence.jpa.entities.EventStatsEntity</class>
6565
<class>org.orcid.persistence.jpa.entities.EmailDomainEntity</class>
6666
<class>org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity</class>
67+
<class>org.orcid.persistence.jpa.entities.ProfileInterstitialFlagEntity</class>
6768

6869
<!-- OAuth entities -->
6970
<class>org.orcid.persistence.jpa.entities.ClientDetailsEntity</class>

orcid-persistence/src/main/resources/db-master.xml

+1
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,5 @@
410410
<include file="/db/updates/add_generated_by_script_column_to_profile_email_domain.xml" />
411411
<include file="/db/updates/oauth2_authoriziation_code_detail_improvements.xml" />
412412
<include file="/db/updates/dw_profile_info_for_spam_check.xml" />
413+
<include file="/db/updates/create_profile_interstitial_flag.xml" />
413414
</databaseChangeLog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
4+
5+
<changeSet id="CREATE-PROFILE-INTERSTITIAL-FLAG-TABLE" author="Andrej Romanov">
6+
<preConditions onFail="MARK_RAN">
7+
<not>
8+
<tableExists tableName="profile_interstitial_flag" />
9+
</not>
10+
</preConditions>
11+
<createTable tableName="profile_interstitial_flag">
12+
<column name="id" type="bigint">
13+
<constraints nullable="false" primaryKey="true"
14+
primaryKeyName="profile_interstitial_flag_pkey" />
15+
</column>
16+
<column name="orcid" type="VARCHAR(255)">
17+
<constraints nullable="false" />
18+
</column>
19+
<column name="interstitial_name" type="VARCHAR(255)" />
20+
<column name="date_created" type="TIMESTAMP WITH TIME ZONE" />
21+
<column name="last_modified" type="TIMESTAMP WITH TIME ZONE" />
22+
</createTable>
23+
<addForeignKeyConstraint constraintName="profile_interstitial_flag_fk" baseTableName="profile_interstitial_flag" baseColumnNames="orcid" referencedTableName="profile" referencedColumnNames="orcid" />
24+
</changeSet>
25+
26+
<changeSet id="CREATE-PROFILE-INTERSTITIAL-FLAG-SEQUENCES" author="Andrej Romanov" dbms="postgresql">
27+
<preConditions onFail="MARK_RAN">
28+
<not>
29+
<sequenceExists sequenceName="profile_interstitial_flag_seq"/>
30+
</not>
31+
</preConditions>
32+
<createSequence sequenceName="profile_interstitial_flag_seq" startValue="1000" />
33+
</changeSet>
34+
35+
<changeSet id="CREATE-PROFILE-INTERSTITIAL-FLAG-AUTOCOLS" author="Andrej Romanov" dbms="hsqldb">
36+
<addAutoIncrement tableName="profile_interstitial_flag" columnName="id" columnDataType="bigint"/>
37+
</changeSet>
38+
39+
<changeSet id="PROFILE-INTERSTITIAL-FLAG-ORCID-INDEX" author="Andrej Romanov">
40+
<preConditions onFail="MARK_RAN">
41+
<not>
42+
<indexExists indexName="profile_interstitial_flag_orcid_index" tableName="profile_interstitial_flag" />
43+
</not>
44+
</preConditions>
45+
<sql>create index profile_interstitial_flag_orcid_index on profile_interstitial_flag(orcid);</sql>
46+
</changeSet>
47+
48+
<changeSet id="GRANT-READ-PERMISSIONS-TO-ORCIDRO-ON-PROFILE-INTERSTITIAL-FLAG" author="Andrej Romanov" dbms="postgresql">
49+
<preConditions>
50+
<sqlCheck expectedResult="1">SELECT 1 FROM pg_roles WHERE rolname='orcidro'</sqlCheck>
51+
</preConditions>
52+
<sql>GRANT SELECT ON profile_interstitial_flag to orcidro;</sql>
53+
</changeSet>
54+
55+
<changeSet id="ADD-ORCID-INDEX-ON-PROFILE-INTERSTITIAL-FLAG" author="Andrej Romanov">
56+
<preConditions onFail="MARK_RAN">
57+
<not>
58+
<indexExists indexName="profile_interstitial_flag_orcid_index" tableName="profile_interstitial_flag" />
59+
</not>
60+
</preConditions>
61+
<sql>create index profile_interstitial_flag_orcid_index on profile_interstitial_flag(orcid);</sql>
62+
</changeSet>
63+
</databaseChangeLog>

orcid-persistence/src/main/resources/orcid-persistence-context.xml

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
<property name="entityManager" ref="entityManagerReadOnly" />
9090
</bean>
9191

92+
<bean id="profileInterstitialFlagDao" class="org.orcid.persistence.dao.impl.ProfileInterstitialFlagDaoImpl" />
93+
94+
<bean id="profileInterstitialFlagDaoReadOnly" class="org.orcid.persistence.dao.impl.ProfileInterstitialFlagDaoImpl">
95+
<property name="entityManager" ref="entityManagerReadOnly" />
96+
</bean>
97+
9298
<bean id="researcherUrlDao" class="org.orcid.persistence.dao.impl.ResearcherUrlDaoImpl" />
9399

94100
<bean id="researcherUrlDaoReadOnly" class="org.orcid.persistence.dao.impl.ResearcherUrlDaoImpl">

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

+20-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.codehaus.jettison.json.JSONException;
2020
import org.codehaus.jettison.json.JSONObject;
2121
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
22-
import org.orcid.core.adapter.impl.MapperFacadeFactory;
2322
import org.orcid.core.constants.EmailConstants;
2423
import org.orcid.core.manager.AdminManager;
2524
import org.orcid.core.manager.EncryptionManager;
@@ -28,11 +27,7 @@
2827
import org.orcid.core.manager.TwoFactorAuthenticationManager;
2928
import org.orcid.core.manager.UserConnectionManager;
3029
import org.orcid.core.manager.v3.*;
31-
import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly;
32-
import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly;
33-
import org.orcid.core.manager.v3.read_only.GivenPermissionToManagerReadOnly;
34-
import org.orcid.core.manager.v3.read_only.ProfileEntityManagerReadOnly;
35-
import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly;
30+
import org.orcid.core.manager.v3.read_only.*;
3631
import org.orcid.core.togglz.Features;
3732
import org.orcid.core.utils.JsonUtils;
3833
import org.orcid.core.utils.v3.OrcidIdentifierUtils;
@@ -43,10 +38,7 @@
4338
import org.orcid.jaxb.model.v3.release.record.Biography;
4439
import org.orcid.jaxb.model.v3.release.record.Emails;
4540
import org.orcid.jaxb.model.v3.release.record.Name;
46-
import org.orcid.persistence.jpa.entities.EmailEntity;
47-
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity;
48-
import org.orcid.persistence.jpa.entities.ProfileEntity;
49-
import org.orcid.persistence.jpa.entities.UserconnectionEntity;
41+
import org.orcid.persistence.jpa.entities.*;
5042
import org.orcid.pojo.AddEmail;
5143
import org.orcid.pojo.ApplicationSummary;
5244
import org.orcid.pojo.ChangePassword;
@@ -58,8 +50,6 @@
5850
import org.orcid.pojo.ajaxForm.*;
5951
import org.orcid.utils.OrcidStringUtils;
6052
import org.orcid.utils.alerting.SlackManager;
61-
import org.springframework.beans.factory.annotation.Autowired;
62-
import org.springframework.beans.factory.annotation.Qualifier;
6353
import org.springframework.stereotype.Controller;
6454
import org.springframework.validation.MapBindingResult;
6555
import org.springframework.validation.ObjectError;
@@ -70,7 +60,6 @@
7060
import org.springframework.web.bind.annotation.RequestParam;
7161
import org.springframework.web.bind.annotation.ResponseBody;
7262
import org.springframework.web.servlet.ModelAndView;
73-
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
7463

7564
/**
7665
* @author Declan Newman (declan) Date: 22/02/2012
@@ -139,6 +128,12 @@ public class ManageProfileController extends BaseWorkspaceController {
139128
@Resource(name = "notificationManagerV3")
140129
private NotificationManager notificationManager;
141130

131+
@Resource(name = "profileInterstitialFlagManagerReadOnly")
132+
private ProfileInterstitialFlagManagerReadOnly profileInterstitialFlagManagerReadOnly;
133+
134+
@Resource(name = "profileInterstitialFlagManager")
135+
private ProfileInterstitialFlagManager profileInterstitialFlagManager;
136+
142137
@RequestMapping
143138
public ModelAndView manageProfile() {
144139
return new ModelAndView("manage");
@@ -1061,4 +1056,16 @@ private void verifyPrimaryEmailIfNeeded(String orcid) {
10611056
public @ResponseBody EmailFrequencyOptions getEmailFrequencyOptions() {
10621057
return emailManagerReadOnly.getEmailFrequencyOptions();
10631058
}
1059+
1060+
@RequestMapping(value = "/hasInterstitialFlag/{interstitialName}")
1061+
public @ResponseBody Boolean hasInterstitialFlag(@PathVariable("interstitialName") String interstitialName) {
1062+
String orcid = getCurrentUserOrcid();
1063+
return profileInterstitialFlagManagerReadOnly.hasInterstitialFlag(orcid, interstitialName);
1064+
}
1065+
1066+
@RequestMapping(value = "/addInterstitialFlag", method = RequestMethod.POST)
1067+
public @ResponseBody ProfileInterstitialFlagEntity addInterstitialFlag(@RequestBody String interstitialName) {
1068+
String orcid = getCurrentUserOrcid();
1069+
return profileInterstitialFlagManager.addInterstitialFlag(orcid, interstitialName);
1070+
}
10641071
}

0 commit comments

Comments
 (0)