import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.SimulationContextType;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.SimulationContextDAO;
import org.splat.dal.dao.som.SimulationContextTypeDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.log.AppLogger;
import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.springframework.transaction.annotation.Transactional;
/**
// .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(
*
* @see org.splat.service.SimulationContextService#selectAllTypes()
*/
- @SuppressWarnings("unchecked")
public List<SimulationContextType> selectAllTypes() {
// Useless to order by names as the result mixes localized
// and non localized types
- return getSimulationContextTypeDAO().getFilteredList(null,
- Order.asc("step"));
+ return getSimulationContextTypeDAO().getAll(Order.asc("step"));
}
/**
*
* @see org.splat.service.SimulationContextService#selectTypesOf(org.splat.service.technical.ProjectSettingsService.Step[])
*/
- @SuppressWarnings("unchecked")
public List<SimulationContextType> selectTypesOf(
ProjectSettingsService.Step... step) {
- // --------------------------------------------------------------------------------------
- StringBuffer query = new StringBuffer(
- "from SimulationContextType where step='").append(
- step[0].getNumber()).append("'");
+ // StringBuffer query = new StringBuffer(
+ // "from SimulationContextType where step='").append(
+ // step[0].getNumber()).append("'");
+ // for (int i = 1; i < step.length; i++) { // Useless to order as the result mixes localized and non localized types
+ // query = query.append(" or step='").append(step[i].getNumber())
+ // .append("'");
+ // }
+ // 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
- query = query.append(" or step='").append(step[i].getNumber())
- .append("'");
+ aCondition = Restrictions.or(aCondition,
+ Restrictions.eq("step", step[i].getNumber()));
}
- query = query.append(" order by step asc");
- return Database.getSession().createQuery(query.toString()).list();
+ return getSimulationContextTypeDAO().getFilteredList(aCondition,
+ Order.asc("step"));
}
/**
*
* @see org.splat.service.SimulationContextService#selectTypesWhere(org.splat.dal.bo.som.SimulationContextType.Properties)
*/
- @SuppressWarnings("unchecked")
public List<SimulationContextType> selectTypesWhere(
SimulationContextType.Properties sprop) {
- StringBuffer query = new StringBuffer("from SimulationContextType");
- String separator = " where";
+ // StringBuffer query = new StringBuffer("from SimulationContextType");
+ // String separator = " where";
ProjectSettingsService.Step step = sprop.getStep();
ProgressState state = sprop.getProgressState();
- String order = " order by step asc";
-
+ // String order = " order by step asc";
+ //
+ // if (step != null) {
+ // query = query.append(separator).append(" step='")
+ // .append(step.getNumber()).append("'");
+ // separator = " and";
+ // order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i)
+ // }
+ // if (state != null) {
+ // query = query.append(separator).append(" state='")
+ // .append(state.toString()).append("'");
+ // // separator = " and";
+ // if (step != null) {
+ // if (state != ProgressState.APPROVED)
+ // order = " order by name asc";
+ // else
+ // order = ""; // Approved types are localized
+ // }
+ // }
+ // query = query.append(order);
+ Criterion aCondition = null;
+ Order anOrder = Order.asc("step");
if (step != null) {
- query = query.append(separator).append(" step='").append(
- step.getNumber()).append("'");
- separator = " and";
- order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i)
+ aCondition = Restrictions.eq("step", step.getNumber());
+ anOrder = Order.desc("state"); // APPROVED (upper case A) is grater than inCHECK (lower case i)
}
if (state != null) {
- query = query.append(separator).append(" state='").append(
- state.toString()).append("'");
- // separator = " and";
+ aCondition = Restrictions.and(aCondition,
+ Restrictions.eq("state", state));
if (step != null) {
- if (state != ProgressState.APPROVED)
- order = " order by name asc";
- else
- order = ""; // Approved types are localized
+ if (state != ProgressState.APPROVED) {
+ anOrder = Order.asc("name");
+ } else {
+ anOrder = null; // Approved types are localized
+ }
}
}
- query = query.append(order);
- return Database.getSession().createQuery(query.toString()).list();
+ return getSimulationContextTypeDAO().getFilteredList(aCondition,
+ anOrder);
}
/**
}
}
+ /**
+ * Approve the simulation context.
+ *
+ * @param simCtx
+ * the context to approve
+ * @return true if approval succeeded
+ */
+ public boolean approve(SimulationContext simCtx) {
+ if (simCtx.getProgressState() != ProgressState.inCHECK)
+ return false;
+ simCtx.setProgressState(ProgressState.APPROVED); // The type name is supposed being localized
+ if (simCtx.isSaved()) {
+ getSimulationContextDAO().update(simCtx);
+ }
+ 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
+ */
+ public ProjectSettingsService.Step getAttachedStep(
+ SimulationContextType simCtxType) {
+ return ProjectSettingsServiceImpl.getStep(simCtxType.getStep());
+ }
+
/**
* Get the simulationContextDAO.
*