Search in sources :

Example 1 with Experiment

use of org.jbei.ice.storage.model.Experiment in project ice by JBEI.

the class ExperimentDAO method getByUrl.

public Experiment getByUrl(String url) throws DAOException {
    try {
        CriteriaQuery<Experiment> query = getBuilder().createQuery(Experiment.class);
        Root<Experiment> from = query.from(Experiment.class);
        query.where(getBuilder().equal(from.get("url"), url));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Experiment(org.jbei.ice.storage.model.Experiment)

Example 2 with Experiment

use of org.jbei.ice.storage.model.Experiment in project ice by JBEI.

the class Experiments method deleteStudy.

/**
 * Deletes a study associated with the specified part and with the specified unique identifier.
 * User making request must have created the study ({@see createOrUpdateStudy()}) or must have write
 * permissions for the part that the study is associated with
 *
 * @param studyId id of study to be deleted
 * @return true if study is found and deleted successfully, false otherwise
 */
public boolean deleteStudy(long studyId) {
    Experiment experiment = dao.get(studyId);
    if (experiment == null)
        return false;
    if (!userId.equalsIgnoreCase(experiment.getOwnerEmail()) && !entryAuthorization.canWrite(userId, entry)) {
        throw new PermissionException("Cannot delete experiment");
    }
    dao.delete(experiment);
    return true;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Experiment(org.jbei.ice.storage.model.Experiment)

Example 3 with Experiment

use of org.jbei.ice.storage.model.Experiment in project ice by JBEI.

the class Experiments method getPartStudies.

/**
 * Retrieves experiment data associated with a specific entry
 *
 * @return list of experiment studies associated with the specified entry, or null if the entry does not exist
 * @throws PermissionException if the specified user does not have read privileges on the specified entry
 */
public ArrayList<Study> getPartStudies() {
    entryAuthorization.expectRead(userId, entry);
    List<Experiment> experimentList = dao.getExperimentList(entry.getId());
    ArrayList<Study> studies = new ArrayList<>();
    for (Experiment experiment : experimentList) {
        studies.add(experiment.toDataTransferObject());
    }
    return studies;
}
Also used : Experiment(org.jbei.ice.storage.model.Experiment) ArrayList(java.util.ArrayList)

Example 4 with Experiment

use of org.jbei.ice.storage.model.Experiment in project ice by JBEI.

the class Experiments method createOrUpdateStudy.

/**
 * Creates a new study for a particular entry. If a unique identifier is associated with the {@link Study} object
 * then an update occurs instead of a new object being created.
 * <p/>
 * Only read access is required to create a new study. To update an existing study
 * the user must be the creator or must have write access on the entry the study is associated with
 *
 * @param study data for study
 * @return saved study (including unique identifier)
 */
public Study createOrUpdateStudy(Study study) {
    if (StringUtils.isEmpty(study.getUrl()))
        return null;
    Experiment experiment = null;
    if (study.getId() > 0) {
        experiment = dao.get(study.getId());
    }
    if (experiment == null)
        experiment = dao.getByUrl(study.getUrl());
    if (experiment == null) {
        entryAuthorization.expectRead(userId, entry);
        experiment = new Experiment();
        experiment.setCreationTime(new Date());
        experiment.setUrl(study.getUrl());
        String label = study.getLabel();
        if (label.length() >= 128)
            label = label.substring(0, 128);
        experiment.setLabel(label);
        experiment.getSubjects().add(entry);
        experiment.setOwnerEmail(userId);
        experiment = dao.create(experiment);
        return experiment.toDataTransferObject();
    }
    if (!userId.equalsIgnoreCase(experiment.getOwnerEmail()))
        entryAuthorization.expectWrite(userId, entry);
    String label = study.getLabel();
    if (label.length() >= 128)
        label = label.substring(0, 128);
    experiment.setUrl(study.getUrl());
    experiment.setLabel(label);
    experiment.getSubjects().add(entry);
    return dao.update(experiment).toDataTransferObject();
}
Also used : Experiment(org.jbei.ice.storage.model.Experiment) Date(java.util.Date)

Example 5 with Experiment

use of org.jbei.ice.storage.model.Experiment in project ice by JBEI.

the class ExperimentDAO method getExperimentList.

public List<Experiment> getExperimentList(long entryId) {
    try {
        CriteriaQuery<Experiment> query = getBuilder().createQuery(Experiment.class);
        Root<Experiment> from = query.from(Experiment.class);
        Join<Experiment, Entry> entryJoin = from.join("subjects");
        query.distinct(true).where(getBuilder().equal(entryJoin.get("id"), entryId));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Entry(org.jbei.ice.storage.model.Entry) HibernateException(org.hibernate.HibernateException) Experiment(org.jbei.ice.storage.model.Experiment)

Aggregations

Experiment (org.jbei.ice.storage.model.Experiment)5 HibernateException (org.hibernate.HibernateException)2 DAOException (org.jbei.ice.storage.DAOException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 Entry (org.jbei.ice.storage.model.Entry)1