package org.splat.service;
+import java.util.Iterator;
import java.util.List;
+import java.util.Vector;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.splat.dal.dao.som.SimulationContextTypeDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.log.AppLogger;
+import org.splat.service.dto.SimulationContextFacade;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.springframework.transaction.annotation.Transactional;
* Injected simulation context type DAO.
*/
private SimulationContextTypeDAO _simulationContextTypeDAO;
+ /**
+ * Injected project settings service.
+ */
+ private ProjectSettingsService _projectSettingsService;
+
+ /**
+ * Get simulation contexts which are currently in the given state.
+ *
+ * @param aState
+ * the progress state to filter contexts
+ * @return the list of found contexts as a vector of SimulationContextFacade
+ * @throws InvalidPropertyException
+ * if the given state is invalid
+ */
+ @Transactional(readOnly=true)
+ public Vector<SimulationContextFacade> getSimulationContextsInState(
+ ProgressState aState) throws InvalidPropertyException {
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ List<SimulationContext> context = selectSimulationContextsWhere(cprop
+ .setState(aState));
+
+ Vector<SimulationContextFacade> result = new Vector<SimulationContextFacade>(
+ context.size());
+ for (Iterator<SimulationContext> i = context.iterator(); i.hasNext();) {
+ result.add(new SimulationContextFacade(i.next(),
+ getProjectSettings().getAllSteps()));
+ }
+ return result;
+ }
/**
* {@inheritDoc}
// .append("'");
// separator = " and";
- aCondition = Restrictions.and(aCondition,
- Restrictions.eq("value", value));
+ aCondition = Restrictions.and(aCondition, Restrictions.eq("value",
+ value));
}
if (state != null) {
// query = query.append(separator).append(" state='").append(state)
// order = " order by type asc";
anOrder = Order.asc("type");
}
- aCondition = Restrictions.and(aCondition,
- Restrictions.eq("state", state));
+ aCondition = Restrictions.and(aCondition, Restrictions.eq("state",
+ state));
}
// query.append(order);
// return (List<SimulationContext>) Database.getSession().createQuery(
return resList;
}
- /**
- * {@inheritDoc}
- *
- * @see org.splat.service.SimulationContextService#createType(java.lang.String, org.splat.service.technical.ProjectSettingsService.Step)
- */
- @Transactional
- public SimulationContextType createType(String name,
- ProjectSettingsService.Step step) throws InvalidPropertyException {
- // TODO: Check for duplicate definition
- SimulationContextType type = new SimulationContextType(name, step);
- getSimulationContextTypeDAO().create(type);
-
- return type;
- }
-
/**
* {@inheritDoc}
*
// query = query.append(" order by step asc");
Criterion aCondition = Restrictions.eq("step", step[0].getNumber());
for (int i = 1; i < step.length; i++) { // Useless to order as the result mixes localized and non localized types
- aCondition = Restrictions.or(aCondition,
- Restrictions.eq("step", step[i].getNumber()));
+ aCondition = Restrictions.or(aCondition, Restrictions.eq("step",
+ step[i].getNumber()));
}
return getSimulationContextTypeDAO().getFilteredList(aCondition,
Order.asc("step"));
anOrder = Order.desc("state"); // APPROVED (upper case A) is grater than inCHECK (lower case i)
}
if (state != null) {
- aCondition = Restrictions.and(aCondition,
- Restrictions.eq("state", state));
+ aCondition = Restrictions.and(aCondition, Restrictions.eq("state",
+ state));
if (step != null) {
if (state != ProgressState.APPROVED) {
anOrder = Order.asc("name");
return true;
}
- /**
- * Approve the simulation context type.
- *
- * @param simCtxType
- * the type to approve
- * @return true if approval succeeded
- */
- public boolean approve(SimulationContextType simCtxType) {
- if (simCtxType.getState() != ProgressState.inCHECK)
- return false;
- simCtxType.setState(ProgressState.APPROVED); // The type name is supposed being localized
- getSimulationContextTypeDAO().update(simCtxType);
- return true;
- }
-
/**
* @param simCtxType
* @return
SimulationContextTypeDAO simulationContextTypeDAO) {
_simulationContextTypeDAO = simulationContextTypeDAO;
}
+
+ /**
+ * Get project settings.
+ *
+ * @return Project settings service
+ */
+ private ProjectSettingsService getProjectSettings() {
+ return _projectSettingsService;
+ }
+
+ /**
+ * Set project settings service.
+ *
+ * @param projectSettingsService
+ * project settings service
+ */
+ public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+ _projectSettingsService = projectSettingsService;
+ }
}