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);
}
}
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;
}
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;
}
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();
}
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);
}
}
Aggregations