import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.KnowledgeElementType;
-import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
return new FileDTO(filePath);
}
- /**
- * Create a file.
- *
- * @param fname
- * file name
- * @throws IOException
- * if file creation failed
- */
- private void createFile(final String fname) throws IOException {
- // Create a file in the download directory
- LOG.debug("Create file: " + fname);
- String filePath = fname;
- FileWriter fw = new FileWriter(filePath);
- fw.write("Simulation of " + fname + " data file at " + new Date());
- fw.close();
- }
-
- /**
- * Get path to the user's downloads directory. The directory is created if it is not exist yet.
- *
- * @param userId
- * user id
- * @return absolute path to downloads directory followed by slash
- */
- private String getDownloadPath(final long userId) {
- // Prepare download directory
- File tmpDir = _repositoryService.getDownloadDirectory(userId);
- if (!tmpDir.exists()) {
- Assert.assertTrue(tmpDir.mkdir(),
- "Can't create temporary directory: "
- + tmpDir.getAbsolutePath());
- }
-
- return tmpDir.getAbsolutePath() + "/";
- }
-
/**
* Create a persistent scenario for tests.
*
LOG.debug(">>>>> END testCopyStudyContent()");
}
- /**
- * Create a document and publish it in the project element.
- *
- * @param aProjElem
- * the project element
- * @param aStep
- * the project element step
- * @param docname
- * document name
- * @param dtype
- * document type
- * @return publication of the created document
- * @throws BusinessException
- * if document creation is failed
- * @throws IOException
- * if file creation is failed
- */
- private Publication addDoc(final ProjectElement aProjElem,
- final org.splat.som.Step aStep, final String docname,
- final DocumentType dtype) throws BusinessException, IOException {
- HibernateTemplate ht = getHibernateTemplate();
- // Add documents to the study activity
- Document.Properties dprop = new Document.Properties().setAuthor(
- aProjElem.getAuthor()).setDate(new Date()).setName(docname)
- .setType(dtype).setFormat("py");
- dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
- dprop.setStep(aStep.getStep());
- Publication pub = _stepService.createDocument(aStep, dprop);
- pub.setStep(aStep);
- aProjElem.add(pub);
- aStep.getDocuments().add(pub);
- ht.saveOrUpdate(pub);
- ht.save(pub.value());
- // Add a converts relation
- // Attach a med file
- ht.saveOrUpdate(_publicationService.attach(pub, "med"));
- String filepath = pub.getSourceFile().asFile().getAbsolutePath();
- createFile(filepath);
- createFile(filepath.substring(0, filepath.lastIndexOf(".")) + ".med");
- return pub;
- }
-
- /**
- * Create a new version of the document.
- *
- * @param pub
- * the current document publication
- * @return the new document version publication
- * @throws IOException
- * if versioning is failed
- * @throws BusinessException
- * if versioning is failed
- */
- private Publication version(final Publication pub)
- throws BusinessException, IOException {
- Document.Properties dprop = new Document.Properties();
- dprop.setDocument(pub.value(), pub.getStep().getStep());
- dprop.setLocalPath(pub.value().getTitle() + "_v1");
- Publication newpub = _stepService.versionDocument(pub.getStep(), pub,
- dprop);
- pub.getOwner().getDocums().remove(pub);
- pub.getStep().getDocuments().remove(pub);
- pub.getOwner().add(newpub);
- pub.getStep().getDocuments().add(newpub);
- String filepath = newpub.getSourceFile().asFile().getAbsolutePath();
- createFile(filepath);
- return newpub;
- }
-
/**
* Test assigning a simulation context to a study.<BR>
* <B>Description :</B> <BR>