no message

This commit is contained in:
Ioannis Kalyvas 2018-02-02 18:21:46 +02:00
parent c36fa5e6f8
commit e437ae354e
5 changed files with 57 additions and 46 deletions

View File

@ -1,6 +1,7 @@
package eu.eudat.dao.entities; package eu.eudat.dao.entities;
import java.util.UUID; import java.util.UUID;
import eu.eudat.dao.DatabaseAccess; import eu.eudat.dao.DatabaseAccess;
import eu.eudat.dao.databaselayer.service.DatabaseService; import eu.eudat.dao.databaselayer.service.DatabaseService;
import eu.eudat.entities.*; import eu.eudat.entities.*;
@ -13,48 +14,53 @@ import org.springframework.stereotype.Component;
@Component("projectDao") @Component("projectDao")
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao { public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
@Autowired @Autowired
public ProjectDaoImpl(DatabaseService<Project> databaseService) { public ProjectDaoImpl(DatabaseService<Project> databaseService) {
this.setDatabaseService(databaseService); this.setDatabaseService(databaseService);
} }
@Override @Override
public QueryableList<Project> getWithCriteria(ProjectCriteria criteria) { public QueryableList<Project> getWithCriteria(ProjectCriteria criteria) {
QueryableList<Project> query = getDatabaseService().getQueryable(Project.class); QueryableList<Project> query = getDatabaseService().getQueryable(Project.class);
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%")); if (criteria.getLike() != null && !criteria.getLike().isEmpty())
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("enddate"),criteria.getPeriodEnd())); query.where((builder, root) -> builder.like(root.get("label"), "%" + criteria.getLike() + "%"));
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("startdate"),criteria.getPeriodStart())); if (criteria.getPeriodEnd() != null)
query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue())); query.where((builder, root) -> builder.lessThan(root.get("enddate"), criteria.getPeriodEnd()));
return query; if (criteria.getPeriodStart() != null)
} query.where((builder, root) -> builder.greaterThan(root.get("startdate"), criteria.getPeriodStart()));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getReference()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue()));
return query;
}
@Override @Override
public Project createOrUpdate(Project item) { public Project createOrUpdate(Project item) {
return getDatabaseService().createOrUpdate(item,Project.class); return getDatabaseService().createOrUpdate(item, Project.class);
} }
@Override @Override
public Project find(UUID id) { public Project find(UUID id) {
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")),id)).getSingle(); return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
} }
@Override @Override
public Long count() { public Long count() {
return this.getDatabaseService().count(Project.class); return this.getDatabaseService().count(Project.class);
} }
@Override @Override
public void delete(Project item) { public void delete(Project item) {
this.getDatabaseService().delete(item); this.getDatabaseService().delete(item);
} }
@Override @Override
public QueryableList<Project> asQueryable() { public QueryableList<Project> asQueryable() {
return this.getDatabaseService().getQueryable(Project.class); return this.getDatabaseService().getQueryable(Project.class);
} }
public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) { public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.get("creator"), principal)); query.where((builder, root) -> builder.equal(root.get("creator"), principal));
return query; return query;
} }
} }

View File

@ -258,6 +258,7 @@ public class DMP implements Serializable, DataEntity<DMP> {
this.label = entity.getLabel(); this.label = entity.getLabel();
this.status = entity.getStatus(); this.status = entity.getStatus();
this.created = entity.created; this.created = entity.created;
this.project = entity.getProject();
this.description = entity.getDescription(); this.description = entity.getDescription();
this.researchers = entity.getResearchers(); this.researchers = entity.getResearchers();
this.organisations = entity.getOrganisations(); this.organisations = entity.getOrganisations();

View File

@ -106,9 +106,9 @@ public class DataManagementPlanManager {
if (newDmp.getProject() != null) { if (newDmp.getProject() != null) {
Project project = newDmp.getProject(); Project project = newDmp.getProject();
ProjectCriteria criteria = new ProjectCriteria(); ProjectCriteria criteria = new ProjectCriteria();
criteria.setLike(project.getReference()); criteria.setReference(project.getReference());
List<eu.eudat.entities.Project> entries = projectDao.getWithCriteria(criteria).toList(); eu.eudat.entities.Project projectEntity = projectDao.getWithCriteria(criteria).getSingleOrDefault();
if (entries != null && !entries.isEmpty()) project.setId(entries.get(0).getId()); if (projectEntity != null) project.setId(projectEntity.getId());
else { else {
project.setCreationUser(userInfo); project.setCreationUser(userInfo);
projectDao.createOrUpdate(project); projectDao.createOrUpdate(project);

View File

@ -7,7 +7,7 @@ import java.util.Date;
public class ProjectCriteria extends Criteria<Project>{ public class ProjectCriteria extends Criteria<Project>{
private Date periodStart; private Date periodStart;
private Date periodEnd; private Date periodEnd;
private String reference;
public Date getPeriodStart() { public Date getPeriodStart() {
return periodStart; return periodStart;
} }
@ -23,4 +23,12 @@ public class ProjectCriteria extends Criteria<Project>{
public void setPeriodEnd(Date periodEnd) { public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd; this.periodEnd = periodEnd;
} }
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
} }

View File

@ -12,9 +12,6 @@ import eu.eudat.models.dmp.DataManagementPlan;
public class Project implements DataModel<eu.eudat.entities.Project> { public class Project implements DataModel<eu.eudat.entities.Project> {
private UUID id; private UUID id;
private List<DataManagementPlan> dmps; private List<DataManagementPlan> dmps;
@ -170,7 +167,6 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
this.created = entity.getCreated(); this.created = entity.getCreated();
this.modified = entity.getModified(); this.modified = entity.getModified();
this.description = entity.getDescription(); this.description = entity.getDescription();
} }
@Override @Override
@ -179,7 +175,7 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
entity.setId(this.id); entity.setId(this.id);
entity.setAbbreviation(this.abbreviation); entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label); entity.setLabel(this.label);
entity.setReference(this.reference); entity.setReference(this.reference == null ? "dmp:"+this.label : this.reference);
entity.setUri(this.uri); entity.setUri(this.uri);
entity.setDefinition(this.definition); entity.setDefinition(this.definition);
entity.setStartdate(this.startDate); entity.setStartdate(this.startDate);