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

This commit is contained in:
Diamantis Tziotzios 2023-11-21 10:07:50 +02:00
commit 033492a25c
2132 changed files with 81159 additions and 77245 deletions

View File

@ -19,6 +19,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.10.0</version>
</dependency>
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>validation</artifactId> <artifactId>validation</artifactId>

View File

@ -67,4 +67,13 @@ public class AuditableAction {
public static final EventId ReferenceType_Persist = new EventId(10002, "ReferenceType_Persist"); public static final EventId ReferenceType_Persist = new EventId(10002, "ReferenceType_Persist");
public static final EventId ReferenceType_Delete = new EventId(10003, "ReferenceType_Delete"); public static final EventId ReferenceType_Delete = new EventId(10003, "ReferenceType_Delete");
public static final EventId User_Query = new EventId(11000, "User_Query");
public static final EventId User_Lookup = new EventId(11001, "User_Lookup");
public static final EventId User_Persist = new EventId(11002, "User_Persist");
public static final EventId User_Delete = new EventId(11003, "User_Delete");
public static final EventId User_LookupByEmail = new EventId(11004, "User_LookupByEmail");
public static final EventId User_ExportCsv = new EventId(11005, "User_ExportCsv");
public static final EventId User_PersistRoles = new EventId(11004, "User_PersistRoles");
} }

View File

@ -3,6 +3,6 @@ package eu.eudat.authorization;
import java.util.EnumSet; import java.util.EnumSet;
public enum AuthorizationFlags { public enum AuthorizationFlags {
None, Permission, DmpAssociated, Public; None, Permission, DmpAssociated, Public, Owner;
public static final EnumSet<AuthorizationFlags> OwnerOrPermissionOrMemberOrPublic = EnumSet.of(DmpAssociated, Permission, Public); public static final EnumSet<AuthorizationFlags> OwnerOrDmpAssociatedOrPermissionOrPublic = EnumSet.of(DmpAssociated, Permission, Public, Owner);
} }

View File

@ -40,6 +40,14 @@ public final class Permission {
public static String CreateNewVersionDescriptionTemplate = "CreateNewVersionDescriptionTemplate"; public static String CreateNewVersionDescriptionTemplate = "CreateNewVersionDescriptionTemplate";
public static String ImportDescriptionTemplate = "ImportDescriptionTemplate"; public static String ImportDescriptionTemplate = "ImportDescriptionTemplate";
public static String ExportDescriptionTemplate = "ExportDescriptionTemplate"; public static String ExportDescriptionTemplate = "ExportDescriptionTemplate";
//User
public static String BrowseUser = "BrowseUser";
public static String EditUser = "EditUser";
public static String DeleteUser = "DeleteUser";
public static String ExportUsers = "ExportUsers";
//DescriptionTemplateType //DescriptionTemplateType
public static String BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType"; public static String BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType";

View File

@ -0,0 +1,30 @@
package eu.eudat.commons.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum ContactInfoType implements DatabaseEnum<Short> {
Email((short) 0);
private final Short value;
ContactInfoType(Short value) {
this.value = value;
}
@Override
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, ContactInfoType> map = EnumUtils.getEnumValueMap(ContactInfoType.class);
public static ContactInfoType of(Short i) {
return map.get(i);
}
}

View File

@ -0,0 +1,58 @@
package eu.eudat.commons.lock;
import org.springframework.stereotype.Service;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
@Service
public class LockByKeyManager {
private static class LockWrapper {
private final ReentrantLock lock = new ReentrantLock();
private final AtomicInteger numberOfThreadsInQueue = new AtomicInteger(1);
private LockWrapper addThreadInQueue() {
numberOfThreadsInQueue.incrementAndGet();
return this;
}
private int removeThreadFromQueue() {
return numberOfThreadsInQueue.decrementAndGet();
}
}
private static ConcurrentHashMap<String, LockWrapper> locks = new ConcurrentHashMap<String, LockWrapper>();
public void lock(String key) {
LockWrapper lockWrapper = locks.compute(key, (k, v) -> v == null ? new LockWrapper() : v.addThreadInQueue());
lockWrapper.lock.lock();
}
public boolean tryLock(String key, long timeout, TimeUnit unit) throws InterruptedException {
LockWrapper lockWrapper = null;
try {
lockWrapper = locks.compute(key, (k, v) -> v == null ? new LockWrapper() : v.addThreadInQueue());
return lockWrapper.lock.tryLock(timeout, unit);
} catch (Exception ex){
if (lockWrapper != null && lockWrapper.removeThreadFromQueue() == 0) {
// NB : We pass in the specific value to remove to handle the case where another thread would queue right before the removal
locks.remove(key, lockWrapper);
}
throw ex;
}
}
public void unlock(String key) {
LockWrapper lockWrapper = locks.get(key);
lockWrapper.lock.unlock();
if (lockWrapper.removeThreadFromQueue() == 0) {
// NB : We pass in the specific value to remove to handle the case where another thread would queue right before the removal
locks.remove(key, lockWrapper);
}
}
}

View File

@ -0,0 +1,60 @@
package eu.eudat.commons.types.user;
import java.util.UUID;
public class AdditionalInfoEntity {
private String avatarUrl;
private String timezone;
private String culture;
private String language;
private String roleOrganization;
private UUID organizationId;
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public UUID getOrganizationId() {
return organizationId;
}
public void setOrganizationId(UUID organizationId) {
this.organizationId = organizationId;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
}

View File

@ -1,186 +0,0 @@
package eu.eudat.data;
import eu.eudat.commons.enums.ProviderType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.ProviderTypeConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"Credential\"")
//@NamedEntityGraphs({
// @NamedEntityGraph(
// name = "credentialUserInfo",
// attributeNodes = {@NamedAttributeNode("userInfo")})
//})
public class CredentialEntity implements DataEntity<CredentialEntity, UUID> {
@Id
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
public final static String _id = "id";
@Column(name = "\"UserId\"", columnDefinition = "uuid", nullable = false)
private UUID userId;
public final static String _userId = "userId";
@Column(name = "\"Status\"", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public final static String _isActive = "isActive";
@Column(name = "\"Provider\"", nullable = false)
@Convert(converter = ProviderTypeConverter.class)
private ProviderType provider;
public final static String _provider = "provider";
@Column(name = "\"Public\"", nullable = false)
private String publicValue;
public final static String _publicValue = "public";
@Column(name = "\"Email\"")
private String email;
public final static String _email = "email";
@Column(name = "\"Secret\"", nullable = false)
private String secret;
public final static String _secret = "secret";
@Column(name = "\"CreationTime\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date creationTime;
public final static String _creationTime = "creationTime";
@Column(name = "\"LastUpdateTime\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date lastUpdateTime;
public final static String _lastUpdateTime = "lastUpdateTime";
@Column(name = "\"ExternalId\"", nullable = false)
private String externalId;
public final static String _externalId = "externalId";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public ProviderType getProvider() {
return provider;
}
public void setProvider(ProviderType provider) {
this.provider = provider;
}
public String getPublicValue() {
return publicValue;
}
public void setPublicValue(String publicValue) {
this.publicValue = publicValue;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public Date getCreationTime() {
return creationTime;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CredentialEntity that = (CredentialEntity) o;
return provider.getValue() == that.provider.getValue();
}
@Override
public int hashCode() {
return provider.getValue();
}
@Override
public void update(CredentialEntity entity) {
this.isActive = entity.isActive;
this.publicValue = entity.getPublicValue();
this.email = entity.getEmail();
this.secret = entity.getSecret();
this.lastUpdateTime = new Date();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public CredentialEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -23,16 +23,16 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
private UUID id; private UUID id;
public static final String _id = "id"; public static final String _id = "id";
@Column(name = "\"label\"", length = DescriptionTemplateEntity._labelLength, nullable = false) @Column(name = "label", length = DescriptionTemplateEntity._labelLength, nullable = false)
private String label; private String label;
public static final String _label = "label"; public static final String _label = "label";
public static final int _labelLength = 250; public static final int _labelLength = 250;
@Column(name = "\"definition\"", nullable = false) @Column(name = "definition", nullable = false)
private String definition; private String definition;
public static final String _definition = "definition"; public static final String _definition = "definition";
@Column(name = "\"status\"", nullable = false) @Column(name = "status", nullable = false)
@Convert(converter = DescriptionTemplateStatusConverter.class) @Convert(converter = DescriptionTemplateStatusConverter.class)
private DescriptionTemplateStatus status; private DescriptionTemplateStatus status;
public static final String _status = "status"; public static final String _status = "status";
@ -43,23 +43,23 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
@Column(name = "\"created_at\"", nullable = false) @Column(name = "created_at", nullable = false)
private Instant createdAt = null; private Instant createdAt = null;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@Column(name = "\"updated_at\"", nullable = false) @Column(name = "updated_at", nullable = false)
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@Column(name = "\"description\"", nullable = false) @Column(name = "description", nullable = false)
private String description; private String description;
public static final String _description = "description"; public static final String _description = "description";
@Column(name = "\"group_id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "group_id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID groupId; private UUID groupId;
public static final String _groupId = "groupId"; public static final String _groupId = "groupId";
@Column(name = "\"version\"", nullable = false) @Column(name = "version", nullable = false)
private Short version; private Short version;
public static final String _version = "version"; public static final String _version = "version";
@ -68,11 +68,11 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
private DescriptionTemplateVersionStatus versionStatus; private DescriptionTemplateVersionStatus versionStatus;
public static final String _versionStatus = "versionStatus"; public static final String _versionStatus = "versionStatus";
@Column(name = "\"language\"", nullable = false) @Column(name = "language", nullable = false)
private String language; private String language;
public static final String _language = "language"; public static final String _language = "language";
@Column(name = "\"type\"", nullable = false) @Column(name = "type", nullable = false)
private UUID typeId; private UUID typeId;
public static final String _typeId = "typeId"; public static final String _typeId = "typeId";

View File

@ -19,17 +19,17 @@ public class DmpBlueprintEntity {
private UUID id; private UUID id;
public static final String _id = "id"; public static final String _id = "id";
@Column(name = "\"label\"", length = DmpBlueprintEntity._labelLength, nullable = false) @Column(name = "label", length = DmpBlueprintEntity._labelLength, nullable = false)
private String label; private String label;
public static final String _label = "label"; public static final String _label = "label";
public static final int _labelLength = 250; public static final int _labelLength = 250;
@Column(name = "\"definition\"", nullable = true) @Column(name = "definition", nullable = true)
private String definition; private String definition;
public static final String _definition = "definition"; public static final String _definition = "definition";
@Column(name = "\"status\"", nullable = false) @Column(name = "status", nullable = false)
@Convert(converter = DmpBlueprintStatusConverter.class) @Convert(converter = DmpBlueprintStatusConverter.class)
private DmpBlueprintStatus status; private DmpBlueprintStatus status;
public static final String _status = "status"; public static final String _status = "status";
@ -40,11 +40,11 @@ public class DmpBlueprintEntity {
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
@Column(name = "\"created_at\"", nullable = false) @Column(name = "created_at", nullable = false)
private Instant createdAt = null; private Instant createdAt = null;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@Column(name = "\"updated_at\"", nullable = false) @Column(name = "updated_at", nullable = false)
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";

View File

@ -4,7 +4,6 @@ import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.DmpVersionStatus; import eu.eudat.commons.enums.DmpVersionStatus;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.DmpAccessTypeConverter; import eu.eudat.data.converters.enums.DmpAccessTypeConverter;
import eu.eudat.data.converters.enums.DmpStatusConverter; import eu.eudat.data.converters.enums.DmpStatusConverter;
import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.data.converters.enums.IsActiveConverter;
@ -63,13 +62,11 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _description = "description"; public static final String _description = "description";
@Column(name = "created_at") @Column(name = "created_at")
@Convert(converter = DateToUTCConverter.class)
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@Column(name = "updated_at") @Column(name = "updated_at")
@Convert(converter = DateToUTCConverter.class)
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@ -86,9 +83,9 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _finalizedAt = "finalizedAt"; public static final String _finalizedAt = "finalizedAt";
@Column(name = "creator") @Column(name = "creator")
private UUID creator; private UUID creatorId;
public static final String _creator = "creator"; public static final String _creatorId = "creatorId";
@Column(name = "access_type", nullable = false) @Column(name = "access_type", nullable = false)
@Convert(converter = DmpAccessTypeConverter.class) @Convert(converter = DmpAccessTypeConverter.class)
@ -97,9 +94,9 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
public static final String _accessType = "accessType"; public static final String _accessType = "accessType";
@Column(name = "blueprint") @Column(name = "blueprint")
private UUID blueprint; private UUID blueprintId;
public static final String _blueprint = "blueprint"; public static final String _blueprintId = "blueprintId";
@Column(name = "language") @Column(name = "language")
private String language; private String language;
@ -199,12 +196,12 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
this.finalizedAt = finalizedAt; this.finalizedAt = finalizedAt;
} }
public UUID getCreator() { public UUID getCreatorId() {
return creator; return creatorId;
} }
public void setCreator(UUID creator) { public void setCreatorId(UUID creatorId) {
this.creator = creator; this.creatorId = creatorId;
} }
public DmpAccessType getAccessType() { public DmpAccessType getAccessType() {
@ -215,12 +212,12 @@ public class DmpEntity implements DataEntity<DmpEntity, UUID> {
this.accessType = accessType; this.accessType = accessType;
} }
public UUID getBlueprint() { public UUID getBlueprintId() {
return blueprint; return blueprintId;
} }
public void setBlueprint(UUID blueprint) { public void setBlueprintId(UUID blueprintId) {
this.blueprint = blueprint; this.blueprintId = blueprintId;
} }
public String getLanguage() { public String getLanguage() {

View File

@ -27,9 +27,9 @@ public class DmpUserEntity implements DataEntity {
public static final String _dmp = "dmp"; public static final String _dmp = "dmp";
@Column(name = "user", columnDefinition = "uuid", nullable = false) @Column(name = "user", columnDefinition = "uuid", nullable = false)
private UUID user; private UUID userId;
public static final String _user = "user"; public static final String _userId = "userId";
@Column(name = "role", nullable = false) @Column(name = "role", nullable = false)
@Convert(converter = DmpUserRoleConverter.class) @Convert(converter = DmpUserRoleConverter.class)
@ -69,12 +69,12 @@ public class DmpUserEntity implements DataEntity {
this.dmp = dmp; this.dmp = dmp;
} }
public UUID getUser() { public UUID getUserId() {
return user; return userId;
} }
public void setUser(UUID user) { public void setUserId(UUID userId) {
this.user = user; this.userId = userId;
} }
public DmpUserRole getRole() { public DmpUserRole getRole() {

View File

@ -68,8 +68,8 @@ public class ReferenceEntity {
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@Column(name = "created_by", columnDefinition = "uuid") @Column(name = "created_by", columnDefinition = "uuid")
private UUID createdBy; private UUID createdById;
public static final String _createdBy = "createdBy"; public static final String _createdById = "createdBy";
public UUID getId() { public UUID getId() {
return id; return id;
@ -167,11 +167,11 @@ public class ReferenceEntity {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public UUID getCreatedBy() { public UUID getCreatedById() {
return createdBy; return createdById;
} }
public void setCreatedBy(UUID createdBy) { public void setCreatedById(UUID createdById) {
this.createdBy = createdBy; this.createdById = createdById;
} }
} }

View File

@ -37,8 +37,8 @@ public class TagEntity {
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@Column(name = "\"created_by\"", nullable = false) @Column(name = "\"created_by\"", nullable = false)
private UUID createdBy; private UUID createdById;
public static final String _createdBy = "createdBy"; public static final String _createdById = "createdById";
public UUID getId() { public UUID getId() {
return id; return id;
@ -80,11 +80,11 @@ public class TagEntity {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public UUID getCreatedBy() { public UUID getCreatedById() {
return createdBy; return createdById;
} }
public void setCreatedBy(UUID createdBy) { public void setCreatedById(UUID createdById) {
this.createdBy = createdBy; this.createdById = createdById;
} }
} }

View File

@ -0,0 +1,95 @@
package eu.eudat.data;
import eu.eudat.commons.enums.ContactInfoType;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.converters.enums.ContactInfoTypeConverter;
import eu.eudat.data.converters.enums.DescriptionStatusConverter;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserContactInfo\"")
public class UserContactInfoEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "\"user\"", nullable = false)
private UUID userId;
public static final String _userId = "userId";
@Column(name = "\"ordinal\"", nullable = false)
private Integer ordinal;
public static final String _ordinal = "ordinal";
@Column(name = "type", nullable = false)
@Convert(converter = ContactInfoTypeConverter.class)
private ContactInfoType type;
public static final String _type = "type";
@Column(name = "value", length = UserContactInfoEntity._valueLength, nullable = false)
private String value;
public static final int _valueLength = 512;
public static final String _value = "value";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public ContactInfoType getType() {
return type;
}
public void setType(ContactInfoType type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Integer getOrdinal() {
return ordinal;
}
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
}

View File

@ -0,0 +1,84 @@
package eu.eudat.data;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserCredential\"")
public class UserCredentialEntity implements DataEntity<UserCredentialEntity, UUID> {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public final static String _id = "id";
@Column(name = "\"user\"", columnDefinition = "uuid", nullable = false)
private UUID userId;
public final static String _userId = "userId";
@Column(name = "\"external_id\"", length = UserCredentialEntity._externalIdLength, nullable = false)
private String externalId;
public final static String _externalId = "externalId";
public final static int _externalIdLength = 512;
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
@Override
public void update(UserCredentialEntity entity) {
this.externalId = entity.getExternalId();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserCredentialEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -21,8 +21,8 @@ public class UserDescriptionTemplateEntity implements DataEntity<UserDescription
public static final String _id = "id"; public static final String _id = "id";
@Column(name = "\"user\"", nullable = false) @Column(name = "\"user\"", nullable = false)
private UUID user; private UUID userId;
public static final String _user = "user"; public static final String _userId = "userId";
@Column(name = "is_active", nullable = false) @Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class) @Convert(converter = IsActiveConverter.class)
@ -39,8 +39,8 @@ public class UserDescriptionTemplateEntity implements DataEntity<UserDescription
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@Column(name = "\"description_template\"", nullable = false) @Column(name = "\"description_template\"", nullable = false)
private UUID descriptionTemplate; private UUID descriptionTemplateId;
public static final String _descriptionTemplate = "descriptionTemplate"; public static final String _descriptionTemplateId = "descriptionTemplateId";
@Column(name = "role", nullable = false) @Column(name = "role", nullable = false)
@Convert(converter = UserDescriptionTemplateRoleConverter.class) @Convert(converter = UserDescriptionTemplateRoleConverter.class)
@ -55,12 +55,12 @@ public class UserDescriptionTemplateEntity implements DataEntity<UserDescription
this.id = id; this.id = id;
} }
public UUID getUser() { public UUID getUserId() {
return user; return userId;
} }
public void setUser(UUID user) { public void setUserId(UUID userId) {
this.user = user; this.userId = userId;
} }
public IsActive getIsActive() { public IsActive getIsActive() {
@ -87,12 +87,12 @@ public class UserDescriptionTemplateEntity implements DataEntity<UserDescription
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public UUID getDescriptionTemplate() { public UUID getDescriptionTemplateId() {
return descriptionTemplate; return descriptionTemplateId;
} }
public void setDescriptionTemplate(UUID descriptionTemplate) { public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplate = descriptionTemplate; this.descriptionTemplateId = descriptionTemplateId;
} }
public UserDescriptionTemplateRole getRole() { public UserDescriptionTemplateRole getRole() {

View File

@ -0,0 +1,116 @@
package eu.eudat.data;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.*;
@Entity
@Table(name = "\"User\"")
public class UserEntity implements DataEntity<UserEntity, UUID> {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public final static String _id = "id";
@Column(name = "name", length = UserEntity._nameLength, nullable = true)
private String name = null;
public final static String _name = "name";
public final static int _nameLength = 250;
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
@Column(name = "additional_info", nullable = true)
private String additionalInfo;
public final static String _additionalInfo = "additionalInfo";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdditionalInfo() {
return additionalInfo;
}
public void setAdditionalInfo(String additionalInfo) {
this.additionalInfo = additionalInfo;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
@Override
public void update(UserEntity entity) {
this.name = entity.getName();
this.additionalInfo = entity.getAdditionalInfo();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -0,0 +1,84 @@
package eu.eudat.data;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserRole\"")
public class UserRoleEntity implements DataEntity<UserRoleEntity, UUID> {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "role", length = UserRoleEntity._roleLength, nullable = false)
private String role;
public static final String _role = "role";
public static final int _roleLength = 512;
@Column(name = "user", nullable = false)
private UUID userId;
public static final String _userId = "userId";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
@Override
public void update(UserRoleEntity entity) {
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserRoleEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -0,0 +1,12 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.ContactInfoType;
import eu.eudat.commons.enums.DescriptionStatus;
import jakarta.persistence.Converter;
@Converter
public class ContactInfoTypeConverter extends DatabaseEnumConverter<ContactInfoType, Short>{
protected ContactInfoType of(Short i) {
return ContactInfoType.of(i);
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -44,7 +45,7 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"") @JoinColumn(name = "\"CreationUser\"")
private UserInfo creationUser; private UserEntity creationUser;
public Short getStatus() { public Short getStatus() {
@ -110,10 +111,10 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
this.definition = definition; this.definition = definition;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -37,7 +38,7 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
public UUID getId() { public UUID getId() {
@ -82,10 +83,10 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
this.modified = modified; this.modified = modified;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -43,7 +44,7 @@ public class FileUpload implements DataEntity<FileUpload, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"") @JoinColumn(name = "\"Creator\"")
private UserInfo creator; private UserEntity creator;
public UUID getId() { public UUID getId() {
return id; return id;
@ -94,10 +95,10 @@ public class FileUpload implements DataEntity<FileUpload, UUID> {
this.isDeleted = isDeleted; this.isDeleted = isDeleted;
} }
public UserInfo getCreator() { public UserEntity getCreator() {
return creator; return creator;
} }
public void setCreator(UserInfo creator) { public void setCreator(UserEntity creator) {
this.creator = creator; this.creator = creator;
} }
@ -121,7 +122,7 @@ public class FileUpload implements DataEntity<FileUpload, UUID> {
public FileUpload buildFromTuple(List<Tuple> tuple, List<String> fields, String base) { public FileUpload buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + "."; String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id"); if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0); this.creator = tuple.stream().map(x -> new UserEntity().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0);
return this; return this;
} }
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
@ -92,7 +93,7 @@ public class Funder implements DataEntity<Funder, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
public UUID getId() { public UUID getId() {
@ -151,10 +152,10 @@ public class Funder implements DataEntity<Funder, UUID> {
this.type = type; this.type = type;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -116,7 +117,7 @@ public class Grant implements DataEntity<Grant, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
private Date created = null; private Date created = null;
@ -236,10 +237,10 @@ public class Grant implements DataEntity<Grant, UUID> {
// this.dmps = dmps; // this.dmps = dmps;
// } // }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }
@ -292,7 +293,7 @@ public class Grant implements DataEntity<Grant, UUID> {
// if (fields.contains(currentBase + "dmps")) // if (fields.contains(currentBase + "dmps"))
// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); // this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
if (fields.contains(currentBase + "creationUser")) if (fields.contains(currentBase + "creationUser"))
this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0); this.creationUser = tuple.stream().map(x -> new UserEntity().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0);
return this; return this;
} }
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -22,7 +23,7 @@ public class Invitation implements DataEntity<Invitation, UUID> {
@OneToOne(fetch = FetchType.EAGER) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"CreationUser\"", nullable = false) @JoinColumn(name = "\"CreationUser\"", nullable = false)
private UserInfo user; private UserEntity user;
// @OneToOne(fetch = FetchType.EAGER) // @OneToOne(fetch = FetchType.EAGER)
// @JoinColumn(name = "\"Dmp\"", nullable = false) // @JoinColumn(name = "\"Dmp\"", nullable = false)
@ -53,11 +54,11 @@ public class Invitation implements DataEntity<Invitation, UUID> {
this.invitationEmail = invitationEmail; this.invitationEmail = invitationEmail;
} }
public UserInfo getUser() { public UserEntity getUser() {
return user; return user;
} }
public void setUser(UserInfo user) { public void setUser(UserEntity user) {
this.user = user; this.user = user;
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -23,7 +24,7 @@ public class Lock implements DataEntity<Lock, UUID> {
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"LockedBy\"", nullable = false) @JoinColumn(name = "\"LockedBy\"", nullable = false)
private UserInfo lockedBy; private UserEntity lockedBy;
@Column(name = "\"LockedAt\"") @Column(name = "\"LockedAt\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
@ -50,11 +51,11 @@ public class Lock implements DataEntity<Lock, UUID> {
this.target = target; this.target = target;
} }
public UserInfo getLockedBy() { public UserEntity getLockedBy() {
return lockedBy; return lockedBy;
} }
public void setLockedBy(UserInfo lockedBy) { public void setLockedBy(UserEntity lockedBy) {
this.lockedBy = lockedBy; this.lockedBy = lockedBy;
} }

View File

@ -4,6 +4,7 @@ import eu.eudat.commons.enums.old.notification.ActiveStatus;
import eu.eudat.commons.enums.old.notification.ContactType; import eu.eudat.commons.enums.old.notification.ContactType;
import eu.eudat.commons.enums.old.notification.NotificationType; import eu.eudat.commons.enums.old.notification.NotificationType;
import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.commons.enums.old.notification.NotifyState;
import eu.eudat.data.UserEntity;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
@ -22,7 +23,7 @@ public class Notification implements DataEntity<Notification, UUID> {
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"UserId\"") @JoinColumn(name = "\"UserId\"")
private UserInfo userId; private UserEntity userId;
@Enumerated @Enumerated
@Column(name = "\"IsActive\"", nullable = false) @Column(name = "\"IsActive\"", nullable = false)
@ -67,11 +68,11 @@ public class Notification implements DataEntity<Notification, UUID> {
this.id = id; this.id = id;
} }
public UserInfo getUserId() { public UserEntity getUserId() {
return userId; return userId;
} }
public void setUserId(UserInfo userId) { public void setUserId(UserEntity userId) {
this.userId = userId; this.userId = userId;
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -101,7 +102,7 @@ public class Project implements DataEntity<Project, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
private Date created = null; private Date created = null;
@ -194,10 +195,10 @@ public class Project implements DataEntity<Project, UUID> {
this.status = status; this.status = status;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }
@ -282,7 +283,7 @@ public class Project implements DataEntity<Project, UUID> {
// if (fields.contains(currentBase + "dmps")) // if (fields.contains(currentBase + "dmps"))
// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); // this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
if (fields.contains(currentBase + "creationUser")) if (fields.contains(currentBase + "creationUser"))
this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0); this.creationUser = tuple.stream().map(x -> new UserEntity().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0);
return this; return this;
} }
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.old;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -52,7 +53,7 @@ public class Registry implements DataEntity<Registry, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
public Short getStatus() { public Short getStatus() {
@ -125,10 +126,10 @@ public class Registry implements DataEntity<Registry, UUID> {
this.descriptionEntities = descriptionEntities; this.descriptionEntities = descriptionEntities;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -8,7 +9,6 @@ import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -58,7 +58,7 @@ public class Researcher implements DataEntity<Researcher, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
public Short getStatus() { public Short getStatus() {
return status; return status;
@ -130,10 +130,10 @@ public class Researcher implements DataEntity<Researcher, UUID> {
// this.dMPs = dMPs; // this.dMPs = dMPs;
// } // }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.old; package eu.eudat.data.old;
import eu.eudat.data.UserEntity;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.queryableentity.DataEntity; import eu.eudat.data.old.queryableentity.DataEntity;
@ -46,7 +47,7 @@ public class Service implements DataEntity<Service, UUID> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserEntity creationUser;
public Short getStatus() { public Short getStatus() {
@ -112,10 +113,10 @@ public class Service implements DataEntity<Service, UUID> {
this.definition = definition; this.definition = definition;
} }
public UserInfo getCreationUser() { public UserEntity getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserEntity creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -1,230 +0,0 @@
package eu.eudat.data.old;
import eu.eudat.data.CredentialEntity;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.*;
@Entity
@Table(name = "\"UserInfo\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "userInfo",
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("additionalinfo")}),
})
public class UserInfo implements DataEntity<UserInfo, UUID> {
@Id
@GeneratedValue
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
public final static String _id = "id";
@Column(name = "email")
private String email = null;
public final static String _email = "email";
@Column(name = "authorization_level", nullable = false)
private Short authorization_level; //0 admin, 1 user
public final static String _authorization_level = "authorization_level";
@Column(name = "usertype", nullable = false)
private Short usertype; // 0 internal, 1 external
public final static String _usertype = "usertype";
@Column(name = "userstatus", nullable = false)
private Short userStatus; // 0 active, 1 inactive
public final static String _userStatus = "userStatus";
@Column(name = "verified_email", nullable = true)
private Boolean verified_email = null;
public final static String _verified_email = "verified_email";
@Column(name = "name", nullable = true)
private String name = null;
public final static String _name = "name";
@Column(name = "created", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date created = null;
public final static String _created = "created";
@Column(name = "lastloggedin", nullable = true)
@Convert(converter = DateToUTCConverter.class)
private Date lastloggedin = null;
public final static String _lastloggedin = "lastloggedin";
@Column(name = "additionalinfo", nullable = true)
private String additionalinfo;
public final static String _additionalinfo = "additionalinfo";
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"UserDMP\"",
// joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")},
// inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}
// )
// private Set<DMP> dmps;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "Id")
private Set<CredentialEntity> credentialEntities = new HashSet<>();
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
private Set<UserRole> userRoles = new HashSet<>();
@OneToMany(mappedBy = "lockedBy", fetch = FetchType.LAZY)
private Set<Lock> locks = new HashSet<>();
@OneToMany(mappedBy = "userId", fetch = FetchType.LAZY)
private Set<Notification> notifications = new HashSet<>();
// public Set<DMP> getDmps() {
// return dmps;
// }
//
// public void setDmps(Set<DMP> dmps) {
// this.dmps = dmps;
// }
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getLastloggedin() {
return lastloggedin;
}
public void setLastloggedin(Date lastloggedin) {
this.lastloggedin = lastloggedin;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Short getAuthorization_level() {
return authorization_level;
}
public void setAuthorization_level(Short authorization_level) {
this.authorization_level = authorization_level;
}
public Short getUsertype() {
return usertype;
}
public void setUsertype(Short usertype) {
this.usertype = usertype;
}
public Boolean getVerified_email() {
return verified_email;
}
public void setVerified_email(Boolean verified_email) {
this.verified_email = verified_email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdditionalinfo() {
return additionalinfo;
}
public void setAdditionalinfo(String additionalinfo) {
this.additionalinfo = additionalinfo;
}
public Set<CredentialEntity> getCredentials() {
return credentialEntities;
}
public void setCredentials(Set<CredentialEntity> credentialEntities) {
this.credentialEntities = credentialEntities;
}
public Set<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
public Set<Lock> getLocks() {
return locks;
}
public void setLocks(Set<Lock> locks) {
this.locks = locks;
}
public Set<Notification> getNotifications() {
return notifications;
}
public void setNotifications(Set<Notification> notifications) {
this.notifications = notifications;
}
public Short getUserStatus() {
return userStatus;
}
public void setUserStatus(Short userStatus) {
this.userStatus = userStatus;
}
@Override
public void update(UserInfo entity) {
this.name = entity.getName();
this.email = entity.getEmail();
this.additionalinfo = entity.getAdditionalinfo();
this.lastloggedin = entity.getLastloggedin();
this.userRoles = entity.getUserRoles();
this.userStatus = entity.getUserStatus();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserInfo buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -1,67 +0,0 @@
package eu.eudat.data.old;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserRole\"")
public class UserRole implements DataEntity<UserRole, UUID> {
@Id
@GeneratedValue
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Role\"", nullable = false)
private int role;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"UserId\"", nullable = false)
private UserInfo userInfo;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
@Override
public void update(UserRole entity) {
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserRole buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

View File

@ -58,7 +58,7 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
m.setStatus(d.getStatus()); m.setStatus(d.getStatus());
m.setAccessType(d.getAccessType()); m.setAccessType(d.getAccessType());
m.setLanguage(d.getLanguage()); m.setLanguage(d.getLanguage());
m.setBlueprintId(d.getBlueprint()); m.setBlueprintId(d.getBlueprintId());
m.setGroupId(d.getGroupId()); m.setGroupId(d.getGroupId());
m.setFinalizedAt(Date.from(d.getFinalizedAt())); m.setFinalizedAt(Date.from(d.getFinalizedAt()));
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null)); if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));

View File

@ -36,7 +36,7 @@ public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder<NestedC
NestedCollaboratorElasticEntity m = new NestedCollaboratorElasticEntity(); NestedCollaboratorElasticEntity m = new NestedCollaboratorElasticEntity();
m.setId(d.getId()); m.setId(d.getId());
m.setRole(d.getRole()); m.setRole(d.getRole());
m.setName(d.getUser().toString()); //TODO: Get UserName m.setName(d.getUserId().toString()); //TODO: Get UserName
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -60,7 +60,7 @@ public class NestedDmpElasticBuilder extends BaseElasticBuilder<NestedDmpElastic
m.setStatus(d.getStatus()); m.setStatus(d.getStatus());
m.setAccessType(d.getAccessType()); m.setAccessType(d.getAccessType());
m.setLanguage(d.getLanguage()); m.setLanguage(d.getLanguage());
m.setBlueprintId(d.getBlueprint()); m.setBlueprintId(d.getBlueprintId());
m.setGroupId(d.getGroupId()); m.setGroupId(d.getGroupId());
m.setGroupId(d.getGroupId()); m.setGroupId(d.getGroupId());
m.setVersionStatus(d.getVersionStatus()); m.setVersionStatus(d.getVersionStatus());

View File

@ -6,15 +6,11 @@ public class UserTouchedEvent {
public UserTouchedEvent() { public UserTouchedEvent() {
} }
public UserTouchedEvent(UUID userId, String subjectId, String previousSubjectId) { public UserTouchedEvent(UUID userId) {
this.userId = userId; this.userId = userId;
this.subjectId = subjectId;
this.previousSubjectId = previousSubjectId;
} }
private UUID userId; private UUID userId;
private String subjectId;
private String previousSubjectId;
public UUID getUserId() { public UUID getUserId() {
return userId; return userId;
@ -23,20 +19,4 @@ public class UserTouchedEvent {
public void setUserId(UUID userId) { public void setUserId(UUID userId) {
this.userId = userId; this.userId = userId;
} }
public String getSubjectId() {
return subjectId;
}
public void setSubjectId(String subjectId) {
this.subjectId = subjectId;
}
public String getPreviousSubjectId() {
return previousSubjectId;
}
public void setPreviousSubjectId(String previousSubjectId) {
this.previousSubjectId = previousSubjectId;
}
} }

View File

@ -31,7 +31,7 @@ public class Description {
public static final String _description = "description"; public static final String _description = "description";
private UUID createdBy; private User createdBy;
public static final String _createdBy = "createdBy"; public static final String _createdBy = "createdBy";
@ -112,11 +112,11 @@ public class Description {
this.description = description; this.description = description;
} }
public UUID getCreatedBy() { public User getCreatedBy() {
return createdBy; return createdBy;
} }
public void setCreatedBy(UUID createdBy) { public void setCreatedBy(User createdBy) {
this.createdBy = createdBy; this.createdBy = createdBy;
} }

View File

@ -31,6 +31,10 @@ public class DescriptionReference {
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -79,4 +83,11 @@ public class DescriptionReference {
this.isActive = isActive; this.isActive = isActive;
} }
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -31,6 +31,10 @@ public class DescriptionTag {
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -79,4 +83,11 @@ public class DescriptionTag {
this.isActive = isActive; this.isActive = isActive;
} }
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -63,7 +63,7 @@ public class Dmp {
public static final String _publishedAt = "publishedAt"; public static final String _publishedAt = "publishedAt";
private UUID creator; private User creator;
public static final String _creator = "creator"; public static final String _creator = "creator";
@ -71,7 +71,7 @@ public class Dmp {
public static final String _accessType = "accessType"; public static final String _accessType = "accessType";
private UUID blueprint; private DmpBlueprint blueprint;
public static final String _blueprint = "blueprint"; public static final String _blueprint = "blueprint";
@ -191,11 +191,11 @@ public class Dmp {
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public UUID getCreator() { public User getCreator() {
return creator; return creator;
} }
public void setCreator(UUID creator) { public void setCreator(User creator) {
this.creator = creator; this.creator = creator;
} }
@ -207,11 +207,11 @@ public class Dmp {
this.accessType = accessType; this.accessType = accessType;
} }
public UUID getBlueprint() { public DmpBlueprint getBlueprint() {
return blueprint; return blueprint;
} }
public void setBlueprint(UUID blueprint) { public void setBlueprint(DmpBlueprint blueprint) {
this.blueprint = blueprint; this.blueprint = blueprint;
} }

View File

@ -37,6 +37,9 @@ public class DmpDescriptionTemplate{
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
public final static String _hash = "hash";
private String hash;
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -92,4 +95,12 @@ public class DmpDescriptionTemplate{
public void setIsActive(IsActive isActive) { public void setIsActive(IsActive isActive) {
this.isActive = isActive; this.isActive = isActive;
} }
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -24,6 +24,9 @@ public class DmpReference {
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
public final static String _hash = "hash";
private String hash;
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -63,4 +66,12 @@ public class DmpReference {
public Instant getUpdatedAt() {return updatedAt;} public Instant getUpdatedAt() {return updatedAt;}
public void setUpdatedAt(Instant updatedAt) {this.updatedAt = updatedAt;} public void setUpdatedAt(Instant updatedAt) {this.updatedAt = updatedAt;}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -3,7 +3,7 @@ package eu.eudat.model;
import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.UserInfo; import eu.eudat.data.UserEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.time.Instant; import java.time.Instant;
@ -19,30 +19,27 @@ public class DmpUser {
public static final String _dmp = "dmp"; public static final String _dmp = "dmp";
@Column(name = "user", columnDefinition = "uuid", nullable = false) private User user;
private UserInfo user;
public static final String _user = "user"; public static final String _user = "user";
@Enumerated(EnumType.STRING) private String hash;
@Column(name = "status", nullable = false) public final static String _hash = "hash";
private DmpUserRole role; private DmpUserRole role;
public static final String _role = "role"; public static final String _role = "role";
@Column(name = "created_at", nullable = false)
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false)
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive; private IsActive isActive;
public static final String _isActive = "isActive";
public UUID getId() { public UUID getId() {
return id; return id;
@ -60,11 +57,11 @@ public class DmpUser {
this.dmp = dmp; this.dmp = dmp;
} }
public UserInfo getUser() { public User getUser() {
return user; return user;
} }
public void setUser(UserInfo user) { public void setUser(User user) {
this.user = user; this.user = user;
} }
@ -100,4 +97,11 @@ public class DmpUser {
this.isActive = isActive; this.isActive = isActive;
} }
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -14,7 +14,7 @@ public class PublicDmpUser {
public static final String _user = "user"; public static final String _user = "user";
private PublicUserInfo user; private PublicUser user;
public static final String _role = "role"; public static final String _role = "role";
@ -36,11 +36,11 @@ public class PublicDmpUser {
this.dmp = dmp; this.dmp = dmp;
} }
public PublicUserInfo getUser() { public PublicUser getUser() {
return user; return user;
} }
public void setUser(PublicUserInfo user) { public void setUser(PublicUser user) {
this.user = user; this.user = user;
} }

View File

@ -0,0 +1,29 @@
package eu.eudat.model;
import java.util.UUID;
public class PublicUser {
public final static String _id = "id";
private UUID id;
public final static String _name = "name";
private String name = null;
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;
}
}

View File

@ -1,29 +0,0 @@
package eu.eudat.model;
import java.util.UUID;
public class PublicUserInfo {
public final static String _id = "id";
private UUID id;
public final static String _name = "name";
private String name = null;
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;
}
}

View File

@ -47,12 +47,15 @@ public class Reference {
private Instant updatedAt; private Instant updatedAt;
public static final String _updatedAt = "updatedAt"; public static final String _updatedAt = "updatedAt";
//private UserInfo createdBy; ToDo private User createdBy;
//public static final String _createdBy = "createdBy"; public static final String _createdBy = "createdBy";
private List<DmpReference> dmpReferences; private List<DmpReference> dmpReferences;
public static final String _dmpReferences = "dmpReferences"; public static final String _dmpReferences = "dmpReferences";
private String hash;
public final static String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -156,4 +159,20 @@ public class Reference {
public void setDmpReferences(List<DmpReference> dmpReferences) { public void setDmpReferences(List<DmpReference> dmpReferences) {
this.dmpReferences = dmpReferences; this.dmpReferences = dmpReferences;
} }
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -30,6 +30,9 @@ public class SupportiveMaterial {
private IsActive isActive; private IsActive isActive;
public static final String _isActive = "isActive"; public static final String _isActive = "isActive";
private String hash;
public final static String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -85,4 +88,12 @@ public class SupportiveMaterial {
public void setIsActive(IsActive isActive) { public void setIsActive(IsActive isActive) {
this.isActive = isActive; this.isActive = isActive;
} }
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
} }

View File

@ -17,7 +17,7 @@ public class Tag {
public static final String _label = "label"; public static final String _label = "label";
private UUID createdBy; private User createdBy;
public static final String _createdBy = "createdBy"; public static final String _createdBy = "createdBy";
@ -53,11 +53,11 @@ public class Tag {
this.label = label; this.label = label;
} }
public UUID getCreatedBy() { public User getCreatedBy() {
return createdBy; return createdBy;
} }
public void setCreatedBy(UUID createdBy) { public void setCreatedBy(User createdBy) {
this.createdBy = createdBy; this.createdBy = createdBy;
} }

View File

@ -0,0 +1,129 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.UserSettingsType;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class User {
private UUID id;
public static final String _id = "id";
private String name;
public static final String _name = "name";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private IsActive isActive;
public static final String _isActive = "isActive";
private String hash;
public static final String _hash = "hash";
private UserAdditionalInfo additionalInfo;
public static final String _additionalInfo = "additionalInfo";
private List<UserContactInfo> contacts;
public static final String _contacts = "contacts";
private List<UserRole> roles;
public static final String _roles = "roles";
private List<UserCredential> credentials;
public static final String _credentials = "credentials";
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 Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public UserAdditionalInfo getAdditionalInfo() {
return additionalInfo;
}
public void setAdditionalInfo(UserAdditionalInfo additionalInfo) {
this.additionalInfo = additionalInfo;
}
public List<UserContactInfo> getContacts() {
return contacts;
}
public void setContacts(List<UserContactInfo> contacts) {
this.contacts = contacts;
}
public List<UserRole> getRoles() {
return roles;
}
public void setRoles(List<UserRole> roles) {
this.roles = roles;
}
public List<UserCredential> getCredentials() {
return credentials;
}
public void setCredentials(List<UserCredential> credentials) {
this.credentials = credentials;
}
}

View File

@ -0,0 +1,74 @@
package eu.eudat.model;
import eu.eudat.commons.enums.ContactInfoType;
import java.time.Instant;
import java.util.UUID;
public class UserAdditionalInfo {
private String avatarUrl;
public static final String _avatarUrl = "avatarUrl";
private String timezone;
public static final String _timezone = "timezone";
private String culture;
public static final String _culture = "culture";
private String language;
public static final String _language = "language";
private String roleOrganization;
public static final String _roleOrganization = "roleOrganization";
private Reference organization;
public static final String _organization = "organization";
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
public Reference getOrganization() {
return organization;
}
public void setOrganization(Reference organization) {
this.organization = organization;
}
}

View File

@ -0,0 +1,75 @@
package eu.eudat.model;
import eu.eudat.commons.enums.ContactInfoType;
import java.time.Instant;
import java.util.UUID;
public class UserContactInfo {
private UUID id;
public static final String _id = "id";
private String value;
public static final String _value = "value";
private ContactInfoType type;
public static final String _type = "type";
private int ordinal;
public static final String _ordinal = "ordinal";
private User user;
public static final String _user = "user";
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public ContactInfoType getType() {
return type;
}
public void setType(ContactInfoType type) {
this.type = type;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
}

View File

@ -0,0 +1,51 @@
package eu.eudat.model;
import java.time.Instant;
import java.util.UUID;
public class UserCredential {
private UUID id;
public static final String _id = "id";
private String externalId;
public static final String _externalId = "externalId";
private User user;
public static final String _user = "user";
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
}

View File

@ -15,9 +15,13 @@ public class UserDescriptionTemplate {
public final static String _descriptionTemplate = "descriptionTemplate"; public final static String _descriptionTemplate = "descriptionTemplate";
private DescriptionTemplate descriptionTemplate; private DescriptionTemplate descriptionTemplate;
public final static String _role = "role"; public final static String _role = "role";
private UserDescriptionTemplateRole role; private UserDescriptionTemplateRole role;
public final static String _user = "user";
private User user;
public final static String _createdAt = "createdAt"; public final static String _createdAt = "createdAt";
private Instant createdAt; private Instant createdAt;
@ -85,4 +89,12 @@ public class UserDescriptionTemplate {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
} }

View File

@ -0,0 +1,52 @@
package eu.eudat.model;
import java.time.Instant;
import java.util.UUID;
public class UserRole {
private UUID id;
public static final String _id = "id";
private String role;
public static final String _role = "role";
private User user;
public static final String _user = "user";
private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
}

View File

@ -3,9 +3,9 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.types.description.PropertyDefinitionEntity; import eu.eudat.commons.types.description.PropertyDefinitionEntity;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.UserRoleEntity;
import eu.eudat.model.*; import eu.eudat.model.*;
import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder; import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder;
import eu.eudat.query.*; import eu.eudat.query.*;
@ -71,6 +71,9 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
FieldSet descriptionTagsFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTags)); FieldSet descriptionTagsFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTags));
Map<UUID, List<DescriptionTag>> descriptionTagsMap = this.collectDescriptionTags(descriptionTagsFields, data); Map<UUID, List<DescriptionTag>> descriptionTagsMap = this.collectDescriptionTags(descriptionTagsFields, data);
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Description._createdBy));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(Description._properties)); FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(Description._properties));
List<Description> models = new ArrayList<>(); List<Description> models = new ArrayList<>();
for (DescriptionEntity d : data) { for (DescriptionEntity d : data) {
@ -79,7 +82,6 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
if (fields.hasField(this.asIndexer(Description._label))) m.setLabel(d.getLabel()); if (fields.hasField(this.asIndexer(Description._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(Description._status))) m.setStatus(d.getStatus()); if (fields.hasField(this.asIndexer(Description._status))) m.setStatus(d.getStatus());
if (fields.hasField(this.asIndexer(Description._description))) m.setDescription(d.getDescription()); if (fields.hasField(this.asIndexer(Description._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(Description._createdBy))) m.setCreatedBy(d.getCreatedById());
if (fields.hasField(this.asIndexer(Description._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(Description._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Description._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(Description._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Description._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(Description._isActive))) m.setIsActive(d.getIsActive());
@ -89,6 +91,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpDescriptionTemplateId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId())); if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpDescriptionTemplateId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId()));
if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) m.setDescriptionReferences(descriptionReferencesMap.get(d.getId())); if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) m.setDescriptionReferences(descriptionReferencesMap.get(d.getId()));
if (!descriptionTagsFields.isEmpty() && descriptionTagsMap != null && descriptionTagsMap.containsKey(d.getId())) m.setDescriptionTags(descriptionTagsMap.get(d.getId())); if (!descriptionTagsFields.isEmpty() && descriptionTagsMap != null && descriptionTagsMap.containsKey(d.getId())) m.setDescriptionTags(descriptionTagsMap.get(d.getId()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
if (!definitionPropertiesFields.isEmpty() && d.getProperties() != null){ if (!definitionPropertiesFields.isEmpty() && d.getProperties() != null){
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
m.setProperties(this.builderFactory.builder(PropertyDefinitionBuilder.class).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition)); m.setProperties(this.builderFactory.builder(PropertyDefinitionBuilder.class).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition));
@ -101,6 +104,36 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
return models; return models;
} }
private Map<UUID, User> collectUsers(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(DescriptionEntity::getCreatedById).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getCreatedById).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, DmpDescriptionTemplate> collectDmpDescriptionTemplates(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException { private Map<UUID, DmpDescriptionTemplate> collectDmpDescriptionTemplates(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;

View File

@ -65,22 +65,13 @@ public class DescriptionReferenceBuilder extends BaseBuilder<DescriptionReferenc
for (DescriptionReferenceEntity d : data) { for (DescriptionReferenceEntity d : data) {
DescriptionReference m = new DescriptionReference(); DescriptionReference m = new DescriptionReference();
if (fields.hasField(this.asIndexer(DescriptionReference._id))) if (fields.hasField(this.asIndexer(DescriptionReference._id))) m.setId(d.getId());
m.setId(d.getId()); if (fields.hasField(this.asIndexer(DescriptionReference._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(DescriptionReference._createdAt))) if (fields.hasField(this.asIndexer(DescriptionReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(DescriptionReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (fields.hasField(this.asIndexer(DescriptionReference._updatedAt))) if (fields.hasField(this.asIndexer(DescriptionReference._isActive))) m.setIsActive(d.getIsActive());
m.setUpdatedAt(d.getUpdatedAt()); if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) m.setReference(referenceItemsMap.get(d.getReferenceId()));
if (fields.hasField(this.asIndexer(DescriptionReference._isActive))) if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) m.setDescription(descriptionItemsMap.get(d.getDescriptionId()));
m.setIsActive(d.getIsActive());
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) {
m.setReference(referenceItemsMap.get(d.getReferenceId()));
}
if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) {
m.setDescription(descriptionItemsMap.get(d.getDescriptionId()));
}
models.add(m); models.add(m);
} }

View File

@ -55,8 +55,8 @@ public class DescriptionTagBuilder extends BaseBuilder<DescriptionTag, Descripti
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._tag)); FieldSet tagFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._tag));
Map<UUID, Tag> referenceItemsMap = this.collectTags(referenceFields, data); Map<UUID, Tag> tagItemsMap = this.collectTags(tagFields, data);
FieldSet descriptionFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._description)); FieldSet descriptionFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._description));
Map<UUID, Description> descriptionItemsMap = this.collectDescriptions(descriptionFields, data); Map<UUID, Description> descriptionItemsMap = this.collectDescriptions(descriptionFields, data);
@ -69,7 +69,8 @@ public class DescriptionTagBuilder extends BaseBuilder<DescriptionTag, Descripti
if (fields.hasField(this.asIndexer(DescriptionTag._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(DescriptionTag._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(DescriptionTag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(DescriptionTag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DescriptionTag._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(DescriptionTag._isActive))) m.setIsActive(d.getIsActive());
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getTagId())) m.setTag(referenceItemsMap.get(d.getTagId())); if (fields.hasField(this.asIndexer(DescriptionTag._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!tagFields.isEmpty() && tagItemsMap != null && tagItemsMap.containsKey(d.getTagId())) m.setTag(tagItemsMap.get(d.getTagId()));
if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) m.setDescription(descriptionItemsMap.get(d.getDescriptionId())); if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) m.setDescription(descriptionItemsMap.get(d.getDescriptionId()));
models.add(m); models.add(m);

View File

@ -4,9 +4,10 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.model.*; import eu.eudat.model.*;
import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.query.DmpReferenceQuery; import eu.eudat.query.DmpReferenceQuery;
import eu.eudat.query.DmpUserQuery; import eu.eudat.query.DmpUserQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -62,6 +63,12 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet dmpUsersFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpUsers)); FieldSet dmpUsersFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpUsers));
Map<UUID, List<DmpUser>> dmpUsersMap = this.collectDmpUsers(dmpUsersFields, data); Map<UUID, List<DmpUser>> dmpUsersMap = this.collectDmpUsers(dmpUsersFields, data);
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Dmp._creator));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
FieldSet blueprintFields = fields.extractPrefixed(this.asPrefix(Dmp._blueprint));
Map<UUID, DmpBlueprint> blueprintItemsMap = this.collectDmpBlueprints(blueprintFields, data);
for (DmpEntity d : data) { for (DmpEntity d : data) {
Dmp m = new Dmp(); Dmp m = new Dmp();
if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId()); if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId());
@ -76,11 +83,12 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
if (fields.hasField(this.asIndexer(Dmp._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(Dmp._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Dmp._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt()); if (fields.hasField(this.asIndexer(Dmp._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt());
if (fields.hasField(this.asIndexer(Dmp._accessType))) m.setAccessType(d.getAccessType()); if (fields.hasField(this.asIndexer(Dmp._accessType))) m.setAccessType(d.getAccessType());
if (fields.hasField(this.asIndexer(Dmp._blueprint))) m.setBlueprint(d.getBlueprint());
if (fields.hasField(this.asIndexer(Dmp._language))) m.setLanguage(d.getLanguage()); if (fields.hasField(this.asIndexer(Dmp._language))) m.setLanguage(d.getLanguage());
if (fields.hasField(this.asIndexer(Dmp._versionStatus))) m.setVersionStatus(d.getVersionStatus()); if (fields.hasField(this.asIndexer(Dmp._versionStatus))) m.setVersionStatus(d.getVersionStatus());
if (fields.hasField(this.asIndexer(Dmp._publicAfter))) m.setPublicAfter(d.getPublicAfter()); if (fields.hasField(this.asIndexer(Dmp._publicAfter))) m.setPublicAfter(d.getPublicAfter());
if (fields.hasField(this.asIndexer(Dmp._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); if (fields.hasField(this.asIndexer(Dmp._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatorId())) m.setCreator(userItemsMap.get(d.getCreatorId()));
if (!blueprintFields.isEmpty() && blueprintItemsMap != null && blueprintItemsMap.containsKey(d.getBlueprintId())) m.setBlueprint(blueprintItemsMap.get(d.getBlueprintId()));
if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setDmpReferences(dmpReferencesMap.get(d.getId())); if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setDmpReferences(dmpReferencesMap.get(d.getId()));
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId())); if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
@ -108,6 +116,66 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
return itemMap; return itemMap;
} }
private Map<UUID, DmpBlueprint> collectDmpBlueprints(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DmpBlueprint.class.getSimpleName());
Map<UUID, DmpBlueprint> itemMap;
if (!fields.hasOtherField(this.asIndexer(DmpBlueprint._id))) {
itemMap = this.asEmpty(
data.stream().map(DmpEntity::getBlueprintId).distinct().collect(Collectors.toList()),
x -> {
DmpBlueprint item = new DmpBlueprint();
item.setId(x);
return item;
},
DmpBlueprint::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DmpBlueprint._id);
DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).authorize(this.authorize).ids(data.stream().map(DmpEntity::getBlueprintId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpBlueprint::getId);
}
if (!fields.hasField(DmpBlueprint._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, User> collectUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(DmpEntity::getCreatorId).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(DmpEntity::getCreatorId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, List<DmpUser>> collectDmpUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException { private Map<UUID, List<DmpUser>> collectDmpUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())

View File

@ -62,20 +62,13 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
List<DmpDescriptionTemplate> models = new ArrayList<>(); List<DmpDescriptionTemplate> models = new ArrayList<>();
for (DmpDescriptionTemplateEntity d : data) { for (DmpDescriptionTemplateEntity d : data) {
DmpDescriptionTemplate m = new DmpDescriptionTemplate(); DmpDescriptionTemplate m = new DmpDescriptionTemplate();
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._id))) if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._id))) m.setId(d.getId());
m.setId(d.getId()); if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._sectionId))) m.setSectionId(d.getSectionId());
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._sectionId))) if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._createdAt))) m.setCreatedAt(d.getCreatedAt());
m.setSectionId(d.getSectionId()); if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._createdAt))) if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
m.setCreatedAt(d.getCreatedAt()); if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(templateItemsMap.get(d.getDescriptionTemplateId()));
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._updatedAt))) if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
m.setUpdatedAt(d.getUpdatedAt());
if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplateId())) {
m.setDescriptionTemplate(templateItemsMap.get(d.getDescriptionTemplateId()));
}
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) {
m.setDmp(dmpItemsMap.get(d.getDmpId()));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
@ -64,20 +65,13 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
List<DmpReference> models = new ArrayList<>(); List<DmpReference> models = new ArrayList<>();
for (DmpReferenceEntity d : data) { for (DmpReferenceEntity d : data) {
DmpReference m = new DmpReference(); DmpReference m = new DmpReference();
if (fields.hasField(this.asIndexer(DmpReference._id))) if (fields.hasField(this.asIndexer(DmpReference._id))) m.setId(d.getId());
m.setId(d.getId()); if (fields.hasField(this.asIndexer(DmpReference._data))) m.setData(d.getData());
if (fields.hasField(this.asIndexer(DmpReference._data))) if (fields.hasField(this.asIndexer(DmpReference._createdAt))) m.setCreatedAt(d.getCreatedAt());
m.setData(d.getData()); if (fields.hasField(this.asIndexer(DmpReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DmpReference._createdAt))) if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
m.setCreatedAt(d.getCreatedAt()); if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) m.setReference(referenceItemsMap.get(d.getReferenceId()));
if (fields.hasField(this.asIndexer(DmpReference._updatedAt))) if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
m.setUpdatedAt(d.getUpdatedAt());
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) {
m.setReference(referenceItemsMap.get(d.getReferenceId()));
}
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) {
m.setDmp(dmpItemsMap.get(d.getDmpId()));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -2,12 +2,11 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpUserEntity; import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.UserInfo; import eu.eudat.model.*;
import eu.eudat.model.Dmp;
import eu.eudat.model.DmpUser;
import eu.eudat.model.Reference;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -55,62 +54,57 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(DmpUser._user));
Map<UUID, UserInfo> userItemsMap = this.collectUsers(userFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpUser._dmp)); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpUser._dmp));
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data); Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
FieldSet userFields = fields.extractPrefixed(this.asPrefix(DmpUser._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<DmpUser> models = new ArrayList<>(); List<DmpUser> models = new ArrayList<>();
for (DmpUserEntity d : data) { for (DmpUserEntity d : data) {
DmpUser m = new DmpUser(); DmpUser m = new DmpUser();
if (fields.hasField(this.asIndexer(DmpUser._id))) if (fields.hasField(this.asIndexer(DmpUser._id))) m.setId(d.getId());
m.setId(d.getId()); if (fields.hasField(this.asIndexer(DmpUser._role))) m.setRole(d.getRole());
if (fields.hasField(this.asIndexer(DmpUser._role))) if (fields.hasField(this.asIndexer(DmpUser._createdAt))) m.setCreatedAt(d.getCreatedAt());
m.setRole(d.getRole()); if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DmpUser._createdAt))) if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
m.setCreatedAt(d.getCreatedAt()); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp())) m.setDmp(dmpItemsMap.get(d.getDmp()));
m.setUpdatedAt(d.getUpdatedAt()); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUser())) {
m.setUser(userItemsMap.get(d.getUser()));
}
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp())) {
m.setDmp(dmpItemsMap.get(d.getDmp()));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
//TODO: Hookup user info when refactored private Map<UUID, User> collectUsers(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException {
private Map<UUID, UserInfo> collectUsers(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;
this.logger.debug("checking related - {}", UserInfo.class.getSimpleName()); this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, UserInfo> itemMap; Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer("id"))) { if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty( itemMap = this.asEmpty(
data.stream().map(DmpUserEntity::getUser).distinct().collect(Collectors.toList()), data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()),
x -> { x -> {
UserInfo item = new UserInfo(); User item = new User();
item.setId(x); item.setId(x);
return item; return item;
}, },
UserInfo::getId); User::getId);
} else { } else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure("id"); FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
// ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()));
// itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId); itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
} }
if (!fields.hasField(Reference._id)) { if (!fields.hasField(User._id)) {
// itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
} }
// return itemMap; return itemMap;
return new HashMap<>();
} }
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException { private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException {

View File

@ -3,11 +3,13 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpUserEntity; import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.UserInfo; import eu.eudat.data.UserRoleEntity;
import eu.eudat.model.PublicDmp; import eu.eudat.model.PublicDmp;
import eu.eudat.model.PublicDmpUser; import eu.eudat.model.PublicDmpUser;
import eu.eudat.model.PublicUserInfo; import eu.eudat.model.PublicUser;
import eu.eudat.model.User;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -56,7 +58,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
return new ArrayList<>(); return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(PublicDmpUser._user)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(PublicDmpUser._user));
Map<UUID, PublicUserInfo> userItemsMap = new HashMap<>(); //TODO Map<UUID, PublicUser> userItemsMap = this.collectUsers(userFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(PublicDmpUser._dmp)); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(PublicDmpUser._dmp));
Map<UUID, PublicDmp> dmpItemsMap = this.collectDmps(dmpFields, data); Map<UUID, PublicDmp> dmpItemsMap = this.collectDmps(dmpFields, data);
@ -66,7 +68,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
PublicDmpUser m = new PublicDmpUser(); PublicDmpUser m = new PublicDmpUser();
if (fields.hasField(this.asIndexer(PublicDmpUser._id))) m.setId(d.getId()); if (fields.hasField(this.asIndexer(PublicDmpUser._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(PublicDmpUser._role))) m.setRole(d.getRole()); if (fields.hasField(this.asIndexer(PublicDmpUser._role))) m.setRole(d.getRole());
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUser())) m.setUser(userItemsMap.get(d.getUser())); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp())) m.setDmp(dmpItemsMap.get(d.getDmp())); if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp())) m.setDmp(dmpItemsMap.get(d.getDmp()));
models.add(m); models.add(m);
} }
@ -74,6 +76,36 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
return models; return models;
} }
private Map<UUID, PublicUser> collectUsers(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, PublicUser> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()),
x -> {
PublicUser item = new PublicUser();
item.setId(x);
return item;
},
PublicUser::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PublicUserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicUser::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, PublicDmp> collectDmps(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException { private Map<UUID, PublicDmp> collectDmps(FieldSet fields, List<DmpUserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;

View File

@ -0,0 +1,57 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserEntity;
import eu.eudat.model.PublicUser;
import eu.eudat.model.User;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicUserBuilder extends BaseBuilder<PublicUser, UserEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public PublicUserBuilder(ConventionService conventionService
) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicUserBuilder.class)));
}
public PublicUserBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<PublicUser> build(FieldSet fields, List<UserEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<PublicUser> models = new ArrayList<>();
for (UserEntity d : data) {
PublicUser m = new PublicUser();
if (fields.hasField(this.asIndexer(User._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(User._name))) m.setName(d.getName());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -4,11 +4,14 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.User;
import eu.eudat.model.builder.referencedefinition.DefinitionBuilder; import eu.eudat.model.builder.referencedefinition.DefinitionBuilder;
import eu.eudat.query.DmpReferenceQuery; import eu.eudat.query.DmpReferenceQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -62,6 +65,9 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences)); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences));
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data); Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Reference._createdBy));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<Reference> models = new ArrayList<>(); List<Reference> models = new ArrayList<>();
for (ReferenceEntity d : data) { for (ReferenceEntity d : data) {
Reference m = new Reference(); Reference m = new Reference();
@ -70,6 +76,7 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
if (fields.hasField(this.asIndexer(Reference._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(Reference._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Reference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(Reference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Reference._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(Reference._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Reference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!definitionFields.isEmpty() && d.getDefinition() != null){ if (!definitionFields.isEmpty() && d.getDefinition() != null){
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition)); m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition));
@ -80,16 +87,44 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource()); if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource());
if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType()); if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType());
if (fields.hasField(this.asIndexer(Reference._type))) m.setType(d.getType()); if (fields.hasField(this.asIndexer(Reference._type))) m.setType(d.getType());
// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){ if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) m.setDmpReferences(dmpReferenceMap.get(d.getId()));
// //ToDo if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
// }
if (!dmpReferenceMap.isEmpty() && dmpReferenceMap != null && dmpReferenceMap.containsKey(d.getId())) m.setDmpReferences(dmpReferenceMap.get(d.getId()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, User> collectUsers(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(ReferenceEntity::getCreatedById).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(ReferenceEntity::getCreatedById).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException { private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null; if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());

View File

@ -4,10 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.data.SupportiveMaterialEntity; import eu.eudat.data.SupportiveMaterialEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.*;
import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference;
import eu.eudat.model.SupportiveMaterial;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.ReferenceQuery; import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
@ -65,6 +62,7 @@ public class SupportiveMaterialBuilder extends BaseBuilder<SupportiveMaterial, S
if (fields.hasField(this.asIndexer(SupportiveMaterial._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(SupportiveMaterial._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(SupportiveMaterial._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(SupportiveMaterial._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(SupportiveMaterial._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(SupportiveMaterial._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(SupportiveMaterial._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -4,7 +4,12 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.TagEntity; import eu.eudat.data.TagEntity;
import eu.eudat.model.Tag; import eu.eudat.model.Tag;
import eu.eudat.model.User;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -15,17 +20,23 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TagBuilder extends BaseBuilder<Tag, TagEntity>{ public class TagBuilder extends BaseBuilder<Tag, TagEntity>{
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public TagBuilder( public TagBuilder(
ConventionService conventionService) { ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TagBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(TagBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
} }
public TagBuilder authorize(EnumSet<AuthorizationFlags> values) { public TagBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -40,6 +51,9 @@ public class TagBuilder extends BaseBuilder<Tag, TagEntity>{
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Tag._createdBy));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<Tag> models = new ArrayList<>(); List<Tag> models = new ArrayList<>();
for (TagEntity d : data) { for (TagEntity d : data) {
Tag m = new Tag(); Tag m = new Tag();
@ -48,10 +62,40 @@ public class TagBuilder extends BaseBuilder<Tag, TagEntity>{
if (fields.hasField(this.asIndexer(Tag._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(Tag._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Tag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); if (fields.hasField(this.asIndexer(Tag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Tag._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(Tag._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Tag._createdBy))) m.setCreatedBy(d.getCreatedBy()); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, User> collectUsers(FieldSet fields, List<TagEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(TagEntity::getCreatedById).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(TagEntity::getCreatedById).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
} }

View File

@ -0,0 +1,109 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.user.AdditionalInfoEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference;
import eu.eudat.model.UserAdditionalInfo;
import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserAdditionalInfoBuilder extends BaseBuilder<UserAdditionalInfo, AdditionalInfoEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserAdditionalInfoBuilder(
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserAdditionalInfoBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public UserAdditionalInfoBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<UserAdditionalInfo> build(FieldSet fields, List<AdditionalInfoEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(DescriptionReference._reference));
Map<UUID, Reference> referenceItemsMap = this.collectReferences(referenceFields, data);
List<UserAdditionalInfo> models = new ArrayList<>();
for (AdditionalInfoEntity d : data) {
UserAdditionalInfo m = new UserAdditionalInfo();
if (fields.hasField(this.asIndexer(UserAdditionalInfo._language))) m.setLanguage(d.getLanguage());
if (fields.hasField(this.asIndexer(UserAdditionalInfo._culture))) m.setCulture(d.getCulture());
if (fields.hasField(this.asIndexer(UserAdditionalInfo._avatarUrl))) m.setAvatarUrl(d.getAvatarUrl());
if (fields.hasField(this.asIndexer(UserAdditionalInfo._timezone))) m.setTimezone(d.getTimezone());
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getOrganizationId())) m.setOrganization(referenceItemsMap.get(d.getOrganizationId()));
if (fields.hasField(this.asIndexer(UserAdditionalInfo._roleOrganization))) m.setRoleOrganization(d.getRoleOrganization());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, Reference> collectReferences(FieldSet fields, List<AdditionalInfoEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
Map<UUID, Reference> itemMap;
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
itemMap = this.asEmpty(
data.stream().map(AdditionalInfoEntity::getOrganizationId).filter(Objects::nonNull).distinct().collect(Collectors.toList()),
x -> {
Reference item = new Reference();
item.setId(x);
return item;
},
Reference::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(AdditionalInfoEntity::getOrganizationId).filter(Objects::nonNull).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
}
if (!fields.hasField(Reference._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -0,0 +1,149 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.types.user.AdditionalInfoEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserEntity;
import eu.eudat.model.*;
import eu.eudat.query.UserContactInfoQuery;
import eu.eudat.query.UserCredentialQuery;
import eu.eudat.query.UserRoleQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserBuilder extends BaseBuilder<User, UserEntity> {
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
private final JsonHandlingService jsonHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserBuilder(ConventionService conventionService,
QueryFactory queryFactory,
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
this.jsonHandlingService = jsonHandlingService;
}
public UserBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<User> build(FieldSet fields, List<UserEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<User> models = new ArrayList<>();
FieldSet contactsFields = fields.extractPrefixed(this.asPrefix(User._contacts));
Map<UUID, List<UserContactInfo>> contactsMap = this.collectUserContactInfos(contactsFields, data);
FieldSet rolesFields = fields.extractPrefixed(this.asPrefix(User._roles));
Map<UUID, List<UserRole>> rolesMap = this.collectUserRoles(rolesFields, data);
FieldSet credentialsFields = fields.extractPrefixed(this.asPrefix(User._credentials));
Map<UUID, List<UserCredential>> credentialsMap = this.collectUserCredentials(credentialsFields, data);
FieldSet additionalInfoFields = fields.extractPrefixed(this.asPrefix(User._additionalInfo));
for (UserEntity d : data) {
User m = new User();
if (fields.hasField(this.asIndexer(User._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(User._name))) m.setName(d.getName());
if (fields.hasField(this.asIndexer(User._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(User._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(User._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(User._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (contactsMap != null && !contactsFields.isEmpty() && contactsMap.containsKey(d.getId())) m.setContacts(contactsMap.get(d.getId()));
if (rolesMap != null && !rolesFields.isEmpty() && rolesMap.containsKey(d.getId())) m.setRoles(rolesMap.get(d.getId()));
if (credentialsMap != null && !credentialsFields.isEmpty() && credentialsMap.containsKey(d.getId())) m.setCredentials(credentialsMap.get(d.getId()));
if (!additionalInfoFields.isEmpty() && d.getAdditionalInfo() != null){
AdditionalInfoEntity definition = this.jsonHandlingService.fromJsonSafe(AdditionalInfoEntity.class, d.getAdditionalInfo());
m.setAdditionalInfo(this.builderFactory.builder(UserAdditionalInfoBuilder.class).authorize(this.authorize).build(additionalInfoFields, definition));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, List<UserContactInfo>> collectUserContactInfos(FieldSet fields, List<UserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", UserContactInfo.class.getSimpleName());
Map<UUID, List<UserContactInfo>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(UserContactInfo._user, User._id));
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).authorize(this.authorize).userIds(data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserContactInfoBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserContactInfo._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
x.getUser().setId(null);
});
}
return itemMap;
}
private Map<UUID, List<UserRole>> collectUserRoles(FieldSet fields, List<UserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", UserRole.class.getSimpleName());
Map<UUID, List<UserRole>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(UserRole._user, User._id));
UserRoleQuery query = this.queryFactory.query(UserRoleQuery.class).authorize(this.authorize).userIds(data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserRoleBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserRole._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
x.getUser().setId(null);
});
}
return itemMap;
}
private Map<UUID, List<UserCredential>> collectUserCredentials(FieldSet fields, List<UserEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", UserCredential.class.getSimpleName());
Map<UUID, List<UserCredential>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(UserCredential._user, User._id));
UserCredentialQuery query = this.queryFactory.query(UserCredentialQuery.class).authorize(this.authorize).userIds(data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserCredentialBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId());
if (!fields.hasField(this.asIndexer(UserCredential._user, User._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> {
x.getUser().setId(null);
});
}
return itemMap;
}
}

View File

@ -0,0 +1,111 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserContactInfoEntity;
import eu.eudat.model.Description;
import eu.eudat.model.User;
import eu.eudat.model.UserContactInfo;
import eu.eudat.model.User;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserContactInfoBuilder extends BaseBuilder<UserContactInfo, UserContactInfoEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserContactInfoBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserContactInfoBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public UserContactInfoBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<UserContactInfo> build(FieldSet fields, List<UserContactInfoEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserContactInfo._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<UserContactInfo> models = new ArrayList<>();
for (UserContactInfoEntity d : data) {
UserContactInfo m = new UserContactInfo();
if (fields.hasField(this.asIndexer(UserContactInfo._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(UserContactInfo._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(UserContactInfo._ordinal))) m.setOrdinal(d.getOrdinal());
if (fields.hasField(this.asIndexer(UserContactInfo._value))) m.setValue(d.getValue());
if (fields.hasField(this.asIndexer(UserContactInfo._type))) m.setType(d.getType());
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, User> collectUsers(FieldSet fields, List<UserContactInfoEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(UserContactInfoEntity::getUserId).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(UserContactInfoEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -0,0 +1,106 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserCredentialEntity;
import eu.eudat.model.User;
import eu.eudat.model.UserCredential;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserCredentialBuilder extends BaseBuilder<UserCredential, UserCredentialEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserCredentialBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public UserCredentialBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<UserCredential> build(FieldSet fields, List<UserCredentialEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserCredential._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<UserCredential> models = new ArrayList<>();
for (UserCredentialEntity d : data) {
UserCredential m = new UserCredential();
if (fields.hasField(this.asIndexer(UserCredential._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(UserCredential._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(UserCredential._externalId))) m.setExternalId(d.getExternalId());
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, User> collectUsers(FieldSet fields, List<UserCredentialEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(UserCredentialEntity::getUserId).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(UserCredentialEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -4,9 +4,12 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserDescriptionTemplateEntity; import eu.eudat.data.UserDescriptionTemplateEntity;
import eu.eudat.model.Description;
import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.User;
import eu.eudat.model.UserDescriptionTemplate; import eu.eudat.model.UserDescriptionTemplate;
import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -56,6 +59,8 @@ public class UserDescriptionTemplateBuilder extends BaseBuilder<UserDescriptionT
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(UserDescriptionTemplate._descriptionTemplate)); FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(UserDescriptionTemplate._descriptionTemplate));
Map<UUID, DescriptionTemplate> descriptionTemplateMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); Map<UUID, DescriptionTemplate> descriptionTemplateMap = this.collectDescriptionTemplates(descriptionTemplateFields, data);
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Description._createdBy));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<UserDescriptionTemplate> models = new ArrayList<>(); List<UserDescriptionTemplate> models = new ArrayList<>();
for (UserDescriptionTemplateEntity d : data) { for (UserDescriptionTemplateEntity d : data) {
@ -66,13 +71,44 @@ public class UserDescriptionTemplateBuilder extends BaseBuilder<UserDescriptionT
if (fields.hasField(this.asIndexer(UserDescriptionTemplate._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(UserDescriptionTemplate._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(UserDescriptionTemplate._role))) m.setRole(d.getRole()); if (fields.hasField(this.asIndexer(UserDescriptionTemplate._role))) m.setRole(d.getRole());
if (fields.hasField(this.asIndexer(UserDescriptionTemplate._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); if (fields.hasField(this.asIndexer(UserDescriptionTemplate._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!descriptionTemplateFields.isEmpty() && descriptionTemplateMap != null && descriptionTemplateMap.containsKey(d.getDescriptionTemplate())) m.setDescriptionTemplate(descriptionTemplateMap.get(d.getDescriptionTemplate())); if (!descriptionTemplateFields.isEmpty() && descriptionTemplateMap != null && descriptionTemplateMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplateMap.get(d.getDescriptionTemplateId()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, User> collectUsers(FieldSet fields, List<UserDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(UserDescriptionTemplateEntity::getUserId).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(UserDescriptionTemplateEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, DescriptionTemplate> collectDescriptionTemplates(FieldSet fields, List<UserDescriptionTemplateEntity> data) throws MyApplicationException { private Map<UUID, DescriptionTemplate> collectDescriptionTemplates(FieldSet fields, List<UserDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null; if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
@ -80,7 +116,7 @@ public class UserDescriptionTemplateBuilder extends BaseBuilder<UserDescriptionT
Map<UUID, DescriptionTemplate> itemMap = null; Map<UUID, DescriptionTemplate> itemMap = null;
if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) { if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) {
itemMap = this.asEmpty( itemMap = this.asEmpty(
data.stream().map(UserDescriptionTemplateEntity::getDescriptionTemplate).distinct().collect(Collectors.toList()), data.stream().map(UserDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()),
x -> { x -> {
DescriptionTemplate item = new DescriptionTemplate(); DescriptionTemplate item = new DescriptionTemplate();
item.setId(x); item.setId(x);
@ -89,7 +125,7 @@ public class UserDescriptionTemplateBuilder extends BaseBuilder<UserDescriptionT
x -> x.getId()); x -> x.getId());
} else { } else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).ids(data.stream().map(UserDescriptionTemplateEntity::getDescriptionTemplate).distinct().collect(Collectors.toList())); DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).ids(data.stream().map(UserDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).asForeignKey(q, clone, DescriptionTemplate::getId); itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).asForeignKey(q, clone, DescriptionTemplate::getId);
} }
if (!fields.hasField(DescriptionTemplate._id)) { if (!fields.hasField(DescriptionTemplate._id)) {

View File

@ -0,0 +1,106 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.UserRoleEntity;
import eu.eudat.model.User;
import eu.eudat.model.UserRole;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
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.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserRoleBuilder extends BaseBuilder<UserRole, UserRoleEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserRoleBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserRoleBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public UserRoleBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<UserRole> build(FieldSet fields, List<UserRoleEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserRole._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
List<UserRole> models = new ArrayList<>();
for (UserRoleEntity d : data) {
UserRole m = new UserRole();
if (fields.hasField(this.asIndexer(UserRole._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(UserRole._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(UserRole._role))) m.setRole(d.getRole());
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, User> collectUsers(FieldSet fields, List<UserRoleEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) {
itemMap = this.asEmpty(
data.stream().map(UserRoleEntity::getUserId).distinct().collect(Collectors.toList()),
x -> {
User item = new User();
item.setId(x);
return item;
},
User::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().map(UserRoleEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId);
}
if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -54,9 +54,8 @@ public class DescriptionCensor extends BaseCensor {
FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix(Description._properties)); FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix(Description._properties));
this.censorFactory.censor(PropertyDefinitionCensor.class).censor(propertiesFields, userId); this.censorFactory.censor(PropertyDefinitionCensor.class).censor(propertiesFields, userId);
//ToDo FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Description._createdBy));
// FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Description._createdBy)); this.censorFactory.censor(UserCensor.class).censor(createdByFields, userId);
// this.censorFactory.censor(UserInfo.class).censor(createdByFields, userId);
} }
} }

View File

@ -44,6 +44,8 @@ public class DmpCensor extends BaseCensor {
this.censorFactory.censor(DmpUserCensor.class).censor(dmpUsersFields, userId); this.censorFactory.censor(DmpUserCensor.class).censor(dmpUsersFields, userId);
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences)); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences));
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId);
FieldSet creatorFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._creator));
this.censorFactory.censor(UserCensor.class).censor(creatorFields, userId);
} }
} }

View File

@ -40,6 +40,8 @@ public class DmpUserCensor extends BaseCensor {
this.authService.authorizeForce(Permission.BrowseDmpUser); this.authService.authorizeForce(Permission.BrowseDmpUser);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpUser._dmp)); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpUser._dmp));
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(DmpUser._user));
this.censorFactory.censor(UserCensor.class).censor(userFields, userId);
} }
} }

View File

@ -2,7 +2,6 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.DmpUser;
import eu.eudat.model.PublicDmpUser; import eu.eudat.model.PublicDmpUser;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.data.censor.CensorFactory;
@ -14,8 +13,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.UUID;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicDmpUserCensor extends BaseCensor { public class PublicDmpUserCensor extends BaseCensor {
@ -40,7 +37,7 @@ public class PublicDmpUserCensor extends BaseCensor {
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpUser._dmp)); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpUser._dmp));
this.censorFactory.censor(PublicDmpCensor.class).censor(dmpFields); this.censorFactory.censor(PublicDmpCensor.class).censor(dmpFields);
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpUser._user)); FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpUser._user));
this.censorFactory.censor(PublicUserInfoCensor.class).censor(userFields); this.censorFactory.censor(PublicUserCensor.class).censor(userFields);
} }
} }

View File

@ -0,0 +1,40 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicUserCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PublicUserCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public PublicUserCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.PublicBrowseUser);
}
}

View File

@ -1,42 +0,0 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicUserInfoCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PublicUserInfoCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public PublicUserInfoCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.PublicBrowseUser);
}
}

View File

@ -43,9 +43,8 @@ public class ReferenceCensor extends BaseCensor {
this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId); this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId);
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._dmpReferences)); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._dmpReferences));
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId);
//ToDo FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._createdBy));
//FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._createdBy)); this.censorFactory.censor(UserCensor.class).censor(createdByFields, userId);
//this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId);
} }
} }

View File

@ -40,9 +40,8 @@ public class TagCensor extends BaseCensor {
return; return;
this.authService.authorizeForce(Permission.BrowseTag); this.authService.authorizeForce(Permission.BrowseTag);
//ToDo FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Tag._createdBy));
// FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Tag._createdBy)); this.censorFactory.censor(UserCensor.class).censor(createdByFields, userId);
// this.censorFactory.censor(UserInfo.class).censor(createdByFields, userId);
} }
} }

View File

@ -0,0 +1,42 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.UserAdditionalInfo;
import eu.eudat.model.UserContactInfo;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserAdditionalInfoCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserAdditionalInfoCensor.class));
protected final AuthorizationService authService;
public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
}
}

View File

@ -0,0 +1,58 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.Description;
import eu.eudat.model.User;
import eu.eudat.model.UserContactInfo;
import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public UserCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
FieldSet rolesFields = fields.extractPrefixed(this.asIndexerPrefix(User._roles));
this.censorFactory.censor(UserRoleCensor.class).censor(rolesFields, userId);
FieldSet contactsFields = fields.extractPrefixed(this.asIndexerPrefix(User._contacts));
this.censorFactory.censor(UserContactInfoCensor.class).censor(contactsFields, userId);
FieldSet credentialsFields = fields.extractPrefixed(this.asIndexerPrefix(User._credentials));
this.censorFactory.censor(UserCredentialCensor.class).censor(credentialsFields, userId);
FieldSet additionalInfoFields = fields.extractPrefixed(this.asIndexerPrefix(User._additionalInfo));
this.censorFactory.censor(UserAdditionalInfoCensor.class).censor(additionalInfoFields, userId);
}
}

View File

@ -0,0 +1,46 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.UserContactInfo;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserContactInfoCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public UserContactInfoCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserContactInfo._user));
this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId);
}
}

View File

@ -0,0 +1,46 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.UserCredential;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserCredentialCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCredentialCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public UserCredentialCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._user));
this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId);
}
}

View File

@ -38,8 +38,10 @@ public class UserDescriptionTemplateCensor extends BaseCensor {
return; return;
this.authService.authorizeForce(Permission.BrowseDescriptionTemplate); this.authService.authorizeForce(Permission.BrowseDescriptionTemplate);
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(UserDescriptionTemplate._descriptionTemplate)); FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(UserDescriptionTemplate._descriptionTemplate));
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(userFields, userId); this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId);
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(UserDescriptionTemplate._user));
this.censorFactory.censor(UserCensor.class).censor(userFields, userId);
} }
} }

View File

@ -0,0 +1,48 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.Description;
import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import eu.eudat.model.UserRole;
import java.util.List;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserRoleCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRoleCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public UserRoleCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserRole._user));
this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId);
}
}

View File

@ -0,0 +1,68 @@
package eu.eudat.model.deleter;
import eu.eudat.data.UserContactInfoEntity;
import eu.eudat.query.UserContactInfoQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
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 javax.management.InvalidApplicationException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserContactInfoDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
@Autowired
public UserContactInfoDeleter(
EntityManager entityManager,
QueryFactory queryFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<UserContactInfoEntity> data = this.queryFactory.query(UserContactInfoQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<UserContactInfoEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<UserContactInfoEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
for (UserContactInfoEntity item : data) {
logger.trace("deleting item {}", item.getId());
logger.trace("deleting item");
this.entityManager.remove(item);
logger.trace("deleted item");
}
}
}

View File

@ -0,0 +1,68 @@
package eu.eudat.model.deleter;
import eu.eudat.data.UserCredentialEntity;
import eu.eudat.query.UserCredentialQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
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 javax.management.InvalidApplicationException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserCredentialDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCredentialDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
@Autowired
public UserCredentialDeleter(
EntityManager entityManager,
QueryFactory queryFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<UserCredentialEntity> data = this.queryFactory.query(UserCredentialQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<UserCredentialEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<UserCredentialEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
for (UserCredentialEntity item : data) {
logger.trace("deleting item {}", item.getId());
logger.trace("deleting item");
this.entityManager.remove(item);
logger.trace("deleted item");
}
}
}

View File

@ -0,0 +1,103 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.*;
import eu.eudat.query.*;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
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 javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public UserDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<UserEntity> data = this.queryFactory.query(UserQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<UserEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<UserEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
List<UUID> ids = data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList());
{
logger.debug("checking related - {}", UserRoleEntity.class.getSimpleName());
List<UserRoleEntity> items = this.queryFactory.query(UserRoleQuery.class).userIds(ids).collect();
UserRoleDeleter deleter = this.deleterFactory.deleter(UserRoleDeleter.class);
deleter.delete(items);
}
{
logger.debug("checking related - {}", UserCredentialEntity.class.getSimpleName());
List<UserCredentialEntity> items = this.queryFactory.query(UserCredentialQuery.class).userIds(ids).collect();
UserCredentialDeleter deleter = this.deleterFactory.deleter(UserCredentialDeleter.class);
deleter.delete(items);
}
{
logger.debug("checking related - {}", UserContactInfoEntity.class.getSimpleName());
List<UserContactInfoEntity> items = this.queryFactory.query(UserContactInfoQuery.class).userIds(ids).collect();
UserContactInfoDeleter deleter = this.deleterFactory.deleter(UserContactInfoDeleter.class);
deleter.delete(items);
}
// {
// logger.debug("checking related - {}", DmpUserEntity.class.getSimpleName());
// List<DmpUserEntity> items = this.queryFactory.query(DmpUserQuery.class).userIds(ids).collect();
// DmpUserDeleter deleter = this.deleterFactory.deleter(DmpUserDeleter.class);
// deleter.delete(items);
// }
Instant now = Instant.now();
for (UserEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,71 @@
package eu.eudat.model.deleter;
import eu.eudat.data.UserRoleEntity;
import eu.eudat.query.UserRoleQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
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 javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserRoleDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRoleDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
@Autowired
public UserRoleDeleter(
EntityManager entityManager,
QueryFactory queryFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<UserRoleEntity> data = this.queryFactory.query(UserRoleQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<UserRoleEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<UserRoleEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
for (UserRoleEntity item : data) {
logger.trace("deleting item {}", item.getId());
logger.trace("deleting item");
this.entityManager.remove(item);
logger.trace("deleted item");
}
}
}

View File

@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity; import eu.eudat.data.UserEntity;
import eu.eudat.data.old.*; import eu.eudat.data.old.*;
import eu.eudat.depositinterface.models.*; import eu.eudat.depositinterface.models.*;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlBuilder;
@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
public class DMPToDepositMapper { public class DMPToDepositMapper {
@ -127,10 +126,10 @@ public class DMPToDepositMapper {
// return deposit; // return deposit;
// } // }
private static UserInfoDepositModel fromUserInfo(UserInfo entity){ private static UserInfoDepositModel fromUserInfo(UserEntity entity){
UserInfoDepositModel deposit = new UserInfoDepositModel(); UserInfoDepositModel deposit = new UserInfoDepositModel();
deposit.setName(entity.getName()); deposit.setName(entity.getName());
deposit.setEmail(entity.getEmail()); //deposit.setEmail(entity.getEmail());//TODO: GetEmail
return deposit; return deposit;
} }

View File

@ -5,15 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.data.*; import eu.eudat.data.*;
import eu.eudat.data.old.UserInfo; import eu.eudat.data.UserEntity;
import eu.eudat.depositinterface.models.*; import eu.eudat.depositinterface.models.*;
import eu.eudat.query.DescriptionQuery; import eu.eudat.model.UserContactInfo;
import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.*;
import eu.eudat.query.DmpDescriptionTemplateQuery; import gr.cite.tools.data.query.Ordering;
import eu.eudat.query.DmpUserQuery;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -149,9 +147,11 @@ public class DmpEntityDepositMapper {
private UserDMPDepositModel toUserDeposit(DmpUserEntity user) { private UserDMPDepositModel toUserDeposit(DmpUserEntity user) {
UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel(); UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel();
userDMPDepositModel.setUser(new UserInfoDepositModel()); userDMPDepositModel.setUser(new UserInfoDepositModel());
UserInfo userInfo = this.entityManager.find(UserInfo.class, user.getUser()); UserEntity userInfo = this.entityManager.find(UserEntity.class, user.getUserId());
userDMPDepositModel.getUser().setName(userInfo.getName()); userDMPDepositModel.getUser().setName(userInfo.getName());
userDMPDepositModel.getUser().setEmail(userInfo.getEmail()); UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userInfo.getId());
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
userDMPDepositModel.getUser().setEmail(query.first().getValue());
userDMPDepositModel.setRole(user.getRole().getValue().intValue()); userDMPDepositModel.setRole(user.getRole().getValue().intValue());
return userDMPDepositModel; return userDMPDepositModel;

View File

@ -0,0 +1,77 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;
public class UserAdditionalInfoPersist {
private String avatarUrl;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String timezone;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String culture;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String language;
private String roleOrganization;
@ValidId(message = "{validation.invalidid}")
private UUID organizationId;
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
public UUID getOrganizationId() {
return organizationId;
}
public void setOrganizationId(UUID organizationId) {
this.organizationId = organizationId;
}
}

View File

@ -0,0 +1,74 @@
package eu.eudat.model.persist;
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidEnum;
import eu.eudat.commons.validation.ValidId;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.model.UserAdditionalInfo;
import eu.eudat.model.UserContactInfo;
import eu.eudat.model.UserCredential;
import eu.eudat.model.UserRole;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = UserEntity._nameLength, message = "{validation.largerthanmax}")
private String name;
private String hash;
@Valid
private UserAdditionalInfoPersist additionalInfo;
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 String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public UserAdditionalInfoPersist getAdditionalInfo() {
return additionalInfo;
}
public void setAdditionalInfo(UserAdditionalInfoPersist additionalInfo) {
this.additionalInfo = additionalInfo;
}
}

View File

@ -0,0 +1,53 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidId;
import eu.eudat.data.UserEntity;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserRolePatchPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
private List<String> roles;
@NotNull(message = "{validation.empty}")
private String hash;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -1,125 +0,0 @@
package eu.eudat.query;
import eu.eudat.data.CredentialEntity;
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 CredentialQuery extends QueryBase<CredentialEntity> {
private Collection<UUID> ids;
private Collection<UUID> userIds;
private Collection<Short> statuses;
public CredentialQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public CredentialQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public CredentialQuery ids(List<UUID> value) {
this.ids = value;
return this;
}
public CredentialQuery userIds(UUID value) {
this.userIds = List.of(value);
return this;
}
public CredentialQuery userIds(UUID... value) {
this.userIds = Arrays.asList(value);
return this;
}
public CredentialQuery userIds(List<UUID> value) {
this.userIds = value;
return this;
}
public CredentialQuery statuses(Short value) {
this.statuses = List.of(value);
return this;
}
public CredentialQuery statuses(Short... value) {
this.statuses = Arrays.asList(value);
return this;
}
public CredentialQuery statuses(List<Short> value) {
this.statuses = value;
return this;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.userIds) || this.isEmpty(this.statuses);
}
@Override
protected Class<CredentialEntity> entityClass() {
return CredentialEntity.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(CredentialEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.userIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._userId));
for (UUID item : this.userIds)
inClause.value(item);
predicates.add(inClause);
}
if (this.statuses != null) {
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._isActive));
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 CredentialEntity convert(Tuple tuple, Set<String> columns) {
return null;
}
}

View File

@ -263,9 +263,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
else if (item.match(Description._status) || item.match(PublicDescription._status)) return DescriptionEntity._status; else if (item.match(Description._status) || item.match(PublicDescription._status)) return DescriptionEntity._status;
else if (item.match(Description._description) || item.match(PublicDescription._description)) return DescriptionEntity._description; else if (item.match(Description._description) || item.match(PublicDescription._description)) return DescriptionEntity._description;
else if (item.match(Description._createdBy)) return DescriptionEntity._createdById; else if (item.match(Description._createdBy)) return DescriptionEntity._createdById;
else if (item.prefix(Description._createdBy)) return DescriptionEntity._createdById;
else if (item.match(Description._createdAt) || item.match(PublicDescription._createdAt)) return DescriptionEntity._createdAt; else if (item.match(Description._createdAt) || item.match(PublicDescription._createdAt)) return DescriptionEntity._createdAt;
else if (item.match(Description._updatedAt) || item.match(PublicDescription._updatedAt)) return DescriptionEntity._updatedAt; else if (item.match(Description._updatedAt) || item.match(PublicDescription._updatedAt)) return DescriptionEntity._updatedAt;
else if (item.match(Description._isActive)) return DescriptionEntity._isActive; else if (item.match(Description._isActive)) return DescriptionEntity._isActive;
else if (item.match(Description._hash)) return DescriptionEntity._updatedAt;
else if (item.match(Description._finalizedAt) || item.match(PublicDescription._finalizedAt)) return DescriptionEntity._finalizedAt; else if (item.match(Description._finalizedAt) || item.match(PublicDescription._finalizedAt)) return DescriptionEntity._finalizedAt;
else if (item.prefix(Description._dmpDescriptionTemplate) || item.prefix(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; else if (item.prefix(Description._dmpDescriptionTemplate) || item.prefix(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId;
else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId; else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId;

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