compiler.max.memory=256m
compiler.optimize=on
compiler.deprecation=on
+
+siman-common.project.name=Siman-Common
<!-- ===================================================================== -->
<target name="compile-java" depends="splat" description="Builds the java classes">
<echo message="Compile Siman-Common java classes" />
- <mkdir dir="${siman-common.bin.dir}/temp"/>
- <javac target="1.6" srcdir="${siman-common.src.dir}" destdir="${siman-common.bin.dir}/temp" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memoryMaximumSize="${compiler.max.memory}" fork="true" optimize="${compiler.optimize}" deprecation="${compiler.deprecation}">
+<!-- <delete dir="${basedir}/../${siman-common.project.name}/temp" quiet="true"/>-->
+ <mkdir dir="temp"/>
+ <javac target="1.6" srcdir="${basedir}/../${siman-common.project.name}/${siman-common.src.dir}"
+ destdir="temp" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memoryMaximumSize="${compiler.max.memory}" optimize="${compiler.optimize}" deprecation="${compiler.deprecation}">
<classpath>
<path refid="ext.classpath" />
- <fileset dir="../${splat.project.name}/${splat.dist.dir}" includes="**/*" />
- <fileset dir="../${splat.project.name}/${splat.lib.dir}" includes="**/*" />
- <fileset dir="${siman-common.lib.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${splat.project.name}/${splat.dist.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${splat.project.name}/${splat.lib.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${siman-common.project.name}/${siman-common.lib.dir}" includes="**/*" />
</classpath>
<exclude name="test/**" />
</javac>
<target name="build-dist" depends="clean, splat, compile-java, build-stub" description="Builds the JAR distribution">
<echo message="build ${siman-common.jar.name}" />
- <!-- <antcall target="compile-java">
- </antcall>-->
-
<mkdir dir="${siman-common.dist.dir}" />
<jar destfile="${siman-common.dist.dir}/${siman-common.jar.name}">
<zipfileset dir="${siman-common.bin.dir}">
package org.splat.service;
-import java.util.List;
-
import org.splat.dal.bo.som.KnowledgeElement;
-import org.splat.dal.bo.som.KnowledgeElementType;
-import org.splat.dal.bo.som.ProgressState;
import org.splat.kernel.InvalidPropertyException;
import org.splat.service.dto.KnowledgeElementDTO;
* @throws InvalidPropertyException
* if renaming is failed
*/
- public void rename(KnowledgeElement knowledgeElement, String title)
+ public void rename(KnowledgeElementDTO knowledgeElement, String title)
throws InvalidPropertyException;
/**
* @param description
* the new description
*/
- public void update(KnowledgeElement kelm, String description);
+ public void update(KnowledgeElementDTO kelm, String description);
}
/**
* The logger for the service.
*/
- public final static AppLogger logger = AppLogger
+ public final static AppLogger LOGGER = AppLogger
.getLogger(KnowledgeElementServiceImpl.class);
/**
* @see org.splat.service.KnowledgeElementService#approve(org.splat.dal.bo.som.KnowledgeElement)
*/
@Transactional
- public boolean approve(KnowledgeElement knowledgeElement) {
- if (knowledgeElement.getProgressState() != ProgressState.inCHECK)
+ public boolean approve(final KnowledgeElement knowledgeElement) {
+ if (knowledgeElement.getProgressState() != ProgressState.inCHECK) {
return false;
+ }
knowledgeElement.setProgressState(ProgressState.APPROVED);
return update(knowledgeElement);
}
* @see org.splat.service.KnowledgeElementService#demote(org.splat.dal.bo.som.KnowledgeElement)
*/
@Transactional
- public boolean demote(KnowledgeElement knowledgeElement) {
+ public boolean demote(final KnowledgeElement knowledgeElement) {
if (knowledgeElement.getProgressState() != ProgressState.APPROVED
- && knowledgeElement.getProgressState() != ProgressState.inCHECK)
+ && knowledgeElement.getProgressState() != ProgressState.inCHECK) {
return false;
+ }
knowledgeElement.setProgressState(ProgressState.inDRAFT);
return update(knowledgeElement);
}
* the knowledge element to update
* @return true if updating succeeded
*/
- protected boolean update(KnowledgeElement knowledgeElement) {
+ protected boolean update(final KnowledgeElement knowledgeElement) {
try {
getKnowledgeElementDAO().update(knowledgeElement);
getIndexService().update(knowledgeElement);
return true;
} catch (Exception error) {
- logger.error("Unable to re-index the knowledge '"
+ LOGGER.error("Unable to re-index the knowledge '"
+ knowledgeElement.getIndex() + "', reason:", error);
return false;
}
* @see org.splat.service.KnowledgeElementService#promote(org.splat.dal.bo.som.KnowledgeElement)
*/
@Transactional
- public boolean promote(KnowledgeElement knowledgeElement) {
- // -------------------------
- if (knowledgeElement.getProgressState() != ProgressState.inDRAFT)
+ public boolean promote(final KnowledgeElement knowledgeElement) {
+ if (knowledgeElement.getProgressState() != ProgressState.inDRAFT) {
return false;
+ }
knowledgeElement.setProgressState(ProgressState.inCHECK);
return update(knowledgeElement);
}
* @see org.splat.service.KnowledgeElementService#rename(org.splat.dal.bo.som.KnowledgeElement, java.lang.String)
*/
@Transactional
- public void rename(KnowledgeElement knowledgeElement, String title)
+ public void rename(final KnowledgeElementDTO kelmDTO, final String title)
throws InvalidPropertyException {
- if (title.length() == 0)
+ if (title.length() == 0) {
throw new InvalidPropertyException("name");
- knowledgeElement.setTitle(title);
- update(knowledgeElement);
+ }
+ KnowledgeElement kelm = getKnowledgeElementDAO().get(kelmDTO.getIndex());
+ kelm.setTitle(title);
+ // Update lucene index.
+ update(kelm);
+ }
+
+ /**
+ * Update the description of the knowledge element.
+ *
+ * @param kelm
+ * the knoledge element to update
+ * @param description
+ * the new description
+ */
+ @Transactional
+ public void update(final KnowledgeElementDTO kelmDTO, final String description) {
+ KnowledgeElement kelm = getKnowledgeElementDAO().get(kelmDTO.getIndex());
+ kelm.setValue(description.trim());
+ if (!kelm.getValue().startsWith("<p>")) {
+ StringBuffer text = new StringBuffer("<p>");
+ int index = kelm.getValue().indexOf("<p>");
+ if (index > 0) {
+ kelm.setValue(text.append(kelm.getValue().substring(0, index))
+ .append("</p>")
+ .append(kelm.getValue().substring(index)).toString());
+ } else {
+ kelm.setValue(text.append(kelm.getValue()).append("</p>")
+ .toString());
+ }
+ }
}
/**
* @see org.splat.service.KnowledgeElementService#selectKnowledgeElement(long)
*/
@Transactional(readOnly = true)
- public KnowledgeElement selectKnowledgeElement(long index) {
+ public KnowledgeElement selectKnowledgeElement(final long index) {
KnowledgeElement result = getKnowledgeElementDAO().get(index);
getStudyService().loadWorkflow(
result.getOwnerScenario().getOwnerStudy());
* @see org.splat.service.KnowledgeElementService#getKnowledgeElement(long)
*/
@Transactional(readOnly = true)
- public KnowledgeElementDTO getKnowledgeElement(long index) {
+ public KnowledgeElementDTO getKnowledgeElement(final long index) {
KnowledgeElement kelm = getKnowledgeElementDAO().get(index);
getStudyService().loadWorkflow(kelm.getOwnerScenario().getOwnerStudy());
KnowledgeElementDTO result = BeanHelper.copyBean(kelm,
* @param scenar the scenario
* @return collection of steps
*/
- private Collection<? extends Step> getAllSteps(Scenario scenar) {
+ private Collection<? extends Step> getAllSteps(final Scenario scenar) {
Vector<Step> result = new Vector<Step>();
Step[] step = getProjectElementService().getSteps(scenar);
}
step = getProjectElementService().getSteps(scenar.getOwnerStudy());
for (int i = step.length - 1; i > -1; i--) {
- if (step[i].getNumber() >= base)
+ if (step[i].getNumber() >= base) {
continue;
+ }
result.add(0, step[i]);
}
for (int i = 0; i < step.length; i++) {
- if (step[i].getNumber() <= last)
+ if (step[i].getNumber() <= last) {
continue;
+ }
result.add(step[i]);
}
return result;
}
- /**
- * Update the description of the knowledge element.
- *
- * @param kelm
- * the knoledge element to update
- * @param description
- * the new description
- */
- @Transactional
- public void update(KnowledgeElement kelm, String description) {
- kelm.setValue(description.trim());
- if (!kelm.getValue().startsWith("<p>")) {
- StringBuffer text = new StringBuffer("<p>");
- int index = kelm.getValue().indexOf("<p>");
- if (index > 0) {
- kelm.setValue(text.append(kelm.getValue().substring(0, index))
- .append("</p>")
- .append(kelm.getValue().substring(index)).toString());
- } else {
- kelm.setValue(text.append(kelm.getValue()).append("</p>")
- .toString());
- }
- }
- getKnowledgeElementDAO().update(kelm); // No need to update the Lucene index
- }
-
/**
* Get the indexService.
*
* @param indexService
* the indexService to set
*/
- public void setIndexService(IndexService indexService) {
+ public void setIndexService(final IndexService indexService) {
_indexService = indexService;
}
* @param knowledgeElementDAO
* the knowledgeElementDAO to set
*/
- public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
+ public void setKnowledgeElementDAO(final KnowledgeElementDAO knowledgeElementDAO) {
_knowledgeElementDAO = knowledgeElementDAO;
}
* @param studyService
* the studyService to set
*/
- public void setStudyService(StudyService studyService) {
+ public void setStudyService(final StudyService studyService) {
_studyService = studyService;
}
* Set the projectElementService.
* @param projectElementService the projectElementService to set
*/
- public void setProjectElementService(ProjectElementService projectElementService) {
+ public void setProjectElementService(final ProjectElementService projectElementService) {
_projectElementService = projectElementService;
}
}
* the projectElementService to set
*/
public void setProjectElementService(
- ProjectElementService projectElementService) {
+ final ProjectElementService projectElementService) {
_projectElementService = projectElementService;
}
* @param publicationService
* the publicationService to set
*/
- public void setPublicationService(PublicationService publicationService) {
+ public void setPublicationService(final PublicationService publicationService) {
_publicationService = publicationService;
}
* @param stepService
* the stepService to set
*/
- public void setStepService(StepService stepService) {
+ public void setStepService(final StepService stepService) {
_stepService = stepService;
}
* if some property occurs several times
*/
@Transactional
- public Study createStudy(Study.Properties sprop, Scenario.Properties oprop,
- SimulationContext.Properties cprop) throws MissedPropertyException,
+ public Study createStudy(final Study.Properties sprop, final Scenario.Properties oprop,
+ final SimulationContext.Properties cprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
Study study = getStudyService().createStudy(sprop);
addScenario(study, oprop);
* org.splat.dal.bo.som.KnowledgeElement.Properties)
*/
@Transactional
- public KnowledgeElement addKnowledgeElement(Scenario aScenarioDTO,
- KnowledgeElement.Properties kprop) throws MissedPropertyException,
+ public KnowledgeElement addKnowledgeElement(final Scenario aScenarioDTO,
+ final KnowledgeElement.Properties kprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
KnowledgeElement kelm = null;
try {
} else if (aScenarioDTO.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
aScenarioDTO.getKnowledgeElementsList().add(kelm);
}
+
+ // Load the workflow for the parent study to take into account
+ // all study actors durng reindexing.
+ getStudyService().loadWorkflow(aScenario.getOwnerStudy());
+
// Update the lucene index of knowledge elements.
getIndexService().add(kelm);
if (logger.isDebugEnabled()) {
* @return true if updating succeeded
*/
@Transactional
- private boolean update(Scenario aScenario) {
+ private boolean update(final Scenario aScenario) {
boolean isOk = false;
try {
getScenarioDAO().update(aScenario); // Update of relational base
*
* @see org.splat.service.ScenarioService#checkin(org.splat.dal.bo.som.Scenario)
*/
- public void checkin(Scenario aScenario) {
+ public void checkin(final Scenario aScenario) {
aScenario.setUser(null);
aScenario.setLastModificationDate(Calendar.getInstance().getTime());
getScenarioDAO().update(aScenario);
*
* @see org.splat.service.ScenarioService#checkout(org.splat.dal.bo.som.Scenario, org.splat.dal.bo.kernel.User)
*/
- public boolean checkout(Scenario aScenario, User user) {
- if (!getStudyService().isStaffedBy(aScenario.getOwnerStudy(), user))
+ public boolean checkout(final Scenario aScenario, final User user) {
+ if (!getStudyService().isStaffedBy(aScenario.getOwnerStudy(), user)) {
return false;
+ }
aScenario.setUser(user);
aScenario.setLastModificationDate(Calendar.getInstance().getTime());
*
* @see org.splat.service.ScenarioService#copyContentsUpTo(org.splat.dal.bo.som.Scenario, org.splat.som.Step)
*/
- public void copyContentsUpTo(Scenario scenario, Step lastep) {
+ public void copyContentsUpTo(final Scenario scenario, final Step lastep) {
Scenario base = (Scenario) lastep.getOwner();
Step[] from = getProjectElementService().getSteps(base);
Step[] to = getProjectElementService().getSteps(scenario);
for (int i = 0; i < from.length; i++) {
Step step = from[i];
- if (step.getNumber() > lastep.getNumber())
+ if (step.getNumber() > lastep.getNumber()) {
break;
+ }
List<Publication> docs = step.getAllDocuments();
for (Iterator<Publication> j = docs.iterator(); j.hasNext();) {
*
* @see org.splat.service.ScenarioService#isEmpty(org.splat.dal.bo.som.Scenario)
*/
- public boolean isEmpty(Scenario scenario) {
+ public boolean isEmpty(final Scenario scenario) {
Step[] mystep = getProjectElementService().getSteps(scenario);
boolean isEmp = true;
for (int i = 0; i < mystep.length; i++) {
* @param scenario
* @return
*/
- public boolean isFinished(Scenario scenario) {
+ public boolean isFinished(final Scenario scenario) {
Step[] mystep = getProjectElementService().getSteps(scenario);
boolean notempty = false; // If this is empty, this is not finished
for (int i = 0; i < mystep.length; i++) {
- if (!mystep[i].isStarted())
+ if (!mystep[i].isStarted()) {
continue;
- if (!mystep[i].isFinished())
+ }
+ if (!mystep[i].isFinished()) {
return false;
+ }
notempty = true;
}
return notempty;
* @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
*/
@Transactional
- public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
+ public Scenario addScenario(final Study aStudy, final Scenario.Properties sprop)
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException {
- if (sprop.getManager() == null)
+ if (sprop.getManager() == null) {
sprop.setManager(aStudy.getAuthor());
+ }
Scenario scenario = new Scenario(sprop.setOwnerStudy(aStudy));
- if (sprop.getBaseStep() != null)
+ if (sprop.getBaseStep() != null) {
copyContentsUpTo(scenario, sprop.getBaseStep());
+ }
Scenario previous = sprop.getInsertAfter();
if (previous == null) {
* the knowledge element to remove
* @return true if removal succeeded
*/
- public boolean removeKnowledgeElement(Scenario scenario,
- KnowledgeElement kelm) {
+ public boolean removeKnowledgeElement(final Scenario scenario,
+ final KnowledgeElement kelm) {
KnowledgeElement torem = scenario.getKnowledgeElement(kelm.getIndex());
- if (torem == null)
+ if (torem == null) {
return false;
+ }
boolean done = scenario.getKnowledgeElements().remove(torem);
if (done) {
// Update of my transient data
// RKV: List<KnowledgeElement> kelms = scenario.getKnowledgeByType().get(
// RKV: kelm.getType().getIndex());
// RKV: kelms.remove(torem);
- if (scenario.getKnowledgeElementsList() != null)
+ if (scenario.getKnowledgeElementsList() != null) {
scenario.getKnowledgeElementsList().remove(torem);
+ }
getScenarioDAO().update(scenario);
// TODO: If the owner study is not private, remove the knowledge from the Lucene index
return true;
* @param knowledgeElementDAO
* the knowledgeElementDAO to set
*/
- public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
+ public void setKnowledgeElementDAO(final KnowledgeElementDAO knowledgeElementDAO) {
_knowledgeElementDAO = knowledgeElementDAO;
}
* @param indexService
* the indexService to set
*/
- public void setIndexService(IndexService indexService) {
+ public void setIndexService(final IndexService indexService) {
_indexService = indexService;
}
* @param scenarioDAO
* the scenarioDAO to set
*/
- public void setScenarioDAO(ScenarioDAO scenarioDAO) {
+ public void setScenarioDAO(final ScenarioDAO scenarioDAO) {
_scenarioDAO = scenarioDAO;
}
* @param studyDAO
* the studyDAO to set
*/
- public void setStudyDAO(StudyDAO studyDAO) {
+ public void setStudyDAO(final StudyDAO studyDAO) {
_studyDAO = studyDAO;
}
* the knowledgeElementTypeService to set
*/
public void setKnowledgeElementTypeService(
- KnowledgeElementTypeService knowledgeElementTypeService) {
+ final KnowledgeElementTypeService knowledgeElementTypeService) {
_knowledgeElementTypeService = knowledgeElementTypeService;
}
* @param studyService
* the studyService to set
*/
- public void setStudyService(StudyService studyService) {
+ public void setStudyService(final StudyService studyService) {
_studyService = studyService;
}
* @param userService
* the userService to set
*/
- public void setUserService(UserService userService) {
+ public void setUserService(final UserService userService) {
_userService = userService;
}
* @param userDAO
* the userDAO to set
*/
- public void setUserDAO(UserDAO userDAO) {
+ public void setUserDAO(final UserDAO userDAO) {
_userDAO = userDAO;
}
* the knowledgeElementTypeDAO to set
*/
public void setKnowledgeElementTypeDAO(
- KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
+ final KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
_knowledgeElementTypeDAO = knowledgeElementTypeDAO;
}
* the simulationContextService to set
*/
public void setSimulationContextService(
- SimulationContextService simulationContextService) {
+ final SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
*/
private String _scenarioTitle;
- // ==============================================================================================================================
- // Public member functions
- // ==============================================================================================================================
+ /**
+ * Default constructor.
+ */
+ public KnowledgeElementDTO() {
+ // Create empty bean.
+ }
+
+ /**
+ * Constructor with fields values.
+ *
+ * @param index
+ * knowledge element primary key
+ * @param title
+ * knowledge title
+ * @param value
+ * knowledge value
+ */
+ public KnowledgeElementDTO(final long index, final String title,
+ final String value) {
+ _index = index;
+ _title = title;
+ _value = value;
+ }
/**
* Compare this knowledge element with the given one.
* the knowledge element to compare to
* @return true if knowledge elements are equal
*/
- public boolean equals(final KnowledgeElementDTO given) { //NOPMD: RKV: TODO: to be refined
+ public boolean equals(final KnowledgeElementDTO given) { // NOPMD: RKV: TODO: to be refined
return (this.getType().equals(given.getType()) && this.getValue()
.equals(given.getValue()));
}
<!-- ===================================================================== -->
<!-- compile-java : compile the java classes -->
<!-- ===================================================================== -->
- <target name="compile-java" depends="siman-common" description="Builds the java classes">
+ <target name="compile-java" depends="clean, siman-common" description="Builds the java classes">
<echo message="Compile Siman java classes" />
- <mkdir dir="${siman.bin.dir}/temp"/>
- <javac target="1.6" srcdir="${siman.src.dir}" destdir="${siman.bin.dir}/temp" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memoryMaximumSize="${compiler.max.memory}" fork="true" optimize="${compiler.optimize}" deprecation="${compiler.deprecation}">
+<!-- <delete dir="${siman.bin.dir}/temp" quiet="true"/>-->
+ <mkdir dir="temp"/>
+ <javac target="1.6" srcdir="${siman.src.dir}" destdir="temp" debug="${compiler.debug}"
+ nowarn="${compiler.generate.no.warnings}" memoryMaximumSize="${compiler.max.memory}"
+ optimize="${compiler.optimize}" deprecation="${compiler.deprecation}">
<classpath>
- <fileset dir="../${siman-common.project.name}/${siman-common.ext.dir}" includes="**/*" />
- <fileset dir="../${splat.project.name}/${splat.dist.dir}" includes="**/*" />
- <fileset dir="../${splat.project.name}/${splat.lib.dir}" includes="**/*" />
- <fileset dir="../${siman-common.project.name}/${siman-common.dist.dir}" includes="**/*" />
- <fileset dir="../${siman-common.project.name}/${siman-common.lib.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${siman-common.project.name}/${siman-common.ext.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${splat.project.name}/${splat.dist.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${splat.project.name}/${splat.lib.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${siman-common.project.name}/${siman-common.dist.dir}" includes="**/*" />
+ <fileset dir="${basedir}/../${siman-common.project.name}/${siman-common.lib.dir}" includes="**/*" />
<fileset dir="${siman.content.dir}/WEB-INF/lib" includes="**/*" />
</classpath>
<exclude name="test/**" />
-# Generated at 02/11/2012 08:35:56
+# Generated at 02/11/2012 05:50:20
# Don't edit manually. See the source in D:\users\rkv\SIMAN\SIMAN_SRC\Workspace\Siman\conf\templates.
# Connection properties
connection.driver_class=com.mysql.jdbc.Driver
-# Generated at 02/11/2012 08:35:56
+# Generated at 02/11/2012 05:50:20
# Don't edit manually. See the source in D:\users\rkv\SIMAN\SIMAN_SRC\Workspace\Siman\conf\templates.
# Connection properties
connection.url=jdbc:mysql://localhost/simer
import org.splat.service.KnowledgeElementService;
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.ScenarioService;
+import org.splat.service.dto.KnowledgeElementDTO;
import org.splat.som.Step;
/**
private String _menuProperty;
/**
- * Value of the title bar property.
- * It can be: study, knowledge.
+ * Value of the title bar property. It can be: study, knowledge.
*/
private String _titleProperty;
/**
- * Property that indicates whether the current open study is editable or not.
- * On the screen it looks like pen on the status icon, pop-up menu also can be called.
- * It is necessary for correct building the title bar.
+ * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
+ * menu also can be called. It is necessary for correct building the title bar.
*/
private String _editDisabledProperty = "false";
/**
- * Value of the tool bar property.
- * It can be: none, standard, study, back.
+ * Value of the tool bar property. It can be: none, standard, study, back.
*/
private String _toolProperty;
-
+
/**
- * Value of the left menu property.
- * It can be: open, study, knowledge, scenario.
+ * Value of the left menu property. It can be: open, study, knowledge, scenario.
*/
private String _leftMenuProperty;
setMenuProperty("study");
setTitleProperty("study");
- if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
+ if ("true".equals(getWriteAccess())
+ && getUserRights().canCreateDocument()) {
setToolProperty("study");
} else {
setToolProperty("standard");
}
setLeftMenuProperty("study");
- initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(_menuProperty, _titleProperty,
+ _editDisabledProperty, _toolProperty, _leftMenuProperty);
return SUCCESS;
}
setMenuProperty("study");
setTitleProperty("study");
- if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
+ if ("true".equals(getWriteAccess())
+ && getUserRights().canCreateDocument()) {
setToolProperty("study");
} else {
setToolProperty("standard");
}
setLeftMenuProperty("study");
- initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(_menuProperty, _titleProperty,
+ _editDisabledProperty, _toolProperty, _leftMenuProperty);
try {
User user = getConnectedUser();
Step step = mystudy.getSelectedStep();
Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
- if (title != null && value != null) { // Addition of a new Knowledge Element
+ if ((title == null) || (value == null)) {
+ KnowledgeElementDTO kelm = new KnowledgeElementDTO(Integer
+ .valueOf(type), title, value);
+ if (value == null) { // Renaming of an existing Knowledge Element
+ getKnowledgeElementService().rename(kelm, title);
+ } else { // Edition of a knowledge
+ getKnowledgeElementService().update(kelm, value);
+ }
+ mystudy.update(kelm); // For updating the truncated value
+ } else { // Addition of a new Knowledge Element
KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
KnowledgeElementType ktype = getKnowledgeElementTypeService()
.selectType(Integer.valueOf(type));
mystudy.add(getScenarioService().addKnowledgeElement(scene,
kprop));
getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
- } else if (title != null) { // Renaming of an existing Knowledge Element
- KnowledgeElement kelm = scene.getKnowledgeElement(Integer
- .valueOf(type));
- getKnowledgeElementService().rename(kelm, title);
- // Useless to update the open study
- } else if (value != null) { // Edition of a knowledge
- KnowledgeElement kelm = scene.getKnowledgeElement(Integer
- .valueOf(type));
- getKnowledgeElementService().update(kelm, value);
- mystudy.update(kelm); // For updating the truncated value
}
return SUCCESS;
} catch (RuntimeException saverror) {
setMenuProperty("study");
setTitleProperty("study");
- if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
+ if ("true".equals(getWriteAccess())
+ && getUserRights().canCreateDocument()) {
setToolProperty("study");
} else {
setToolProperty("standard");
}
setLeftMenuProperty("study");
- initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(_menuProperty, _titleProperty,
+ _editDisabledProperty, _toolProperty, _leftMenuProperty);
}
* @param type
* the knowledge type name
*/
- public void setKnowledgeType(String type) {
+ public void setKnowledgeType(final String type) {
// ------------------------------------------
this.type = type;
}
* @param title
* the new knowledge title
*/
- public void setKnowledgeTitle(String title) {
+ public void setKnowledgeTitle(final String title) {
// --------------------------------------------
this.title = title;
}
* @param value
* the knowledge value
*/
- public void setKnowledgeValue(String value) {
+ public void setKnowledgeValue(final String value) {
// --------------------------------------------
this.value = value;
}
* @param scenarioService
* the scenarioService to set
*/
- public void setScenarioService(ScenarioService scenarioService) {
+ public void setScenarioService(final ScenarioService scenarioService) {
_scenarioService = scenarioService;
}
* the knowledgeElementService to set
*/
public void setKnowledgeElementService(
- KnowledgeElementService knowledgeElementService) {
+ final KnowledgeElementService knowledgeElementService) {
_knowledgeElementService = knowledgeElementService;
}
* the knowledgeElementTypeService to set
*/
public void setKnowledgeElementTypeService(
- KnowledgeElementTypeService knowledgeElementTypeService) {
+ final KnowledgeElementTypeService knowledgeElementTypeService) {
_knowledgeElementTypeService = knowledgeElementTypeService;
}
*
* @return the menuProperty
*/
+ @Override
public String getMenuProperty() {
return _menuProperty;
}
* @param menuProperty
* the menuProperty to set
*/
+ @Override
public void setMenuProperty(final String menuProperty) {
this._menuProperty = menuProperty;
}
*
* @return the _titleProperty
*/
+ @Override
public String getTitleProperty() {
return _titleProperty;
}
* @param titleProperty
* the titleProperty to set
*/
+ @Override
public void setTitleProperty(final String titleProperty) {
_titleProperty = titleProperty;
}
*
* @return the editDisabledProperty
*/
+ @Override
public String getEditDisabledProperty() {
return _editDisabledProperty;
}
* @param editDisabledProperty
* the editDisabledProperty to set
*/
+ @Override
public void setEditDisabledProperty(final String editDisabledProperty) {
_editDisabledProperty = editDisabledProperty;
}
*
* @return the toolProperty
*/
+ @Override
public String getToolProperty() {
return _toolProperty;
}
* @param toolProperty
* the toolProperty to set
*/
+ @Override
public void setToolProperty(final String toolProperty) {
_toolProperty = toolProperty;
}
/**
* Get the leftMenuProperty.
+ *
* @return the leftMenuProperty
*/
+ @Override
public String getLeftMenuProperty() {
return _leftMenuProperty;
}
/**
* Set the leftMenuProperty.
- * @param leftMenuProperty the leftMenuProperty to set
+ *
+ * @param leftMenuProperty
+ * the leftMenuProperty to set
*/
+ @Override
public void setLeftMenuProperty(final String leftMenuProperty) {
_leftMenuProperty = leftMenuProperty;
}
-
}
\ No newline at end of file
package org.splat.simer;
-import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.service.dto.KnowledgeElementDTO;
import org.splat.wapp.PopupMenu;
-
public class KnowledgeElementFacade {
- private KnowledgeElement my;
- private State state;
- private String value;
- private PopupMenu popup;
-
- private enum State { closed, open }
-
-// ==============================================================================================================================
-// Constructor
-// ==============================================================================================================================
-
- public KnowledgeElementFacade (KnowledgeElement represented) {
-// ------------------------------------------------------------
- my = represented;
- state = State.closed;
-
- this.refresh(); // Initializes the presentation of my knowledge
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- public void develop () {
-// ----------------------
- state = State.open;
- }
-
- public void reduce () {
-// ---------------------
- state = State.closed;
- }
-
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public String getFullValue () {
-// -----------------------------
- return my.getValue().replaceAll("'", "‘").replaceAll("\"", """);
- }
- public String getIndex () {
-// -------------------------
- return String.valueOf(my.getIndex());
- }
- public PopupMenu getPopup () {
-// ----------------------------
- popup.setContext("feedbex", my); // Cannot be done at construction because pop-ups are shared
- return popup;
- }
- public String getPresentationState () {
-// -------------------------------------
- return state.toString();
- }
- public String getProgressState () {
-// ---------------------------------
- return my.getProgressState().toString();
- }
- public String getTitle () {
-// -------------------------
- return my.getTitle();
- }
- public String getValue () {
-// -------------------------
- if (state == State.closed) return value;
- else return my.getValue();
- }
- public boolean isFacadeOf (KnowledgeElement represented) {
-// --------------------------------------------------------
- return my.equals(represented);
- }
-
-// ==============================================================================================================================
-// Protected services
-// ==============================================================================================================================
-
- protected void refresh () {
-// -------------------------
- String[] tags = {"<b>", "<i>", "<u>", "<sup>", "<sub>" };
-
- popup = ApplicationSettings.getPopupMenu("feedbex");
- value = my.getValue();
-
-// One line extract of the knowledge value
- int size = 70 + 3; // Maximum length displayable on 1 line, including the starting <p> tag
- int i;
- for (i=0; i<tags.length; i++) {
- int pos = value.indexOf(tags[i]);
- if (pos > -1 && pos < size) size = size + 2*tags[i].length() + 1; // Inclusion of the open and close tags
- }
- if (value.startsWith("<p>")) {
- int endex = value.indexOf("</p>");
- if ((i=value.indexOf("<br")) > 0) if (i < endex) endex = i;
- if ((i=value.indexOf("<ul>")) > 0) if (i < endex) endex = i;
- if ((i=value.indexOf("<ol>")) > 0) if (i < endex) endex = i;
- int next = endex + 4; // Index of the next paragraph, if exist
- if (endex > size) {
- endex = size;
- char endchar = value.charAt(endex);
- if (endchar == '-' || endchar == ',' || endchar == ';' || endchar == '.') endex += 1;
- else if (endchar != ' ') while (--endex > 0) {
- endchar = value.charAt(endex);
- if (endchar == ' ') break;
- if (endchar == '-' || endchar == ',' || endchar == ';' || endchar == '.') {
- endex += 1;
- break;
- }
- }
- }
- else size = 0;
-
- value = value.substring(3, endex).trim();
- if ((i=value.lastIndexOf("b>")) > 0) if (value.charAt(i-1) == '<') value = value + "</b>";
- if ((i=value.lastIndexOf("i>")) > 0) if (value.charAt(i-1) == '<') value = value + "</i>";
- if ((i=value.lastIndexOf("u>")) > 0) if (value.charAt(i-1) == '<') value = value + "</u>";
- if (my.getValue().length() > next || size > 0) value = value + " ...";
- }
- else {
- if (value.length() > size-3) value = value.substring(0, size-3) + " ...";
- }
- }
+ private transient final KnowledgeElementDTO _my;
+ private transient State _state;
+ private transient String _value;
+ private transient PopupMenu _popup;
+
+ private enum State {
+ closed, open
+ }
+
+ // ==============================================================================================================================
+ // Constructor
+ // ==============================================================================================================================
+
+ public KnowledgeElementFacade(final KnowledgeElementDTO represented) {
+ _my = represented;
+ _state = State.closed;
+
+ this.refresh(); // Initializes the presentation of my knowledge
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ public void develop() {
+ _state = State.open;
+ }
+
+ public void reduce() {
+ _state = State.closed;
+ }
+
+ // ==============================================================================================================================
+ // Getters
+ // ==============================================================================================================================
+
+ public String getFullValue() {
+ return _my.getValue().replaceAll("'", "‘").replaceAll("\"", """);
+ }
+
+ public String getIndex() {
+ return String.valueOf(_my.getIndex());
+ }
+
+ public PopupMenu getPopup() {
+ _popup.setContext("feedbex", _my); // Cannot be done at construction because pop-ups are shared
+ return _popup;
+ }
+
+ public String getPresentationState() {
+ return _state.toString();
+ }
+
+ public String getProgressState() {
+ return _my.getProgressState().toString();
+ }
+
+ public String getTitle() {
+ return _my.getTitle();
+ }
+
+ public String getValue() {
+ String res;
+ if (_state == State.closed) {
+ res = _value;
+ } else {
+ res = _my.getValue();
+ }
+ return res;
+ }
+
+ public boolean isFacadeOf(final KnowledgeElementDTO represented) {
+ return _my.equals(represented);
+ }
+
+ /**
+ * Set and refresh the knoledge element value.
+ *
+ * @param aValue
+ * the knowledge element to set
+ */
+ public void refresh(final KnowledgeElementDTO represented) {
+ if (represented.getTitle() != null) {
+ _my.setTitle(represented.getTitle());
+ }
+ if (represented.getValue() != null) {
+ _my.setValue(represented.getValue());
+ refresh();
+ }
+ }
+
+ // ==============================================================================================================================
+ // Protected services
+ // ==============================================================================================================================
+
+ /**
+ * Refresh knowledge element text and create a trimmed value for preview.
+ */
+ private void refresh() {
+ String[] tags = { "<b>", "<i>", "<u>", "<sup>", "<sub>" };
+
+ _popup = ApplicationSettings.getPopupMenu("feedbex");
+ _value = _my.getValue();
+
+ // One line extract of the knowledge value
+ int size = 70 + 3; // Maximum length displayable on 1 line, including the starting <p> tag
+ int i;
+ for (i = 0; i < tags.length; i++) {
+ int pos = _value.indexOf(tags[i]);
+ if (pos > -1 && pos < size) {
+ size = size + 2 * tags[i].length() + 1; // Inclusion of the open and close tags
+ }
+ }
+ if (_value.startsWith("<p>")) {
+ int endex = _value.indexOf("</p>");
+ endex = nearestPositionOf(_value, "<br", endex);
+ endex = nearestPositionOf(_value, "<ul>", endex);
+ endex = nearestPositionOf(_value, "<ol>", endex);
+ int next = endex + 4; // Index of the next paragraph, if exist
+ if (endex > size) {
+ endex = endOfExpressionPosition(_value, size);
+ } else {
+ size = 0;
+ }
+
+ _value = _value.substring(3, endex).trim();
+ _value = closeTag(_value, "b");
+ _value = closeTag(_value, "i");
+ _value = closeTag(_value, "u");
+ if (_my.getValue().length() > next || size > 0) {
+ _value = _value + " ...";
+ }
+ } else {
+ if (_value.length() > size - 3) {
+ _value = _value.substring(0, size - 3) + " ...";
+ }
+ }
+ }
+
+ /**
+ * Find the end position of an expression taking into account specific symbols.
+ *
+ * @param aValue
+ * the string
+ * @param size
+ * one line length limit
+ * @return actual end of expression position
+ */
+ private int endOfExpressionPosition(final String aValue, final int size) {
+ int res = size;
+ char endchar = aValue.charAt(res);
+ if (endchar == '-' || endchar == ',' || endchar == ';'
+ || endchar == '.') {
+ res += 1;
+ } else if (endchar != ' ') {
+ while (--res > 0) {
+ endchar = aValue.charAt(res);
+ if (endchar == ' ') {
+ break;
+ }
+ if (endchar == '-' || endchar == ',' || endchar == ';'
+ || endchar == '.') {
+ res += 1;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Append a closing tag to the string.
+ *
+ * @param aValue
+ * the string
+ * @param aTag
+ * the tag to close
+ * @return the string with closed tag
+ */
+ private String closeTag(String aValue, final String aTag) {
+ int i = aValue.lastIndexOf(aTag + ">");
+ if ((i > 0) && (aValue.charAt(i - 1) == '<')) {
+ aValue = aValue + "</" + aTag + ">";
+ }
+ return aValue;
+ }
+
+ /**
+ * Find a nearest position of the given substring looking from the beginning till the given position.
+ *
+ * @param aValue
+ * the string
+ * @param toFind
+ * the substring to search
+ * @param endex
+ * the end of expression position
+ * @return the position of the first occurrence or the given end of expression position
+ */
+ private int nearestPositionOf(final String aValue, final String toFind,
+ final int endex) {
+ int res = aValue.indexOf(toFind);
+ if ((res <= 0) || (res >= endex)) {
+ res = endex;
+ }
+ return res;
+ }
}
\ No newline at end of file
/**
* The open knowledge element DTO.
*/
- private KnowledgeElementDTO myknelm = new KnowledgeElementDTO();
+ private transient KnowledgeElementDTO _myknelm = new KnowledgeElementDTO();
/**
* Creation date.
*/
- private String credate;
+ private transient String _credate;
/**
* Knowledge element left menu.
* @param context
* the list of steps
*/
- public Menu(List<Step> context) {
+ public Menu(final List<Step> context) {
super("steps", "study");
int i = 0;
int j = 0;
Step step = k.next();
int number = step.getNumber();
String icon;
- if (step.mayContain(KnowledgeElement.class))
+ if (step.mayContain(KnowledgeElement.class)) {
j = i + 1; // Steps are numbered from 1 to N
- if (!step.isStarted())
- icon = "icon.empty.png";
- else
+ }
+ if (step.isStarted()) {
icon = "icon.done.png";
+ } else {
+ icon = "icon.empty.png";
+ }
addItem(String.valueOf(number), "folder.step." + number, icon,
"step-knowledge?selection=" + number);
}
* the knowledge element DTO
* @return the open knowledge presentation
*/
- public OpenKnowledge open(KnowledgeElementDTO knelm) {
+ public OpenKnowledge open(final KnowledgeElementDTO knelm) {
ResourceBundle label = ResourceBundle.getBundle("labels",
getApplicationSettings().getCurrentLocale());
ResourceBundle custom = ResourceBundle.getBundle("som",
String sceneTitle = knelm.getScenarioTitle();
String studyTitle = knelm.getStudyTitle();
- myknelm = knelm;
+ _myknelm = knelm;
// Preparation of the display
- credate = convert.format(myknelm.getDate());
+ _credate = convert.format(_myknelm.getDate());
// involving = getAllSteps(knelm.getOwnerScenario());
involving = knelm.getInvolving();
context = new ArrayList<SimulationContextFacade>();
int index = Integer.valueOf(selection);
for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
Step next = i.next();
- if (next.getNumber() == index)
+ if (next.getNumber() == index) {
ustep = next;
+ }
for (Iterator<SimulationContext> j = next
.getAllSimulationContexts().iterator(); j.hasNext();) {
context.add(new SimulationContextFacade(j.next(),
// ==============================================================================================================================
public String getAuthorName() {
- return myknelm.getAuthor().toString();
+ return _myknelm.getAuthor().toString();
}
public String getDate() {
- return credate;
+ return _credate;
}
public Long getIndex() {
- return myknelm.getIndex();
+ return _myknelm.getIndex();
}
+ @Override
public Menu getMenu() {
return (Menu) menu;
}
public ProgressState getProgressState() {
- return myknelm.getProgressState();
+ return _myknelm.getProgressState();
}
public String getReference() {
- return myknelm.getReference();
+ return _myknelm.getReference();
}
public KnowledgeElementDTO getKnowledgeObject() {
- return myknelm;
+ return _myknelm;
}
public String getTitle() {
- return myknelm.getTitle();
+ return _myknelm.getTitle();
}
public String getType() {
return ResourceBundle.getBundle("som",
getApplicationSettings().getCurrentLocale()).getString(
- "type.knowledge." + myknelm.getType().getName());
+ "type.knowledge." + _myknelm.getType().getName());
}
- public void setSelection(String step) {
+ public void setSelection(final String step) {
selection = step;
int index = Integer.valueOf(selection);
for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
ustep = i.next();
- if (ustep.getNumber() == index)
+ if (ustep.getNumber() == index) {
break;
+ }
}
menu.selects(selection);
setupContents(); // The contents may have changed even if the selection is the same
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.Publication;
+import org.splat.dal.bo.som.Scenario;
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.ProjectElementService;
import org.splat.service.PublicationService;
+import org.splat.service.dto.KnowledgeElementDTO;
import org.splat.service.dto.Proxy;
import org.splat.service.technical.ProjectSettingsService;
-import org.splat.dal.bo.som.Publication;
-import org.splat.dal.bo.som.Scenario;
import org.splat.som.Step;
+import org.splat.util.BeanHelper;
import org.splat.wapp.Menu;
import org.splat.wapp.PopupMenu;
protected KnowledgeElementType type;
protected List<KnowledgeElementFacade> list;
- public KnowledgeIterator(KnowledgeElementType type,
- List<KnowledgeElementFacade> list) {
+ public KnowledgeIterator(final KnowledgeElementType type,
+ final List<KnowledgeElementFacade> list) {
this.type = type;
this.list = list;
}
protected OpenObject() {
// -----------------------
// All member fields are supposed initialized by subclasses
- if (docpres == null)
+ if (docpres == null) {
docpres = new HashMap<Long, DocumentFacade>();
- if (knowpres == null)
+ }
+ if (knowpres == null) {
knowpres = new HashMap<Long, KnowledgeElementFacade>();
+ }
}
// ==============================================================================================================================
// Public member functions
// ==============================================================================================================================
- public void developDocument(String index) {
+ public void developDocument(final String index) {
// ------------------------------------------
for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index))
+ if (!doc.getIndex().equals(index)) {
continue;
+ }
doc.develop();
return;
}
}
- public void developKnowledge(String index) {
+ public void developKnowledge(final String index) {
// -------------------------------------------
for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
List<KnowledgeElementFacade> knowelms = i.next()
for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
.hasNext();) {
KnowledgeElementFacade kelm = j.next();
- if (!kelm.getIndex().equals(index))
+ if (!kelm.getIndex().equals(index)) {
continue;
+ }
kelm.develop();
return;
}
knowpres.clear(); // For eventually reopening the knowledge from a fresh context
}
- public List<Document> collectInvolvedDocuments(DocumentType type) {
+ public List<Document> collectInvolvedDocuments(final DocumentType type) {
// ------------------------------------------------------------------
List<Document> found = new Vector<Document>();
for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
List<Publication> exist = step.getAllDocuments();
for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
Document doc = j.next().value();
- if (doc.getType().equals(type))
+ if (doc.getType().equals(type)) {
found.add(doc);
+ }
}
}
return found;
return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
}
- public void reduceDocument(String index) {
+ public void reduceDocument(final String index) {
// -----------------------------------------
for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index))
+ if (!doc.getIndex().equals(index)) {
continue;
+ }
doc.reduceAll();
return;
}
}
- public void reduceHistory(String index) {
+ public void reduceHistory(final String index) {
// ----------------------------------------
for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index))
+ if (!doc.getIndex().equals(index)) {
continue;
+ }
doc.reduce();
return;
}
}
- public void reduceKnowledge(String index) {
+ public void reduceKnowledge(final String index) {
// ------------------------------------------
for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
List<KnowledgeElementFacade> knowelms = i.next()
for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
.hasNext();) {
KnowledgeElementFacade kelm = j.next();
- if (!kelm.getIndex().equals(index))
+ if (!kelm.getIndex().equals(index)) {
continue;
+ }
kelm.reduce();
return;
}
List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
Iterator<KnowledgeElement> more = kelms.iterator();
KnowledgeElement current = null;
- if (more.hasNext())
+ if (more.hasNext()) {
current = more.next();
+ }
knowledge = new Vector<KnowledgeIterator>(types.size());
for (Iterator<KnowledgeElementType> i = types.iterator(); i
KnowledgeElementFacade facade = knowpres.get(current
.getIndex());
if (facade == null) {
- facade = new KnowledgeElementFacade(current);
+ facade = new KnowledgeElementFacade(BeanHelper.copyBean(current, KnowledgeElementDTO.class));
knowpres.put(current.getIndex(), facade);
}
display.add(facade);
- if (more.hasNext())
+ if (more.hasNext()) {
current = more.next();
- else
+ } else {
current = null;
+ }
}
knowledge.add(new KnowledgeIterator(type, display));
}
* @param projectSettingsService
* project settings service
*/
- public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+ public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
_projectSettingsService = projectSettingsService;
}
* @param publicationService
* the publicationService to set
*/
- public void setPublicationService(PublicationService publicationService) {
+ public void setPublicationService(final PublicationService publicationService) {
_publicationService = publicationService;
}
* @param menu
* the menu to set
*/
- public void setMenu(Menu menu) {
+ public void setMenu(final Menu menu) {
this.menu = menu;
}
* the projectElementService to set
*/
public void setProjectElementService(
- ProjectElementService projectElementService) {
+ final ProjectElementService projectElementService) {
_projectElementService = projectElementService;
}
* @param knowledgeElementTypeService the knowledgeElementTypeService to set
*/
public void setKnowledgeElementTypeService(
- KnowledgeElementTypeService knowledgeElementTypeService) {
+ final KnowledgeElementTypeService knowledgeElementTypeService) {
_knowledgeElementTypeService = knowledgeElementTypeService;
}
* Set the applicationSettings.
* @param applicationSettings the applicationSettings to set
*/
- public void setApplicationSettings(ApplicationSettings applicationSettings) {
+ public void setApplicationSettings(final ApplicationSettings applicationSettings) {
_applicationSettings = applicationSettings;
}
}
\ No newline at end of file
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
-import org.splat.kernel.Do;
import org.splat.dal.bo.kernel.User;
-import org.splat.manox.Toolbox;
-import org.splat.manox.Writer;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
+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.Study;
+import org.splat.kernel.Do;
+import org.splat.manox.Toolbox;
+import org.splat.manox.Writer;
import org.splat.service.DocumentService;
import org.splat.service.DocumentTypeService;
import org.splat.service.StepService;
import org.splat.service.StudyService;
+import org.splat.service.dto.KnowledgeElementDTO;
import org.splat.service.technical.RepositoryService;
-import org.splat.dal.bo.som.Publication;
import org.splat.som.Revision;
-import org.splat.dal.bo.som.Scenario;
-import org.splat.dal.bo.som.SimulationContext;
import org.splat.som.Step;
import org.splat.som.StepRights;
-import org.splat.dal.bo.som.Study;
import org.splat.som.StudyRights;
+import org.splat.util.BeanHelper;
import org.splat.wapp.ToolBar;
public class OpenStudy extends OpenObject implements OpenStudyServices {
/**
* Serial version ID.
*/
- protected final static Logger logger = org.splat.simer.Action.logger;
-
- private Study mystudy;
- private StudyRights urightstudy; // User rights on the open study
- private StepRights urightstep; // User rights on the selected step
- private String version;
- private String credate;
- private String lasdate;
- private Publication selecdoc;
+ protected final static Logger LOGGER = org.splat.simer.Action.logger;
+
+ private transient Study _mystudy;
+ private transient StudyRights _urightstudy; // User rights on the open study
+ private transient StepRights _urightstep; // User rights on the selected step
+ private transient String _version;
+ private transient String _credate;
+ private transient String _lasdate;
+ private transient Publication _selecdoc;
/**
* Injected step service.
*/
* the study to open
* @return this open study object
*/
- public OpenStudy open(User user, Study study) {
- // -----------------------------------------
+ public OpenStudy open(final User user, final Study study) {
ResourceBundle custom = ResourceBundle.getBundle("som",
getApplicationSettings().getCurrentLocale());
SimpleDateFormat datstring = new SimpleDateFormat(custom
.getRevisionPattern());
cuser = user; // May be null if nobody connected
- mystudy = study;
+ _mystudy = study;
selection = "0.1"; // Default selection
- selecdoc = null;
+ _selecdoc = null;
// Preparation of the display
- version = verstring.format(mystudy.getVersion());
- credate = datstring.format(mystudy.getDate());
- lasdate = ""; // Not yet supported
- description = mystudy.getDescription();
+ _version = verstring.format(_mystudy.getVersion());
+ _credate = datstring.format(_mystudy.getDate());
+ _lasdate = ""; // Not yet supported
+ description = _mystudy.getDescription();
involving = new ArrayList<Step>(1);
context = new ArrayList<SimulationContextFacade>();
- ustep = getProjectElementService().getFirstStep(mystudy);
+ ustep = getProjectElementService().getFirstStep(_mystudy);
ustep.setActor(cuser);
involving.add(ustep);
for (Iterator<SimulationContext> i = ustep.getAllSimulationContexts()
context.add(new SimulationContextFacade(i.next(),
getProjectSettings().getAllSteps()));
}
- if (getStudyService().isStaffedBy(mystudy, cuser) || getStudyService().hasActor(mystudy, cuser)) {
+ if (getStudyService().isStaffedBy(_mystudy, cuser)
+ || getStudyService().hasActor(_mystudy, cuser)) {
// ProgressState state = mystudy.getProgressState();
// if (state == ProgressState.inCHECK) popup = getApplicationSettings().getPopupMenu("stapprovable");
// else if (state == ProgressState.APPROVED) popup = getApplicationSettings().getPopupMenu("stapproved");
- /* else */popup = getApplicationSettings()
- .getPopupMenu("steditable");
- popup.setContext("study", new StudyRights(cuser, mystudy));
+ /* else */popup = getApplicationSettings().getPopupMenu(
+ "steditable");
+ popup.setContext("study", new StudyRights(cuser, _mystudy));
}
- urightstudy = new StudyRights(cuser, mystudy);
- urightstep = new StepRights(cuser, ustep);
+ _urightstudy = new StudyRights(cuser, _mystudy);
+ _urightstep = new StepRights(cuser, ustep);
// RKV menu = new StudyMenu(mystudy);
- menu = ((StudyMenu) getMenu()).init(mystudy); // RKV
+ menu = (getMenu()).init(_mystudy); // RKV
menu.selects(selection); // Initializes menu items to be displayed
setupContents(); // Initializes documents and knowledge at ustep
return this;
// ==============================================================================================================================
public String getAuthorName() {
- // -----------------------------
- return mystudy.getAuthor().toString();
+ return _mystudy.getAuthor().toString();
}
public Long getIndex() {
- // -------------------------
- return mystudy.getIndex();
+ return _mystudy.getIndex();
}
public String getDate() {
- // ------------------------
- return credate;
+ return _credate;
}
+ @Override
public StudyMenu getMenu() {
- // ---------------------------
return (StudyMenu) menu;
}
- public void setMenu(StudyMenu aMenu) {
+ public void setMenu(final StudyMenu aMenu) {
menu = aMenu;
}
public ProgressState getProgressState() {
- // ----------------------------------------
- return mystudy.getProgressState();
+ return _mystudy.getProgressState();
}
public String getLastModificationDate() {
- // ----------------------------------------
- return lasdate;
+ return _lasdate;
}
public ToolBar getModuleBar() {
- // ------------------------------
return getApplicationSettings().getModuleBar(getSelectedStep());
}
public String getReference() {
- // ----------------------------
- return mystudy.getReference();
+ return _mystudy.getReference();
}
public Publication getSelectedDocument() {
- // -----------------------------------------
- return selecdoc;
+ return _selecdoc;
}
public StepRights getSelectedStepRights() {
- // ------------------------------------------
- return urightstep;
+ return _urightstep;
}
public StudyRights getStudyRights() {
- // ------------------------------------
- return urightstudy;
+ return _urightstudy;
}
public Study getStudyObject() {
- // ------------------------------
- return mystudy;
+ return _mystudy;
}
public String getTitle() {
- // ------------------------
- return mystudy.getTitle();
+ return _mystudy.getTitle();
}
public String getType() {
- // ------------------------
return ResourceBundle.getBundle("labels",
- getApplicationSettings().getCurrentLocale())
- .getString("label.study");
+ getApplicationSettings().getCurrentLocale()).getString(
+ "label.study");
}
public String getVersion() {
- // ---------------------------
- return version;
+ return _version;
}
public boolean isStepEnabled() {
- // -------------------------------
- return urightstep.isEnabled();
+ return _urightstep.isEnabled();
}
// ==============================================================================================================================
// Public services
// ==============================================================================================================================
- public URL newTemplateBasedDocument(String typename, User author) {
- // ------------------------------------------------------------------
+ public URL newTemplateBasedDocument(final String typename, final User author) {
String filename = typename + ".xml"; // Only XML templates are writeable
File template = new File(getRepositoryService().getTemplatePath()
+ filename);
- if (!template.exists())
+ if (!template.exists()) {
return null;
+ }
-// Session connex = Database.getCurSession();
-// Transaction transax = connex.beginTransaction();
+ // Session connex = Database.getCurSession();
+ // Transaction transax = connex.beginTransaction();
try {
File udir = getRepositoryService().getDownloadDirectory(author);
File credoc = new File(udir.getPath() + "/" + filename);
Document medoc = getStepService().createDocument(step,
dprop.setType(type).setFormat("xml").setAuthor(author))
.value();
-// transax.commit();
+ // transax.commit();
// Instantiation of the template into the user download directory
- if (!udir.exists())
+ if (!udir.exists()) {
udir.mkdir();
- if (credoc.exists())
+ }
+ if (credoc.exists()) {
credoc.delete();
+ }
Do.copy(template, credoc);
// Transfer to the document of all known properties
}
}
tool.updateProperty("reference", medoc.getReference());
- tool.updateProperty("study", mystudy.getTitle());
+ tool.updateProperty("study", _mystudy.getTitle());
tool.updateProperty("step", locale.getString(
"folder.step." + step.getNumber()).replaceAll("''", "'"));
tool.updateProperty("author", author.getUsername().toUpperCase());
return new URL(getApplicationSettings().getDownloadURL(author)
+ filename);
} catch (Exception saverror) {
- logger.error("Reason:", saverror);
+ LOGGER.error("Reason:", saverror);
return null;
}
}
- public void selectDocument(String docurl) {
- // ------------------------------------------
+ public void selectDocument(final String docurl) {
String prefix = getApplicationSettings().getRepositoryURL();
- if (docurl.startsWith(prefix))
+ if (docurl.startsWith(prefix)) {
try {
String path = docurl.substring(prefix.length());
Document value = getDocumentService().getDocumentByPath(path);
- selecdoc = ustep.getDocument(value.getIndex());
+ _selecdoc = ustep.getDocument(value.getIndex());
} catch (Exception error) {
- logger.error("Reason:", error);
+ LOGGER.error("Reason:", error);
}
+ }
}
- public void setSelection(String step) {
- // --------------------------------------
+ public void setSelection(final String step) {
if (!step.equals(selection)) {
selection = step;
- selecdoc = null;
+ _selecdoc = null;
setupPreviousToSelectedSteps();
updateSimulationContexts(); // Initializes contexts according to the selected steps
}
ustep = involving.get(involving.size() - 1);
- urightstep = new StepRights(cuser, ustep);
+ _urightstep = new StepRights(cuser, ustep);
ustep.setActor(cuser);
menu.selects(selection); // Updates menu items to be displayed
setupContents(); // The contents may have changed even if the selection is the same
// Protected services
// ==============================================================================================================================
- protected void add(Publication doc) {
- // ------------------------------------
+ protected void add(final Publication doc) {
DocumentFacade facade = new DocumentFacade(this, doc,
getProjectSettings(), getPublicationService());
boolean first = (contents.size() == 0);
docpres.put(doc.getIndex(), facade);
contents.add(0, facade); // Prepend the new publication
- if (first)
+ if (first) {
this.getMenu().refreshSelectedItem();
+ }
}
- protected void add(SimulationContext contex) {
- // ---------------------------------------------
+ protected void add(final SimulationContext contex) {
SimulationContextFacade facade = new SimulationContextFacade(contex,
getProjectSettings().getAllSteps());
context.add(facade);
}
- protected void add(KnowledgeElement kelm) {
- // ------------------------------------------
- KnowledgeElementFacade facade = new KnowledgeElementFacade(kelm);
+ protected void add(final KnowledgeElement kelm) {
+ KnowledgeElementFacade facade = new KnowledgeElementFacade(BeanHelper
+ .copyBean(kelm, KnowledgeElementDTO.class));
// RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2);
// Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
// RKV:Begin: Find a knowledge iterator for appropriate knowledge type
}
}
- protected void remove(Publication doctag) {
- // ------------------------------------------
+ protected void remove(final Publication doctag) {
for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
DocumentFacade facade = i.next();
- if (!facade.isFacadeOf(doctag))
+ if (!facade.isFacadeOf(doctag)) {
continue;
+ }
i.remove();
break;
}
- if (contents.size() == 0)
+ if (contents.size() == 0) {
this.getMenu().refreshSelectedItem();
+ }
}
- protected void changeUser(User user) {
- // -------------------------------------
+ protected void changeUser(final User user) {
cuser = user;
popup = null;
- if (getStudyService().isStaffedBy(mystudy, cuser)) {
+ if (getStudyService().isStaffedBy(_mystudy, cuser)) {
popup = getApplicationSettings().getPopupMenu("steditable");
- popup.setContext("study", new StudyRights(cuser, mystudy));
+ popup.setContext("study", new StudyRights(cuser, _mystudy));
}
- //ustep = getProjectElementService().getFirstStep(mystudy);
+ // ustep = getProjectElementService().getFirstStep(mystudy);
if (ustep != null) {
ustep.setActor(cuser);
}
- urightstudy = new StudyRights(cuser, mystudy);
- urightstep = new StepRights(cuser, ustep);
+ _urightstudy = new StudyRights(cuser, _mystudy);
+ _urightstep = new StepRights(cuser, ustep);
}
- protected void remove(SimulationContext contex) {
- // ------------------------------------------------
+ protected void remove(final SimulationContext contex) {
for (Iterator<SimulationContextFacade> i = context.iterator(); i
.hasNext();) {
SimulationContextFacade facade = i.next();
- if (!facade.isFacadeOf(contex))
+ if (!facade.isFacadeOf(contex)) {
continue;
+ }
i.remove();
break;
}
}
- protected void remove(KnowledgeElement kelm) {
- // ---------------------------------------------
+ protected void remove(final KnowledgeElement kelm) {
KnowledgeIterator known = knowledge.get((int) (kelm.getType()
.getIndex() - 2));
// Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
for (Iterator<KnowledgeElementFacade> i = known.list.iterator(); i
.hasNext();) {
KnowledgeElementFacade facade = i.next();
- if (!facade.isFacadeOf(kelm))
+ if (!facade.isFacadeOf(BeanHelper.copyBean(kelm,
+ KnowledgeElementDTO.class))) {
continue;
+ }
i.remove();
break;
}
}
- protected void update(Publication doc) {
- // ---------------------------------------
+ protected void update(final Publication doc) {
DocumentFacade facade = docpres.get(doc.getIndex());
if (facade != null) {
facade.refresh();
}
}
- protected void update(KnowledgeElement kelm) {
- // ---------------------------------------------
+ protected void update(final KnowledgeElementDTO kelm) {
KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
if (facade != null) {
- facade.refresh();
+ facade.refresh(kelm);
}
}
protected void updateSimulationContexts() {
- // ------------------------------------------
context.clear();
for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
for (Iterator<SimulationContext> j = i.next()
// ==============================================================================================================================
private void setupPreviousToSelectedSteps() {
- // --------------------------------------------
String[] item = selection.split("\\x2E");
int major = Integer.valueOf(item[0]);
int minor = Integer.valueOf(item[1]);
involving.clear();
if (major > 0) {
- Scenario[] branch = mystudy.getScenarii();
+ Scenario[] branch = _mystudy.getScenarii();
Scenario scenar = branch[0];
for (int i = 0; i < branch.length; i++) {
scenar = branch[i];
- if (scenar.getIndex() == major)
+ if (scenar.getIndex() == major) {
break; // Supposed exist
+ }
}
step = getProjectElementService().getSteps(scenar);
base = step[0].getNumber() - 1;
involving.add(step[i]);
}
}
- step = getProjectElementService().getSteps(mystudy);
+ step = getProjectElementService().getSteps(_mystudy);
for (int i = step.length - 1; i > -1; i--) {
Step firstep = step[i];
- if (firstep.getNumber() > base)
+ if (firstep.getNumber() > base) {
continue;
+ }
involving.add(0, firstep);
}
}
* @param stepService
* the stepService to set
*/
- public void setStepService(StepService stepService) {
+ public void setStepService(final StepService stepService) {
_stepService = stepService;
}
* @param repositoryService
* the repositoryService to set
*/
- public void setRepositoryService(RepositoryService repositoryService) {
+ public void setRepositoryService(final RepositoryService repositoryService) {
_repositoryService = repositoryService;
}
/**
* Get the documentTypeService.
+ *
* @return the documentTypeService
*/
public DocumentTypeService getDocumentTypeService() {
/**
* Set the documentTypeService.
- * @param documentTypeService the documentTypeService to set
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
*/
- public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ public void setDocumentTypeService(
+ final DocumentTypeService documentTypeService) {
_documentTypeService = documentTypeService;
}
* @param studyService
* the studyService to set
*/
- public void setStudyService(StudyService studyService) {
+ public void setStudyService(final StudyService studyService) {
_studyService = studyService;
}
/**
* Get the documentService.
+ *
* @return the documentService
*/
public DocumentService getDocumentService() {
/**
* Set the documentService.
- * @param documentService the documentService to set
+ *
+ * @param documentService
+ * the documentService to set
*/
- public void setDocumentService(DocumentService documentService) {
+ public void setDocumentService(final DocumentService documentService) {
_documentService = documentService;
}
-
+
public Study getMystudy() {
- return mystudy;
+ return _mystudy;
}
- public void setMystudy(Study mystudy) {
- this.mystudy = mystudy;
+ public void setMystudy(final Study mystudy) {
+ this._mystudy = mystudy;
}
}
\ No newline at end of file