import java.util.Iterator;
import java.util.List;
-import org.hibernate.Session;
import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.VersionsRelation;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.ProjectElementDAO;
+import org.splat.dal.dao.som.SimulationContextDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.NotApplicableException;
+import org.splat.log.AppLogger;
import org.splat.service.technical.IndexService;
import org.splat.som.Revision;
import org.splat.som.Step;
/**
* Step service implementation.
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class StepServiceImpl implements StepService {
+ /**
+ * logger for the service.
+ */
+ public final static AppLogger logger = AppLogger
+ .getLogger(StepServiceImpl.class);
/**
* Injected index service.
*/
* Injected simulation context service.
*/
private SimulationContextService _simulationContextService;
+ /**
+ * Injected simulation context DAO.
+ */
+ private SimulationContextDAO _simulationContextDAO;
+ /**
+ * Injected project element DAO.
+ */
+ private ProjectElementDAO _projectElementDAO;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties)
+ */
public SimulationContext addSimulationContext(Step aStep,
SimulationContext.Properties dprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException,
return addSimulationContext(aStep, context);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
+ */
+ @Transactional
public SimulationContext addSimulationContext(Step aStep,
SimulationContext context) {
getSimulationContextService().hold(context); // Increments the reference count of simulation context
if (aStep.getOwner().isSaved())
try {
- Session session = Database.getSession();
- IndexService lucin = getIndexService();
-
if (!context.isSaved())
- session.save(context);
+ getSimulationContextDAO().create(context);
aStep.getOwner().add(context);
aStep.getContex().add(context); // The context is also referenced from this (transient) Step
- session.update(aStep.getOwner());
- updateKnowledgeElementsIndex(aStep, lucin);
+ getProjectElementDAO().update(aStep.getOwner());
+ updateKnowledgeElementsIndex(aStep);
} catch (Exception error) {
return null;
}
return context;
}
- private void updateKnowledgeElementsIndex(Step aStep, IndexService lucin) {
- // ------------------------------------------------------
+ /**
+ * Update lucene index of knowledge elements of a scenario or a study which the given step is related to.
+ *
+ * @param aStep
+ * the step (activity)
+ */
+ private void updateKnowledgeElementsIndex(Step aStep) {
Scenario[] scenarii;
if (aStep.getOwner() instanceof Scenario) {
scenarii = new Scenario[1];
for (Iterator<KnowledgeElement> j = knelm.iterator(); j
.hasNext();) {
KnowledgeElement kelm = j.next();
- lucin.update(kelm);
+ getIndexService().update(kelm);
}
- scene.updateMyIndex(lucin);
+ updateScenarioIndex(scene);
}
} catch (Exception error) {
- // logger.error("Unable to re-index Knowledge Elements, reason:", error);
+ logger.error("Unable to re-index Knowledge Elements, reason:", error);
+ }
+ }
+
+ /**
+ * Update lucene index for knowledge elements of the scenario.
+ *
+ * @param scene
+ * the scenario
+ * @throws IOException
+ * if can't update lucene index
+ */
+ private void updateScenarioIndex(Scenario scene) throws IOException {
+ if (scene.getUcase() == null) {
+ for (Iterator<KnowledgeElement> i = scene.getKnowledgeElements()
+ .iterator(); i.hasNext();) {
+ KnowledgeElement kelm = i.next();
+ if (!kelm.getType().equals("usecase"))
+ continue;
+ scene.setUcase(kelm);
+ break;
+ }
}
+ getIndexService().update(scene.getUcase());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
+ */
+ @Transactional
+ public boolean removeSimulationContext(Step aStep, SimulationContext context) {
+ boolean isOk = false;
+ SimulationContext torem = aStep
+ .getSimulationContext(context.getIndex());
+
+ if ((torem != null) && (aStep.getOwner().remove(torem))) {
+
+ aStep.getContex().remove(torem);
+ getProjectElementDAO().update(aStep.getOwner());
+ if (torem.isShared()) {
+ getSimulationContextService().release(torem);
+ getSimulationContextDAO().update(torem);
+ } else {
+ getSimulationContextDAO().delete(torem);
+ }
+ isOk = true;
+ }
+ return isOk;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
+ */
+ @Transactional
+ public Publication createDocument(Step aStep, Document.Properties dprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException, IOException {
+ Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
+ .setStep(aStep.getStep()));
+ getDocumentService().generateDocumentId(newdoc, dprop);
+
+ // Creation of the save directory
+ File wdir = getDocumentService().getSaveDirectory(newdoc);
+ if (!wdir.exists())
+ if (!wdir.mkdirs())
+ throw new IOException(
+ "Cannot create the repository vault directory");
+
+ // Identification and save
+ newdoc.buildReferenceFrom(aStep.getOwnerStudy());
+ getDocumentDAO().create(newdoc);
+
+ return new Publication(newdoc, aStep.getOwner());
}
- public boolean removeSimulationContext (Step aStep, SimulationContext context) {
-// ------------------------------------------------------------------
- SimulationContext torem = aStep.getSimulationContext(context.getIndex());
- Session session = Database.getSession();
-
- if (torem == null) return false;
- if (!aStep.getOwner().remove(torem)) return false;
-
- aStep.getContex().remove(torem);
- session.update(aStep.getOwner());
- if (torem.isShared()) {
- getSimulationContextService().release(torem);
- session.update(torem);
- } else {
- session.delete(torem);
- }
- return true;
- }
-
- @Transactional
- public Publication createDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException {
- Document newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
- getDocumentService().generateDocumentId(newdoc, dprop);
-
-// Creation of the save directory
- File wdir = getDocumentService().getSaveDirectory(newdoc);
- if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory");
-
-// Identification and save
- newdoc.buildReferenceFrom(aStep.getOwnerStudy());
- getDocumentDAO().create(newdoc);
-
- return new Publication(newdoc, aStep.getOwner());
- }
-
- public Publication assignDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException {
- String refid = dprop.getReference();
- if (refid == null) return null;
-
- Document slot = getDocumentService().selectDocument(refid, new Revision().toString());
- if ( slot == null ) return null;
- if (!slot.isUndefined()) return null; // Should not happen
-
- getDocumentService().initialize(slot, dprop.setOwner(aStep.getOwnerStudy()));
- return new Publication(slot, aStep.getOwner());
- }
-
- public Publication versionDocument (Step aStep, Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
- // -----------------------------------------------------
- return versionDocument(aStep, base, new Document.Properties());
- }
-
- public Publication versionDocument (Step aStep, Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
- // --------------------------------------------------------------------
- return versionDocument(aStep, base, new Document.Properties().setDescription(reason));
- }
-
- @Transactional
- public Publication versionDocument (Step aStep, Publication base, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
- // --------------------------------------------------------------------------------
- Document previous = base.value();
-
- dprop.setDocument(previous); // Initializes the Step property
- if (dprop.getStep().getNumber() != aStep.getNumber()) throw new MismatchException();
-
- if (dprop.getAuthor() == null) dprop.setAuthor(previous.getAuthor());
- String summary = dprop.getDescription();
-
-// Creation of the document
- Document newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
- getDocumentService().generateDocumentId(newdoc, dprop);
- newdoc.buildReferenceFrom(aStep.getOwner(), previous);
- getDocumentDAO().create(newdoc);
-
-// Versioning
- if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
- else newdoc.addRelation( new VersionsRelation(newdoc, previous, summary) );
-
-// Update of usedby relations, if exist
- List<Relation> relist = previous.getRelations(UsedByRelation.class);
- Study scope = aStep.getOwnerStudy();
- for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
- UsedByRelation relation = (UsedByRelation)i.next();
- Document relatedoc = relation.getTo();
- if (scope.shares(relatedoc)) relatedoc.addRelation( new UsesRelation(relatedoc, newdoc) );
- else relation.moveTo(newdoc);
- }
- return new Publication(newdoc, aStep.getOwner());
- }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
+ */
+ public Publication assignDocument(Step aStep, Document.Properties dprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ NotApplicableException {
+ String refid = dprop.getReference();
+ if (refid == null)
+ return null;
+
+ Document slot = getDocumentService().selectDocument(refid,
+ new Revision().toString());
+ if (slot == null)
+ return null;
+ if (!slot.isUndefined())
+ return null; // Should not happen
+
+ getDocumentService().initialize(slot,
+ dprop.setOwner(aStep.getOwnerStudy()));
+ return new Publication(slot, aStep.getOwner());
+ }
/**
+ * @param aStep
+ * @param base
* @return
+ * @throws MissedPropertyException
+ * @throws InvalidPropertyException
+ * @throws MultiplyDefinedException
+ * @throws IOException
+ * @throws MismatchException
*/
- public IndexService getIndexService() {
- return _indexService;
+ public Publication versionDocument(Step aStep, Publication base)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException, IOException, MismatchException {
+ return versionDocument(aStep, base, new Document.Properties());
}
- public void setIndexService(IndexService indexService) {
- _indexService = indexService;
+ /**
+ * @param aStep
+ * @param base
+ * @param reason
+ * @return
+ * @throws MissedPropertyException
+ * @throws InvalidPropertyException
+ * @throws MultiplyDefinedException
+ * @throws IOException
+ * @throws MismatchException
+ */
+ public Publication versionDocument(Step aStep, Publication base,
+ String reason) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException, IOException,
+ MismatchException {
+ return versionDocument(aStep, base, new Document.Properties()
+ .setDescription(reason));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication,
+ * org.splat.dal.bo.som.Document.Properties)
+ */
+ @Transactional
+ public Publication versionDocument(Step aStep, Publication base,
+ Document.Properties dprop) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException, IOException,
+ MismatchException {
+ Document previous = base.value();
+
+ dprop.setDocument(previous); // Initializes the Step property
+ if (dprop.getStep().getNumber() != aStep.getNumber())
+ throw new MismatchException();
+
+ if (dprop.getAuthor() == null)
+ dprop.setAuthor(previous.getAuthor());
+ String summary = dprop.getDescription();
+
+ // Creation of the document
+ Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
+ .setStep(aStep.getStep()));
+ getDocumentService().generateDocumentId(newdoc, dprop);
+ newdoc.buildReferenceFrom(aStep.getOwner(), previous);
+ getDocumentDAO().create(newdoc);
+
+ // Versioning
+ if (summary == null)
+ newdoc.addRelation(new VersionsRelation(newdoc, previous));
+ else
+ newdoc.addRelation(new VersionsRelation(newdoc, previous, summary));
+
+ // Update of usedby relations, if exist
+ List<Relation> relist = previous.getRelations(UsedByRelation.class);
+ Study scope = aStep.getOwnerStudy();
+ for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
+ UsedByRelation relation = (UsedByRelation) i.next();
+ Document relatedoc = relation.getTo();
+ if (scope.shares(relatedoc))
+ relatedoc.addRelation(new UsesRelation(relatedoc, newdoc));
+ else
+ relation.moveTo(newdoc);
+ }
+ return new Publication(newdoc, aStep.getOwner());
}
/**
* 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) {
_documentService = documentService;
/**
* Get the simulationContextService.
+ *
* @return the simulationContextService
*/
public SimulationContextService getSimulationContextService() {
/**
* Set the simulationContextService.
- * @param simulationContextService the simulationContextService to set
+ *
+ * @param simulationContextService
+ * the simulationContextService to set
*/
public void setSimulationContextService(
SimulationContextService simulationContextService) {
/**
* Get the documentDAO.
+ *
* @return the documentDAO
*/
public DocumentDAO getDocumentDAO() {
/**
* Set the documentDAO.
- * @param documentDAO the documentDAO to set
+ *
+ * @param documentDAO
+ * the documentDAO to set
*/
public void setDocumentDAO(DocumentDAO documentDAO) {
_documentDAO = documentDAO;
}
+
+ /**
+ * Get the simulationContextDAO.
+ *
+ * @return the simulationContextDAO
+ */
+ public SimulationContextDAO getSimulationContextDAO() {
+ return _simulationContextDAO;
+ }
+
+ /**
+ * Set the simulationContextDAO.
+ *
+ * @param simulationContextDAO
+ * the simulationContextDAO to set
+ */
+ public void setSimulationContextDAO(
+ SimulationContextDAO simulationContextDAO) {
+ _simulationContextDAO = simulationContextDAO;
+ }
+
+ /**
+ * Get the projectElementDAO.
+ *
+ * @return the projectElementDAO
+ */
+ public ProjectElementDAO getProjectElementDAO() {
+ return _projectElementDAO;
+ }
+
+ /**
+ * Set the projectElementDAO.
+ *
+ * @param projectElementDAO
+ * the projectElementDAO to set
+ */
+ public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+ _projectElementDAO = projectElementDAO;
+ }
+
+ /**
+ * Get the indexService.
+ *
+ * @return the indexService
+ */
+ public IndexService getIndexService() {
+ return _indexService;
+ }
+
+ /**
+ * Set the indexService.
+ *
+ * @param indexService
+ * the indexService to set
+ */
+ public void setIndexService(IndexService indexService) {
+ _indexService = indexService;
+ }
}