+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#promote(org.splat.dal.bo.som.KnowledgeElement)
+ */
+ @Transactional
+ public boolean promote(final KnowledgeElement knowledgeElement) {
+ if (knowledgeElement.getProgressState() != ProgressState.inDRAFT) {
+ return false;
+ }
+ knowledgeElement.setProgressState(ProgressState.inCHECK);
+ return update(knowledgeElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#rename(org.splat.dal.bo.som.KnowledgeElement, java.lang.String)
+ */
+ @Transactional
+ public void rename(final KnowledgeElementDTO kelmDTO, final String title)
+ throws InvalidPropertyException {
+ if (title.length() == 0) {
+ throw new InvalidPropertyException("name");
+ }
+ 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());
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#selectKnowledgeElement(long)
+ */
+ @Transactional(readOnly = true)
+ public KnowledgeElement selectKnowledgeElement(final long index) {
+ KnowledgeElement result = getKnowledgeElementDAO().get(index);
+ getStudyService().loadWorkflow(
+ result.getOwnerScenario().getOwnerStudy());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#getKnowledgeElement(long)
+ */
+ @Transactional(readOnly = true)
+ public KnowledgeElementDTO getKnowledgeElement(final long index) {
+ KnowledgeElement kelm = getKnowledgeElementDAO().get(index);
+ getStudyService().loadWorkflow(kelm.getOwnerScenario().getOwnerStudy());
+ KnowledgeElementDTO result = BeanHelper.copyBean(kelm,
+ KnowledgeElementDTO.class);
+ result.setScenarioTitle(kelm.getOwnerScenario().getTitle());
+ result.setStudyTitle(kelm.getOwnerScenario().getOwnerStudy().getTitle());
+ result.getInvolving().addAll(getAllSteps(kelm.getOwnerScenario()));
+ return result;
+ }
+
+ /**
+ * Get all steps of the scenario.
+ * @param scenar the scenario
+ * @return collection of steps
+ */
+ private Collection<? extends Step> getAllSteps(final Scenario scenar) {
+ Vector<Step> result = new Vector<Step>();
+ Step[] step = getProjectElementService().getSteps(scenar);