add getMyRecentActivityItems
This commit is contained in:
parent
2dee73ce1f
commit
2fb99d2fe7
|
@ -93,5 +93,7 @@ public class AuditableAction {
|
||||||
public static final EventId StorageFile_Download = new EventId(14000, "StorageFile_Download");
|
public static final EventId StorageFile_Download = new EventId(14000, "StorageFile_Download");
|
||||||
public static final EventId StorageFile_Upload = new EventId(14001, "StorageFile_Upload");
|
public static final EventId StorageFile_Upload = new EventId(14001, "StorageFile_Upload");
|
||||||
|
|
||||||
|
public static final EventId Dashboard_MyRecentActivityItems = new EventId(15000, "Dashboard_MyRecentActivityItems");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum RecentActivityItemType implements DatabaseEnum<Short> {
|
||||||
|
|
||||||
|
Dmp((short) 0),
|
||||||
|
Description((short) 1);
|
||||||
|
|
||||||
|
private final Short value;
|
||||||
|
|
||||||
|
RecentActivityItemType(Short value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonValue
|
||||||
|
public Short getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<Short, RecentActivityItemType> map = EnumUtils.getEnumValueMap(RecentActivityItemType.class);
|
||||||
|
|
||||||
|
public static RecentActivityItemType of(Short i) {
|
||||||
|
return map.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.eudat.commons.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import eu.eudat.data.converters.enums.DatabaseEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum RecentActivityOrder implements DatabaseEnum<Short> {
|
||||||
|
UpdatedAt((short) 0),
|
||||||
|
Label((short) 1),
|
||||||
|
Status((short) 2);
|
||||||
|
|
||||||
|
private final Short value;
|
||||||
|
|
||||||
|
RecentActivityOrder(Short value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonValue
|
||||||
|
public Short getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<Short, RecentActivityOrder> map = EnumUtils.getEnumValueMap(RecentActivityOrder.class);
|
||||||
|
|
||||||
|
public static RecentActivityOrder of(Short i) {
|
||||||
|
return map.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package eu.eudat.commons.types.dashborad;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.RecentActivityItemType;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class RecentActivityItemEntity {
|
||||||
|
private RecentActivityItemType type;
|
||||||
|
private UUID id;
|
||||||
|
private Instant updatedAt;
|
||||||
|
private String label;
|
||||||
|
private Short statusValue;
|
||||||
|
|
||||||
|
public RecentActivityItemEntity(RecentActivityItemType type, UUID id, Instant updatedAt, String label, Short statusValue) {
|
||||||
|
this.type = type;
|
||||||
|
this.id = id;
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
this.label = label;
|
||||||
|
this.statusValue = statusValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityItemType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(RecentActivityItemType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(Instant updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Short getStatusValue() {
|
||||||
|
return statusValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusValue(Short statusValue) {
|
||||||
|
this.statusValue = statusValue;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,9 +20,9 @@ public class DmpUserEntity {
|
||||||
public static final String _id = "id";
|
public static final String _id = "id";
|
||||||
|
|
||||||
@Column(name = "dmp", columnDefinition = "uuid", nullable = false)
|
@Column(name = "dmp", columnDefinition = "uuid", nullable = false)
|
||||||
private UUID dmp;
|
private UUID dmpId;
|
||||||
|
|
||||||
public static final String _dmp = "dmp";
|
public static final String _dmpId = "dmpId";
|
||||||
|
|
||||||
@Column(name = "\"user\"", columnDefinition = "uuid", nullable = false)
|
@Column(name = "\"user\"", columnDefinition = "uuid", nullable = false)
|
||||||
private UUID userId;
|
private UUID userId;
|
||||||
|
@ -59,12 +59,12 @@ public class DmpUserEntity {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getDmp() {
|
public UUID getDmpId() {
|
||||||
return dmp;
|
return dmpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDmp(UUID dmp) {
|
public void setDmpId(UUID dmpId) {
|
||||||
this.dmp = dmp;
|
this.dmpId = dmpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUserId() {
|
public UUID getUserId() {
|
||||||
|
|
|
@ -136,9 +136,9 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
|
||||||
|
|
||||||
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
||||||
for (DmpUserEntity associationEntity : associationEntities){
|
for (DmpUserEntity associationEntity : associationEntities){
|
||||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmp(), new ArrayList<>());
|
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
|
||||||
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||||
if (item != null) itemMap.get(associationEntity.getDmp()).add(item);
|
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
|
||||||
}
|
}
|
||||||
return itemMap;
|
return itemMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,9 +106,9 @@ public class NestedDmpElasticBuilder extends BaseElasticBuilder<NestedDmpElastic
|
||||||
|
|
||||||
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
||||||
for (DmpUserEntity associationEntity : associationEntities){
|
for (DmpUserEntity associationEntity : associationEntities){
|
||||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmp(), new ArrayList<>());
|
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
|
||||||
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||||
if (item != null) itemMap.get(associationEntity.getDmp()).add(item);
|
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
|
||||||
}
|
}
|
||||||
return itemMap;
|
return itemMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), excludedIds)._toQuery())._toQuery());
|
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), excludedIds)._toQuery())._toQuery());
|
||||||
}
|
}
|
||||||
if (statuses != null) {
|
if (statuses != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), statuses.stream().map(DescriptionStatus::getValue).toList().toArray(new Short[statuses.size()]))._toQuery());
|
||||||
}
|
}
|
||||||
if (this.finalizedAfter != null) {
|
if (this.finalizedAfter != null) {
|
||||||
predicates.add(this.dateGreaterThanQuery(this.elasticFieldOf(DescriptionElasticEntity._finalizedAt), this.finalizedAfter)._toQuery());
|
predicates.add(this.dateGreaterThanQuery(this.elasticFieldOf(DescriptionElasticEntity._finalizedAt), this.finalizedAfter)._toQuery());
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package eu.eudat.elastic.query;
|
package eu.eudat.elastic.query;
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.enums.DmpUserRole;
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
|
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
||||||
import eu.eudat.elastic.data.DmpElasticEntity;
|
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||||
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
|
@ -22,6 +24,9 @@ import java.util.stream.Collectors;
|
||||||
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
|
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
|
||||||
|
|
||||||
|
private Collection<DmpUserRole> userRoles;
|
||||||
|
|
||||||
public NestedCollaboratorElasticQuery ids(UUID value) {
|
public NestedCollaboratorElasticQuery ids(UUID value) {
|
||||||
this.ids = List.of(value);
|
this.ids = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -36,6 +41,21 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
|
||||||
this.ids = values;
|
this.ids = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NestedCollaboratorElasticQuery userRoles(DmpUserRole value) {
|
||||||
|
this.userRoles = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NestedCollaboratorElasticQuery userRoles(DmpUserRole... value) {
|
||||||
|
this.userRoles = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NestedCollaboratorElasticQuery userRoles(Collection<DmpUserRole> values) {
|
||||||
|
this.userRoles = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
private String nestedPath;
|
private String nestedPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +79,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return this.isEmpty(this.ids);
|
return this.isEmpty(this.ids) || this.isEmpty(this.userRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,6 +94,10 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
|
||||||
predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._id), ids)._toQuery());
|
predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._id), ids)._toQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userRoles != null) {
|
||||||
|
predicates.add(this.contains(this.elasticFieldOf(NestedCollaboratorElasticEntity._role), userRoles.stream().map(DmpUserRole::getValue).toList().toArray(new Short[userRoles.size()]))._toQuery());
|
||||||
|
}
|
||||||
|
|
||||||
if (!predicates.isEmpty()) {
|
if (!predicates.isEmpty()) {
|
||||||
return this.and(predicates);
|
return this.and(predicates);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package eu.eudat.model;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.enums.RecentActivityItemType;
|
||||||
|
import eu.eudat.model.dmpblueprintdefinition.Definition;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class RecentActivityItem {
|
||||||
|
private RecentActivityItemType type;
|
||||||
|
public final static String _type = "type";
|
||||||
|
private Dmp dmp;
|
||||||
|
public final static String _dmp = "dmp";
|
||||||
|
private Description description;
|
||||||
|
|
||||||
|
public final static String _description = "description";
|
||||||
|
|
||||||
|
public RecentActivityItemType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(RecentActivityItemType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dmp getDmp() {
|
||||||
|
return dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmp(Dmp dmp) {
|
||||||
|
this.dmp = dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Description getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(Description description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package eu.eudat.model;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.enums.RecentActivityOrder;
|
||||||
|
import eu.eudat.query.lookup.DescriptionLookup;
|
||||||
|
import eu.eudat.query.lookup.DmpLookup;
|
||||||
|
import eu.eudat.query.lookup.DmpUserLookup;
|
||||||
|
import gr.cite.tools.data.query.Lookup;
|
||||||
|
import gr.cite.tools.data.query.Ordering;
|
||||||
|
import gr.cite.tools.data.query.Paging;
|
||||||
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class RecentActivityItemLookup{
|
||||||
|
|
||||||
|
private String like;
|
||||||
|
private Boolean onlyDraft;
|
||||||
|
private List<UUID> userIds;
|
||||||
|
private Paging page;
|
||||||
|
private BaseFieldSet project;
|
||||||
|
private RecentActivityOrder orderField;
|
||||||
|
|
||||||
|
public String getLike() {
|
||||||
|
return like;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLike(String like) {
|
||||||
|
this.like = like;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getOnlyDraft() {
|
||||||
|
return onlyDraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnlyDraft(Boolean onlyDraft) {
|
||||||
|
this.onlyDraft = onlyDraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getUserIds() {
|
||||||
|
return userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIds(List<UUID> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Paging getPage() {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPage(Paging page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseFieldSet getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProject(BaseFieldSet project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityOrder getOrderField() {
|
||||||
|
return orderField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderField(RecentActivityOrder orderField) {
|
||||||
|
this.orderField = orderField;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DescriptionLookup asDescriptionLookup() {
|
||||||
|
DescriptionLookup lookup = new DescriptionLookup();
|
||||||
|
lookup.setIsActive(List.of(IsActive.Active));
|
||||||
|
if (this.like != null) lookup.setLike(this.like);
|
||||||
|
if (this.onlyDraft != null) lookup.setStatuses(List.of(DescriptionStatus.Draft));
|
||||||
|
if (this.userIds != null) {
|
||||||
|
DmpLookup dmpLookup = new DmpLookup();
|
||||||
|
DmpUserLookup dmpUserLookup = new DmpUserLookup();
|
||||||
|
dmpUserLookup.setUserIds(this.userIds);
|
||||||
|
dmpUserLookup.setIsActive(List.of(IsActive.Active));
|
||||||
|
dmpLookup.setDmpUserSubQuery(dmpUserLookup);
|
||||||
|
dmpLookup.setIsActive(List.of(IsActive.Active));
|
||||||
|
lookup.setDmpSubQuery(dmpLookup);
|
||||||
|
}
|
||||||
|
if (this.page != null) lookup.setPage(new Paging(this.page.getOffset(), this.page.getSize()));
|
||||||
|
Ordering ordering = new Ordering();
|
||||||
|
if (this.orderField != null) {
|
||||||
|
switch (this.orderField){
|
||||||
|
case Label -> ordering.addDescending(Description._label).addDescending(Description._updatedAt);
|
||||||
|
case UpdatedAt -> ordering.addDescending(Description._updatedAt);
|
||||||
|
case Status -> ordering.addDescending(Description._status).addDescending(Description._updatedAt);
|
||||||
|
default -> throw new IllegalArgumentException("Type not found" + this.orderField) ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ordering.addDescending(Description._updatedAt);
|
||||||
|
}
|
||||||
|
lookup.setOrder(ordering);
|
||||||
|
if (this.project !=null) lookup.setProject((BaseFieldSet) this.project.extractPrefixed(RecentActivityItem._description));
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpLookup asDmpLookup() {
|
||||||
|
DmpLookup lookup = new DmpLookup();
|
||||||
|
lookup.setIsActive(List.of(IsActive.Active));
|
||||||
|
if (this.like != null) lookup.setLike(this.like);
|
||||||
|
if (this.onlyDraft != null) lookup.setStatuses(List.of(DmpStatus.Draft));
|
||||||
|
if (this.userIds != null) {
|
||||||
|
DmpUserLookup dmpUserLookup = new DmpUserLookup();
|
||||||
|
dmpUserLookup.setUserIds(this.userIds);
|
||||||
|
dmpUserLookup.setIsActive(List.of(IsActive.Active));
|
||||||
|
lookup.setDmpUserSubQuery(dmpUserLookup);
|
||||||
|
}
|
||||||
|
if (this.page != null) lookup.setPage(new Paging(this.page.getOffset(), this.page.getSize()));
|
||||||
|
Ordering ordering = new Ordering();
|
||||||
|
if (this.orderField != null) {
|
||||||
|
switch (this.orderField){
|
||||||
|
case Label -> ordering.addDescending(Dmp._label);
|
||||||
|
case UpdatedAt -> ordering.addDescending(Dmp._updatedAt);
|
||||||
|
case Status -> ordering.addDescending(Dmp._status).addDescending(Dmp._updatedAt);
|
||||||
|
default -> throw new IllegalArgumentException("Type not found" + this.orderField) ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ordering.addDescending(Dmp._updatedAt);
|
||||||
|
}
|
||||||
|
lookup.setOrder(ordering);
|
||||||
|
if (this.project !=null)lookup.setProject((BaseFieldSet) this.project.extractPrefixed(RecentActivityItem._dmp));
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ 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.model.*;
|
import eu.eudat.model.*;
|
||||||
import eu.eudat.query.DmpQuery;
|
import eu.eudat.query.DmpQuery;
|
||||||
|
@ -69,7 +68,7 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
|
||||||
if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
if (fields.hasField(this.asIndexer(DmpUser._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
||||||
if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
if (fields.hasField(this.asIndexer(DmpReference._hash))) m.setHash(this.hashValue(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.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.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
|
||||||
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +114,7 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
|
||||||
Map<UUID, Dmp> itemMap;
|
Map<UUID, Dmp> itemMap;
|
||||||
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
||||||
itemMap = this.asEmpty(
|
itemMap = this.asEmpty(
|
||||||
data.stream().map(DmpUserEntity::getDmp).distinct().collect(Collectors.toList()),
|
data.stream().map(DmpUserEntity::getDmpId).distinct().collect(Collectors.toList()),
|
||||||
x -> {
|
x -> {
|
||||||
Dmp item = new Dmp();
|
Dmp item = new Dmp();
|
||||||
item.setId(x);
|
item.setId(x);
|
||||||
|
@ -124,7 +123,7 @@ public class DmpUserBuilder extends BaseBuilder<DmpUser, DmpUserEntity>{
|
||||||
Dmp::getId);
|
Dmp::getId);
|
||||||
} else {
|
} else {
|
||||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
||||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getDmp).distinct().collect(Collectors.toList()));
|
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
||||||
}
|
}
|
||||||
if (!fields.hasField(Dmp._id)) {
|
if (!fields.hasField(Dmp._id)) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ 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.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.PublicUser;
|
import eu.eudat.model.PublicUser;
|
||||||
|
@ -69,7 +68,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
|
||||||
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.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
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.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));
|
||||||
|
@ -114,7 +113,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
|
||||||
Map<UUID, PublicDmp> itemMap;
|
Map<UUID, PublicDmp> itemMap;
|
||||||
if (!fields.hasOtherField(this.asIndexer(PublicDmp._id))) {
|
if (!fields.hasOtherField(this.asIndexer(PublicDmp._id))) {
|
||||||
itemMap = this.asEmpty(
|
itemMap = this.asEmpty(
|
||||||
data.stream().map(DmpUserEntity::getDmp).distinct().collect(Collectors.toList()),
|
data.stream().map(DmpUserEntity::getDmpId).distinct().collect(Collectors.toList()),
|
||||||
x -> {
|
x -> {
|
||||||
PublicDmp item = new PublicDmp();
|
PublicDmp item = new PublicDmp();
|
||||||
item.setId(x);
|
item.setId(x);
|
||||||
|
@ -123,7 +122,7 @@ public class PublicDmpUserBuilder extends BaseBuilder<PublicDmpUser, DmpUserEnti
|
||||||
PublicDmp::getId);
|
PublicDmp::getId);
|
||||||
} else {
|
} else {
|
||||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDmp._id);
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDmp._id);
|
||||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getDmp).distinct().collect(Collectors.toList()));
|
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDmp::getId);
|
itemMap = this.builderFactory.builder(PublicDmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDmp::getId);
|
||||||
}
|
}
|
||||||
if (!fields.hasField(PublicDmp._id)) {
|
if (!fields.hasField(PublicDmp._id)) {
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
package eu.eudat.model.builder;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commons.enums.DescriptionTemplateVersionStatus;
|
||||||
|
import eu.eudat.commons.enums.RecentActivityItemType;
|
||||||
|
import eu.eudat.commons.types.dashborad.RecentActivityItemEntity;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.model.*;
|
||||||
|
import eu.eudat.query.DescriptionQuery;
|
||||||
|
import eu.eudat.query.DescriptionTemplateQuery;
|
||||||
|
import eu.eudat.query.DmpQuery;
|
||||||
|
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 RecentActivityItemBuilder extends BaseBuilder<RecentActivityItem, RecentActivityItemEntity> {
|
||||||
|
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
|
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RecentActivityItemBuilder(
|
||||||
|
ConventionService conventionService,
|
||||||
|
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||||
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(RecentActivityItemBuilder.class)));
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityItemBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
this.authorize = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RecentActivityItem> build(FieldSet fields, List<RecentActivityItemEntity> 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 descriptionFields = fields.extractPrefixed(this.asPrefix(RecentActivityItem._description));
|
||||||
|
Map<UUID, Description> descriptionItemsMap = this.collectDescriptions(descriptionFields, data);
|
||||||
|
|
||||||
|
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(RecentActivityItem._dmp));
|
||||||
|
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
|
||||||
|
|
||||||
|
List<RecentActivityItem> models = new ArrayList<>();
|
||||||
|
for (RecentActivityItemEntity d : data) {
|
||||||
|
RecentActivityItem m = new RecentActivityItem();
|
||||||
|
if (fields.hasField(this.asIndexer(RecentActivityItem._type))) m.setType(d.getType());
|
||||||
|
if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getId())) m.setDescription(descriptionItemsMap.get(d.getId()));
|
||||||
|
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getId())) m.setDmp(dmpItemsMap.get(d.getId()));
|
||||||
|
models.add(m);
|
||||||
|
}
|
||||||
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<RecentActivityItemEntity> data) throws MyApplicationException {
|
||||||
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
|
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
|
||||||
|
|
||||||
|
Map<UUID, Dmp> itemMap;
|
||||||
|
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
||||||
|
itemMap = this.asEmpty(
|
||||||
|
data.stream().filter(x-> x.getType().equals(RecentActivityItemType.Dmp)).map(RecentActivityItemEntity::getId).distinct().collect(Collectors.toList()),
|
||||||
|
x -> {
|
||||||
|
Dmp item = new Dmp();
|
||||||
|
item.setId(x);
|
||||||
|
return item;
|
||||||
|
},
|
||||||
|
Dmp::getId);
|
||||||
|
} else {
|
||||||
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
||||||
|
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().filter(x-> x.getType().equals(RecentActivityItemType.Dmp)).map(RecentActivityItemEntity::getId).distinct().collect(Collectors.toList()));
|
||||||
|
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
||||||
|
}
|
||||||
|
if (!fields.hasField(Dmp._id)) {
|
||||||
|
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<UUID, Description> collectDescriptions(FieldSet fields, List<RecentActivityItemEntity> data) throws MyApplicationException {
|
||||||
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
|
this.logger.debug("checking related - {}", Description.class.getSimpleName());
|
||||||
|
|
||||||
|
Map<UUID, Description> itemMap;
|
||||||
|
if (!fields.hasOtherField(this.asIndexer(Description._id))) {
|
||||||
|
itemMap = this.asEmpty(
|
||||||
|
data.stream().filter(x-> x.getType().equals(RecentActivityItemType.Description)).map(RecentActivityItemEntity::getId).distinct().collect(Collectors.toList()),
|
||||||
|
x -> {
|
||||||
|
Description item = new Description();
|
||||||
|
item.setId(x);
|
||||||
|
return item;
|
||||||
|
},
|
||||||
|
Description::getId);
|
||||||
|
} else {
|
||||||
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Description._id);
|
||||||
|
DescriptionQuery q = this.queryFactory.query(DescriptionQuery.class).authorize(this.authorize).ids(data.stream().filter(x-> x.getType().equals(RecentActivityItemType.Description)).map(RecentActivityItemEntity::getId).distinct().collect(Collectors.toList()));
|
||||||
|
itemMap = this.builderFactory.builder(DescriptionBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Description::getId);
|
||||||
|
}
|
||||||
|
if (!fields.hasField(Description._id)) {
|
||||||
|
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package eu.eudat.model.censorship;
|
||||||
|
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.model.RecentActivityItem;
|
||||||
|
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 RecentActivityItemCensor extends BaseCensor {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(RecentActivityItemCensor.class));
|
||||||
|
|
||||||
|
protected final AuthorizationService authService;
|
||||||
|
|
||||||
|
protected final CensorFactory censorFactory;
|
||||||
|
|
||||||
|
public RecentActivityItemCensor(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;
|
||||||
|
|
||||||
|
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(RecentActivityItem._dmp));
|
||||||
|
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
|
||||||
|
|
||||||
|
FieldSet descriptionFields = fields.extractPrefixed(this.asIndexerPrefix(RecentActivityItem._description));
|
||||||
|
this.censorFactory.censor(DescriptionCensor.class).censor(descriptionFields, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -195,7 +195,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
||||||
|
|
||||||
List<Predicate> predicates = new ArrayList<>();
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
if (userId != null || usePublic ) {
|
if (userId != null || usePublic ) {
|
||||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
|
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
|
||||||
}
|
}
|
||||||
if (!predicates.isEmpty()) {
|
if (!predicates.isEmpty()) {
|
||||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||||
|
|
|
@ -7,11 +7,10 @@ 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.commons.scope.user.UserScope;
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||||
import eu.eudat.data.DmpEntity;
|
import eu.eudat.data.DmpEntity;
|
||||||
|
import eu.eudat.data.DmpUserEntity;
|
||||||
import eu.eudat.model.Dmp;
|
import eu.eudat.model.Dmp;
|
||||||
import eu.eudat.model.DmpDescriptionTemplate;
|
|
||||||
import eu.eudat.model.PublicDmp;
|
import eu.eudat.model.PublicDmp;
|
||||||
import eu.eudat.query.utils.QueryUtilsService;
|
import eu.eudat.query.utils.QueryUtilsService;
|
||||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
|
@ -24,7 +23,6 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
@ -45,6 +43,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
private Collection<Integer> versions;
|
private Collection<Integer> versions;
|
||||||
|
|
||||||
private Collection<UUID> groupIds;
|
private Collection<UUID> groupIds;
|
||||||
|
private DmpUserQuery dmpUserQuery;
|
||||||
|
|
||||||
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
|
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
|
||||||
|
|
||||||
|
@ -190,6 +189,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DmpQuery dmpUserSubQuery(DmpUserQuery subQuery) {
|
||||||
|
this.dmpUserQuery = subQuery;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpQuery authorize(EnumSet<AuthorizationFlags> values) {
|
public DmpQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
this.authorize = values;
|
this.authorize = values;
|
||||||
return this;
|
return this;
|
||||||
|
@ -197,7 +201,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses)|| this.isFalseQuery(this.dmpDescriptionTemplateQuery);
|
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses)|| this.isFalseQuery(this.dmpDescriptionTemplateQuery)|| this.isFalseQuery(this.dmpUserQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -287,6 +291,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.dmpUserQuery != null) {
|
||||||
|
QueryContext<DmpUserEntity, UUID> subQuery = this.applySubQuery(this.dmpUserQuery, queryContext, UUID.class, root -> root.get(DmpUserEntity._dmpId));
|
||||||
|
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpEntity._id)).value(subQuery.Query));
|
||||||
|
}
|
||||||
|
|
||||||
if (this.dmpDescriptionTemplateQuery != null) {
|
if (this.dmpDescriptionTemplateQuery != null) {
|
||||||
QueryContext<DmpDescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, dmpDescriptionTemplateEntityRoot -> dmpDescriptionTemplateEntityRoot.get(DmpDescriptionTemplateEntity._dmpId));
|
QueryContext<DmpDescriptionTemplateEntity, UUID> subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, dmpDescriptionTemplateEntityRoot -> dmpDescriptionTemplateEntityRoot.get(DmpDescriptionTemplateEntity._dmpId));
|
||||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpEntity._id)).value(subQuery.Query));
|
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpEntity._id)).value(subQuery.Query));
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
|
||||||
List<Predicate> predicates = new ArrayList<>();
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
if (userId != null || usePublic ) {
|
if (userId != null || usePublic ) {
|
||||||
predicates.add(queryContext.CriteriaBuilder.or(
|
predicates.add(queryContext.CriteriaBuilder.or(
|
||||||
usePublic ? queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmp)).value(queryUtilsService.buildPublicDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, usePublic)) : queryContext.CriteriaBuilder.or(), //Creates a false query
|
usePublic ? queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildPublicDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, usePublic)) : queryContext.CriteriaBuilder.or(), //Creates a false query
|
||||||
userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._userId), userId) : queryContext.CriteriaBuilder.or() //Creates a false query
|
userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._userId), userId) : queryContext.CriteriaBuilder.or() //Creates a false query
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
if (this.dmpIds != null) {
|
if (this.dmpIds != null) {
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmp));
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmpId));
|
||||||
for (UUID item : this.dmpIds)
|
for (UUID item : this.dmpIds)
|
||||||
inClause.value(item);
|
inClause.value(item);
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
|
@ -212,7 +212,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
|
||||||
protected DmpUserEntity convert(Tuple tuple, Set<String> columns) {
|
protected DmpUserEntity convert(Tuple tuple, Set<String> columns) {
|
||||||
DmpUserEntity item = new DmpUserEntity();
|
DmpUserEntity item = new DmpUserEntity();
|
||||||
item.setId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._id, UUID.class));
|
item.setId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._id, UUID.class));
|
||||||
item.setDmp(QueryBase.convertSafe(tuple, columns, DmpUserEntity._dmp, UUID.class));
|
item.setDmpId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._dmpId, UUID.class));
|
||||||
item.setUserId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._userId, UUID.class));
|
item.setUserId(QueryBase.convertSafe(tuple, columns, DmpUserEntity._userId, UUID.class));
|
||||||
item.setRole(QueryBase.convertSafe(tuple, columns, DmpUserEntity._role, DmpUserRole.class));
|
item.setRole(QueryBase.convertSafe(tuple, columns, DmpUserEntity._role, DmpUserRole.class));
|
||||||
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._createdAt, Instant.class));
|
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpUserEntity._createdAt, Instant.class));
|
||||||
|
@ -223,7 +223,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
|
||||||
@Override
|
@Override
|
||||||
protected String fieldNameOf(FieldResolver item) {
|
protected String fieldNameOf(FieldResolver item) {
|
||||||
if (item.match(DmpUser._id) || item.match(PublicDmpUser._id)) return DmpUserEntity._id;
|
if (item.match(DmpUser._id) || item.match(PublicDmpUser._id)) return DmpUserEntity._id;
|
||||||
else if (item.prefix(DmpUser._dmp) || item.prefix(PublicDmpUser._dmp)) return DmpUserEntity._dmp;
|
else if (item.prefix(DmpUser._dmp) || item.prefix(PublicDmpUser._dmp)) return DmpUserEntity._dmpId;
|
||||||
else if (item.prefix(DmpUser._user) || item.prefix(PublicDmpUser._user)) return DmpUserEntity._userId;
|
else if (item.prefix(DmpUser._user) || item.prefix(PublicDmpUser._user)) return DmpUserEntity._userId;
|
||||||
else if (item.match(DmpUser._role) || item.match(PublicDmpUser._role)) return DmpUserEntity._role;
|
else if (item.match(DmpUser._role) || item.match(PublicDmpUser._role)) return DmpUserEntity._role;
|
||||||
else if (item.match(DmpUser._createdAt)) return DmpUserEntity._createdAt;
|
else if (item.match(DmpUser._createdAt)) return DmpUserEntity._createdAt;
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class DmpLookup extends Lookup {
|
||||||
private List<Integer> versions;
|
private List<Integer> versions;
|
||||||
|
|
||||||
private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery;
|
private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery;
|
||||||
|
private DmpUserLookup dmpUserSubQuery;
|
||||||
|
|
||||||
public String getLike() {
|
public String getLike() {
|
||||||
return like;
|
return like;
|
||||||
|
@ -113,6 +114,14 @@ public class DmpLookup extends Lookup {
|
||||||
this.groupIds = groupIds;
|
this.groupIds = groupIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DmpUserLookup getDmpUserSubQuery() {
|
||||||
|
return dmpUserSubQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmpUserSubQuery(DmpUserLookup dmpUserSubQuery) {
|
||||||
|
this.dmpUserSubQuery = dmpUserSubQuery;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpQuery enrich(QueryFactory queryFactory) {
|
public DmpQuery enrich(QueryFactory queryFactory) {
|
||||||
DmpQuery query = queryFactory.query(DmpQuery.class);
|
DmpQuery query = queryFactory.query(DmpQuery.class);
|
||||||
if (this.like != null) query.like(this.like);
|
if (this.like != null) query.like(this.like);
|
||||||
|
@ -125,6 +134,7 @@ public class DmpLookup extends Lookup {
|
||||||
if (this.versions != null) query.versions(this.versions);
|
if (this.versions != null) query.versions(this.versions);
|
||||||
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
||||||
if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery.enrich(queryFactory));
|
if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery.enrich(queryFactory));
|
||||||
|
if (this.dmpUserSubQuery != null) query.dmpUserSubQuery(this.dmpUserSubQuery.enrich(queryFactory));
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
@ -142,6 +152,7 @@ public class DmpLookup extends Lookup {
|
||||||
if (this.versions != null) query.versions(this.versions);
|
if (this.versions != null) query.versions(this.versions);
|
||||||
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
||||||
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
|
if (this.dmpUserSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
@ -159,6 +170,7 @@ public class DmpLookup extends Lookup {
|
||||||
if (this.versions != null) query.versions(this.versions);
|
if (this.versions != null) query.versions(this.versions);
|
||||||
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
||||||
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
|
if (this.dmpUserSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
package eu.eudat.query.lookup;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.*;
|
||||||
|
import eu.eudat.elastic.query.DmpElasticQuery;
|
||||||
|
import eu.eudat.elastic.query.InnerObjectDmpElasticQuery;
|
||||||
|
import eu.eudat.elastic.query.NestedCollaboratorElasticQuery;
|
||||||
|
import eu.eudat.query.DmpUserQuery;
|
||||||
|
import gr.cite.tools.data.query.Lookup;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DmpUserLookup extends Lookup {
|
||||||
|
|
||||||
|
|
||||||
|
private List<UUID> ids;
|
||||||
|
|
||||||
|
private List<UUID> dmpIds;
|
||||||
|
private List<UUID> userIds;
|
||||||
|
|
||||||
|
private List<IsActive> isActive;
|
||||||
|
private List<DmpUserRole> userRoles;
|
||||||
|
|
||||||
|
public List<UUID> getIds() {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIds(List<UUID> ids) {
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getDmpIds() {
|
||||||
|
return dmpIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmpIds(List<UUID> dmpIds) {
|
||||||
|
this.dmpIds = dmpIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getUserIds() {
|
||||||
|
return userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIds(List<UUID> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IsActive> getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(List<IsActive> isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DmpUserRole> getUserRoles() {
|
||||||
|
return userRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserRoles(List<DmpUserRole> userRoles) {
|
||||||
|
this.userRoles = userRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpUserQuery enrich(QueryFactory queryFactory) {
|
||||||
|
DmpUserQuery query = queryFactory.query(DmpUserQuery.class);
|
||||||
|
if (this.ids != null) query.ids(this.ids);
|
||||||
|
if (this.dmpIds != null) query.dmpIds(this.dmpIds);
|
||||||
|
if (this.userIds != null) query.userIds(this.userIds);
|
||||||
|
if (this.userRoles != null) query.userRoles(this.userRoles);
|
||||||
|
if (this.isActive != null) query.isActives(this.isActive);
|
||||||
|
|
||||||
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NestedCollaboratorElasticQuery enrichElastic(QueryFactory queryFactory) {
|
||||||
|
NestedCollaboratorElasticQuery query = queryFactory.query(NestedCollaboratorElasticQuery.class);
|
||||||
|
if (this.ids != null) query.ids(this.ids);
|
||||||
|
if (this.userRoles != null) query.userRoles(this.userRoles);
|
||||||
|
|
||||||
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
}
|
|
@ -63,7 +63,7 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
|
||||||
return this.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class)
|
return this.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class)
|
||||||
.query(query)
|
.query(query)
|
||||||
.criteriaBuilder(criteriaBuilder)
|
.criteriaBuilder(criteriaBuilder)
|
||||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._dmp))
|
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._dmpId))
|
||||||
.filterFunc((subQueryRoot, cb) ->
|
.filterFunc((subQueryRoot, cb) ->
|
||||||
userId != null ? cb.and(
|
userId != null ? cb.and(
|
||||||
cb.equal(subQueryRoot.get(DmpUserEntity._userId), userId),
|
cb.equal(subQueryRoot.get(DmpUserEntity._userId), userId),
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package eu.eudat.service.dashborad;
|
||||||
|
|
||||||
|
import eu.eudat.model.RecentActivityItem;
|
||||||
|
import eu.eudat.model.RecentActivityItemLookup;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DashboardService {
|
||||||
|
List<RecentActivityItem> getMyRecentActivityItems(RecentActivityItemLookup model) throws InvalidApplicationException;
|
||||||
|
}
|
|
@ -0,0 +1,167 @@
|
||||||
|
package eu.eudat.service.dashborad;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
|
import eu.eudat.commons.XmlHandlingService;
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.enums.RecentActivityItemType;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
|
import eu.eudat.commons.types.dashborad.RecentActivityItemEntity;
|
||||||
|
import eu.eudat.commons.types.description.FieldEntity;
|
||||||
|
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
|
||||||
|
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.data.*;
|
||||||
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
|
import eu.eudat.event.DescriptionTouchedEvent;
|
||||||
|
import eu.eudat.event.EventBroker;
|
||||||
|
import eu.eudat.model.*;
|
||||||
|
import eu.eudat.model.builder.DescriptionBuilder;
|
||||||
|
import eu.eudat.model.builder.RecentActivityItemBuilder;
|
||||||
|
import eu.eudat.model.deleter.DescriptionDeleter;
|
||||||
|
import eu.eudat.model.deleter.DescriptionReferenceDeleter;
|
||||||
|
import eu.eudat.model.deleter.DescriptionTagDeleter;
|
||||||
|
import eu.eudat.model.persist.DescriptionPersist;
|
||||||
|
import eu.eudat.model.persist.DescriptionReferencePersist;
|
||||||
|
import eu.eudat.model.persist.DescriptionStatusPersist;
|
||||||
|
import eu.eudat.model.persist.ReferencePersist;
|
||||||
|
import eu.eudat.model.persist.descriptionproperties.FieldPersist;
|
||||||
|
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||||
|
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
|
||||||
|
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
|
||||||
|
import eu.eudat.model.result.QueryResult;
|
||||||
|
import eu.eudat.query.*;
|
||||||
|
import eu.eudat.query.lookup.DescriptionLookup;
|
||||||
|
import eu.eudat.query.lookup.DmpLookup;
|
||||||
|
import eu.eudat.service.elastic.ElasticQueryHelperService;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
|
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||||
|
import gr.cite.tools.data.query.Ordering;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static eu.eudat.authorization.AuthorizationFlags.Public;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DashboardServiceImpl implements DashboardService {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DashboardServiceImpl.class));
|
||||||
|
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
|
private final AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
private final DeleterFactory deleterFactory;
|
||||||
|
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
|
|
||||||
|
private final ConventionService conventionService;
|
||||||
|
|
||||||
|
private final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
|
private final EventBroker eventBroker;
|
||||||
|
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
|
private final JsonHandlingService jsonHandlingService;
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
private final XmlHandlingService xmlHandlingService;
|
||||||
|
|
||||||
|
private final ElasticQueryHelperService elasticQueryHelperService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DashboardServiceImpl(
|
||||||
|
EntityManager entityManager,
|
||||||
|
AuthorizationService authorizationService,
|
||||||
|
DeleterFactory deleterFactory,
|
||||||
|
BuilderFactory builderFactory,
|
||||||
|
ConventionService conventionService,
|
||||||
|
ErrorThesaurusProperties errors,
|
||||||
|
MessageSource messageSource,
|
||||||
|
EventBroker eventBroker,
|
||||||
|
QueryFactory queryFactory,
|
||||||
|
JsonHandlingService jsonHandlingService,
|
||||||
|
UserScope userScope,
|
||||||
|
XmlHandlingService xmlHandlingService, ElasticQueryHelperService elasticQueryHelperService) {
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
this.authorizationService = authorizationService;
|
||||||
|
this.deleterFactory = deleterFactory;
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
|
this.conventionService = conventionService;
|
||||||
|
this.errors = errors;
|
||||||
|
this.messageSource = messageSource;
|
||||||
|
this.eventBroker = eventBroker;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.xmlHandlingService = xmlHandlingService;
|
||||||
|
this.elasticQueryHelperService = elasticQueryHelperService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RecentActivityItem> getMyRecentActivityItems(RecentActivityItemLookup model) throws InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("collecting recent activity").And("model", model));
|
||||||
|
model.setUserIds(List.of(this.userScope.getUserId()));
|
||||||
|
|
||||||
|
List<RecentActivityItemEntity> recentActivityItemEntities = new ArrayList<>();
|
||||||
|
DescriptionLookup descriptionLookup = model.asDescriptionLookup();
|
||||||
|
descriptionLookup.getPage().setOffset(0);
|
||||||
|
QueryResult<Description> descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(Description._status).ensure(Description._label));
|
||||||
|
if (!this.conventionService.isListNullOrEmpty(descriptions.getItems())) {
|
||||||
|
for (Description description : descriptions.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Description, description.getId(), description.getUpdatedAt(), description.getLabel(), description.getStatus().getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
DmpLookup dmpLookup = model.asDmpLookup();
|
||||||
|
dmpLookup.getPage().setOffset(0);
|
||||||
|
QueryResult<Dmp> dmps = this.elasticQueryHelperService.collect(dmpLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._updatedAt).ensure(Dmp._label).ensure(Dmp._status));
|
||||||
|
if (!this.conventionService.isListNullOrEmpty(dmps.getItems())) {
|
||||||
|
for (Dmp dmp : dmps.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Dmp, dmp.getId(), dmp.getUpdatedAt(), dmp.getLabel(), dmp.getStatus().getValue()));
|
||||||
|
}
|
||||||
|
Comparator<RecentActivityItemEntity> comparator = Comparator.comparing(RecentActivityItemEntity::getUpdatedAt);
|
||||||
|
|
||||||
|
Ordering ordering = new Ordering();
|
||||||
|
if (model.getOrderField() != null) {
|
||||||
|
switch (model.getOrderField()){
|
||||||
|
case Label -> comparator = Comparator.comparing(RecentActivityItemEntity::getLabel).thenComparing(RecentActivityItemEntity::getUpdatedAt);
|
||||||
|
case UpdatedAt -> comparator = Comparator.comparing(RecentActivityItemEntity::getUpdatedAt);
|
||||||
|
case Status -> comparator = Comparator.comparing(RecentActivityItemEntity::getStatusValue).thenComparing(RecentActivityItemEntity::getUpdatedAt);
|
||||||
|
default -> throw new IllegalArgumentException("Type not found" + model.getOrderField()) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recentActivityItemEntities = recentActivityItemEntities.stream().sorted(comparator).toList().reversed();
|
||||||
|
|
||||||
|
if (model.getPage() != null){
|
||||||
|
recentActivityItemEntities = recentActivityItemEntities.stream().skip(model.getPage().getOffset()).limit(model.getPage().getSize()).toList();
|
||||||
|
}
|
||||||
|
return this.builderFactory.builder(RecentActivityItemBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(model.getProject()), recentActivityItemEntities);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -190,7 +190,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
for (DmpUserEntity dmpUser : dmpUsers) {
|
for (DmpUserEntity dmpUser : dmpUsers) {
|
||||||
DmpUserEntity newUser = new DmpUserEntity();
|
DmpUserEntity newUser = new DmpUserEntity();
|
||||||
newUser.setId(UUID.randomUUID());
|
newUser.setId(UUID.randomUUID());
|
||||||
newUser.setDmp(newDmp.getId());
|
newUser.setDmpId(newDmp.getId());
|
||||||
newUser.setUserId(dmpUser.getUserId());
|
newUser.setUserId(dmpUser.getUserId());
|
||||||
newUser.setRole(dmpUser.getRole());
|
newUser.setRole(dmpUser.getRole());
|
||||||
newUser.setCreatedAt(Instant.now());
|
newUser.setCreatedAt(Instant.now());
|
||||||
|
@ -278,7 +278,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
for (DmpUserEntity dmpUser : dmpUsers) {
|
for (DmpUserEntity dmpUser : dmpUsers) {
|
||||||
DmpUserEntity newUser = new DmpUserEntity();
|
DmpUserEntity newUser = new DmpUserEntity();
|
||||||
newUser.setId(UUID.randomUUID());
|
newUser.setId(UUID.randomUUID());
|
||||||
newUser.setDmp(newDmp.getId());
|
newUser.setDmpId(newDmp.getId());
|
||||||
newUser.setUserId(dmpUser.getUserId());
|
newUser.setUserId(dmpUser.getUserId());
|
||||||
newUser.setRole(dmpUser.getRole());
|
newUser.setRole(dmpUser.getRole());
|
||||||
newUser.setCreatedAt(Instant.now());
|
newUser.setCreatedAt(Instant.now());
|
||||||
|
@ -331,11 +331,11 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
List<UUID> updatedCreatedIds = new ArrayList<>();
|
List<UUID> updatedCreatedIds = new ArrayList<>();
|
||||||
for (DmpUserPersist dmpUser : model) {
|
for (DmpUserPersist dmpUser : model) {
|
||||||
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmp().equals(dmp) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null);
|
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmp) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null);
|
||||||
if (dmpUserEntity == null){
|
if (dmpUserEntity == null){
|
||||||
dmpUserEntity = new DmpUserEntity();
|
dmpUserEntity = new DmpUserEntity();
|
||||||
dmpUserEntity.setId(UUID.randomUUID());
|
dmpUserEntity.setId(UUID.randomUUID());
|
||||||
dmpUserEntity.setDmp(dmp);
|
dmpUserEntity.setDmpId(dmp);
|
||||||
dmpUserEntity.setUserId(dmpUser.getUser());
|
dmpUserEntity.setUserId(dmpUser.getUser());
|
||||||
dmpUserEntity.setRole(dmpUser.getRole());
|
dmpUserEntity.setRole(dmpUser.getRole());
|
||||||
dmpUserEntity.setCreatedAt(Instant.now());
|
dmpUserEntity.setCreatedAt(Instant.now());
|
||||||
|
@ -422,7 +422,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
data.setCreatedAt(Instant.now());
|
data.setCreatedAt(Instant.now());
|
||||||
|
|
||||||
dmpUserEntity.setId(UUID.randomUUID());
|
dmpUserEntity.setId(UUID.randomUUID());
|
||||||
dmpUserEntity.setDmp(data.getId());
|
dmpUserEntity.setDmpId(data.getId());
|
||||||
dmpUserEntity.setUserId(userScope.getUserId());
|
dmpUserEntity.setUserId(userScope.getUserId());
|
||||||
dmpUserEntity.setRole(DmpUserRole.Owner);
|
dmpUserEntity.setRole(DmpUserRole.Owner);
|
||||||
dmpUserEntity.setCreatedAt(Instant.now());
|
dmpUserEntity.setCreatedAt(Instant.now());
|
||||||
|
@ -604,7 +604,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
|
|
||||||
private DmpUserEntity checkUserRoleIfExists(List<DmpUserEntity> dmpUserEntities, UUID dmp, UUID user, DmpUserRole role) {
|
private DmpUserEntity checkUserRoleIfExists(List<DmpUserEntity> dmpUserEntities, UUID dmp, UUID user, DmpUserRole role) {
|
||||||
for (DmpUserEntity dmpUser : dmpUserEntities) {
|
for (DmpUserEntity dmpUser : dmpUserEntities) {
|
||||||
if (dmpUser.getDmp().equals(dmp) && dmpUser.getUserId().equals(user) && dmpUser.getRole() == role) {
|
if (dmpUser.getDmpId().equals(dmp) && dmpUser.getUserId().equals(user) && dmpUser.getRole() == role) {
|
||||||
return dmpUser;
|
return dmpUser;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private final BuilderFactory builderFactory;
|
private final BuilderFactory builderFactory;
|
||||||
private final ElasticService elasticService;
|
private final ElasticService elasticService;
|
||||||
|
|
||||||
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService) {
|
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService) {
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
|
@ -87,6 +86,7 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
||||||
return this.collect(lookup, (d) -> this.builderFactory.builder(DescriptionBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags);
|
return this.collect(lookup, (d) -> this.builderFactory.builder(DescriptionBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryResult<PublicDescription> collectPublic(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
public QueryResult<PublicDescription> collectPublic(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
||||||
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package eu.eudat.controllers.v2;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import eu.eudat.audit.AuditableAction;
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commons.enums.DmpAccessType;
|
||||||
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
|
import eu.eudat.model.*;
|
||||||
|
import eu.eudat.model.builder.DescriptionBuilder;
|
||||||
|
import eu.eudat.model.builder.UserBuilder;
|
||||||
|
import eu.eudat.model.censorship.DescriptionCensor;
|
||||||
|
import eu.eudat.model.censorship.PublicDescriptionCensor;
|
||||||
|
import eu.eudat.model.censorship.RecentActivityItemCensor;
|
||||||
|
import eu.eudat.model.persist.DescriptionPersist;
|
||||||
|
import eu.eudat.model.persist.DescriptionStatusPersist;
|
||||||
|
import eu.eudat.model.result.QueryResult;
|
||||||
|
import eu.eudat.query.DescriptionQuery;
|
||||||
|
import eu.eudat.query.DmpQuery;
|
||||||
|
import eu.eudat.query.UserQuery;
|
||||||
|
import eu.eudat.query.lookup.DescriptionLookup;
|
||||||
|
import eu.eudat.service.dashborad.DashboardService;
|
||||||
|
import eu.eudat.service.description.DescriptionService;
|
||||||
|
import eu.eudat.service.elastic.ElasticQueryHelperService;
|
||||||
|
import gr.cite.tools.auditing.AuditService;
|
||||||
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
|
import gr.cite.tools.data.censor.CensorFactory;
|
||||||
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
|
import gr.cite.tools.exception.MyNotFoundException;
|
||||||
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import gr.cite.tools.validation.MyValidate;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.management.InvalidApplicationException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static eu.eudat.authorization.AuthorizationFlags.Public;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(path = "api/dashboard")
|
||||||
|
public class DashboardController {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DashboardController.class));
|
||||||
|
|
||||||
|
private final AuditService auditService;
|
||||||
|
|
||||||
|
private final DashboardService dashboardService;
|
||||||
|
|
||||||
|
private final CensorFactory censorFactory;
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
public DashboardController(
|
||||||
|
AuditService auditService,
|
||||||
|
DashboardService dashboardService,
|
||||||
|
CensorFactory censorFactory,
|
||||||
|
UserScope userScope) {
|
||||||
|
this.auditService = auditService;
|
||||||
|
this.dashboardService = dashboardService;
|
||||||
|
this.censorFactory = censorFactory;
|
||||||
|
this.userScope = userScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("recent-activity/mine")
|
||||||
|
public List<RecentActivityItem> getMyRecentActivityItems(@RequestBody RecentActivityItemLookup lookup) throws InvalidApplicationException {
|
||||||
|
logger.debug(new MapLogEntry("retrieving" + User.class.getSimpleName()).And("lookup", lookup));
|
||||||
|
|
||||||
|
this.censorFactory.censor(RecentActivityItemCensor.class).censor(lookup.getProject(), this.userScope.getUserId());
|
||||||
|
|
||||||
|
lookup.setUserIds(List.of(this.userScope.getUserId()));
|
||||||
|
List<RecentActivityItem> models = this.dashboardService.getMyRecentActivityItems(lookup);
|
||||||
|
|
||||||
|
this.auditService.track(AuditableAction.Dashboard_MyRecentActivityItems, Map.ofEntries(
|
||||||
|
new AbstractMap.SimpleEntry<String, Object>("lookup", lookup)
|
||||||
|
));
|
||||||
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||||
|
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -784,7 +784,7 @@ public class DataManagementPlanManager {
|
||||||
DmpUserEntity temp = new DmpUserEntity();
|
DmpUserEntity temp = new DmpUserEntity();
|
||||||
temp.setUserId(userDMP.getUserId());
|
temp.setUserId(userDMP.getUserId());
|
||||||
temp.setRole(userDMP.getRole());
|
temp.setRole(userDMP.getRole());
|
||||||
temp.setDmp(newDmp.getId());
|
temp.setDmpId(newDmp.getId());
|
||||||
// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(temp);
|
// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(temp);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2403,7 +2403,7 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
private void assignUser(DmpEntity dmp, UserEntity userInfo, DmpUserRole role) {
|
private void assignUser(DmpEntity dmp, UserEntity userInfo, DmpUserRole role) {
|
||||||
DmpUserEntity userDMP = new DmpUserEntity();
|
DmpUserEntity userDMP = new DmpUserEntity();
|
||||||
userDMP.setDmp(dmp.getId());
|
userDMP.setDmpId(dmp.getId());
|
||||||
userDMP.setUserId(userInfo.getId());
|
userDMP.setUserId(userInfo.getId());
|
||||||
userDMP.setRole(role);
|
userDMP.setRole(role);
|
||||||
// databaseRepository.getUserDmpDao().createOrUpdate(userDMP);
|
// databaseRepository.getUserDmpDao().createOrUpdate(userDMP);
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class QuickWizardManager {
|
||||||
|
|
||||||
private void assignUser(DmpEntity dmp, UserEntity userInfo, ApiContext apiContext) {
|
private void assignUser(DmpEntity dmp, UserEntity userInfo, ApiContext apiContext) {
|
||||||
DmpUserEntity userDMP = new DmpUserEntity();
|
DmpUserEntity userDMP = new DmpUserEntity();
|
||||||
userDMP.setDmp(dmp.getId());
|
userDMP.setDmpId(dmp.getId());
|
||||||
userDMP.setUserId(userInfo.getId());
|
userDMP.setUserId(userInfo.getId());
|
||||||
userDMP.setRole(DmpUserRole.User);
|
userDMP.setRole(DmpUserRole.User);
|
||||||
//apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
//apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
||||||
|
|
Loading…
Reference in New Issue