* @version $Revision$
*****************************************************************************/
-package org.splat.service;
+package org.splat.service;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.Document.Properties;
import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.DocumentDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.NotApplicableException;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
-import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
/**
+ * Document service implementation.
+ *
* @author RKV
- *
+ *
*/
public class DocumentServiceImpl implements DocumentService {
+ /**
+ * Injected study service.
+ */
private StudyService _studyService;
+ /**
+ * Injected project settings service.
+ */
private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected document service.
+ */
+ private DocumentDAO _documentDAO;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.DocumentService#selectDocument(long)
+ */
+ @Transactional(readOnly = true)
+ public Document selectDocument(long index) {
+ // -------------------------------------------------
+ return getDocumentDAO().get(index);
+ }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.DocumentService#selectDocument(java.lang.String, java.lang.String)
+ */
+ public Document selectDocument(String refid, String version) {
+ // --------------------------------------------------------------------
+ StringBuffer query = new StringBuffer("from Document where did='")
+ .append(refid).append("' and version='").append(version)
+ .append("'");
+ return (Document) Database.getSession().createQuery(query.toString())
+ .uniqueResult();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.DocumentService#generateDocumentId(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties)
+ */
public void generateDocumentId(Document aDoc, Properties dprop) {
Study owner = null;
if (dprop.getOwner() instanceof Study)
String path = owner.getReference();
ProjectSettingsService.Step step = ProjectSettingsServiceImpl
.getStep(aDoc.getStep());
- aDoc.setDid( new StringBuffer(path).append(".%").append(aDoc.suformat).toString()); // Document reference
+ aDoc.setDid(new StringBuffer(path).append(".%").append(
+ Document.suformat).toString()); // Document reference
path = new StringBuffer(year).append("/").append(path).append("/")
- .append(step.getPath()) // File path relative to the repository vault
- .append(filename).append(".").append(aDoc.getFile().getFormat()) // File name and extension
+ .append(step.getPath())
+ // File path relative to the repository vault
+ .append(filename).append(".")
+ .append(aDoc.getFile().getFormat()) // File name and extension
.toString();
aDoc.getFile().changePath(path);
}
+ /**
+ * Generate encoded document file name according to the naming scheme from project settings.
+ *
+ * @param aDoc
+ * the document
+ * @param scope
+ * the study
+ * @return document reference name
+ */
private String generateEncodedName(Document aDoc, Study scope) {
// ------------------------------------------------
StringBuffer encoding = new StringBuffer();
FileNaming scheme = getProjectSettings().getFileNamingScheme();
- DecimalFormat tostring = new DecimalFormat(aDoc.suformat);
+ DecimalFormat tostring = new DecimalFormat(Document.suformat);
int number = getStudyService().generateLocalIndex(scope);
encoding.append(scope.getReference()).append(".").append(
tostring.format(number));
} else { // title and (temporarily) asis
- encoding.append(aDoc.getTitle()).append(".").append(tostring.format(number));
+ encoding.append(aDoc.getTitle()).append(".").append(
+ tostring.format(number));
}
return encoding.toString();
}
+ /**
+ * Get encoded root name for a document file.
+ *
+ * @param aDoc
+ * the document
+ * @param scope
+ * the study
+ * @return file name
+ */
private String getEncodedRootName(Document aDoc, Study scope) {
// -----------------------------------------------
FileNaming scheme = getProjectSettings().getFileNamingScheme();
}
/**
- * Defines this document.
- *
- * @param dprop
- * the properties of the document
+ * {@inheritDoc}
*
- * @see Step#createDocument(Properties)
- * @see #isUndefined()
+ * @see org.splat.service.DocumentService#initialize(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties)
*/
- public void initialize(Document aDoc, Properties dprop) throws MissedPropertyException,
- InvalidPropertyException, NotApplicableException {
+ public void initialize(Document aDoc, Properties dprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ NotApplicableException {
// --------------------------------------------
if (!aDoc.isUndefined())
throw new NotApplicableException(
// throw new InvalidPropertyException("step");
// }
aDoc.setTitle(dprop.getName());
- aDoc.getFile().changePath(aDoc.getFile().getRelativePath().replace("%n",
- getEncodedRootName(aDoc, (Study) dprop.getOwner())));
+ aDoc.getFile().changePath(
+ aDoc.getFile().getRelativePath().replace("%n",
+ getEncodedRootName(aDoc, (Study) dprop.getOwner())));
if (aDoc.getHistory() == -1)
- aDoc.setHistory( 0 );
+ aDoc.setHistory(0);
if (dprop.getDate() == null) {
Calendar current = Calendar.getInstance();
aDoc.setLastModificationDate(current.getTime()); // Today
Database.getSession().update(aDoc);
}
+ public java.io.File getSaveDirectory(Document aDoc) {
+ String mypath = Database.getRepositoryVaultPath()
+ + aDoc.getSourceFile().getRelativePath();
+ String[] table = mypath.split("/");
+
+ // Cutting the filename
+ StringBuffer path = new StringBuffer(table[0]);
+ for (int i = 1; i < table.length - 1; i++)
+ path = path.append("/").append(table[i]);
+ return new java.io.File(path.append("/").toString());
+ }
+
/**
* Get the studyService.
+ *
* @return the studyService
*/
public StudyService getStudyService() {
/**
* Set the studyService.
- * @param studyService the studyService to set
+ *
+ * @param studyService
+ * the studyService to set
*/
public void setStudyService(StudyService studyService) {
_studyService = studyService;
_projectSettingsService = projectSettingsService;
}
+ /**
+ * Get the documentDAO.
+ *
+ * @return the documentDAO
+ */
+ public DocumentDAO getDocumentDAO() {
+ return _documentDAO;
+ }
+
+ /**
+ * Set the documentDAO.
+ *
+ * @param documentDAO
+ * the documentDAO to set
+ */
+ public void setDocumentDAO(DocumentDAO documentDAO) {
+ _documentDAO = documentDAO;
+ }
+
}