no message

This commit is contained in:
Ioannis Kalyvas 2018-03-19 18:58:34 +02:00
parent dac219c627
commit 6c0dfb95b6
5 changed files with 83 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package eu.eudat.entities;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
@ -17,6 +18,11 @@ import java.util.UUID;
name = "projectRecentActivity", name = "projectRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")}, attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")}) subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")})
),
@NamedEntityGraph(
name = "projectListingItem",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")})
) )
}) })
public class Project implements DataEntity<Project, UUID> { public class Project implements DataEntity<Project, UUID> {

View File

@ -6,6 +6,7 @@ import eu.eudat.dao.entities.ContentDao;
import eu.eudat.dao.entities.ProjectDao; import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.UserInfoDao; import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.Content; import eu.eudat.entities.Content;
import eu.eudat.entities.DMP;
import eu.eudat.exceptions.files.TempFileNotFoundException; import eu.eudat.exceptions.files.TempFileNotFoundException;
import eu.eudat.models.HintedModelFactory; import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.external.ExternalSourcesItemModel; import eu.eudat.models.external.ExternalSourcesItemModel;
@ -30,6 +31,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class ProjectManager { public class ProjectManager {
@ -42,7 +44,18 @@ public class ProjectManager {
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(authItems, projectTableRequest); QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(authItems, projectTableRequest);
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<>(); DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<>();
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> { CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> {
item.setDmps(item.getDmps().stream().filter(
dmp -> dmp.getCreator().getId().equals(principal.getId()) || dmp.getUsers().stream().filter(user -> user.getId().equals(principal.getId())).collect(Collectors.toList()).size() > 0)
.collect(Collectors.groupingBy(DMP::getGroupId))
.values().stream()
.map(dmps -> dmps.stream().reduce((first, second) -> {
if (first.getVersion() > second.getVersion()) return first;
else return second;
}).get())
.collect(Collectors.toSet()));
return new ProjectListingModel().fromDataModel(item);
}).whenComplete((results, throwable) -> {
dataTable.setData(results); dataTable.setData(results);
}); });

View File

@ -3,20 +3,19 @@ package eu.eudat.models.project;
import eu.eudat.entities.Project; import eu.eudat.entities.Project;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.files.ContentFile; import eu.eudat.models.files.ContentFile;
import eu.eudat.models.urls.DataManagementPlanUrlListing;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class ProjectListingModel implements DataModel<eu.eudat.entities.Project, ProjectListingModel> { public class ProjectListingModel implements DataModel<eu.eudat.entities.Project, ProjectListingModel> {
private UUID id; private UUID id;
private List<DataManagementPlan> dmps;
private String label; private String label;
private String abbreviation; private String abbreviation;
@ -43,6 +42,8 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
private List<ContentFile> files; private List<ContentFile> files;
private List<DataManagementPlanUrlListing> dmps;
public UUID getId() { public UUID getId() {
return id; return id;
@ -52,11 +53,11 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
this.id = id; this.id = id;
} }
public List<DataManagementPlan> getDmps() { public List<DataManagementPlanUrlListing> getDmps() {
return dmps; return dmps;
} }
public void setDmps(List<DataManagementPlan> dmps) { public void setDmps(List<DataManagementPlanUrlListing> dmps) {
this.dmps = dmps; this.dmps = dmps;
} }
@ -178,6 +179,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
this.created = entity.getCreated().toString(); this.created = entity.getCreated().toString();
this.modified = entity.getModified().toString(); this.modified = entity.getModified().toString();
this.description = entity.getDescription(); this.description = entity.getDescription();
this.dmps = entity.getDmps().stream().map(item -> new DataManagementPlanUrlListing().fromDataModel(item)).collect(Collectors.toList());
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null)); this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
return this; return this;
} }
@ -189,6 +191,6 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
@Override @Override
public String getHint() { public String getHint() {
return null; return "projectListingItem";
} }
} }

View File

@ -0,0 +1,26 @@
package eu.eudat.models.urls;
import eu.eudat.entities.DMP;
/**
* Created by ikalyvas on 3/19/2018.
*/
public class DataManagementPlanUrlListing extends UrlListing<DMP, DataManagementPlanUrlListing> {
@Override
public DataManagementPlanUrlListing fromDataModel(DMP entity) {
this.setLabel(entity.getLabel());
this.setUrl(entity.getId().toString());
return this;
}
@Override
public DMP toDataModel() throws Exception {
return null;
}
@Override
public String getHint() {
return null;
}
}

View File

@ -0,0 +1,29 @@
package eu.eudat.models.urls;
import eu.eudat.entities.DataEntity;
import eu.eudat.models.DataModel;
/**
* Created by ikalyvas on 3/19/2018.
*/
public abstract class UrlListing<T extends DataEntity,M extends DataModel> implements DataModel<T,M>{
private String label;
private String url;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}