Add type to the recent activity model

This commit is contained in:
George Kalampokis 2020-07-02 11:59:58 +03:00
parent 325979a896
commit f5093a6995
3 changed files with 37 additions and 1 deletions

View File

@ -16,6 +16,7 @@ public abstract class RecentActivityModel<T> {
private Date finalizedAt;
private Date publishedAt;
private String profile;
private RecentActivityType type;
public String getId() {
return id;
@ -121,5 +122,39 @@ public abstract class RecentActivityModel<T> {
this.profile = profile;
}
public RecentActivityType getType() {
return type;
}
public void setType(RecentActivityType type) {
this.type = type;
}
public abstract RecentActivityModel fromEntity(T entity);
public enum RecentActivityType {
DMP(1), DATASET(2);
private final int index;
RecentActivityType(int index) {
this.index = index;
}
public int getIndex() {
return index;
}
public static RecentActivityType fromIndex(int index) {
switch (index) {
case 1:
return DMP;
case 2:
return DATASET;
default:
throw new IllegalArgumentException("Recent Activity Type : \"" + index + "\" is not supported.");
}
}
}
}

View File

@ -4,7 +4,6 @@ import eu.eudat.data.entities.Dataset;
import eu.eudat.logic.utilities.helpers.LabelBuilder;
import eu.eudat.models.data.dataset.DataRepository;
import eu.eudat.models.data.dataset.Service;
import eu.eudat.models.data.listingmodels.DatasetListingModel;
import java.util.Date;
import java.util.stream.Collectors;
@ -80,6 +79,7 @@ public class RecentDatasetModel extends RecentActivityModel<Dataset> {
}
public RecentDatasetModel fromDmpEntity(Dataset entity) {
this.setType(RecentActivityType.DATASET);
this.setId(entity.getId().toString());
this.setTitle(entity.getLabel());
this.setDescription(entity.getDescription());

View File

@ -90,6 +90,7 @@ public class RecentDmpModel extends RecentActivityModel<DMP> {
@Override
@Transactional
public RecentActivityModel fromEntity(DMP entity) {
this.setType(RecentActivityType.DMP);
this.setId(entity.getId().toString());
this.setTitle(entity.getLabel());
this.setDescription(entity.getDescription());