use of org.jbei.ice.storage.model.ManuscriptModel in project ice by JBEI.
the class Manuscripts method delete.
public boolean delete(long id) {
ManuscriptModel manuscriptModel = this.dao.get(id);
if (manuscriptModel == null)
return false;
this.dao.delete(manuscriptModel);
return true;
}
use of org.jbei.ice.storage.model.ManuscriptModel in project ice by JBEI.
the class Manuscripts method update.
public Manuscript update(long id, Manuscript manuscript) {
ManuscriptModel model = dao.get(id);
if (model == null)
return null;
if (!StringUtils.isEmpty(manuscript.getTitle()))
model.setTitle(manuscript.getTitle());
if (!StringUtils.isEmpty(manuscript.getAuthorFirstName()))
model.setAuthorFirstName(manuscript.getAuthorFirstName());
if (!StringUtils.isEmpty(manuscript.getAuthorLastName()))
model.setAuthorLastName(manuscript.getAuthorLastName());
if (!StringUtils.isEmpty(manuscript.getParagonUrl()))
model.setParagonUrl(manuscript.getParagonUrl());
if (manuscript.getStatus() != null && manuscript.getStatus() != model.getStatus()) {
// update status
model.setStatus(manuscript.getStatus());
FolderPermissions folderPermissions = new FolderPermissions(this.userId, model.getFolder().getId());
if (model.getStatus() == ManuscriptStatus.ACCEPTED) {
// make public
setFolderType(model.getFolder(), FolderType.PUBLIC);
folderPermissions.enablePublicReadAccess();
} else {
// remove public
setFolderType(model.getFolder(), FolderType.PRIVATE);
folderPermissions.disablePublicReadAccess();
}
}
return dao.update(model).toDataTransferObject();
}
use of org.jbei.ice.storage.model.ManuscriptModel in project ice by JBEI.
the class Manuscripts method get.
public Results<Manuscript> get(String sort, boolean asc, int offset, int size, String filter) {
Results<Manuscript> results = new Results<>();
results.setResultCount(dao.getTotalCount(filter));
List<ManuscriptModel> list = dao.list(sort, asc, offset, size, filter);
if (!list.isEmpty()) {
for (ManuscriptModel manuscriptModel : list) results.getData().add(manuscriptModel.toDataTransferObject());
}
return results;
}
use of org.jbei.ice.storage.model.ManuscriptModel in project ice by JBEI.
the class ManuscriptModelDAO method list.
public List<ManuscriptModel> list(String sort, boolean asc, int offset, int size, String filter) {
try {
CriteriaQuery<ManuscriptModel> query = getBuilder().createQuery(ManuscriptModel.class);
Root<ManuscriptModel> from = query.from(ManuscriptModel.class);
if (filter != null && !filter.trim().isEmpty()) {
query.where(getBuilder().like(getBuilder().lower(from.get("title")), "%" + filter.toLowerCase() + "%"));
}
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.ManuscriptModel in project ice by JBEI.
the class ManuscriptModelDAO method getTotalCount.
public int getTotalCount(String filter) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<ManuscriptModel> from = query.from(ManuscriptModel.class);
if (filter != null && !filter.trim().isEmpty()) {
query.where(getBuilder().like(getBuilder().lower(from.get("title")), "%" + filter.toLowerCase() + "%"));
}
query.select(getBuilder().countDistinct(from.get("id")));
return currentSession().createQuery(query).uniqueResult().intValue();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations