From 0bbad595f59f8f4cb8f293a540a81a33fd60f0fe Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 8 Nov 2023 13:37:16 +0200 Subject: [PATCH] update logging, db configurations --- .gitignore | 1 + .../typedefinition/DataType.java | 13 -- .../typedefinition/DatabaseColumnType.java | 5 - .../PostgreSQLDatabaseColumnType.java | 25 ---- .../typedefinition/PostgreSQLEnumType.java | 31 ----- .../typedefinition/UUIDType.java | 118 ------------------ .../typedefinition/XMLType.java | 95 -------------- .../eudat/data/DescriptionTemplateEntity.java | 7 +- .../eu/eudat/data/DmpBlueprintEntity.java | 14 +-- .../java/eu/eudat/data/DmpUserEntity.java | 1 + .../java/eu/eudat/data/ReferenceEntity.java | 4 +- .../eu/eudat/data/ReferenceTypeEntity.java | 4 +- .../main/java/eu/eudat/data/TagEntity.java | 5 - .../main/java/eu/eudat/data/old/Content.java | 2 - .../src/main/java/eu/eudat/data/old/DMP.java | 2 - .../eu/eudat/data/old/DMPDatasetProfile.java | 2 - .../eu/eudat/data/old/DMPOrganisation.java | 3 - .../java/eu/eudat/data/old/DMPResearcher.java | 3 - .../eu/eudat/data/old/DataRepository.java | 5 +- .../eu/eudat/data/old/EmailConfirmation.java | 2 - .../main/java/eu/eudat/data/old/Funder.java | 7 +- .../main/java/eu/eudat/data/old/Grant.java | 2 - .../java/eu/eudat/data/old/Invitation.java | 6 +- .../src/main/java/eu/eudat/data/old/Lock.java | 2 - .../java/eu/eudat/data/old/Notification.java | 2 - .../java/eu/eudat/data/old/Organisation.java | 9 +- .../main/java/eu/eudat/data/old/Project.java | 6 +- .../main/java/eu/eudat/data/old/Registry.java | 4 +- .../java/eu/eudat/data/old/Researcher.java | 9 +- .../main/java/eu/eudat/data/old/Service.java | 4 +- .../main/java/eu/eudat/data/old/UserDMP.java | 2 - .../main/java/eu/eudat/data/old/UserInfo.java | 4 - .../main/java/eu/eudat/data/old/UserRole.java | 2 - .../mapper/deposit/DMPToDepositMapper.java | 2 +- .../java/eu/eudat/query/DescriptionQuery.java | 4 - .../query/DmpDescriptionTemplateQuery.java | 17 ++- .../java/eu/eudat/query/DmpUserQuery.java | 25 ++++ .../lookup/DmpDescriptionTemplateLookup.java | 10 ++ .../service/DatabaseService.java | 2 +- .../eudat/data/dao/entities/DMPDaoImpl.java | 2 +- dmp-backend/pom.xml | 1 + dmp-backend/web/pom.xml | 5 +- .../main/java/eu/eudat/EuDatApplication.java | 2 + .../DevelDatabaseConfiguration.java | 73 ----------- .../ProductionDatabaseConfiguration.java | 76 ----------- .../resources/config/application-devel.yml | 2 - .../src/main/resources/config/db-devel.yml | 7 +- .../web/src/main/resources/config/db.yml | 33 ++++- .../main/resources/config/logging-devel.yml | 36 ++++++ .../web/src/main/resources/config/logging.yml | 35 +++++- .../main/resources/logging/logback-devel.xml | 61 ++++++--- .../main/resources/logging/logback-docker.xml | 33 ----- .../resources/logging/logback-production.xml | 33 ----- 53 files changed, 230 insertions(+), 630 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/configurations/ProductionDatabaseConfiguration.java create mode 100644 dmp-backend/web/src/main/resources/config/logging-devel.yml delete mode 100644 dmp-backend/web/src/main/resources/logging/logback-docker.xml delete mode 100644 dmp-backend/web/src/main/resources/logging/logback-production.xml diff --git a/.gitignore b/.gitignore index 15bf058e9..8823d8abe 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ bin/ openDMP/dmp-backend/uploads/ openDMP/dmp-backend/tmp/ storage/ +logs/ diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java deleted file mode 100644 index bf144db9d..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public enum DataType { - TINY, - SHORT, - INTEGER, - LONG, - DOUBLE, - FLOAT, - DATE, - STRING, - TEXT -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java deleted file mode 100644 index 6e24625b4..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public interface DatabaseColumnType { - public String getType(DataType dt); -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java deleted file mode 100644 index bf8812277..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public class PostgreSQLDatabaseColumnType implements DatabaseColumnType { - - public String getType(DataType dt) { - switch (dt) { - case TINY: - case SHORT: - case INTEGER: - return "integer"; - case LONG: - return "bigint"; - case FLOAT: - case DOUBLE: - return "numeric"; - case DATE: - return "timestamp"; - case STRING: - return "character varying(250)"; - case TEXT: - return "text"; - } - return "character varying(250)"; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java deleted file mode 100644 index 20be832a8..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Types; - -/** - * @deprecated hibernate's abstract class is depricated and those type of conversions and checks - * are done by hibernate itself - */ -@Deprecated -public class PostgreSQLEnumType extends org.hibernate.type.EnumType { - - public void nullSafeSet( - PreparedStatement st, - Object value, - int index, - SharedSessionContractImplementor session) - throws HibernateException, SQLException { - st.setObject( - index, - value != null ? - ((Enum) value).name() : - null, - Types.OTHER - ); - } -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java deleted file mode 100644 index 042fed955..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java +++ /dev/null @@ -1,118 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.UUID; - -/** - * Currently not used - */ -public class UUIDType implements UserType { - private final int[] sqlTypesSupported = new int[]{Types.NUMERIC}; - private final String CAST_EXCEPTION_TEXT = " cannot be cast to a java.util.UUID"; - - public int[] sqlTypes() { - return sqlTypesSupported; - } - - @Override - public int getSqlType() { - return sqlTypesSupported[0]; - } - - public Class returnedClass() { - return UUID.class; - } - - public boolean equals(UUID x, UUID y) throws HibernateException { - if (x == null) return y == null; - else return x.equals(y); - } - - public int hashCode(UUID x) throws HibernateException { - return x == null ? -1 : x.hashCode(); - } - - @Override - public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { - assert (position >= 0); - Object value = rs.getObject(position); - if (value == null) return null; - - UUID uuid = UUID.fromString(rs.getString(position)); - return rs.wasNull() ? null : uuid; - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { - assert (names.length == 1); - Object value = rs.getObject(names[0]); - if (value == null) return null; - - UUID uuid = UUID.fromString(rs.getString(names[0])); - return rs.wasNull() ? null : uuid; - } - - public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { - if (value == null) { - st.setNull(index, Types.NULL); - return; - } - - if (!UUID.class.isAssignableFrom(value.getClass())) - throw new HibernateException(value.getClass().toString() + CAST_EXCEPTION_TEXT); - - UUID uuid = (UUID) value; - st.setObject(index, uuid, Types.OTHER); - } - - public UUID deepCopy(UUID value) throws HibernateException { - if (value == null) return null; - return new UUID(value.getMostSignificantBits(), value.getLeastSignificantBits()); - } - - public boolean isMutable() { - return false; - } - - public Serializable disassemble(UUID value) throws HibernateException { - return value; - } - - public UUID assemble(Serializable cached, Object owner) throws HibernateException { - return (UUID) cached; - } - - public UUID replace(UUID original, Object target, Object owner) throws HibernateException { - return original; - } - -// public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) -// throws HibernateException, SQLException -// { -// return nullSafeGet(rs, names, owner); -// } -// -// public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) -// throws HibernateException, SQLException -// { -// nullSafeSet(st, value, index); -// -// } - - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) - throws HibernateException, SQLException { - return nullSafeGet(rs, names, owner); - } - - public void nullSafeSet(PreparedStatement st, UUID value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { - nullSafeSet(st, value, index); - } -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java deleted file mode 100644 index ea4b1f9d0..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java +++ /dev/null @@ -1,95 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; - -/** - * Store and retrieve a PostgreSQL "xml" column as a Java string. - */ -public class XMLType implements UserType { - - private final int[] sqlTypesSupported = new int[]{Types.VARCHAR}; - - public int[] sqlTypes() { - return sqlTypesSupported; - } - - @Override - public int getSqlType() { - return sqlTypesSupported[0]; - } - - public Class returnedClass() { - return String.class; - } - - public boolean equals(String x, String y) throws HibernateException { - if (x == null) { - return y == null; - } else { - return x.equals(y); - } - } - - public int hashCode(String x) throws HibernateException { - return x == null ? -1 : x.hashCode(); - } - - @Override - public String nullSafeGet(ResultSet resultSet, int i, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws SQLException { - assert (i >= 0); - String xmldoc = resultSet.getString(i); - return resultSet.wasNull() ? null : xmldoc; - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { - assert (names.length == 1); - String xmldoc = rs.getString(names[0]); - return rs.wasNull() ? null : xmldoc; - } - - public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { - if (value == null) { - st.setNull(index, Types.OTHER); - } else { - st.setObject(index, value, Types.OTHER); - } - } - - public String deepCopy(String value) throws HibernateException { - return value; - } - - public boolean isMutable() { - return false; - } - - public Serializable disassemble(String value) throws HibernateException { - return value; - } - - public String assemble(Serializable cached, Object owner) throws HibernateException { - return (String) cached; - } - - public String replace(String original, String target, Object owner) throws HibernateException { - return original; - } - - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) - throws HibernateException, SQLException { - return nullSafeGet(rs, names, owner); - } - - public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - nullSafeSet(st, value, index); - } - -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java index d3cc5145c..d8166558c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java @@ -7,10 +7,10 @@ import eu.eudat.data.converters.enums.DescriptionTemplateStatusConverter; import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.queryable.queryableentity.DataEntity; import jakarta.persistence.*; -import org.hibernate.annotations.Type; import java.time.Instant; -import java.util.*; +import java.util.List; +import java.util.UUID; @Entity @@ -26,8 +26,7 @@ public class DescriptionTemplateEntity implements DataEntity { //IGNORE ME @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java index c00aac796..af9249e04 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java @@ -6,7 +6,6 @@ import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.*; @@ -90,7 +89,6 @@ public class DMP implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java index 744a62927..2342cc1d9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.List; @@ -14,7 +13,6 @@ public class DMPDatasetProfile implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java index e3b9b40c7..920b6351b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java @@ -1,8 +1,6 @@ package eu.eudat.data.old; -import org.hibernate.annotations.GenericGenerator; - import jakarta.persistence.*; import java.io.Serializable; import java.util.UUID; @@ -14,7 +12,6 @@ public class DMPOrganisation { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java index 9f419d6c7..e633606de 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java @@ -1,8 +1,6 @@ package eu.eudat.data.old; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.UUID; @@ -14,7 +12,6 @@ public class DMPResearcher { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java index be5b0d4f4..db1182e29 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java @@ -3,13 +3,11 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.io.Serializable; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.UUID; @Entity @@ -32,8 +30,7 @@ public class DataRepository implements Serializable, DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false) private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java index 4e4e0810e..3a64acfb8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java @@ -1,7 +1,6 @@ package eu.eudat.data.old; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -73,12 +72,10 @@ public class Funder implements DataEntity { @Column(name = "\"Label\"") private String label; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Column(name = "\"Status\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java index e8996e02b..2766087b0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java @@ -4,7 +4,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -101,7 +100,6 @@ public class Grant implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) private String definition; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java index b8da71354..4bce27cf9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java @@ -2,8 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.List; @@ -16,7 +14,6 @@ public class Invitation implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false) private UUID id; @@ -37,8 +34,7 @@ public class Invitation implements DataEntity { @Column(name = "\"AcceptedInvitation\"", nullable = false) private boolean acceptedInvitation; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Properties\"", nullable = true) private String properties; public UUID getId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java index 4f50dd645..526e1b467 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.Date; @@ -16,7 +15,6 @@ public class Lock implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java index 143237d15..3c68e4953 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java @@ -5,7 +5,6 @@ import eu.eudat.commons.enums.old.notification.ContactType; import eu.eudat.commons.enums.old.notification.NotificationType; import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.Date; @@ -18,7 +17,6 @@ public class Notification implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java index 6cfded45d..a14b39fd7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java @@ -3,8 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.io.Serializable; @@ -25,7 +23,6 @@ public class Organisation implements Serializable, DataEntity @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @@ -35,15 +32,13 @@ public class Organisation implements Serializable, DataEntity @Column(name = "\"Abbreviation\"") private String abbreviation; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @OneToMany(fetch = FetchType.LAZY) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java index bccc1ef58..90dd6b193 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -80,14 +79,13 @@ public class Project implements DataEntity { @Column(name = "\"Abbreviation\"") private String abbreviation; - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Column(name = "\"StartDate\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java index 29c860824..3fcf00878 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java @@ -5,7 +5,6 @@ import eu.eudat.data.DescriptionEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -34,8 +33,7 @@ public class Registry implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Transient diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java index a11bb1520..e59ef9481 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java @@ -4,7 +4,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -18,8 +17,6 @@ import java.util.UUID; public class Researcher implements DataEntity { @Id - /*@GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2")*/ @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @@ -32,12 +29,10 @@ public class Researcher implements DataEntity { @Column(name = "\"PrimaryEmail\"") private String primaryEmail; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java index 732b89927..8ade40d65 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -32,8 +31,7 @@ public class Service implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false) + @Column(name = "\"Definition\"", nullable = false) private String definition; @Column(name = "\"Status\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java index a42e2e862..688f1e096 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.LinkedList; @@ -49,7 +48,6 @@ public class UserDMP implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java index cb2e04992..a7b615108 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java @@ -4,8 +4,6 @@ import eu.eudat.data.CredentialEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -22,7 +20,6 @@ public class UserInfo implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; public final static String _id = "id"; @@ -65,7 +62,6 @@ public class UserInfo implements DataEntity { public final static String _lastloggedin = "lastloggedin"; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) @Column(name = "additionalinfo", nullable = true) private String additionalinfo; public final static String _additionalinfo = "additionalinfo"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java index 0c3c8c385..bf8b58ace 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.List; @@ -15,7 +14,6 @@ public class UserRole implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java index 88bfdfef3..72804b73f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java @@ -6,9 +6,9 @@ import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.*; import eu.eudat.depositinterface.models.*; import eu.eudat.commons.types.xml.XmlBuilder; -import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java index 3a3fd7208..25205d991 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java @@ -24,9 +24,7 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class DescriptionQuery extends QueryBase { - private String like; - private Collection ids; private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery; private Collection excludedIds; @@ -61,8 +59,6 @@ public class DescriptionQuery extends QueryBase { return this; } - - public DescriptionQuery dmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery subQuery) { this.dmpDescriptionTemplateQuery = subQuery; return this; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java index ce457fb1e..964d3888f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java @@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.model.DmpDescriptionTemplate; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -11,6 +12,7 @@ import gr.cite.tools.data.query.QueryContext; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Subquery; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -25,6 +27,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase ids; private Collection dmpIds; + private DmpQuery dmpQuery; private Collection descriptionTemplateIds; @@ -93,6 +96,11 @@ public class DmpDescriptionTemplateQuery extends QueryBase values) { this.dmpIds = values; return this; + } + + public DmpDescriptionTemplateQuery dmpSubQuery(DmpQuery subQuery) { + this.dmpQuery = subQuery; + return this; } public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) { @@ -126,7 +134,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id)); + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._id)); for (UUID item : this.excludedIds) notInClause.value(item); predicates.add(notInClause.not()); } + if (this.dmpQuery != null) { + Subquery subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass()); + this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)).value(subQuery)); + } if (this.dmpIds != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)); for (UUID item : this.dmpIds) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java index 262b7480b..711e1bce8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java @@ -1,8 +1,12 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; +import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpUserEntity; import eu.eudat.model.DmpUser; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -12,6 +16,7 @@ import gr.cite.tools.data.query.QueryContext; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Subquery; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -121,6 +126,26 @@ public class DmpUserQuery extends QueryBase { return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.userIds); } + @Override + protected Predicate applyAuthZ(QueryContext queryContext) { + if (this.authorize.contains(AuthorizationFlags.None)) return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDmp)) return null; + UUID ownerId = null; + if (this.authorize.contains(AuthorizationFlags.Owner)) ownerId = this.userScope.getUserIdSafe(); + + List predicates = new ArrayList<>(); + if (ownerId != null) { + predicates.add(queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._user), ownerId)); + + } + if (predicates.size() > 0) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return queryContext.CriteriaBuilder.or(); //Creates a false query + } + } + @Override protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java index 637315f31..23f85a022 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java @@ -15,6 +15,7 @@ public class DmpDescriptionTemplateLookup extends Lookup { private List ids; private List dmpIds; private List descriptionTemplateIds; + private DmpLookup dmpSubQuery; private List excludedIds; @@ -60,6 +61,14 @@ public class DmpDescriptionTemplateLookup extends Lookup { this.descriptionTemplateIds = descriptionTemplateIds; } + public DmpLookup getDmpSubQuery() { + return dmpSubQuery; + } + + public void setDmpSubQuery(DmpLookup dmpSubQuery) { + this.dmpSubQuery = dmpSubQuery; + } + public DmpDescriptionTemplateQuery enrich(QueryFactory queryFactory) { DmpDescriptionTemplateQuery query = queryFactory.query(DmpDescriptionTemplateQuery.class); if (this.ids != null) query.ids(this.ids); @@ -67,6 +76,7 @@ public class DmpDescriptionTemplateLookup extends Lookup { if (this.descriptionTemplateIds != null) query.ids(this.descriptionTemplateIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.isActive != null) query.isActive(this.isActive); + if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory)); this.enrichCommon(query); diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java index 6ef82d736..d596ee688 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java @@ -6,8 +6,8 @@ import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.queryableentity.DataEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import jakarta.transaction.Transactional; import java.util.Set; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java index e67a6ac22..efff8b70a 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java @@ -12,10 +12,10 @@ import eu.eudat.queryable.types.SelectionField; import eu.eudat.types.grant.GrantStateType; import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.JoinType; -import jakarta.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import javax.management.InvalidApplicationException; import java.util.Arrays; diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 68b0418ca..b02a37cf4 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -99,6 +99,7 @@ org.hibernate.orm hibernate-core + 6.3.1.Final diff --git a/dmp-backend/web/pom.xml b/dmp-backend/web/pom.xml index e8d5643dd..e09628fa6 100644 --- a/dmp-backend/web/pom.xml +++ b/dmp-backend/web/pom.xml @@ -102,7 +102,10 @@ org.postgresql postgresql - 42.6.0 + + + org.hibernate.orm + hibernate-core