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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import java.util.Date;
public class ProjectCriteria extends Criteria<Project>{
private Date periodStart;
private Date periodEnd;
private String reference;
public Date getPeriodStart() {
return periodStart;
}
@ -23,4 +23,12 @@ public class ProjectCriteria extends Criteria<Project>{
public void setPeriodEnd(Date 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> {
private UUID id;
private List<DataManagementPlan> dmps;
@ -170,7 +167,6 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
this.created = entity.getCreated();
this.modified = entity.getModified();
this.description = entity.getDescription();
}
@Override
@ -179,7 +175,7 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
entity.setId(this.id);
entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label);
entity.setReference(this.reference);
entity.setReference(this.reference == null ? "dmp:"+this.label : this.reference);
entity.setUri(this.uri);
entity.setDefinition(this.definition);
entity.setStartdate(this.startDate);