Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2023-11-17 09:37:37 +02:00
commit 63f9fead96
1880 changed files with 75315 additions and 74715 deletions

View File

@ -1,3 +0,0 @@
artifactId=core
groupId=eu.eudat
version=1.0.0-SNAPSHOT

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.eudat</groupId>
<artifactId>dmp-backend</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,43 @@
package eu.eudat.commons.enums;
public enum DescriptionTemplateTypeStatus {
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
private final short value;
DescriptionTemplateTypeStatus(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static DescriptionTemplateTypeStatus fromInteger(int value) {
switch (value) {
case 0:
return SAVED;
case 1:
return FINALIZED;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported Description Template Type Status");
}
}
public static DescriptionTemplateTypeStatus fromLabel(String value) {
switch (value) {
case "SAVED":
return SAVED;
case "FINALISED":
return FINALIZED;
case "DELETED":
return DELETED;
default:
throw new RuntimeException("Unsupported Description Template Type Status");
}
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.configurations.typedefinition;
public enum DataType {
TINY,
SHORT,
INTEGER,
LONG,
DOUBLE,
FLOAT,
DATE,
STRING,
TEXT
}

View File

@ -0,0 +1,5 @@
package eu.eudat.configurations.typedefinition;
public interface DatabaseColumnType {
public String getType(DataType dt);
}

View File

@ -0,0 +1,25 @@
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)";
}
}

View File

@ -0,0 +1,26 @@
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;
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
);
}
}

View File

@ -0,0 +1,113 @@
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<UUID> {
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<UUID> 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 {
return null;
}
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);
}
}

View File

@ -0,0 +1,93 @@
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<String> {
private final int[] sqlTypesSupported = new int[]{Types.VARCHAR};
public int[] sqlTypes() {
return sqlTypesSupported;
}
@Override
public int getSqlType() {
return sqlTypesSupported[0];
}
public Class<String> 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 {
return null;
}
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);
}
}

View File

@ -0,0 +1,40 @@
package eu.eudat.convention;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
public interface ConventionService {
Boolean isValidId(Integer id);
Boolean isValidGuid(UUID guid);
Boolean isValidUUID(String str);
UUID parseUUIDSafe(String str);
Boolean isValidHash(String hash);
String hashValue(Object value);
String limit(String text, int maxLength);
String truncate(String text, int maxLength);
UUID getEmptyUUID();
boolean isNullOrEmpty(String value);
boolean isListNullOrEmpty(List<?> value);
String stringEmpty();
String asPrefix(String name);
String asIndexerPrefix(String part);
String asIndexer(String... names);
<K, V> Map<K, List<V>> toDictionaryOfList(List<V> items, Function<V, K> keySelector);
}

View File

@ -0,0 +1,150 @@
package eu.eudat.convention;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ConventionServiceImpl implements ConventionService {
private final static Pattern UUID_REGEX_PATTERN = Pattern.compile("^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$");
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ConventionServiceImpl.class));
private final ErrorThesaurusProperties errors;
@Autowired
public ConventionServiceImpl(ErrorThesaurusProperties errors) {
this.errors = errors;
}
@Override
public Boolean isValidId(Integer id) {
return id != null && id > 0;
}
@Override
public Boolean isValidGuid(UUID guid) {
return guid != null && !guid.equals(this.getEmptyUUID());
}
@Override
public Boolean isValidUUID(String str) {
if (this.isNullOrEmpty(str)) {
return false;
}
return UUID_REGEX_PATTERN.matcher(str).matches();
}
@Override
public UUID parseUUIDSafe(String str) {
if (!this.isValidUUID(str)) {
return null;
}
try {
return UUID.fromString(str);
} catch (Exception ex){
logger.warn("invalid uuid" + str, ex);
return null;
}
}
@Override
public Boolean isValidHash(String hash) {
return !this.isNullOrEmpty(hash);
}
@Override
public String hashValue(Object value) throws MyApplicationException {
if (value == null) return this.stringEmpty();
if (value instanceof Instant) return String.format("%ts", (Instant) value);
throw new MyApplicationException(this.errors.getSystemError().getCode(), this.errors.getSystemError().getMessage());
}
@Override
public String limit(String text, int maxLength) {
if (this.isNullOrEmpty(text)) return text;
if (text.length() > maxLength) return String.format("%s...", text.substring(0, maxLength));
else return text;
}
@Override
public String truncate(String text, int maxLength) {
String truncated = text;
if (text.length() < maxLength) return text;
truncated = truncated.trim();
truncated = truncated.replaceAll("\\s+", " ");//remove multiple spaces
if (truncated.length() < maxLength) return truncated;
truncated = truncated.replaceAll("([.!@#$%^&-=':;,<>?*\"/|])+", "");//remove multiple spaces
if (truncated.length() < maxLength) return truncated;
truncated = truncated.replaceAll("([aeiou])+", "");//remove multiple spaces
if (truncated.length() < maxLength) return truncated;
truncated = truncated.replaceAll("([AEIOU])+", "");//remove multiple spaces
if (truncated.length() < maxLength) return truncated;
if (text.length() > maxLength) return String.format("%s...", text.substring(0, maxLength));
return text;
}
@Override
public UUID getEmptyUUID() {
return new UUID(0L, 0L);
}
@Override
public boolean isNullOrEmpty(String value) {
return value == null || value.isEmpty();
}
@Override
public boolean isListNullOrEmpty(List<?> value) {
if(value == null) return true;
return value.isEmpty();
}
@Override
public String stringEmpty() {
return "";
}
@Override
public String asPrefix(String name) {
if (name == null) return null;
return name + ".";
}
@Override
public String asIndexer(String... names) {
if (names == null) return null;
return String.join(".", Arrays.stream(names).filter(x -> !this.isNullOrEmpty(x)).collect(Collectors.toList()));
}
@Override
public String asIndexerPrefix(String part) {
if (part == null) return null;
return part + ".";
}
@Override
public <K, V> Map<K, List<V>> toDictionaryOfList(List<V> items, Function<V, K> keySelector) {
Map<K, List<V>> map = new HashMap<>();
for (V model : items) {
K key = keySelector.apply(model);
if (!map.containsKey(key)) map.put(key, new ArrayList<V>());
map.get(key).add(model);
}
return map;
}
}

View File

@ -0,0 +1,5 @@
package eu.eudat.data;
public interface BaseEntity {
}

View File

@ -0,0 +1,54 @@
package eu.eudat.data;
import org.hibernate.annotations.GenericGenerator;
import jakarta.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "DescriptionTemplateType")
public class DescriptionTemplateTypeEntity implements BaseEntity {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "ID", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
public static final String _id = "ID";
@Column(name = "Name", nullable = false)
private String name;
public static final String _name = "Name";
@Column(name = "Status", nullable = false)
private Short status;
public static final String _status = "Status";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.errorcode;
public class ErrorDescription {
private int code;
private String message;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.errorcode;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(ErrorThesaurusProperties.class)
public class ErrorThesaurusConfiguration {
}

View File

@ -0,0 +1,48 @@
package eu.eudat.errorcode;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "error-thesaurus")
public class ErrorThesaurusProperties {
private ErrorDescription systemError;
public ErrorDescription getSystemError() {
return systemError;
}
public void setSystemError(ErrorDescription systemError) {
this.systemError = systemError;
}
private ErrorDescription forbidden;
public ErrorDescription getForbidden() {
return forbidden;
}
public void setForbidden(ErrorDescription forbidden) {
this.forbidden = forbidden;
}
private ErrorDescription hashConflict;
public ErrorDescription getHashConflict() {
return hashConflict;
}
public void setHashConflict(ErrorDescription hashConflict) {
this.hashConflict = hashConflict;
}
private ErrorDescription modelValidation;
public ErrorDescription getModelValidation() {
return modelValidation;
}
public void setModelValidation(ErrorDescription modelValidation) {
this.modelValidation = modelValidation;
}
}

View File

@ -0,0 +1,37 @@
package eu.eudat.model;
import java.util.UUID;
public class DescriptionTemplateType {
private UUID id;
private String name;
private short status;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public short getStatus() {
return status;
}
public void setStatus(short status) {
this.status = status;
}
}

View File

@ -0,0 +1,97 @@
package eu.eudat.model.builder;
import eu.eudat.convention.ConventionService;
import gr.cite.tools.data.builder.Builder;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import java.time.Instant;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public abstract class BaseBuilder<M, D> implements Builder {
protected final LoggerService logger;
protected final ConventionService conventionService;
public BaseBuilder(
ConventionService conventionService,
LoggerService logger
) {
this.conventionService = conventionService;
this.logger = logger;
}
public M build(FieldSet directives, D data) {
if (data == null) {
return null;
}
List<M> models = this.build(directives == null ? getFullFieldSet() : directives, List.of(data));
return models.stream().findFirst().orElse(null);
}
public abstract List<M> build(FieldSet directives, List<D> data);
public abstract FieldSet getFullFieldSet();
public <K> Map<K, M> asForeignKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
this.logger.trace("Building references from query");
List<D> data = query.collectAs(directives);
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
return this.asForeignKey(data, directives, keySelector);
}
public <K> Map<K, M> asForeignKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
this.logger.trace("building references");
List<M> models = this.build(directives, data);
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
assert models != null;
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
}
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, FieldSet directives, Function<M, K> keySelector) {
this.logger.trace("Building details from query");
List<D> data = query.collectAs(directives);
this.logger.trace("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
return this.asMasterKey(data, directives, keySelector);
}
public <K> Map<K, List<M>> asMasterKey(List<D> data, FieldSet directives, Function<M, K> keySelector) {
this.logger.trace("building details");
List<M> models = this.build(directives, data);
this.logger.trace("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
Map<K, List<M>> map = new HashMap<>();
assert models != null;
for (M model : models) {
K key = keySelector.apply(model);
if (!map.containsKey(key))
map.put(key, new ArrayList<M>());
map.get(key).add(model);
}
return map;
}
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
this.logger.trace("building static references");
List<FM> models = keys.stream().map(mapper).collect(Collectors.toList());
this.logger.trace("mapping {} build items from {} requested", Optional.of(models).map(List::size).orElse(0), Optional.of(keys).map(List::size));
return models.stream().collect(Collectors.toMap(keySelector, o -> o));
}
protected String hashValue(Instant value) {
return this.conventionService.hashValue(value);
}
protected String asPrefix(String name) {
return this.conventionService.asPrefix(name);
}
protected String asIndexer(String... names) {
return this.conventionService.asIndexer(names);
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.builder;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.model.DescriptionTemplateType;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Component
public class DescriptionTemplateTypeBuilder extends BaseBuilder<DescriptionTemplateType, DescriptionTemplateTypeEntity> {
public DescriptionTemplateTypeBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeBuilder.class)));
}
@Override
public List<DescriptionTemplateType> build(FieldSet directives, List<DescriptionTemplateTypeEntity> data) {
if (directives == null || directives.isEmpty())
return new ArrayList<>();
List<DescriptionTemplateType> models = new ArrayList<>(100);
if (data == null)
return models;
for (DescriptionTemplateTypeEntity d : data) {
DescriptionTemplateType m = new DescriptionTemplateType();
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._id)))
m.setId(d.getId());
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._name)))
m.setName(d.getName());
if (directives.hasField(this.asIndexer(DescriptionTemplateTypeEntity._status)))
m.setStatus(d.getStatus());
models.add(m);
}
return models;
}
@Override
public FieldSet getFullFieldSet() {
BaseFieldSet fieldSet = new BaseFieldSet();
fieldSet.setFields(Set.of(
DescriptionTemplateTypeEntity._id,
DescriptionTemplateTypeEntity._name,
DescriptionTemplateTypeEntity._status
));
return fieldSet;
}
}

View File

@ -0,0 +1,71 @@
package eu.eudat.model.result;
import java.util.ArrayList;
import java.util.List;
public class QueryResult<M> {
public QueryResult() {
}
public QueryResult(List<M> items, long count, long countOverride) {
this.items = items;
this.count = count;
this.countOverride = countOverride;
}
public QueryResult(List<M> items, long count) {
this.items = items;
this.count = count;
this.countOverride = 0;
}
public QueryResult(M item) {
this.items = List.of(item);
this.count = 1;
this.countOverride = 0;
}
public QueryResult(List<M> items) {
this.items = items;
if (items != null)
this.count = items.size();
else
this.count = 0;
}
private List<M> items;
private long count;
private long countOverride;
public List<M> getItems() {
return items;
}
public void setItems(List<M> items) {
this.items = items;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public long getCountOverride() {
return countOverride;
}
public void setCountOverride(long countOverride) {
this.countOverride = countOverride;
}
public static QueryResult<?> empty() {
return new QueryResult<>(new ArrayList<>(), 0L);
}
}

View File

@ -0,0 +1,132 @@
package eu.eudat.query;
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
import eu.eudat.query.lookup.LookupAware;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateTypeEntity> implements LookupAware<DescriptionTemplateTypeQuery, DescriptionTemplateTypeLookup> {
private Collection<UUID> ids;
private Collection<String> names;
private Collection<Short> statuses;
public DescriptionTemplateTypeQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public DescriptionTemplateTypeQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public DescriptionTemplateTypeQuery ids(List<UUID> value) {
this.ids = value;
return this;
}
public DescriptionTemplateTypeQuery names(String value) {
this.names = List.of(value);
return this;
}
public DescriptionTemplateTypeQuery names(String... value) {
this.names = Arrays.asList(value);
return this;
}
public DescriptionTemplateTypeQuery names(List<String> value) {
this.names = value;
return this;
}
public DescriptionTemplateTypeQuery statuses(Short value) {
this.statuses = List.of(value);
return this;
}
public DescriptionTemplateTypeQuery statuses(Short... value) {
this.statuses = Arrays.asList(value);
return this;
}
public DescriptionTemplateTypeQuery statuses(List<Short> value) {
this.statuses = value;
return this;
}
@Override
public DescriptionTemplateTypeQuery fromLookup(DescriptionTemplateTypeLookup lookup) {
if (lookup == null) return this;
if (lookup.getName() != null) names(lookup.getName());
if (lookup.getStatus() != null) statuses(DescriptionTemplateTypeStatus.fromLabel(lookup.getStatus()).getValue());
return this;
}
@Override
protected Boolean isFalseQuery() {
return Boolean.FALSE;
}
@Override
protected Class<DescriptionTemplateTypeEntity> entityClass() {
return DescriptionTemplateTypeEntity.class;
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._id));
for (UUID item : this.ids) inClause.value(item);
predicates.add(inClause);
}
if (this.names != null) {
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._name));
for (String item : this.names) inClause.value(item);
predicates.add(inClause);
}
if (this.statuses != null) {
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateTypeEntity._status));
for (Short item : this.statuses) inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return queryContext.CriteriaBuilder.and();
}
}
@Override
protected String fieldNameOf(FieldResolver item) {
return null;
}
@Override
protected DescriptionTemplateTypeEntity convert(Tuple tuple, Set<String> columns) {
return null;
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.query.lookup;
import gr.cite.tools.data.query.Lookup;
public class DescriptionTemplateTypeLookup extends Lookup {
private String name, status;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.query.lookup;
public interface LookupAware<Q, L> {
/**
* Every query that supports building from a lookup object should implement this interface
* @param lookup The object containing all the lookup options
* @return The query built from all the set options
*/
Q fromLookup(L lookup);
}

View File

@ -0,0 +1,101 @@
package eu.eudat.service;
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
import eu.eudat.query.DescriptionTemplateTypeQuery;
import eu.eudat.query.lookup.DescriptionTemplateTypeLookup;
import gr.cite.tools.data.builder.BuilderFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.List;
import java.util.UUID;
@Service
public class DescriptionTemplateTypeService {
private final ApplicationContext applicationContext;
private final BuilderFactory builderFactory;
private final PlatformTransactionManager transactionManager;
@PersistenceContext
private EntityManager entityManager;
public DescriptionTemplateTypeService(ApplicationContext applicationContext, BuilderFactory builderFactory, PlatformTransactionManager platformTransactionManager) {
this.applicationContext = applicationContext;
this.builderFactory = builderFactory;
this.transactionManager = platformTransactionManager;
}
public List<DescriptionTemplateType> getAll(DescriptionTemplateTypeLookup lookup) {
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
.build(lookup.getProject(), query.fromLookup(lookup).collect());
}
public DescriptionTemplateType getById(UUID id) {
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
.build(null, query.ids(id).first());
}
public DescriptionTemplateType create(DescriptionTemplateType payload) {
DescriptionTemplateTypeEntity created = new DescriptionTemplateTypeEntity();
created.setId(UUID.randomUUID());
created.setName(payload.getName());
created.setStatus(DescriptionTemplateTypeStatus.SAVED.getValue());
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setName(UUID.randomUUID().toString());
definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = null;
try {
status = transactionManager.getTransaction(definition);
entityManager.persist(created);
entityManager.flush();
transactionManager.commit(status);
} catch (Exception ex) {
if (status != null)
transactionManager.rollback(status);
throw ex;
}
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
return builderFactory
.builder(DescriptionTemplateTypeBuilder.class)
.build(null, query.ids(created.getId()).first());
}
public DescriptionTemplateType update(DescriptionTemplateType payload) {
DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, payload.getId());
entity.setName(payload.getName());
entity.setStatus(payload.getStatus());
entityManager.merge(entity);
entityManager.flush();
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(null, entity);
}
public boolean delete (UUID id) {
DescriptionTemplateTypeEntity entity = entityManager.find(DescriptionTemplateTypeEntity.class, id);
if (entity == null) return false;
entity.setStatus(DescriptionTemplateTypeStatus.DELETED.getValue());
entityManager.merge(entity);
entityManager.flush();
return true;
}
}

View File

@ -15,6 +15,13 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>eu.eudat</groupId>
<artifactId>core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>dmp-backend</groupId> <groupId>dmp-backend</groupId>
<artifactId>queryable</artifactId> <artifactId>queryable</artifactId>

View File

@ -0,0 +1,49 @@
package eu.eudat.data.converters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.datetime.DateFormatter;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Created by ikalyvas on 9/25/2018.
*/
@Converter
public class DateToUTCConverter implements AttributeConverter<Date, Date> {
private static final Logger logger = LoggerFactory.getLogger(DateToUTCConverter.class);
@Override
public Date convertToDatabaseColumn(Date attribute) {
if(attribute == null) return null;
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
String date = formatterIST.format(attribute);
return formatterIST.parse(date);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public Date convertToEntityAttribute(Date dbData) {
if(dbData == null) return null;
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
String date = formatterIST.format(dbData);
return formatterIST.parse(date);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
return null;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.data.dao;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.queryable.queryableentity.DataEntity;
public class DatabaseAccess<T extends DataEntity> {
public DatabaseAccess(DatabaseService<T> databaseService) {
this.databaseService = databaseService;
}
private DatabaseService<T> databaseService;
public DatabaseService<T> getDatabaseService() {
return databaseService;
}
public void setDatabaseService(DatabaseService<T> databaseService) {
this.databaseService = databaseService;
}
}

View File

@ -0,0 +1,21 @@
package eu.eudat.data.dao;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity;
import java.util.concurrent.CompletableFuture;
public interface DatabaseAccessLayer<T extends DataEntity, I> {
T createOrUpdate(T item);
CompletableFuture<T> createOrUpdateAsync(T item);
T find(I id);
T find(I id, String hint);
void delete(T item);
QueryableList<T> asQueryable();
}

View File

@ -0,0 +1,18 @@
package eu.eudat.data.dao.criteria;
import io.swagger.annotations.ApiModelProperty;
public abstract class Criteria<T> {
@ApiModelProperty(value = "like", name = "like", dataType = "String", allowEmptyValue = true, example = "\"\"")
private String like;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMPProfile;
public class DataManagementPlanBlueprintCriteria extends Criteria<DMPProfile> {
private Integer status;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@ -0,0 +1,126 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Grant;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DataManagementPlanCriteria extends Criteria<DMP> {
private Date periodStart;
private Date periodEnd;
private List<eu.eudat.data.entities.Grant> grants;
private boolean allVersions;
private List<UUID> groupIds;
private Integer status;
private List<String> organisations;
private Integer role;
private List<UUID> collaborators;
private List<UUID> datasetTemplates;
private boolean isPublic;
private boolean onlyPublic;
private Short grantStatus;
private boolean hasDoi;
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
public Date getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd;
}
public List<Grant> getGrants() {
return grants;
}
public void setGrants(List<Grant> grants) {
this.grants = grants;
}
public boolean getAllVersions() {
return allVersions;
}
public void setAllVersions(boolean allVersions) {
this.allVersions = allVersions;
}
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public List<String> getOrganisations() {
return organisations;
}
public void setOrganisations(List<String> organisations) {
this.organisations = organisations;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public List<UUID> getCollaborators() {
return collaborators;
}
public void setCollaborators(List<UUID> collaborators) {
this.collaborators = collaborators;
}
public List<UUID> getDatasetTemplates() {
return datasetTemplates;
}
public void setDatasetTemplates(List<UUID> datasetTemplates) {
this.datasetTemplates = datasetTemplates;
}
public boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(boolean isPublic) {
this.isPublic = isPublic;
}
public boolean isOnlyPublic() {
return onlyPublic;
}
public void setOnlyPublic(boolean onlyPublic) {
this.onlyPublic = onlyPublic;
}
public Short getGrantStatus() {
return grantStatus;
}
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
}

View File

@ -0,0 +1,9 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMPProfile;
/**
* Created by ikalyvas on 3/21/2018.
*/
public class DataManagementPlanProfileCriteria extends Criteria<DMPProfile> {
}

View File

@ -0,0 +1,66 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.types.grant.GrantStateType;
import java.util.List;
import java.util.UUID;
public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
private GrantStateType grantStatus;
private List<UUID> grants;
public List<UUID> datasetProfile;
private List<String> dmpOrganisations;
private Integer role;
private boolean allVersions;
private List<UUID> groupIds;
public GrantStateType getGrantStatus() {
return grantStatus;
}
public void setGrantStatus(GrantStateType grantStatus) {
this.grantStatus = grantStatus;
}
public List<UUID> getGrants() {
return grants;
}
public void setGrants(List<UUID> grants) {
this.grants = grants;
}
public List<UUID> getDatasetProfile() {
return datasetProfile;
}
public void setDatasetProfile(List<UUID> datasetProfile) {
this.datasetProfile = datasetProfile;
}
public List<String> getDmpOrganisations() {
return dmpOrganisations;
}
public void setDmpOrganisations(List<String> dmpOrganisations) {
this.dmpOrganisations = dmpOrganisations;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public boolean getAllVersions() {
return allVersions;
}
public void setAllVersions(boolean allVersions) {
this.allVersions = allVersions;
}
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DataRepository;
import java.util.UUID;
public class DataRepositoryCriteria extends Criteria<DataRepository> {
private UUID creationUserId;
public UUID getCreationUserId() {
return creationUserId;
}
public void setCreationUserId(UUID creationUserId) {
this.creationUserId = creationUserId;
}
}

View File

@ -0,0 +1,144 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
import eu.eudat.types.grant.GrantStateType;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DatasetCriteria extends Criteria<Dataset> {
private Integer status;
private Date periodStart;
private Date periodEnd;
private List<UUID> dmpIds;
private List<Tag> tags;
private boolean allVersions;
private UUID profileDatasetId;
private List<String> organisations;
private Integer role;
private List<UUID> grants;
private List<UUID> collaborators;
private List<UUID> datasetTemplates;
private List<UUID> groupIds;
private Boolean isPublic;
private Short grantStatus;
private boolean hasDoi;
public boolean getAllVersions() {
return allVersions;
}
public void setAllVersions(boolean allVersions) {
this.allVersions = allVersions;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
public Date getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd;
}
public List<UUID> getDmpIds() {
return dmpIds;
}
public void setDmpIds(List<UUID> dmpIds) {
this.dmpIds = dmpIds;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public UUID getProfileDatasetId() {
return profileDatasetId;
}
public void setProfileDatasetId(UUID profileDatasetId) {
this.profileDatasetId = profileDatasetId;
}
public List<String> getOrganisations() {
return organisations;
}
public void setOrganisations(List<String> organisations) {
this.organisations = organisations;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public List<UUID> getGrants() {
return grants;
}
public void setGrants(List<UUID> grants) {
this.grants = grants;
}
public List<UUID> getCollaborators() {
return collaborators;
}
public void setCollaborators(List<UUID> collaborators) {
this.collaborators = collaborators;
}
public List<UUID> getDatasetTemplates() {
return datasetTemplates;
}
public void setDatasetTemplates(List<UUID> datasetTemplates) {
this.datasetTemplates = datasetTemplates;
}
public List<UUID> getGroupIds() {
return groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
this.groupIds = groupIds;
}
public Boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(Boolean isPublic) {
this.isPublic = isPublic;
}
public Short getGrantStatus() {
return grantStatus;
}
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
}

View File

@ -0,0 +1,101 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DescriptionTemplate;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DatasetProfileCriteria extends Criteria<DescriptionTemplate> {
public enum DatasetProfileFilter {
DMPs((short) 0), Datasets((short) 1);
private short value;
private DatasetProfileFilter(short value) {
this.value = value;
}
public short getValue() { return value; }
public static DatasetProfileFilter fromInteger(short value) {
switch (value) {
case 0:
return DMPs;
case 1:
return Datasets;
default:
throw new RuntimeException("Unsupported DescriptionTemplate filter");
}
}
}
private boolean allVersions;
private List<UUID> groupIds;
private Short filter;
private UUID userId;
private boolean finalized;
private Integer status;
private Integer role;
private List<UUID> ids;
private Date periodStart;
public boolean getAllVersions() { return allVersions; }
public void setAllVersions(boolean allVersions) { this.allVersions = allVersions; }
public List<UUID> getGroupIds() { return groupIds; }
public void setGroupIds(List<UUID> groupIds) { this.groupIds = groupIds; }
public Short getFilter() {
return filter;
}
public void setFilter(Short filter) {
this.filter = filter;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public boolean getFinalized() {
return finalized;
}
public void setFinalized(boolean finalized) {
this.finalized = finalized;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

View File

@ -0,0 +1,18 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DescriptionTemplate;
import java.util.UUID;
public class DatasetProfileWizardCriteria extends Criteria<DescriptionTemplate> {
private UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}

View File

@ -0,0 +1,70 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Dataset;
import eu.eudat.elastic.entities.Tag;
import eu.eudat.types.grant.GrantStateType;
import java.util.List;
import java.util.UUID;
/**
* Created by ikalyvas on 10/2/2018.
*/
public class DatasetPublicCriteria extends Criteria<Dataset>{
private GrantStateType grantStatus;
private List<UUID> grants;
private List<UUID> datasetProfile;
private List<String> dmpOrganisations;
private List<Tag> tags;
private List<UUID> dmpIds;
private Integer role;
public GrantStateType getGrantStatus() {
return grantStatus;
}
public void setGrantStatus(GrantStateType grantStatus) {
this.grantStatus = grantStatus;
}
public List<UUID> getGrants() {
return grants;
}
public void setGrants(List<UUID> grants) {
this.grants = grants;
}
public List<UUID> getDatasetProfile() {
return datasetProfile;
}
public void setDatasetProfile(List<UUID> datasetProfile) {
this.datasetProfile = datasetProfile;
}
public List<String> getDmpOrganisations() {
return dmpOrganisations;
}
public void setDmpOrganisations(List<String> dmpOrganisations) {
this.dmpOrganisations = dmpOrganisations;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public List<UUID> getDmpIds() {
return dmpIds;
}
public void setDmpIds(List<UUID> dmpIds) {
this.dmpIds = dmpIds;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserInfo;
public class DatasetWizardUserDmpCriteria extends Criteria<DMP> {
private UserInfo userInfo;
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
}

View File

@ -0,0 +1,51 @@
package eu.eudat.data.dao.criteria;
import java.util.List;
/**
* Created by ikalyvas on 3/26/2018.
*/
public class DynamicFieldsCriteria extends Criteria {
public static class DynamicFieldDependencyCriteria {
private String property;
private String value;
public DynamicFieldDependencyCriteria() {
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
private String id;
private List<DynamicFieldDependencyCriteria> dynamicFields;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<DynamicFieldDependencyCriteria> getDynamicFields() {
return dynamicFields;
}
public void setDynamicFields(List<DynamicFieldDependencyCriteria> dynamicFields) {
this.dynamicFields = dynamicFields;
}
}

View File

@ -0,0 +1,6 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.EmailConfirmation;
public class EmailConfirmationCriteria extends Criteria<EmailConfirmation>{
}

View File

@ -0,0 +1,15 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.ExternalDataset;
import java.util.UUID;
public class ExternalDatasetCriteria extends Criteria<ExternalDataset> {
private UUID creationUserId;
public UUID getCreationUserId() {
return creationUserId;
}
public void setCreationUserId(UUID creationUserId) {
this.creationUserId = creationUserId;
}
}

View File

@ -0,0 +1,34 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Funder;
import java.util.Date;
public class FunderCriteria extends Criteria<Funder> {
private String reference;
private String exactReference;
private Date periodStart;
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

View File

@ -0,0 +1,83 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Grant;
import eu.eudat.types.grant.GrantStateType;
import java.util.Date;
public class GrantCriteria extends Criteria<Grant> {
private Date periodStart;
private Date periodEnd;
private String reference;
private Integer grantStateType;
private boolean isPublic;
private String funderId;
private String funderReference;
private String exactReference;
private boolean isActive;
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
public Date getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public Integer getGrantStateType() {
return grantStateType;
}
public void setGrantStateType(Integer grantStateType) {
this.grantStateType = grantStateType;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getFunderId() {
return funderId;
}
public void setFunderId(String funderId) {
this.funderId = funderId;
}
public String getFunderReference() {
return funderReference;
}
public void setFunderReference(String funderReference) {
this.funderReference = funderReference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
}

View File

@ -0,0 +1,6 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Invitation;
public class InvitationCriteria extends Criteria<Invitation> {
}

View File

@ -0,0 +1,38 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Lock;
import eu.eudat.data.entities.UserInfo;
import java.util.Date;
import java.util.UUID;
public class LockCriteria extends Criteria<Lock> {
private UUID target;
private UserInfo lockedBy;
private Date touchedAt;
public UUID getTarget() {
return target;
}
public void setTarget(UUID target) {
this.target = target;
}
public UserInfo getLockedBy() {
return lockedBy;
}
public void setLockedBy(UserInfo lockedBy) {
this.lockedBy = lockedBy;
}
public Date getTouchedAt() {
return touchedAt;
}
public void setTouchedAt(Date touchedAt) {
this.touchedAt = touchedAt;
}
}

View File

@ -0,0 +1,26 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.enumeration.notification.ActiveStatus;
import eu.eudat.data.enumeration.notification.NotifyState;
public class NotificationCriteria {
private ActiveStatus isActive;
private NotifyState notifyState;
public ActiveStatus getIsActive() {
return isActive;
}
public void setIsActive(ActiveStatus isActive) {
this.isActive = isActive;
}
public NotifyState getNotifyState() {
return notifyState;
}
public void setNotifyState(NotifyState notifyState) {
this.notifyState = notifyState;
}
}

View File

@ -0,0 +1,31 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Organisation;
public class OrganisationCriteria extends Criteria<Organisation> {
private String labelLike;
private Boolean isPublic;
private boolean isActive;
public String getLabelLike() {
return labelLike;
}
public void setLabelLike(String labelLike) {
this.labelLike = labelLike;
}
public Boolean getPublic() {
return isPublic;
}
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
}

View File

@ -0,0 +1,34 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Project;
import java.util.Date;
public class ProjectCriteria extends Criteria<Project> {
private String reference;
private String exactReference;
private Date periodStart;
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Registry;
import java.util.UUID;
public class RegistryCriteria extends Criteria<Registry> {
private UUID creationUserId;
public UUID getCreationUserId() {
return creationUserId;
}
public void setCreationUserId(UUID creationUserId) {
this.creationUserId = creationUserId;
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.data.dao.criteria;
/**
* Created by ikalyvas on 3/26/2018.
*/
public class RequestItem<T> {
T criteria;
public T getCriteria() {
return criteria;
}
public void setCriteria(T criteria) {
this.criteria = criteria;
}
}

View File

@ -0,0 +1,35 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Researcher;
import java.util.Date;
public class ResearcherCriteria extends Criteria<Researcher> {
private String name;
private String reference;
private Date periodStart;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Service;
import java.util.UUID;
public class ServiceCriteria extends Criteria<Service> {
private UUID creationUserId;
public UUID getCreationUserId() {
return creationUserId;
}
public void setCreationUserId(UUID creationUserId) {
this.creationUserId = creationUserId;
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.UserInfo;
import java.util.List;
public class UserInfoCriteria extends Criteria<UserInfo> {
private String email;
private List<Integer> appRoles;
private String collaboratorLike;
public List<Integer> getAppRoles() {
return appRoles;
}
public void setAppRoles(List<Integer> appRoles) {
this.appRoles = appRoles;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCollaboratorLike() {
return collaboratorLike;
}
public void setCollaboratorLike(String collaboratorLike) {
this.collaboratorLike = collaboratorLike;
}
}

View File

@ -0,0 +1,20 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.UserRole;
import java.util.List;
/**
* Created by ikalyvas on 2/1/2018.
*/
public class UserRoleCriteria extends Criteria<UserRole> {
private List<Integer> appRoles;
public List<Integer> getAppRoles() {
return appRoles;
}
public void setAppRoles(List<Integer> appRoles) {
this.appRoles = appRoles;
}
}

View File

@ -0,0 +1,50 @@
package eu.eudat.data.dao.databaselayer.context;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.jpa.hibernatequeryablelist.QueryableHibernateList;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContext;
@Repository("databaseCtx")
public class DatabaseContext<T extends DataEntity> {
@PersistenceContext
private EntityManager entityManager;
@Autowired
public DatabaseContext(EntityManagerFactory entityManagerFactory) {
this.entityManager = entityManagerFactory.createEntityManager();
}
public QueryableList<T> getQueryable(Class<T> type) {
return new QueryableHibernateList<>(this.entityManager, type).setEntity(type);
}
@Transactional
public T createOrUpdate(T item, Class<T> type) {
EntityManager entityManager = this.entityManager;
if (item.getKeys() != null) {
T oldItem = entityManager.find(type, item.getKeys());
if (oldItem != null) {
oldItem.update(item);
entityManager.merge(oldItem);
return oldItem;
} else {
entityManager.persist(item);
}
} else entityManager.persist(item);
return item;
}
public void delete(T item) {
this.entityManager.remove(item);
}
}

View File

@ -0,0 +1,41 @@
package eu.eudat.data.dao.databaselayer.service;
import eu.eudat.data.dao.databaselayer.context.DatabaseContext;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import jakarta.transaction.Transactional;
import java.util.Set;
@Service("databaseService")
public class DatabaseService<T extends DataEntity> {
private DatabaseContext<T> databaseCtx;
@Autowired
public DatabaseService(DatabaseContext<T> databaseCtx) {
this.databaseCtx = databaseCtx;
}
public QueryableList<T> getQueryable(Class<T> tClass) {
return this.databaseCtx.getQueryable(tClass);
}
public QueryableList<T> getQueryable(Set<String> hints, Class<T> tClass) {
return this.databaseCtx.getQueryable(tClass);
}
@Transactional
public T createOrUpdate(T item, Class<T> tClass) {
return this.databaseCtx.createOrUpdate(item, tClass);
}
public void delete(T item) {
this.databaseCtx.delete(item);
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.Content;
import java.util.UUID;
/**
* Created by ikalyvas on 3/16/2018.
*/
public interface ContentDao extends DatabaseAccessLayer<Content, UUID> {
}

View File

@ -0,0 +1,55 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Content;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Created by ikalyvas on 3/16/2018.
*/
@Service("contentDao")
public class ContentDaoImpl extends DatabaseAccess<Content> implements ContentDao {
@Autowired
public ContentDaoImpl(DatabaseService<Content> databaseService) {
super(databaseService);
}
@Override
public Content createOrUpdate(Content item) {
return this.getDatabaseService().createOrUpdate(item, Content.class);
}
@Override
@Async
public CompletableFuture<Content> createOrUpdateAsync(Content item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Content find(UUID id) {
return this.getDatabaseService().getQueryable(Content.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public Content find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(Content item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Content> asQueryable() {
return this.getDatabaseService().getQueryable(Content.class);
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID;
public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria);
QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId, List<Integer> roles);
}

View File

@ -0,0 +1,149 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
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 java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("dMPDao")
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
@Autowired
public DMPDaoImpl(DatabaseService<DMP> databaseService) {
super(databaseService);
}
@Override
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria) {
QueryableList<DMP> query = getDatabaseService().getQueryable(DMP.getHints(), DMP.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
query.where(((builder, root) -> root.get("grant").in(criteria.getGrants())));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(
builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")),
builder1.notEqual(nestedRoot.get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
if (criteria.getStatus() != null) {
if (criteria.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.FINALISED.getValue()));
} else if (criteria.getStatus() == DMP.DMPStatus.ACTIVE.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue()));
}
}
if (criteria.getIsPublic()) {
query.where(((builder, root) -> builder.equal(root.get("isPublic"), criteria.getIsPublic())));
}
/*if (criteria.getRole() != null) {
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
} else if (criteria.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())) {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.USER.getValue()));
}
}*/
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty()) {
query.where((builder, root) -> root.join("organisations").get("reference").in(criteria.getOrganisations()));
}
if (criteria.getCollaborators() != null && !criteria.getCollaborators().isEmpty()) {
query.where((builder, root) -> root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
}
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty()) {
query.where((builder, root) -> root.join("associatedDmps", JoinType.LEFT).get("id").in(criteria.getDatasetTemplates()));
}
if (criteria.getGrantStatus() != null) {
if (criteria.getGrantStatus().equals(GrantStateType.FINISHED.getValue().shortValue()))
query.where((builder, root) -> builder.lessThan(root.get("grant").get("enddate"), new Date()));
if (criteria.getGrantStatus().equals(GrantStateType.ONGOING.getValue().shortValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
, builder.isNull(root.get("grant").get("enddate"))));
}
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
return query;
}
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
}
return query;
}
@Override
@Transactional
public DMP createOrUpdate(DMP item) {
return this.getDatabaseService().createOrUpdate(item, DMP.class);
}
@Override
public DMP find(UUID id) {
return getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardUserDmpCriteria, UserInfo userInfo) {
QueryableList<DMP> query = getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"), userInfo), builder.isMember(userInfo, root.get("users"))));
if (datasetWizardUserDmpCriteria.getLike() != null && !datasetWizardUserDmpCriteria.getLike().isEmpty()) {
query.where((builder, root) -> builder.like(root.get("label"), "%" + datasetWizardUserDmpCriteria.getLike() + "%"));
}
return query;
}
@Override
public void delete(DMP item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMP> asQueryable() {
return this.getDatabaseService().getQueryable(DMP.class);
}
@Async
@Override
public CompletableFuture<DMP> createOrUpdateAsync(DMP item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMP find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,21 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.dao.criteria.DataManagementPlanProfileCriteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
/**
* Created by ikalyvas on 3/21/2018.
*/
public interface DMPProfileDao extends DatabaseAccessLayer<DMPProfile, UUID> {
QueryableList<DMPProfile> getWithCriteria(DataManagementPlanProfileCriteria criteria);
QueryableList<DMPProfile> getWithCriteriaBlueprint(DataManagementPlanBlueprintCriteria criteria);
}

View File

@ -0,0 +1,85 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.dao.criteria.DataManagementPlanProfileCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Created by ikalyvas on 3/21/2018.
*/
@Service("dmpProfileDao")
public class DMPProfileDaoImpl extends DatabaseAccess<DMPProfile> implements DMPProfileDao {
@Autowired
public DMPProfileDaoImpl(DatabaseService<DMPProfile> databaseService) {
super(databaseService);
}
@Async
@Override
public CompletableFuture<DMPProfile> createOrUpdateAsync(DMPProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMPProfile createOrUpdate(DMPProfile item) {
return this.getDatabaseService().createOrUpdate(item, DMPProfile.class);
}
@Override
public DMPProfile find(UUID id) {
return getDatabaseService().getQueryable(DMPProfile.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public DMPProfile find(UUID id, String hint) {
return getDatabaseService().getQueryable(DMPProfile.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public void delete(DMPProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMPProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DMPProfile.class);
}
@Override
public QueryableList<DMPProfile> getWithCriteria(DataManagementPlanProfileCriteria criteria) {
QueryableList<DMPProfile> query = getDatabaseService().getQueryable(DMPProfile.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
query.where(((builder, root) -> builder.notEqual(root.get("status"), DMPProfile.Status.DELETED.getValue())));
return query;
}
@Override
public QueryableList<DMPProfile> getWithCriteriaBlueprint(DataManagementPlanBlueprintCriteria criteria){
QueryableList<DMPProfile> query = getDatabaseService().getQueryable(DMPProfile.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
if (criteria.getStatus() != null) {
if (criteria.getStatus() == DMPProfile.Status.FINALIZED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMPProfile.Status.FINALIZED.getValue()));
} else if (criteria.getStatus() == DMPProfile.Status.SAVED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMPProfile.Status.SAVED.getValue()));
}
}
query.where(((builder, root) -> builder.notEqual(root.get("status"), DMPProfile.Status.DELETED.getValue())));
return query;
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.entities.DataRepository;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface DataRepositoryDao extends DatabaseAccessLayer<DataRepository, UUID> {
QueryableList<DataRepository> getWithCriteria(DataRepositoryCriteria criteria);
}

View File

@ -0,0 +1,65 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DataRepository;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("dataRepositoryDao")
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
@Autowired
public DataRepositoryDaoImpl(DatabaseService<DataRepository> databaseService) {
super(databaseService);
}
@Override
public QueryableList<DataRepository> getWithCriteria(DataRepositoryCriteria criteria) {
QueryableList<DataRepository> query = this.getDatabaseService().getQueryable(DataRepository.class);
if (criteria.getLike() != null)
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
if (criteria.getCreationUserId() != null)
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), criteria.getCreationUserId()));
return query;
}
@Override
public DataRepository find(UUID id) {
return this.getDatabaseService().getQueryable(DataRepository.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DataRepository createOrUpdate(DataRepository item) {
return getDatabaseService().createOrUpdate(item, DataRepository.class);
}
@Override
@Async
public CompletableFuture<DataRepository> createOrUpdateAsync(DataRepository item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DataRepository find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DataRepository item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DataRepository> asQueryable() {
return this.getDatabaseService().getQueryable(DataRepository.class);
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID;
public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria);
QueryableList<Dataset> filterFromElastic(DatasetCriteria criteria, List<UUID> ids);
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles);
Dataset isPublicDataset(UUID id);
}

View File

@ -0,0 +1,153 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import eu.eudat.types.grant.GrantStateType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("datasetDao")
public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDao {
@Autowired
public DatasetDaoImpl(DatabaseService<Dataset> databaseService) { super(databaseService); }
@Override
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
QueryableList<Dataset> query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class);
if (criteria.getIsPublic() != null && criteria.getIsPublic()) {
query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true));
query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue()));
/*query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")),
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));*/
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getStatus() != null)
query.where((builder, root) -> builder.equal(root.get("status"), criteria.getStatus()));
if (criteria.getProfileDatasetId() != null)
query.where((builder, root) -> builder.equal(root.get("profile").get("id"), criteria.getProfileDatasetId()));
if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("groupId").in(criteria.getGroupIds()));
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
/*if (criteria.getRole() != null) {
query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole()));
} else {
query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues()));
}*/
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
query.where((builder, root) -> root.join("dmp").join("grant").get("id").in(criteria.getGrants()));
if (criteria.getGrantStatus() != null) {
if (criteria.getGrantStatus().equals(GrantStateType.FINISHED.getValue().shortValue()))
query.where((builder, root) -> builder.lessThan(root.get("dmp").get("grant").get("enddate"), new Date()));
if (criteria.getGrantStatus().equals(GrantStateType.ONGOING.getValue().shortValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("dmp").get("grant").get("enddate"), new Date())
, builder.isNull(root.get("dmp").get("grant").get("enddate"))));
}
if (criteria.getCollaborators() != null && !criteria.getCollaborators().isEmpty())
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dmp").join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()));
return query;
}
public QueryableList<Dataset> filterFromElastic(DatasetCriteria criteria, List<UUID> ids) {
QueryableList<Dataset> query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class);
query.where(((builder, root) -> root.get("id").in(ids)));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
return query;
}
@Override
public Dataset createOrUpdate(Dataset item) {
return getDatabaseService().createOrUpdate(item, Dataset.class);
}
@Override
public Dataset find(UUID id) {
return getDatabaseService().getQueryable(Dataset.class)
.where((builder, root) -> builder.and(builder.notEqual(root.get("status"),Dataset.Status.DELETED.getValue()), builder.notEqual(root.get("status"),Dataset.Status.CANCELED.getValue()), builder.equal((root.get("id")), id))).getSingle();
}
@Override
public Dataset find(UUID id, String hint) {
return getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class).withHint(hint)
.where((builder, root) -> builder.and(builder.notEqual(root.get("status"),Dataset.Status.DELETED.getValue()), builder.notEqual(root.get("status"),Dataset.Status.CANCELED.getValue()), builder.equal((root.get("id")), id))).getSingle();
}
@Override
public Dataset isPublicDataset(UUID id) {
QueryableList<Dataset> query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class);
query.where(((builder, root) -> builder.equal(root.get("id"), id)));
return query.withHint("datasetListingModel").getSingle();
}
@Override
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()));
}
return query;
}
@Override
public void delete(Dataset item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Dataset> asQueryable() {
return this.getDatabaseService().getQueryable(Dataset.class);
}
@Async
public CompletableFuture<Dataset> createOrUpdateAsync(Dataset item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DatasetExternalDataset;
import java.util.UUID;
/**
* Created by ikalyvas on 5/22/2018.
*/
public interface DatasetExternalDatasetDao extends DatabaseAccessLayer<DatasetExternalDataset, UUID> {
}

View File

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DatasetExternalDataset;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Created by ikalyvas on 5/22/2018.
*/
@Component("datasetExternalDatasetDao")
public class DatasetExternalDatasetDaoImpl extends DatabaseAccess<DatasetExternalDataset> implements DatasetExternalDatasetDao {
@Autowired
public DatasetExternalDatasetDaoImpl(DatabaseService<DatasetExternalDataset> databaseService) {
super(databaseService);
}
@Override
public DatasetExternalDataset createOrUpdate(DatasetExternalDataset item) {
return this.getDatabaseService().createOrUpdate(item,DatasetExternalDataset.class);
}
@Override
public CompletableFuture<DatasetExternalDataset> createOrUpdateAsync(DatasetExternalDataset item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
@Async
public DatasetExternalDataset find(UUID id) {
return getDatabaseService().getQueryable(DatasetExternalDataset.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DatasetExternalDataset find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DatasetExternalDataset item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DatasetExternalDataset> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetExternalDataset.class);
}
}

View File

@ -0,0 +1,24 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID;
public interface DatasetProfileDao extends DatabaseAccessLayer<DescriptionTemplate, UUID> {
QueryableList<DescriptionTemplate> getWithCriteria(DatasetProfileCriteria criteria);
QueryableList<DescriptionTemplate> getAll();
QueryableList<DescriptionTemplate> getAuthenticated(QueryableList<DescriptionTemplate> query, UUID principal, List<Integer> roles);
List<DescriptionTemplate> getAllIds();
Long countWithType(DescriptionTemplateType type);
}

View File

@ -0,0 +1,134 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("datasetProfileDao")
public class DatasetProfileDaoImpl extends DatabaseAccess<DescriptionTemplate> implements DatasetProfileDao {
@Autowired
public DatasetProfileDaoImpl(DatabaseService<DescriptionTemplate> databaseService) {
super(databaseService);
}
@Override
public QueryableList<DescriptionTemplate> getWithCriteria(DatasetProfileCriteria criteria) {
QueryableList<DescriptionTemplate> query = getDatabaseService().getQueryable(DescriptionTemplate.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"),
nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
if (criteria.getFilter() != null && criteria.getUserId() != null) {
if (criteria.getFilter().equals(DatasetProfileCriteria.DatasetProfileFilter.DMPs.getValue())) {
query.initSubQuery(UUID.class).where((builder, root) ->
builder.and(root.get("id").in(
query.subQuery((builder1, root1) -> builder1.equal(root1.join("dmps", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), criteria.getUserId()),
Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")))),
builder.notEqual(root.get("id"), criteria.getUserId())));
//query.where(((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), criteria.getUserId())));
}
if (criteria.getFilter().equals(DatasetProfileCriteria.DatasetProfileFilter.Datasets.getValue())) {
query.initSubQuery(UUID.class).where((builder, root) ->
builder.and(root.get("id").in(
query.subQuery((builder1, root1) -> builder1.equal(root1.join("dataset", JoinType.LEFT).join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), criteria.getUserId()),
Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")))),
builder.notEqual(root.get("id"), criteria.getUserId())));
}
}
if (criteria.getStatus() != null) {
query.where(((builder, root) -> builder.equal(root.get("status"), criteria.getStatus())));
}
if (criteria.getIds() != null) {
query.where(((builder, root) -> root.get("id").in(criteria.getIds())));
}
if (criteria.getFinalized()) {
query.where(((builder, root) -> builder.equal(root.get("status"), DescriptionTemplate.Status.FINALIZED.getValue())));
} else {
query.where(((builder, root) -> builder.notEqual(root.get("status"), DescriptionTemplate.Status.DELETED.getValue())));
}
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("created"), criteria.getPeriodStart()));
return query;
}
@Override
public DescriptionTemplate createOrUpdate(DescriptionTemplate item) {
return this.getDatabaseService().createOrUpdate(item, DescriptionTemplate.class);
}
@Override
public DescriptionTemplate find(UUID id) {
return getDatabaseService().getQueryable(DescriptionTemplate.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public QueryableList<DescriptionTemplate> getAll() {
return getDatabaseService().getQueryable(DescriptionTemplate.class);
}
@Override
public List<DescriptionTemplate> getAllIds(){
return getDatabaseService().getQueryable(DescriptionTemplate.class).withFields(Collections.singletonList("id")).toList();
}
@Override
public void delete(DescriptionTemplate item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DescriptionTemplate> asQueryable() {
return this.getDatabaseService().getQueryable(DescriptionTemplate.class);
}
@Async
@Override
public CompletableFuture<DescriptionTemplate> createOrUpdateAsync(DescriptionTemplate item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DescriptionTemplate find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<DescriptionTemplate> getAuthenticated(QueryableList<DescriptionTemplate> query, UUID principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
}
return query;
}
@Override
public Long countWithType(DescriptionTemplateType type) {
return this.getDatabaseService().getQueryable(DescriptionTemplate.class).where((builder, root) -> builder.equal(root.get("type"), type)).count();
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DatasetService;
import java.util.UUID;
/**
* Created by ikalyvas on 5/22/2018.
*/
public interface DatasetServiceDao extends DatabaseAccessLayer<DatasetService, UUID> {
}

View File

@ -0,0 +1,55 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DatasetService;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Created by ikalyvas on 5/22/2018.
*/
@Component("datasetServiceDao")
public class DatasetServiceDaoImpl extends DatabaseAccess<DatasetService> implements DatasetServiceDao {
@Autowired
public DatasetServiceDaoImpl(DatabaseService<DatasetService> databaseService) {
super(databaseService);
}
@Override
public DatasetService createOrUpdate(DatasetService item) {
return this.getDatabaseService().createOrUpdate(item, DatasetService.class);
}
@Async
@Override
public CompletableFuture<DatasetService> createOrUpdateAsync(DatasetService item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DatasetService find(UUID id) {
return getDatabaseService().getQueryable(DatasetService.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DatasetService find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DatasetService item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DatasetService> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetService.class);
}
}

View File

@ -0,0 +1,10 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DescriptionTemplateType;
import java.util.UUID;
public interface DescriptionTemplateTypeDao extends DatabaseAccessLayer<DescriptionTemplateType, UUID> {
DescriptionTemplateType findFromName(String name);
}

View File

@ -0,0 +1,65 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import jakarta.transaction.Transactional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("descriptionTemplateTypeDao")
public class DescriptionTemplateTypeDaoImpl extends DatabaseAccess<DescriptionTemplateType> implements DescriptionTemplateTypeDao {
@Autowired
public DescriptionTemplateTypeDaoImpl(DatabaseService<DescriptionTemplateType> databaseService) {
super(databaseService);
}
@Override
public DescriptionTemplateType findFromName(String name){
try {
return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.equal(root.get("name"), name)).getSingle();
}
catch(Exception e){
return null;
}
}
@Override
@Transactional
public DescriptionTemplateType createOrUpdate(DescriptionTemplateType item) {
return this.getDatabaseService().createOrUpdate(item, DescriptionTemplateType.class);
}
@Override
public DescriptionTemplateType find(UUID id) {
return getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public void delete(DescriptionTemplateType item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DescriptionTemplateType> asQueryable() {
return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.notEqual((root.get("status")), DescriptionTemplateType.Status.DELETED.getValue()));
}
@Async
@Override
public CompletableFuture<DescriptionTemplateType> createOrUpdateAsync(DescriptionTemplateType item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DescriptionTemplateType find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,9 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DMPDatasetProfile;
import java.util.UUID;
public interface DmpDatasetProfileDao extends DatabaseAccessLayer<DMPDatasetProfile, UUID> {
}

View File

@ -0,0 +1,52 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Content;
import eu.eudat.data.entities.DMPDatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("dmpDatasetProfileDao")
public class DmpDatasetProfileDaoImpl extends DatabaseAccess<DMPDatasetProfile> implements DmpDatasetProfileDao {
@Autowired
public DmpDatasetProfileDaoImpl(DatabaseService<DMPDatasetProfile> databaseService) {
super(databaseService);
}
@Override
public DMPDatasetProfile createOrUpdate(DMPDatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, DMPDatasetProfile.class);
}
@Override
@Async
public CompletableFuture<DMPDatasetProfile> createOrUpdateAsync(DMPDatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMPDatasetProfile find(UUID id) {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DMPDatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DMPDatasetProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMPDatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class);
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface EmailConfirmationDao extends DatabaseAccessLayer<EmailConfirmation, UUID> {
QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria);
}

View File

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LoginConfirmationEmailDao")
public class EmailConfirmationDaoImpl extends DatabaseAccess<EmailConfirmation> implements EmailConfirmationDao {
@Autowired
public EmailConfirmationDaoImpl(DatabaseService<EmailConfirmation> databaseService) {
super(databaseService);
}
@Override
public QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria) {
return null;
}
@Override
public EmailConfirmation createOrUpdate(EmailConfirmation item) {
return this.getDatabaseService().createOrUpdate(item, EmailConfirmation.class);
}
@Override
public CompletableFuture<EmailConfirmation> createOrUpdateAsync(EmailConfirmation item) {
return null;
}
@Override
public EmailConfirmation find(UUID id) {
return this.getDatabaseService().getQueryable(EmailConfirmation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public EmailConfirmation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(EmailConfirmation item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<EmailConfirmation> asQueryable() {
return this.getDatabaseService().getQueryable(EmailConfirmation.class);
}
}

View File

@ -0,0 +1,10 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.EntityDoi;
import java.util.UUID;
public interface EntityDoiDao extends DatabaseAccessLayer<EntityDoi, UUID> {
EntityDoi findFromDoi(String doi);
}

View File

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.EntityDoi;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("EntityDoiDao")
public class EntityDoiDaoImpl extends DatabaseAccess<EntityDoi> implements EntityDoiDao {
@Autowired
public EntityDoiDaoImpl(DatabaseService<EntityDoi> databaseService){
super(databaseService);
}
@Override
public EntityDoi createOrUpdate(EntityDoi item) {
return this.getDatabaseService().createOrUpdate(item, EntityDoi.class);
}
@Override
public CompletableFuture<EntityDoi> createOrUpdateAsync(EntityDoi item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public EntityDoi find(UUID id) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public EntityDoi findFromDoi(String doi) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("doi"), doi)).getSingle();
}
@Override
public EntityDoi find(UUID id, String hint) {
return null;
}
@Override
public void delete(EntityDoi item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<EntityDoi> asQueryable() {
return this.getDatabaseService().getQueryable(EntityDoi.class);
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
import eu.eudat.data.entities.ExternalDataset;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface ExternalDatasetDao extends DatabaseAccessLayer<ExternalDataset, UUID> {
QueryableList<ExternalDataset> getWithCriteria(ExternalDatasetCriteria criteria);
}

View File

@ -0,0 +1,66 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.ExternalDataset;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("externalDatasetDao")
public class ExternalDatasetDaoImpl extends DatabaseAccess<ExternalDataset> implements ExternalDatasetDao {
@Autowired
public ExternalDatasetDaoImpl(DatabaseService<ExternalDataset> databaseService) {
super(databaseService);
}
@Override
public QueryableList<ExternalDataset> getWithCriteria(ExternalDatasetCriteria criteria) {
QueryableList<ExternalDataset> query = this.getDatabaseService().getQueryable(ExternalDataset.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
if (criteria.getCreationUserId() != null)
query.where((builder, root) -> builder.equal(root.join("creationUser").get("id"), criteria.getCreationUserId()));
return query;
}
@Override
public ExternalDataset createOrUpdate(ExternalDataset item) {
return this.getDatabaseService().createOrUpdate(item, ExternalDataset.class);
}
@Override
public ExternalDataset find(UUID id) {
return this.getDatabaseService().getQueryable(ExternalDataset.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public void delete(ExternalDataset item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<ExternalDataset> asQueryable() {
return this.getDatabaseService().getQueryable(ExternalDataset.class);
}
@Async
@Override
public CompletableFuture<ExternalDataset> createOrUpdateAsync(ExternalDataset item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public ExternalDataset find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,11 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.FileUpload;
import java.util.List;
import java.util.UUID;
public interface FileUploadDao extends DatabaseAccessLayer<FileUpload, UUID> {
List<FileUpload> getFileUploads(UUID entityId);
}

View File

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.FileUpload;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("FileUploadDao")
public class FileUploadDaoImpl extends DatabaseAccess<FileUpload> implements FileUploadDao {
@Autowired
public FileUploadDaoImpl(DatabaseService<FileUpload> databaseService) {
super(databaseService);
}
@Override
public FileUpload createOrUpdate(FileUpload item) {
return getDatabaseService().createOrUpdate(item, FileUpload.class);
}
//
@Override
public CompletableFuture<FileUpload> createOrUpdateAsync(FileUpload item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public FileUpload find(UUID id) {
return getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public List<FileUpload> getFileUploads(UUID entityId) {
return this.getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("entityId"), entityId)).toList();
}
@Override
public FileUpload find(UUID id, String hint) {
return null;
}
@Override
public void delete(FileUpload item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<FileUpload> asQueryable() {
return this.getDatabaseService().getQueryable(FileUpload.class);
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.FunderCriteria;
import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface FunderDao extends DatabaseAccessLayer<Funder, UUID> {
QueryableList<Funder> getWithCritetia(FunderCriteria criteria);
QueryableList<Funder> getAuthenticated(QueryableList<Funder> query, UserInfo principal);
}

View File

@ -0,0 +1,75 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.FunderCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("funderDao")
public class FunderDaoImpl extends DatabaseAccess<Funder> implements FunderDao {
@Autowired
public FunderDaoImpl(DatabaseService<Funder> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Funder> getWithCritetia(FunderCriteria criteria) {
QueryableList<Funder> query = getDatabaseService().getQueryable(Funder.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) ->
builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), "%" + criteria.getReference().toUpperCase() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), criteria.getExactReference().toUpperCase()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("created"), criteria.getPeriodStart()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue()));
return query;
}
@Override
public QueryableList<Funder> getAuthenticated(QueryableList<Funder> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.get("creationUser"), principal));
return query;
}
@Override
public Funder createOrUpdate(Funder item) {
return this.getDatabaseService().createOrUpdate(item, Funder.class);
}
@Override
public CompletableFuture<Funder> createOrUpdateAsync(Funder item) {
return null;
}
@Override
public Funder find(UUID id) {
return this.getDatabaseService().getQueryable(Funder.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public Funder find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(Funder item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<Funder> asQueryable() {
return this.getDatabaseService().getQueryable(Funder.class);
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.GrantCriteria;
import eu.eudat.data.entities.Grant;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface GrantDao extends DatabaseAccessLayer<Grant, UUID> {
QueryableList<Grant> getWithCriteria(GrantCriteria criteria);
QueryableList<Grant> getAuthenticated(QueryableList<Grant> query, UserInfo principal);
}

View File

@ -0,0 +1,102 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.GrantCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Grant;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import eu.eudat.types.grant.GrantStateType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import schemasMicrosoftComOfficeOffice.LeftDocument;
import jakarta.persistence.criteria.JoinType;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("grantDao")
public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
@Autowired
public GrantDaoImpl(DatabaseService<Grant> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Grant> getWithCriteria(GrantCriteria criteria) {
QueryableList<Grant> query = getDatabaseService().getQueryable(Grant.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) ->
builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.or(builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.lessThan(root.get("enddate"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("startdate"), criteria.getPeriodStart()));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
if (criteria.getGrantStateType() != null) {
if (criteria.getGrantStateType().equals(GrantStateType.FINISHED.getValue()))
query.where((builder, root) -> builder.lessThan(root.get("enddate"), new Date()));
if (criteria.getGrantStateType().equals(GrantStateType.ONGOING.getValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("enddate"), new Date())
, builder.isNull(root.get("enddate"))));
}
if (criteria.isPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct();
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
}
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
if (criteria.getFunderReference() != null && !criteria.getFunderReference().isEmpty())
query.where((builder, root) -> builder.or(builder.like(root.join("funder", JoinType.LEFT).get("reference"), "%" + criteria.getFunderReference())));
query.where((builder, root) -> builder.notEqual(root.get("status"), Grant.Status.DELETED.getValue()));
return query;
}
@Override
public Grant createOrUpdate(Grant item) {
return getDatabaseService().createOrUpdate(item, Grant.class);
}
@Override
public Grant find(UUID id) {
return getDatabaseService().getQueryable(Grant.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public void delete(Grant item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Grant> asQueryable() {
return this.getDatabaseService().getQueryable(Grant.class);
}
public QueryableList<Grant> getAuthenticated(QueryableList<Grant> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId())).distinct();
return query;
}
@Async
@Override
public CompletableFuture<Grant> createOrUpdateAsync(Grant item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Grant find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.InvitationCriteria;
import eu.eudat.data.entities.Invitation;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface InvitationDao extends DatabaseAccessLayer<Invitation, UUID> {
QueryableList<Invitation> getWithCriteria(InvitationCriteria criteria);
}

View File

@ -0,0 +1,59 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.InvitationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Invitation;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("invitationDao")
public class InvitationDaoImpl extends DatabaseAccess<Invitation> implements InvitationDao {
@Autowired
public InvitationDaoImpl(DatabaseService<Invitation> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Invitation> getWithCriteria(InvitationCriteria criteria) {
return null;
}
@Override
public Invitation createOrUpdate(Invitation item) {
return this.getDatabaseService().createOrUpdate(item, Invitation.class);
}
@Override
public Invitation find(UUID id) {
return this.getDatabaseService().getQueryable(Invitation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public void delete(Invitation item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Invitation> asQueryable() {
return this.getDatabaseService().getQueryable(Invitation.class);
}
@Async
@Override
public CompletableFuture<Invitation> createOrUpdateAsync(Invitation item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Invitation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.LockCriteria;
import eu.eudat.data.entities.Lock;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface LockDao extends DatabaseAccessLayer<Lock, UUID> {
QueryableList<Lock> getWithCriteria(LockCriteria criteria);
}

View File

@ -0,0 +1,65 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.LockCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Lock;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LockDao")
public class LockDaoImpl extends DatabaseAccess<Lock> implements LockDao {
@Autowired
public LockDaoImpl(DatabaseService<Lock> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Lock> getWithCriteria(LockCriteria criteria) {
QueryableList<Lock> query = this.getDatabaseService().getQueryable(Lock.class);
if (criteria.getTouchedAt() != null)
query.where((builder, root) -> builder.equal(root.get("touchedAt"), criteria.getTouchedAt()));
if (criteria.getLockedBy() != null)
query.where(((builder, root) -> builder.equal(root.get("lockedBy"), criteria.getLockedBy())));
if (criteria.getTarget() != null)
query.where(((builder, root) -> builder.equal(root.get("target"), criteria.getTarget())));
return query;
}
@Override
public Lock createOrUpdate(Lock item) {
return this.getDatabaseService().createOrUpdate(item, Lock.class);
}
@Async
@Override
public CompletableFuture<Lock> createOrUpdateAsync(Lock item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Lock find(UUID id) {
return this.getDatabaseService().getQueryable(Lock.class).where(((builder, root) -> builder.equal(root.get("id"), id))).getSingle();
}
@Override
public Lock find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(Lock item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Lock> asQueryable() {
return this.getDatabaseService().getQueryable(Lock.class);
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.NotificationCriteria;
import eu.eudat.data.entities.Notification;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface NotificationDao extends DatabaseAccessLayer<Notification, UUID> {
QueryableList<Notification> getWithCriteria(NotificationCriteria criteria);
}

View File

@ -0,0 +1,61 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.NotificationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Lock;
import eu.eudat.data.entities.Notification;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("NotificationDao")
public class NotificationDaoImpl extends DatabaseAccess<Notification> implements NotificationDao {
@Autowired
public NotificationDaoImpl(DatabaseService<Notification> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Notification> getWithCriteria(NotificationCriteria criteria) {
QueryableList<Notification> query = this.getDatabaseService().getQueryable(Notification.class);
if (criteria.getIsActive() != null)
query.where((builder, root) -> builder.equal(root.get("isActive"), criteria.getIsActive()));
if (criteria.getNotifyState() != null)
query.where(((builder, root) -> builder.equal(root.get("notifyState"), criteria.getNotifyState())));
return query;
}
@Override
public Notification createOrUpdate(Notification item) {
return this.getDatabaseService().createOrUpdate(item, Notification.class);
}
@Override
public CompletableFuture<Notification> createOrUpdateAsync(Notification item) {
return CompletableFuture.supplyAsync(() -> this.getDatabaseService().createOrUpdate(item, Notification.class));
}
@Override
public Notification find(UUID id) {
return this.getDatabaseService().getQueryable(Notification.class).where(((builder, root) -> builder.equal(root.get("id"), id))).getSingle();
}
@Override
public Notification find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(Notification item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Notification> asQueryable() {
return this.getDatabaseService().getQueryable(Notification.class);
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface OrganisationDao extends DatabaseAccessLayer<Organisation, UUID> {
QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria);
QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal);
}

View File

@ -0,0 +1,84 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import jakarta.persistence.criteria.JoinType;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("organisationDao")
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
@Autowired
public OrganisationDaoImpl(DatabaseService<Organisation> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria) {
QueryableList<Organisation> query = this.getDatabaseService().getQueryable(Organisation.class);
if (criteria.getLabelLike() != null && criteria.getLike() != null) {
query.where((builder, root) -> builder.or(builder.equal(root.get("reference"), criteria.getLike()), builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")));
} else {
if (criteria.getLike() != null)
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
if (criteria.getLabelLike() != null) {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.getPublic() != null && criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
}
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
}
return query;
}
@Override
public Organisation createOrUpdate(Organisation item) {
return this.getDatabaseService().createOrUpdate(item, Organisation.class);
}
@Override
public Organisation find(UUID id) {
return this.getDatabaseService().getQueryable(Organisation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public void delete(Organisation item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<Organisation> asQueryable() {
return this.getDatabaseService().getQueryable(Organisation.class);
}
@Async
@Override
public CompletableFuture<Organisation> createOrUpdateAsync(Organisation item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
public QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.join("dmps").join("users").get("user"), principal));
return query;
}
@Override
public Organisation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.ProjectCriteria;
import eu.eudat.data.entities.Project;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface ProjectDao extends DatabaseAccessLayer<Project, UUID> {
QueryableList<Project> getWithCritetia(ProjectCriteria criteria);
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
}

View File

@ -0,0 +1,73 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.ProjectCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Project;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service;
import jakarta.persistence.criteria.JoinType;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("projectDao")
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
public ProjectDaoImpl(DatabaseService<Project> databaseService) {
super(databaseService);
}
@Override
public QueryableList<Project> getWithCritetia(ProjectCriteria criteria) {
QueryableList<Project> query = getDatabaseService().getQueryable(Project.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) ->
builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
builder.or(builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("startdate"), criteria.getPeriodStart()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue()));
return query;
}
public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) {
query.where((builder, root) -> builder.or(builder.equal(root.get("creationUser"), principal), builder.equal(root.join("dmps", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()))).distinct();
return query;
}
@Override
public Project createOrUpdate(Project item) {
return this.getDatabaseService().createOrUpdate(item, Project.class);
}
@Override
public CompletableFuture<Project> createOrUpdateAsync(Project item) {
return null;
}
@Override
public Project find(UUID id) {
return this.getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public Project find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(Project item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<Project> asQueryable() {
return this.getDatabaseService().getQueryable(Project.class);
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.RegistryCriteria;
import eu.eudat.data.entities.Registry;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface RegistryDao extends DatabaseAccessLayer<Registry, UUID> {
QueryableList<Registry> getWithCriteria(RegistryCriteria criteria);
}

Some files were not shown because too many files have changed in this diff Show More