package org.splat.service;
import java.io.IOException;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import org.apache.log4j.Logger;
+import org.hibernate.Query;
import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ActorRelation;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
-import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationCycleRelation;
import org.splat.dal.bo.som.Visibility;
import org.splat.dal.bo.som.Study.Properties;
import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.StudyDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.service.technical.IndexService;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.som.Revision;
+import org.springframework.transaction.annotation.Transactional;
/**
* This class defines all methods for creation, modification the study.
+ *
* @author Maria KRUCHININA
- *
+ *
*/
public class StudyServiceImpl implements StudyService {
/**
* logger for the service.
*/
- public final static AppLogger logger = AppLogger.getLogger(StudyServiceImpl.class);
+ public final static AppLogger logger = AppLogger
+ .getLogger(StudyServiceImpl.class);
+ /**
+ * Injected index service.
+ */
private IndexService _indexService;
+ /**
+ * Injected step service.
+ */
private StepService _stepService;
+ /**
+ * Injected scenario service.
+ */
private ScenarioService _scenarioService;
+ /**
+ * Injected project service.
+ */
private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected project element service.
+ */
private ProjectElementService _projectElementService;
-
+
/**
- * Get the simulation context list for displaying drop-down list values populating
- * on the "Create new study" screen.
+ * Injected study DAO.
+ */
+ private StudyDAO _studyDAO;
+
+ /**
* {@inheritDoc}
- * @see org.splat.service.StudyService#getSimulationContextList()
+ * @see org.splat.service.StudyService#selectStudy(long)
*/
- public List<SimulationContext> getSimulationContextList() {
- //TODO: remove the commit transaction ...
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- SimulationContext.Properties cprop = new SimulationContext.Properties();
- SimulationContextType product = SimulationContext.selectType("product");
- List<SimulationContext> resList = Database.selectSimulationContextsWhere(cprop.setType(product));
-
- transax.commit();
-
- return resList;
- }
-
+ @Transactional
public Study selectStudy(long index) {
- // -------------------------------------------
- StringBuffer query = new StringBuffer("from Study where rid='").append(
- index).append("'");
- Study result = (Study) Database.getSession().createQuery(
- query.toString()).uniqueResult();
-
+ Study result = getStudyDAO().get(index);
result.loadWorkflow();
return result;
}
return result;
}
+ @Transactional
public Study createStudy(Study.Properties sprop)
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException, RuntimeException {
Study study = new Study(sprop);
buildReference(study);
- Database.getSession().save(study); // TODO: use StudyDAO and throw out Database.
+ getStudyDAO().create(study);
try {
IndexService lucin = getIndex();
lucin.add(study);
public boolean buildReference(Study aStudy) {
String pattern = aStudy.getReference(); // The study being supposed just created, its reference is the reference pattern
- IDBuilder tool = Database.selectIDBuilder(aStudy.getDate());
+ IDBuilder tool = selectIDBuilder(aStudy.getDate());
if (tool == null) {
tool = new IDBuilder(aStudy.getDate());
Database.getSession().save(tool);
return true;
}
+ public IDBuilder selectIDBuilder(Date date) {
+ // ------------------------------------------------------
+ SimpleDateFormat year = new SimpleDateFormat("yyyy");
+ String cycle = year.format(date);
+ StringBuffer buffer = new StringBuffer("from IDBuilder where cycle='")
+ .append(cycle).append("'");
+ String qstring = buffer.toString();
+ Query query = Database.getSession().createQuery(qstring);
+ IDBuilder result = (IDBuilder) query.uniqueResult();
+
+ return result;
+ }
+
public boolean publishes(Study aStudy, Document doc) {
// ---------------------------------------
if (!aStudy.publishes(doc)) {
KnowledgeElementType ucase = KnowledgeElement.selectType("usecase");
KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
User admin = UserDirectory.selectUser(1); // First user created when creating the database
- kprop.setType(ucase).setTitle(aStudy.getTitle())
- .setValue(scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
- // knowledges
+ kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
+ scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
+ // knowledges
getScenarioService().addKnowledgeElement(scenario, kprop);
return scenario;
}
}
}
- /**
- * @return
- */
- public IndexService getIndexService() {
- return _indexService;
- }
-
- public void setIndexService(IndexService indexService) {
- _indexService = indexService;
- }
-
/**
* Get project settings.
*
/**
* Get the stepService.
+ *
* @return the stepService
*/
public StepService getStepService() {
/**
* Set the stepService.
- * @param stepService the stepService to set
+ *
+ * @param stepService
+ * the stepService to set
*/
public void setStepService(StepService stepService) {
_stepService = stepService;
}
+
+ /**
+ * Get the indexService.
+ * @return the indexService
+ */
+ public IndexService getIndexService() {
+ return _indexService;
+ }
+
+ /**
+ * Set the indexService.
+ * @param indexService the indexService to set
+ */
+ public void setIndexService(IndexService indexService) {
+ _indexService = indexService;
+ }
+
+ /**
+ * Get the studyDAO.
+ * @return the studyDAO
+ */
+ public StudyDAO getStudyDAO() {
+ return _studyDAO;
+ }
+
+ /**
+ * Set the studyDAO.
+ * @param studyDAO the studyDAO to set
+ */
+ public void setStudyDAO(StudyDAO studyDAO) {
+ _studyDAO = studyDAO;
+ }
}