/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
package org.splat.service;
-import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.Vector;
import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.File;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.FileDAO;
import org.splat.dal.dao.som.ProjectElementDAO;
import org.splat.dal.dao.som.SimulationContextDAO;
import org.splat.kernel.InvalidPropertyException;
* Injected document service.
*/
private DocumentService _documentService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
/**
* Injected document DAO.
*/
private DocumentDAO _documentDAO;
+ /**
+ * Injected file DAO.
+ */
+ private FileDAO _fileDAO;
/**
* Injected simulation context service.
*/
*/
public SimulationContext addSimulationContext(Step aStep,
SimulationContext.Properties dprop) throws MissedPropertyException,
- InvalidPropertyException, MultiplyDefinedException,
- RuntimeException {
+ InvalidPropertyException, MultiplyDefinedException {
SimulationContext context = new SimulationContext(dprop.setStep(aStep
.getStep()));
return addSimulationContext(aStep, context);
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);
}
}
getDocumentService().generateDocumentId(newdoc, dprop);
// Creation of the save directory
- File wdir = getDocumentService().getSaveDirectory(newdoc);
+ java.io.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());
+ getDocumentService().buildReferenceFrom(newdoc, aStep.getOwnerStudy());
getDocumentDAO().create(newdoc);
return new Publication(newdoc, aStep.getOwner());
}
/**
+ * Create a new version of a document in the given study step.
+ *
* @param aStep
+ * the study step
* @param base
- * @return
+ * the base document published version
+ * @return the new version publication
* @throws MissedPropertyException
+ * if a mandatory property is missed
* @throws InvalidPropertyException
+ * if some property doesn't exist
* @throws MultiplyDefinedException
+ * if some property is defined several times
* @throws IOException
+ * if a file system error occurs
* @throws MismatchException
+ * if the document is not applicable to the given study step
*/
public Publication versionDocument(Step aStep, Publication base)
throws MissedPropertyException, InvalidPropertyException,
}
/**
+ * Create a new version of a document in the given study step.
+ *
* @param aStep
+ * the study step
* @param base
+ * the base document published version
* @param reason
- * @return
+ * the comment for the new version
+ * @return the new version publication
* @throws MissedPropertyException
+ * if a mandatory property is missed
* @throws InvalidPropertyException
+ * if some property doesn't exist
* @throws MultiplyDefinedException
+ * if some property is defined several times
* @throws IOException
+ * if a file system error occurs
* @throws MismatchException
+ * if the document is not applicable to the given study step
*/
public Publication versionDocument(Step aStep, Publication base,
String reason) throws MissedPropertyException,
}
/**
- * {@inheritDoc}
+ * Create a new version of a document in the given study step.
*
- * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication,
- * org.splat.dal.bo.som.Document.Properties)
+ * @param aStep
+ * the study step
+ * @param base
+ * the base document published version
+ * @param dprop
+ * properties of the new version
+ * @return the new version publication
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ * @throws IOException
+ * if a file system error occurs
+ * @throws MismatchException
+ * if the document is not applicable to the given study step
*/
@Transactional
public Publication versionDocument(Step aStep, Publication base,
Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
.setStep(aStep.getStep()));
getDocumentService().generateDocumentId(newdoc, dprop);
- newdoc.buildReferenceFrom(aStep.getOwner(), previous);
+ getDocumentService().buildReferenceFrom(newdoc, aStep.getOwner(),
+ previous);
getDocumentDAO().create(newdoc);
// Versioning
return new Publication(newdoc, aStep.getOwner());
}
+ /**
+ * Get document types which are applicable for the given study step (activity).
+ *
+ * @param aStep
+ * the study step
+ * @return the list of document types
+ */
+ public List<DocumentType> getValidDocumentTypes(Step aStep) {
+ return getDocumentTypeService().selectTypesOf(aStep.getStep());
+ }
+
+ /**
+ * Add a document publication to the given step.
+ *
+ * @param aStep
+ * the target study step
+ * @param newdoc
+ * the document publication to add
+ * @return true if publication succeeded
+ */
+ public boolean add(Step aStep, Publication newdoc) {
+ if (!aStep.getOwner().add(newdoc))
+ return false; // Updates the study in memory
+ aStep.getDocuments().add(0, newdoc); // Updates this step
+ getDocumentService().hold(newdoc.value()); // Increments the configuration tag count of document
+ // If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
+ // database (it will be saved later by cascading the update of owner scenario).
+ return true;
+ }
+
+ /**
+ * Remove a document publication from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param oldoc
+ * the document publication to remove
+ * @return true if removing of the publication succeeded
+ */
+ public boolean remove(Step aStep, Publication oldoc) {
+ if (!aStep.getOwner().remove(oldoc))
+ return false; // Updates the study in memory
+ aStep.getDocuments().remove(oldoc); // Updates this step
+ getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document
+ // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
+ return true;
+ }
+
+ /**
+ * Remove a document from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param doctag
+ * the document publication
+ * @return true if removing of the document succeeded
+ */
+ public boolean removeDocument(Step aStep, Publication doctag) {
+ Document value = doctag.value();
+ Publication torem = aStep.getDocument(value.getIndex());
+
+ if (torem == null)
+ return false;
+
+ remove(aStep, torem);
+ getProjectElementDAO().update(aStep.getOwner());
+ if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
+ Set<Relation> links = value.getAllRelations(); // Get all relation of the document to remove them
+ List<Document> using = new Vector<Document>();
+ for (Iterator<Relation> i = links.iterator(); i.hasNext();) {
+ Relation link = i.next();
+ if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
+ getFileDAO().delete((File) link.getTo()); // The corresponding physical file is not removed from the vault
+ } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
+ using.add((Document) link.getTo());
+ }
+ }
+ for (Iterator<Document> i = using.iterator(); i.hasNext();) {
+ i.next().removeRelation(UsedByRelation.class, value); // TODO: RKV: don't use Database.getSession in removeRelation
+ }
+ getDocumentDAO().delete(value); // The corresponding physical file is not removed from the vault
+ }
+ return true;
+ }
+
/**
* Get the documentService.
*
public void setIndexService(IndexService indexService) {
_indexService = indexService;
}
+
+ /**
+ * Get the fileDAO.
+ *
+ * @return the fileDAO
+ */
+ public FileDAO getFileDAO() {
+ return _fileDAO;
+ }
+
+ /**
+ * Set the fileDAO.
+ *
+ * @param fileDAO
+ * the fileDAO to set
+ */
+ public void setFileDAO(FileDAO fileDAO) {
+ _fileDAO = fileDAO;
+ }
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}