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.Type;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import java.util.Date;
@ -17,6 +18,11 @@ import java.util.UUID;
name = "projectRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
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> {

View File

@ -6,6 +6,7 @@ import eu.eudat.dao.entities.ContentDao;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.Content;
import eu.eudat.entities.DMP;
import eu.eudat.exceptions.files.TempFileNotFoundException;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.external.ExternalSourcesItemModel;
@ -30,6 +31,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class ProjectManager {
@ -42,7 +44,18 @@ public class ProjectManager {
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(authItems, projectTableRequest);
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);
});

View File

@ -3,20 +3,19 @@ package eu.eudat.models.project;
import eu.eudat.entities.Project;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.DataModel;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.files.ContentFile;
import eu.eudat.models.urls.DataManagementPlanUrlListing;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class ProjectListingModel implements DataModel<eu.eudat.entities.Project, ProjectListingModel> {
private UUID id;
private List<DataManagementPlan> dmps;
private String label;
private String abbreviation;
@ -43,6 +42,8 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
private List<ContentFile> files;
private List<DataManagementPlanUrlListing> dmps;
public UUID getId() {
return id;
@ -52,11 +53,11 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
this.id = id;
}
public List<DataManagementPlan> getDmps() {
public List<DataManagementPlanUrlListing> getDmps() {
return dmps;
}
public void setDmps(List<DataManagementPlan> dmps) {
public void setDmps(List<DataManagementPlanUrlListing> dmps) {
this.dmps = dmps;
}
@ -178,6 +179,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
this.created = entity.getCreated().toString();
this.modified = entity.getModified().toString();
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));
return this;
}
@ -189,6 +191,6 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
@Override
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;
}
}