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

Remove orcid, redirect_url, public_page and last_modified from event #6930

Merged
merged 2 commits into from
Nov 14, 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
@@ -1,19 +1,16 @@
package org.orcid.core.common.manager;

import org.orcid.core.utils.EventType;
import org.orcid.pojo.ajaxForm.RequestInfoForm;

import javax.servlet.http.HttpServletRequest;

import org.orcid.core.utils.EventType;

/**
*
* @author Daniel Palafox
*
*/
public interface EventManager {

boolean removeEvents(String orcid);

void createEvent(String orcid, EventType eventType, HttpServletRequest request);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.orcid.core.common.manager.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

Expand All @@ -17,10 +22,6 @@
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.orcid.pojo.ajaxForm.RequestInfoForm;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
*
* @author Daniel Palafox
Expand All @@ -35,18 +36,12 @@ public class EventManagerImpl implements EventManager {
private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;

@Resource(name = "recordNameManagerReadOnlyV3")
private RecordNameManagerReadOnly recordNameManagerReadOnly;

@Override
public boolean removeEvents(String orcid) {
return eventDao.removeEvents(orcid);
}
private RecordNameManagerReadOnly recordNameManagerReadOnly;

@Override
public void createEvent(String orcid, EventType eventType, HttpServletRequest request) {
String label = "Website";
String clientId = null;
String redirectUrl = null;
String publicPage = null;

if (eventType == EventType.PUBLIC_PAGE) {
Expand All @@ -58,12 +53,10 @@ public void createEvent(String orcid, EventType eventType, HttpServletRequest re
RequestInfoForm requestInfoForm = (RequestInfoForm) request.getSession().getAttribute("requestInfoForm");
if (requestInfoForm != null) {
clientId = requestInfoForm.getClientId();
redirectUrl = removeAttributesFromUrl(requestInfoForm.getRedirectUrl());
label = "OAuth " + requestInfoForm.getMemberName() + " " + requestInfoForm.getClientName();
} else if (isOauth2ScreensRequest != null && isOauth2ScreensRequest) {
String queryString = (String) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_QUERY_STRING);
clientId = getParameterValue(queryString, "client_id");
redirectUrl = getParameterValue(queryString, "redirect_uri");
ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(clientId);
String memberName = "";
String clientName = clientDetailsEntity.getClientName();
Expand All @@ -87,13 +80,10 @@ public void createEvent(String orcid, EventType eventType, HttpServletRequest re

EventEntity eventEntity = new EventEntity();

eventEntity.setOrcid(orcid);
eventEntity.setEventType(eventType.getValue());
eventEntity.setClientId(clientId);
eventEntity.setRedirectUrl(redirectUrl);
eventEntity.setLabel(label);
eventEntity.setPublicPage(publicPage);

eventEntity.setDateCreated(new Date());
eventDao.createEvent(eventEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import org.orcid.persistence.jpa.entities.EventEntity;

import java.util.List;

/**
*
* @author Daniel Palafox
*
*/
public interface EventDao extends GenericDao<EventEntity, Long>{

boolean removeEvents(String orcid);

List<EventEntity> getEvents(String orcid);
public interface EventDao {

void createEvent(EventEntity eventEntity);

EventEntity find(long id);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package org.orcid.persistence.dao.impl;

import org.orcid.persistence.aop.UpdateProfileLastModified;
import javax.annotation.Resource;
import javax.persistence.EntityManager;

import org.orcid.persistence.dao.EventDao;
import org.orcid.persistence.jpa.entities.EmailEntity;
import org.orcid.persistence.jpa.entities.EventEntity;
import org.orcid.persistence.jpa.entities.SpamEntity;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.List;

/**
* @author Daniel Palafox
*/
public class EventDaoImpl extends GenericDaoImpl<EventEntity, Long> implements EventDao {
public class EventDaoImpl implements EventDao {

@Resource(name="entityManager")
protected EntityManager entityManager;

public EventDaoImpl() {
super(EventEntity.class);
}

@Override
public List<EventEntity> getEvents(String orcid) {
TypedQuery<EventEntity> query = entityManager.createQuery("from EventEntity where orcid=:orcid", EventEntity.class);
query.setParameter("orcid", orcid);
List<EventEntity> results = query.getResultList();
return results.isEmpty() ? null : results;
}

}

@Override
@Transactional
Expand All @@ -35,11 +26,8 @@ public void createEvent(EventEntity eventEntity) {
}

@Override
@Transactional
public boolean removeEvents(String orcid) {
Query query = entityManager.createQuery("delete from EventEntity where orcid = :orcid");
query.setParameter("orcid", orcid);
query.executeUpdate();
return query.executeUpdate() > 0;
public EventEntity find(long id) {
return entityManager.find(EventEntity.class, id);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.orcid.persistence.jpa.entities;

import java.util.Date;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -15,15 +18,13 @@
*/
@Entity
@Table(name = "event")
public class EventEntity extends BaseEntity<Long> implements OrcidAware {
public class EventEntity {
private static final long serialVersionUID = 1L;
private Long id;
private String orcid;
private String eventType;
private String clientId;
private String redirectUrl;
private String eventType;
private String label;
private String publicPage;
private Date dateCreated;

@Id
@Column(name = "id")
Expand All @@ -37,37 +38,58 @@ public void setId(Long id) {
this.id = id;
}

@Column(name = "orcid")
public String getOrcid() {
return orcid;
@Column(name = "event_type")
public String getEventType() {
return eventType;
}

public void setOrcid(String orcid) {
this.orcid = orcid;
public void setEventType(String eventType) {
this.eventType = eventType;
}

@Column(name = "event_type")
public String getEventType() { return eventType; }

public void setEventType(String eventType) { this.eventType = eventType; }

@Column(name = "client_id")
public String getClientId() { return clientId; }
public String getClientId() {
return clientId;
}

public void setClientId(String client_id) {
this.clientId = client_id;
}

public void setClientId(String client_id) { this.clientId = client_id; }
@Column(name = "label")
public String getLabel() {
return label;
}

@Column(name = "redirect_url")
public String getRedirectUrl() { return redirectUrl; }
public void setLabel(String label) {
this.label = label;
}

public void setRedirectUrl(String redirect_url) { this.redirectUrl = redirect_url; }
@Column(name = "date_created")
public Date getDateCreated() {
return dateCreated;
}

@Column(name = "label")
public String getLabel() { return label; }
public void setDateCreated(Date date) {
this.dateCreated = date;
}

public void setLabel(String label) { this.label = label; }
@Override
public int hashCode() {
return Objects.hash(clientId, dateCreated, eventType, id, label);
}

@Column(name = "public_page")
public String getPublicPage() { return publicPage; }
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EventEntity other = (EventEntity) obj;
return Objects.equals(clientId, other.clientId) && Objects.equals(dateCreated, other.dateCreated) && Objects.equals(eventType, other.eventType)
&& Objects.equals(id, other.id) && Objects.equals(label, other.label);
}

public void setPublicPage(String public_page) { this.publicPage = public_page; }
}
1 change: 1 addition & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,5 @@
<include file="/db/updates/dw_event.xml" />
<include file="/db/updates/create_event_indexes.xml" />
<include file="/db/updates/dw_alter_event.xml" />
<include file="/db/updates/dw_alter_event_2.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet id="DROP-ORCID-INDEX-ON-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<indexExists indexName="event_orcid_index" tableName="event"/>
</preConditions>
<dropIndex tableName="event" indexName="event_orcid_index"/>
</changeSet>

<changeSet id="DROP-ORCID-FK-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<foreignKeyConstraintExists foreignKeyTableName="event" foreignKeyName="event_orcid_fk"/>
</preConditions>
<dropForeignKeyConstraint baseTableName="event" constraintName="event_orcid_fk"/>
</changeSet>

<changeSet id="ALTER-DW-EVENT-VIEW-GROUP-BY-DAY-CLIENT_ID-AND-EVENT_TYPE" author="Angel Montenegro" dbms="postgresql">
<dropView viewName="dw_event"/>

<createView viewName="dw_event">
SELECT event_type, client_id, COUNT(id), DATE_TRUNC('day', date_created), DATE_TRUNC('day', date_created) as last_modified
FROM event
GROUP BY event_type, client_id, DATE_TRUNC('day', date_created)
ORDER BY DATE_TRUNC('day', date_created) DESC;
</createView>
</changeSet>

<changeSet id="DROP-VIEW-FOR-PUBLIC-PAGE" author="Angel Montenegro" dbms="postgresql">
<dropView viewName="dw_event_public_page"/>
</changeSet>

<changeSet id="DROP-ORCID-FROM-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<columnExists tableName="event" columnName="orcid"/>
</preConditions>
<dropColumn tableName="event" columnName="orcid"/>
</changeSet>

<changeSet id="DROP-REDIRECT-URL-FROM-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<columnExists tableName="event" columnName="redirect_url"/>
</preConditions>
<dropColumn tableName="event" columnName="redirect_url"/>
</changeSet>

<changeSet id="DROP-PUBLIC-PAGE-FROM-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<columnExists tableName="event" columnName="public_page"/>
</preConditions>
<dropColumn tableName="event" columnName="public_page"/>
</changeSet>

<changeSet id="DROP-LAST-MODIFIED-FROM-EVENT" author="Angel Montenegro">
<preConditions onFail="MARK_RAN">
<columnExists tableName="event" columnName="last_modified"/>
</preConditions>
<dropColumn tableName="event" columnName="last_modified"/>
</changeSet>

</databaseChangeLog>
Loading
Loading