Search in sources :

Example 1 with ManuscriptModel

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;
}
Also used : ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel)

Example 2 with ManuscriptModel

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();
}
Also used : ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel) FolderPermissions(org.jbei.ice.lib.folder.FolderPermissions)

Example 3 with ManuscriptModel

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;
}
Also used : Results(org.jbei.ice.lib.dto.common.Results) ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel)

Example 4 with ManuscriptModel

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel)

Example 5 with ManuscriptModel

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) ManuscriptModel(org.jbei.ice.storage.model.ManuscriptModel)

Aggregations

ManuscriptModel (org.jbei.ice.storage.model.ManuscriptModel)7 HibernateException (org.hibernate.HibernateException)2 DAOException (org.jbei.ice.storage.DAOException)2 Date (java.util.Date)1 Results (org.jbei.ice.lib.dto.common.Results)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 EntriesAsCSV (org.jbei.ice.lib.entry.EntriesAsCSV)1 FolderPermissions (org.jbei.ice.lib.folder.FolderPermissions)1 Folder (org.jbei.ice.storage.model.Folder)1