Migrating packages to resolve conflicts with the refactored project

This commit is contained in:
Thomas Georgios Giannos 2023-11-20 12:19:02 +02:00
parent 75471e5587
commit ee4636e508
1851 changed files with 72998 additions and 73226 deletions

View File

@ -1,43 +0,0 @@
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

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

View File

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

View File

@ -1,25 +0,0 @@
package eu.eudat.configurations.typedefinition;
public class PostgreSQLDatabaseColumnType implements DatabaseColumnType {
public String getType(DataType dt) {
switch (dt) {
case TINY:
case SHORT:
case INTEGER:
return "integer";
case LONG:
return "bigint";
case FLOAT:
case DOUBLE:
return "numeric";
case DATE:
return "timestamp";
case STRING:
return "character varying(250)";
case TEXT:
return "text";
}
return "character varying(250)";
}
}

View File

@ -1,26 +0,0 @@
package eu.eudat.configurations.typedefinition;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
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

@ -1,113 +0,0 @@
package eu.eudat.configurations.typedefinition;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
/**
* Currently not used
*/
public class UUIDType implements UserType<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

@ -1,93 +0,0 @@
package eu.eudat.configurations.typedefinition;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
/**
* Store and retrieve a PostgreSQL "xml" column as a Java string.
*/
public class XMLType implements UserType<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

@ -1,40 +0,0 @@
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

@ -1,150 +0,0 @@
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

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

View File

@ -1,54 +0,0 @@
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

@ -1,25 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,48 +0,0 @@
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

@ -1,37 +0,0 @@
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

@ -1,97 +0,0 @@
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

@ -1,56 +0,0 @@
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

@ -1,71 +0,0 @@
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

@ -1,132 +0,0 @@
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

@ -1,25 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,101 +0,0 @@
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

@ -0,0 +1,43 @@
package eu.old.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.old.eudat.configurations.typedefinition;
public enum DataType {
TINY,
SHORT,
INTEGER,
LONG,
DOUBLE,
FLOAT,
DATE,
STRING,
TEXT
}

View File

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

View File

@ -0,0 +1,25 @@
package eu.old.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.old.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.old.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.old.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.old.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.old.eudat.convention;
import eu.old.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.old.eudat.data;
public interface BaseEntity {
}

View File

@ -0,0 +1,54 @@
package eu.old.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.old.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.old.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.old.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.old.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,96 @@
package eu.old.eudat.model.builder;
import eu.old.eudat.convention.ConventionService;
import gr.cite.tools.data.builder.Builder;
import gr.cite.tools.data.query.QueryBase;
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.old.eudat.model.builder;
import eu.old.eudat.convention.ConventionService;
import eu.old.eudat.data.DescriptionTemplateTypeEntity;
import eu.old.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.old.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.old.eudat.query;
import eu.old.eudat.commons.enums.DescriptionTemplateTypeStatus;
import eu.old.eudat.data.DescriptionTemplateTypeEntity;
import eu.old.eudat.query.lookup.DescriptionTemplateTypeLookup;
import eu.old.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.old.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.old.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.old.eudat.service;
import eu.old.eudat.commons.enums.DescriptionTemplateTypeStatus;
import eu.old.eudat.data.DescriptionTemplateTypeEntity;
import eu.old.eudat.model.DescriptionTemplateType;
import eu.old.eudat.model.builder.DescriptionTemplateTypeBuilder;
import eu.old.eudat.query.DescriptionTemplateTypeQuery;
import eu.old.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

@ -1,49 +0,0 @@
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

@ -1,22 +0,0 @@
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

@ -1,21 +0,0 @@
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

@ -1,18 +0,0 @@
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

@ -1,16 +0,0 @@
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

@ -1,126 +0,0 @@
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

@ -1,9 +0,0 @@
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

@ -1,66 +0,0 @@
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

@ -1,17 +0,0 @@
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

@ -1,144 +0,0 @@
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

@ -1,101 +0,0 @@
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

@ -1,18 +0,0 @@
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

@ -1,70 +0,0 @@
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

@ -1,17 +0,0 @@
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

@ -1,51 +0,0 @@
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

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

View File

@ -1,15 +0,0 @@
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

@ -1,34 +0,0 @@
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

@ -1,83 +0,0 @@
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

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

View File

@ -1,38 +0,0 @@
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

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

@ -1,31 +0,0 @@
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

@ -1,34 +0,0 @@
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

@ -1,17 +0,0 @@
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

@ -1,16 +0,0 @@
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

@ -1,35 +0,0 @@
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

@ -1,17 +0,0 @@
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

@ -1,33 +0,0 @@
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

@ -1,20 +0,0 @@
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

@ -1,50 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,55 +0,0 @@
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

@ -1,22 +0,0 @@
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

@ -1,149 +0,0 @@
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

@ -1,21 +0,0 @@
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

@ -1,85 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,65 +0,0 @@
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

@ -1,22 +0,0 @@
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

@ -1,153 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,56 +0,0 @@
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

@ -1,24 +0,0 @@
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

@ -1,134 +0,0 @@
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

@ -1,12 +0,0 @@
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

@ -1,55 +0,0 @@
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

@ -1,10 +0,0 @@
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

@ -1,65 +0,0 @@
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

@ -1,9 +0,0 @@
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

@ -1,52 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,56 +0,0 @@
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

@ -1,10 +0,0 @@
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

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

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