LCK-000004=Lock reference is timeout and could have been modified by user {2}.
STD-000001=Unable to re-index the study #{1}, reason: {2}
SCN-000001=Scenario doesn't contain the step number #{1}
-SCN-000002=Scenario doesn't contain the document #{1}
\ No newline at end of file
+SCN-000002=Scenario doesn't contain the document #{1}
+KNT-000001=Knowledge element type "{1}" already exists
+SCT-000001=Simulation context type "{1}" already exists
+DCT-000001=Document type "{1}" already exists
LCK-000002=Lock reference does not exists.
LCK-000003=Lock reference protected and can be only deleted or updated by user {2}.
LCK-000004=Lock reference is timeout and could have been modified by user {2}.
-STD-000001="Unable to re-index the study #{1}, reason: {2}"
\ No newline at end of file
+STD-000001=Unable to re-index the study #{1}, reason: {2}
+SCN-000001=Scenario doesn't contain the step number #{1}
+SCN-000002=Scenario doesn't contain the document #{1}
+KNT-000001=Knowledge element type "{1}" already exists
+SCT-000001=Simulation context type "{1}" already exists
+DCT-000001=Document type "{1}" already exists
/**
* Scenario doesn't contain the document #{1}.
*/
- SCN_000002("SCN-000002");
+ SCN_000002("SCN-000002"),
+ /**
+ * Simulation context type "{1}" already exists.
+ */
+ KNT_000001("KNT-000001"),
+ /**
+ * Knowledge element type "{1}" already exists.
+ */
+ SCT_000001("SCT-000001"),
+ /**
+ * Document type "{1}" already exists.
+ */
+ DCT_000001("DCT-000001");
/**
* Value.
package org.splat.dal.bo.som;
+
/**
*
* @author Daniel Brunier-Coulin
import org.splat.kernel.InvalidPropertyException;
import org.splat.service.technical.ProjectSettingsService;
-
+/**
+ * Persistent simulation context type.
+ */
public class SimulationContextType extends Persistent implements Serializable {
-
-// Persistent fields
- private String name;
- private ProgressState state;
- private int step;
-// Required by the serialization
+ /**
+ * Serialization version id.
+ */
private static final long serialVersionUID = 4819425038576161242L;
-// ==============================================================================================================================
-// Constructors
-// ==============================================================================================================================
-
-// Search properties class
- public static class Properties {
-// ------------------------------
- private ProgressState state = null;
- private ProjectSettingsService.Step step = null;
-
- public ProgressState getProgressState () {
- return state;
- }
- public ProjectSettingsService.Step getStep () {
- return step;
- }
- public Properties setProgressState (final ProgressState state) {
- this.state = state;
- return this;
- }
- public Properties setStep (final ProjectSettingsService.Step step) {
- this.step = step;
- return this;
- }
- }
-// Database fetch constructor
- protected SimulationContextType () {
- }
-// Initialization constructor
- public SimulationContextType (final String name, final ProjectSettingsService.Step step) throws InvalidPropertyException {
-// ------------------------------------------------------------------------
- super();
- this.name = name;
- this.state = ProgressState.inCHECK;
- this.step = step.getNumber();
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- @Override
+ // Persistent fields
+ /**
+ * Context type name.
+ */
+ private String name;
+ /**
+ * Context progress state.
+ */
+ private ProgressState state;
+ /**
+ * Context type first applicable step.
+ */
+ private int step;
+
+ // ==============================================================================================================================
+ // Constructors
+ // ==============================================================================================================================
+
+ /**
+ * Search properties class.
+ */
+ public static class Properties {
+ private ProgressState state = null;
+ private ProjectSettingsService.Step step = null;
+
+ public ProgressState getProgressState() {
+ return state;
+ }
+
+ public ProjectSettingsService.Step getStep() {
+ return step;
+ }
+
+ public Properties setProgressState(final ProgressState state) {
+ this.state = state;
+ return this;
+ }
+
+ public Properties setStep(final ProjectSettingsService.Step step) {
+ this.step = step;
+ return this;
+ }
+ }
+
+ /**
+ * Database fetch constructor.
+ */
+ protected SimulationContextType() {
+ super();
+ }
+
+ /**
+ * Initialization constructor.
+ *
+ * @param name
+ * context type name
+ * @param step
+ * first applicable step for this type of context
+ * @throws InvalidPropertyException
+ * from constructor of parent class
+ */
+ public SimulationContextType(final String name,
+ final ProjectSettingsService.Step step)
+ throws InvalidPropertyException {
+ super();
+ this.name = name;
+ this.state = ProgressState.inCHECK;
+ this.step = step.getNumber();
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ /**
+ * Saved context types are equal if their persistent ids are equal. <BR>
+ * Before becoming persistent context types are compared by their names.
+ *
+ * @param entity
+ * object to compare with
+ * @return true if this context type equals to the given object
+ * @see org.splat.dal.bo.kernel.Persistent#equals(java.lang.Object)
+ */
+ @Override
public boolean equals(final Object entity) {
-// ------------------------------------
- if (entity == null) {
- return false;
+
+ if (entity == null) {
+ return false;
+ }
+ if (entity instanceof String) {
+ return this.name.equals(entity); // Names are unique
+ } else if (entity instanceof SimulationContextType) {
+ SimulationContextType object = (SimulationContextType) entity;
+ long he = object.getIndex();
+ long me = this.getIndex();
+ if (me * he == 0) {
+ return this.getName().equals(object.getName());
+ } else {
+ return (he == me);
+ }
+ } else {
+ return false;
+ }
}
- if (entity instanceof String) {
- return this.name.equals(entity); // Names are unique
- } else if (entity instanceof SimulationContextType) {
- SimulationContextType object = (SimulationContextType)entity;
- long he = object.getIndex();
- long me = this.getIndex();
- if (me*he != 0) {
- return (he == me);
- } else {
- return this.getName().equals(object.getName());
- }
- } else {
- return false;
- }
- }
-
- public String getName () {
-// ------------------------
- return name;
- }
-
- public boolean isAttachedTo (final ProjectSettingsService.Step step) {
-// -------------------------------------------------------
- if (this.step == step.getNumber()) {
- return true;
+
+ /**
+ * Get context type name.
+ *
+ * @return context type name
+ */
+ public String getName() {
+ return name;
}
- return false;
- }
-
- public boolean isApproved () {
-// ----------------------------
- return (state == ProgressState.APPROVED);
- }
- /**
+
+ /**
+ * Check if contexts of this type are attached to the given study step.
+ *
+ * @param step
+ * the study step
+ * @return true if contexts of this type are attached to the given study step
+ */
+ public boolean isAttachedTo(final ProjectSettingsService.Step step) {
+ return (this.step == step.getNumber());
+ }
+
+ /**
+ * Check if the context is approved.
+ *
+ * @return true if the context is approved
+ */
+ public boolean isApproved() {
+ return (state == ProgressState.APPROVED);
+ }
+
+ /**
* Get the state.
+ *
* @return the state
*/
public ProgressState getState() {
return state;
}
+
/**
* Set the state.
- * @param state the state to set
+ *
+ * @param state
+ * the state to set
*/
public void setState(final ProgressState state) {
this.state = state;
}
+
/**
* Get the step.
+ *
* @return the step
*/
public int getStep() {
return step;
}
+
/**
* Set the step.
- * @param step the step to set
+ *
+ * @param step
+ * the step to set
*/
public void setStep(final int step) {
this.step = step;
import org.hibernate.Hibernate;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
+import org.splat.common.properties.MessageKeyEnum;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.dao.som.DocumentTypeDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
+import org.splat.log.AppLogger;
import org.splat.service.technical.ProjectSettingsService;
import org.springframework.transaction.annotation.Transactional;
*/
public class DocumentTypeServiceImpl implements DocumentTypeService {
+ /**
+ * The logger for the service.
+ */
+ public final static AppLogger LOG = AppLogger
+ .getLogger(DocumentTypeServiceImpl.class);
/**
* Injected document type DAO.
*/
type = new DocumentType(tprop);
getDocumentTypeDAO().create(type);
} else {
+ LOG.info(MessageKeyEnum.DCT_000001.toString(), tprop.getName());
type.setProperties(tprop); // Update properties of persistent type
}
return type;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
+import org.splat.common.properties.MessageKeyEnum;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
+import org.splat.log.AppLogger;
import org.springframework.transaction.annotation.Transactional;
/**
public class KnowledgeElementTypeServiceImpl implements
KnowledgeElementTypeService {
+ /**
+ * The logger for the service.
+ */
+ public final static AppLogger LOG = AppLogger
+ .getLogger(KnowledgeElementTypeServiceImpl.class);
/**
* Injected knowledge element type DAO.
*/
* the new type name
* @return the created knowledge type
*/
- public KnowledgeElementType createType(String name) {
- // TODO: Check for duplicate definition
- KnowledgeElementType kelt = new KnowledgeElementType(name);
- getKnowledgeElementTypeDAO().create(kelt);
+ public KnowledgeElementType createType(final String name) {
+ KnowledgeElementType kelt = getKnowledgeElementTypeDAO()
+ .findByCriteria(Restrictions.eq("name", name));
+ if (kelt == null) {
+ kelt = new KnowledgeElementType(name);
+ getKnowledgeElementTypeDAO().create(kelt);
+ } else {
+ LOG.info(MessageKeyEnum.KNT_000001.toString(), name);
+ }
return kelt;
}
* the progress state
* @return the list of found knowledge types
*/
- public List<KnowledgeElementType> selectTypesWhere(ProgressState state) {
+ public List<KnowledgeElementType> selectTypesWhere(final ProgressState state) {
return getKnowledgeElementTypeDAO().getFilteredList(
Restrictions.eq("state", state), Order.asc("rid"));
}
* the knowledge type name
* @return the found knowledge type
*/
- public KnowledgeElementType selectType(String name) {
+ public KnowledgeElementType selectType(final String name) {
return getKnowledgeElementTypeDAO().findByCriteria(
Restrictions.eq("name", name));
}
* the id of a knowledge type
* @return the found knowledge type
*/
- public KnowledgeElementType selectType(long index) {
+ public KnowledgeElementType selectType(final long index) {
return getKnowledgeElementTypeDAO().get(index);
}
* @return true if approval succeeded
*/
@Transactional
- public boolean approve(KnowledgeElementType kelt) {
- if (kelt.getState() != ProgressState.inCHECK)
- return false;
- kelt.setState(ProgressState.APPROVED); // The type name is supposed being localized
- if (kelt.isSaved()) {
- getKnowledgeElementTypeDAO().update(kelt);
+ public boolean approve(final KnowledgeElementType kelt) {
+ boolean res = (kelt.getState() == ProgressState.inCHECK);
+ if (res) {
+ kelt.setState(ProgressState.APPROVED); // The type name is supposed being localized
+ if (kelt.isSaved()) {
+ getKnowledgeElementTypeDAO().update(kelt);
+ }
}
- return true;
+ return res;
}
/**
* @return true if approval succeeded
*/
@Transactional
- public boolean reserve(KnowledgeElementType kelt) {
- if (kelt.getState() != ProgressState.inCHECK)
- return false;
- kelt.setState(ProgressState.inWORK);
- if (kelt.isSaved()) {
- getKnowledgeElementTypeDAO().update(kelt);
+ public boolean reserve(final KnowledgeElementType kelt) {
+ boolean res = (kelt.getState() == ProgressState.inCHECK);
+ if (res) {
+ kelt.setState(ProgressState.inWORK);
+ if (kelt.isSaved()) {
+ getKnowledgeElementTypeDAO().update(kelt);
+ }
}
- return true;
+ return res;
}
/**
* the knowledgeElementTypeDAO to set
*/
public void setKnowledgeElementTypeDAO(
- KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
+ final KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
_knowledgeElementTypeDAO = knowledgeElementTypeDAO;
}
package org.splat.service;
+import org.hibernate.criterion.Restrictions;
+import org.splat.common.properties.MessageKeyEnum;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.SimulationContextType;
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.springframework.transaction.annotation.Transactional;
public class SimulationContextTypeServiceImpl implements
SimulationContextTypeService {
+ /**
+ * The logger for the service.
+ */
+ public final static AppLogger LOG = AppLogger
+ .getLogger(SimulationContextTypeServiceImpl.class);
+
/**
* Injected simulation context type DAO.
*/
* @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);
+ public SimulationContextType createType(final String name,
+ final ProjectSettingsService.Step step) throws InvalidPropertyException {
+ SimulationContextType type = getSimulationContextTypeDAO().findByCriteria(Restrictions.eq("name", name));
+ if (type == null) {
+ type = new SimulationContextType(name, step);
+ getSimulationContextTypeDAO().create(type);
+ } else {
+ LOG.info(MessageKeyEnum.SCT_000001.toString(), name);
+ }
return type;
}
* the type to approve
* @return true if approval succeeded
*/
- public boolean approve(SimulationContextType simCtxType) {
- if (simCtxType.getState() != ProgressState.inCHECK)
+ public boolean approve(final 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;
* the simulationContextTypeDAO to set
*/
public void setSimulationContextTypeDAO(
- SimulationContextTypeDAO simulationContextTypeDAO) {
+ final SimulationContextTypeDAO simulationContextTypeDAO) {
_simulationContextTypeDAO = simulationContextTypeDAO;
}
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Document.Properties;
import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.ScenarioDAO;
import org.splat.kernel.InvalidPropertyException;
for (FileDTO file : doc.getFiles()) {
if (file.getPath().endsWith(format)) {
// Create a file in the download directory
- String filePath = tmpDir.getAbsolutePath()
- + "/" + doc.getTitle() + "_result." + format;
+ String filePath = tmpDir.getAbsolutePath() + "/"
+ + doc.getTitle() + "_result." + format;
FileWriter fw = new FileWriter(filePath);
- fw.write("Simulation of " + format + " file for checkin at " + new Date());
+ fw.write("Simulation of " + format
+ + " file for checkin at " + new Date());
fw.close();
FileDTO fileToCheckin = new FileDTO(filePath);
docToCheckin.addFile(fileToCheckin);
ht.saveOrUpdate(aStudy);
ht.saveOrUpdate(aScenario);
+ // Create documents for each scenario step
Document.Properties dprop = new Document.Properties().setAuthor(
anAuthor).setDate(new Date());
- // Create documents
int i = 0;
for (Step step : steps) {
LOG.debug("Create scenario step: " + i);
List<DocumentType> dtypes = _documentTypeService
.selectTypesOf(step);
for (DocumentType dtype : dtypes) {
+ // Create a document published in the scenario
+ // document<i>: document type[0] - first type used on the step
+ // <source-file>.brep
+ // <attached-file>.med
dprop.setName("document" + i++).setType(dtype);
if (step.getNumber() > 3) {
dprop.setFormat("med");
} else {
dprop.setFormat("brep");
}
- // Create a document published in the scenario
- // document<i>: document type[0] - first type used on the step
- // <source-file>.brep
- // <attached-file>.med
- Publication pub = _stepService.createDocument(aScStep, dprop);
- Assert.assertNotNull(pub.getOwner(),
- "The publication must be attached to the scenario.");
- Assert.assertEquals(pub.getOwner().getIndex(), aScenario
- .getIndex(),
- "The publication was not attached to the scenario.");
+ createDoc(aScenario, aScStep, dprop, "med", false);
- aScenario.add(pub);
- ht.saveOrUpdate(pub);
-
- // Attach a file
- ht.save(pub.value());
- ht.saveOrUpdate(_publicationService.attach(pub, "med"));
-
- // Create a document with outdated publication
+ // Create another document with outdated publication
dprop.setName("document" + i++).setType(dtype)
.setFormat("brep");
- // Create a document published in the scenario
- // document<i>: document type[0] - first type used on the step
- // <source-file>.brep
- // <attached-file>.med
- pub = _stepService.createDocument(aScStep, dprop);
- Assert.assertNotNull(pub.getOwner(),
- "The publication must be attached to the scenario.");
- Assert.assertEquals(pub.getOwner().getIndex(), aScenario
- .getIndex(),
- "The publication was not attached to the scenario.");
-
- pub.setIsnew('O');
- aScenario.add(pub);
- ht.saveOrUpdate(pub);
-
- // Attach a file
- ht.save(pub.value());
- ht.saveOrUpdate(_publicationService.attach(pub, "med"));
+ createDoc(aScenario, aScStep, dprop, "med", true);
}
if (dtypes.size() <= 0) {
}
}
+ // Check that the scenario and its documents have been created correctly.
+
Assert.assertNotNull(ht.find("from Document"),
"No documents in the database.");
Assert.assertTrue(ht.find("from Document").size() > 0,
"The publication was not attached to the scenario.");
}
+ // Remove the scenario from the current hibernate session.
ht.evict(aScenario);
+ // Check that the scenario is created in the database.
Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
Assert.assertTrue(aScen.getDocums().size() > 0,
return aScenario.getIndex();
}
+
+ /**
+ * Create a document published in the scenario. <BR>
+ * document:<BR>
+ * document type[0] - first type used on the step <BR>
+ * <source-file>.brep <BR>
+ * <attached-file>.med
+ *
+ * @param aScenario
+ * the scenario to add the document to
+ * @param aScStep
+ * scenario step where the document to be published
+ * @param dprop
+ * document properties
+ * @param attachedFileExt
+ * extension of the secon attached (exported) file
+ * @param isOutdated
+ * outdated document flag
+ * @return the publication of the created document
+ * @throws IOException
+ * @throws MultiplyDefinedException
+ * @throws InvalidPropertyException
+ * @throws MissedPropertyException
+ */
+ private Publication createDoc(final Scenario aScenario,
+ final org.splat.som.Step aScStep, final Properties dprop,
+ final String attachedFileExt, final boolean isOutdated)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException, IOException {
+ // Create a document published in the scenario
+ // document<i>: document type[0] - first type used on the step
+ // <source-file>.brep
+ // <attached-file>.med
+ Publication pub = _stepService.createDocument(aScStep, dprop);
+ Assert.assertNotNull(pub.getOwner(),
+ "The publication must be attached to the scenario.");
+ Assert.assertEquals(pub.getOwner().getIndex(), aScenario.getIndex(),
+ "The publication was not attached to the scenario.");
+
+ if (isOutdated) {
+ pub.setIsnew('O');
+ }
+ aScenario.add(pub);
+ HibernateTemplate ht = getHibernateTemplate();
+ ht.saveOrUpdate(pub);
+
+ // Attach a file
+ ht.save(pub.value());
+ ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));
+
+ return pub;
+ }
}