Skip to content

Commit

Permalink
Fix code conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Apr 4, 2024
2 parents 585d8b7 + 23b6afb commit 78c6da3
Show file tree
Hide file tree
Showing 36 changed files with 723 additions and 475 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
## v2.57.2 - 2024-04-04

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.57.1...v2.57.2)

### Feature

- Start collection daily pub api stats (#7016)

## v2.57.1 - 2024-04-03

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.57.0...v2.57.1)

- [#7017](https://github.com/ORCID/ORCID-Source/pull/7017): 9181-prod-old-header-layout-displayed-briefly-on-public-page

## v2.57.0 - 2024-04-01

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.56.0...v2.57.0)

## v2.56.0 - 2024-04-01

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.55.0...v2.56.0)

## v2.55.0 - 2024-03-26

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.54.0...v2.55.0)

## v2.54.0 - 2024-03-19

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.53.0...v2.54.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import org.orcid.core.exception.OrcidDuplicatedElementException;
import org.orcid.core.exception.OrcidInvalidScopeException;
import org.orcid.core.exception.OrcidNoBioException;
import org.orcid.core.exception.OrcidNoResultException;
import org.orcid.core.exception.OrcidNonPublicElementException;
import org.orcid.core.exception.OrcidNotClaimedException;
import org.orcid.core.exception.OrcidNotificationException;
import org.orcid.core.exception.OrcidUnauthorizedException;
import org.orcid.core.exception.OrcidValidationException;
import org.orcid.core.locale.LocaleManager;
import org.orcid.core.manager.OrcidSecurityManager;
Expand Down Expand Up @@ -138,6 +140,10 @@ public Response toResponse(Throwable t) {
logShortError(t, clientId);
} else if (t instanceof TokenMgrError) {
logShortError(t, clientId);
} else if (t instanceof OrcidNoResultException) {
logShortError(t, clientId);
} else if (t instanceof OrcidUnauthorizedException) {
logShortError(t, clientId);
} else {
LOGGER.error("An exception has occured processing request from client " + clientId, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javax.servlet.http.HttpServletRequest;

import org.orcid.core.utils.EventType;
import org.orcid.persistence.jpa.entities.EventType;

/**
*
Expand All @@ -13,4 +13,6 @@ public interface EventManager {

void createEvent(EventType eventType, HttpServletRequest request);

void createPapiEvent(String clientId, String ip, boolean anonymous);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import org.orcid.core.constants.OrcidOauth2Constants;
import org.orcid.core.manager.ClientDetailsEntityCacheManager;
import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly;
import org.orcid.core.utils.EventType;
import org.orcid.jaxb.model.clientgroup.ClientType;
import org.orcid.jaxb.model.v3.release.record.Name;
import org.orcid.persistence.dao.EventDao;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.EventEntity;
import org.orcid.persistence.jpa.entities.EventType;
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.orcid.pojo.ajaxForm.RequestInfoForm;

Expand Down Expand Up @@ -105,4 +105,15 @@ private String removeAttributesFromUrl(String url) {
}
return url;
}

@Override
public void createPapiEvent(String clientId, String ip, boolean anonymous) {
EventEntity eventEntity = new EventEntity();
eventEntity.setEventType(EventType.PAPI.getValue());
eventEntity.setClientId(clientId);
eventEntity.setIp(ip);
eventEntity.setLabel(anonymous ? "anonymous" : null);
eventEntity.setDateCreated(new Date());
eventDao.createEvent(eventEntity);
}
}
7 changes: 4 additions & 3 deletions orcid-core/src/main/java/org/orcid/core/togglz/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public enum Features implements Feature {
@Label("Registration 2.1: Add affiliations on registration")
REGISTRATION_2_1,

@Label("New public record header")
NEW_RECORD_HEADER,

@Label("Registration 2.0")
REGISTRATION_2_0,
Expand Down Expand Up @@ -56,7 +54,10 @@ public enum Features implements Feature {
SEND_ADD_WORKS_EMAILS,

@Label("Delete events older than 90 days from the DB ")
DELETE_EVENTS;
DELETE_EVENTS,

@Label("Track public events stats ")
PAPI_EVENTS;

public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.orcid.persistence.dao;

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

import java.util.List;

Expand All @@ -18,6 +19,10 @@ public interface EventDao {
void delete(long id);

List<EventEntity> findAll();

List<EventEntity> findByEventType(EventType eventType);

void deleteEventsByDate(Integer numberOfDays);

void deletePapiEvents(Integer numberOfDays);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.orcid.persistence.dao;

import org.orcid.persistence.jpa.entities.EventStatsEntity;
import org.orcid.persistence.jpa.entities.EventType;

import java.util.List;

Expand All @@ -13,5 +14,9 @@ public interface EventStatsDao {

void createEventStats();

void createPapiEventStats();

List<EventStatsEntity> findAll();

void deleteStatsByType(EventType eventType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

import java.util.List;
Expand Down Expand Up @@ -49,9 +50,27 @@ public List<EventEntity> findAll() {
@Override
@Transactional
public void deleteEventsByDate(Integer numberOfDays) {
String query = "DELETE FROM event where CAST(date_created as date) < CAST(now() - (CAST('1' AS INTERVAL DAY) * :numberOfDays) as date)";
String query = "DELETE FROM event where CAST(date_created as date) < CAST(now() - (CAST('1' AS INTERVAL DAY) * :numberOfDays) as date) AND event_type != :eventType";
Query queryDelete = entityManager.createNativeQuery(query);
queryDelete.setParameter("eventType", EventType.PAPI.getValue());
queryDelete.setParameter("numberOfDays", numberOfDays);
queryDelete.executeUpdate();
}

@Override
@Transactional
public void deletePapiEvents(Integer numberOfDays) {
String query = "DELETE FROM event where CAST(date_created as date) < CAST(now() - (CAST('1' AS INTERVAL DAY) * :numberOfDays) as date) AND event_type = :eventType";
Query queryDelete = entityManager.createNativeQuery(query);
queryDelete.setParameter("eventType", EventType.PAPI.getValue());
queryDelete.setParameter("numberOfDays", numberOfDays);
queryDelete.executeUpdate();
}

@Override
public List<EventEntity> findByEventType(EventType eventType) {
TypedQuery<EventEntity> query = entityManager.createQuery("from EventEntity where eventType = :eventType", EventEntity.class);
query.setParameter("eventType", eventType.getValue());
return query.getResultList();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.orcid.persistence.dao.impl;

import org.orcid.persistence.dao.EventStatsDao;
import org.orcid.persistence.jpa.entities.EventType;
import org.orcid.persistence.jpa.entities.EventStatsEntity;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -25,9 +29,11 @@ public void createEventStats() {
"INSERT INTO event_stats (event_type, client_id, count, date, date_created, last_modified) " +
"SELECT event_type, client_id, COUNT(id), CAST(e.date_created as date), now(), now() " +
"FROM event as e " +
"WHERE CAST(e.date_created as date) = CAST(now() - (CAST('1' AS INTERVAL DAY) * 1) as date) " +
"WHERE event_type != '"+ EventType.PAPI.getValue() + "' " +
"AND CAST(e.date_created as date) = CAST(now() - (CAST('1' AS INTERVAL DAY) * 1) as date) " +
"GROUP BY event_type, client_id, CAST(e.date_created as date) " +
"ORDER BY CAST(e.date_created as date) DESC;";

Query insertQuery = entityManager.createNativeQuery(query);
insertQuery.executeUpdate();
}
Expand All @@ -37,4 +43,49 @@ public List<EventStatsEntity> findAll() {
TypedQuery<EventStatsEntity> query = entityManager.createQuery("from EventStatsEntity", EventStatsEntity.class);
return query.getResultList();
}

@Override
@Transactional
public void createPapiEventStats() {
String query =
"SELECT event_type, client_id, ip, label, count(*), CAST(date_created as date), now(), now() " +
"FROM event " +
"WHERE event_type = '"+ EventType.PAPI.getValue() + "' " +
"AND CAST(date_created as date) = CAST(now() - (CAST('1' AS INTERVAL DAY) * 1) as date) " +
"GROUP BY event_type, client_id, ip, label, CAST(date_created as date) " +
"ORDER BY CAST(date_created as date) DESC;";

Query queryList = entityManager.createNativeQuery(query);
List<Object[]> eventsList = queryList.getResultList();
List<Object[]> eventsListToRemove = new ArrayList<>();
if (eventsList.size() > 0) {
eventsList.forEach(item -> {
if (item[3] == "anonymous" && item[4] != null && ((BigInteger) item[4]).intValue() < 1000) {
eventsListToRemove.add(item);
}
});
eventsList.removeAll(eventsListToRemove);
eventsList.forEach(item -> {
String insertQuery = "INSERT INTO event_stats (event_type, client_id, ip, count, date, date_created, last_modified) VALUES (:eventType, :clientId, :ip, :count, :date, :dateCreated, :lastModified)";
Query insertQueryClients = entityManager.createNativeQuery(insertQuery);
insertQueryClients.setParameter("eventType", item[0]);
insertQueryClients.setParameter("clientId", item[1]);
insertQueryClients.setParameter("ip", item[2]);
insertQueryClients.setParameter("count", item[4]);
insertQueryClients.setParameter("date", item[5]);
insertQueryClients.setParameter("dateCreated", item[6]);
insertQueryClients.setParameter("lastModified", item[7]);
insertQueryClients.executeUpdate();
});
}
}

@Override
@Transactional
public void deleteStatsByType(EventType eventType) {
String query = "DELETE FROM event_stats where event_type = :eventType";
Query queryDelete = entityManager.createNativeQuery(query);
queryDelete.setParameter("eventType", eventType.getValue());
queryDelete.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EventEntity {
private static final long serialVersionUID = 1L;
private Long id;
private String clientId;
private String ip;
private String eventType;
private String label;
private Date dateCreated;
Expand Down Expand Up @@ -56,6 +57,15 @@ public void setClientId(String client_id) {
this.clientId = client_id;
}

@Column(name = "ip")
public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

@Column(name = "label")
public String getLabel() {
return label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EventStatsEntity extends BaseEntity<Long>{
private Long id;
private String eventType;
private String clientId;
private String ip;
private Integer count;
private Date date;

Expand Down Expand Up @@ -55,6 +56,15 @@ public void setClientId(String client_id) {
this.clientId = client_id;
}

@Column(name = "ip")
public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

@Column(name = "count")
public Integer getCount() {
return count;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.orcid.core.utils;
package org.orcid.persistence.jpa.entities;

public enum EventType {
SIGN_IN("Sign-In"),
NEW_REGISTRATION("New-Registration"),
AUTHORIZE("Authorize"),
AUTHORIZE_DENY("Authorize-Deny"),
REAUTHORIZE("Reauthorize"),
PUBLIC_PAGE("Public-Page");
PUBLIC_PAGE("Public-Page"),
PAPI("Public-API");

private final String value;

Expand All @@ -17,4 +18,4 @@ public enum EventType {
public String getValue() {
return value;
}
}
}
2 changes: 2 additions & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,6 @@
<include file="/db/updates/dw_event_stats.xml" />
<include file="/db/updates/add_indexes_2024_02_20.xml" />
<include file="/db/updates/dw_views_with_4_months_interval.xml" />
<include file="/db/updates/dw_papi_event_stats.xml" />
<include file="/db/updates/add_ip_col_in_events.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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="ADD-FIELD-TO-EVENT" author="Daniel Palafox">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="event" columnName="ip"/>
</not>
</preConditions>
<sql>ALTER TABLE event ADD ip VARCHAR(15);</sql>
</changeSet>

<changeSet id="ADD-FIELD-TO-EVENT_STATS" author="Daniel Palafox">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="event_stats" columnName="ip"/>
</not>
</preConditions>
<sql>ALTER TABLE event_stats ADD ip VARCHAR(15);</sql>
</changeSet>

</databaseChangeLog>
Loading

0 comments on commit 78c6da3

Please sign in to comment.