import java.text.SimpleDateFormat;
import java.util.Calendar;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.Scenario;
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.RepositoryService;
import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
import org.springframework.transaction.annotation.Transactional;
/**
* Document service implementation.
*
- * @author RKV
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*
*/
public class DocumentServiceImpl implements DocumentService {
* Injected project settings service.
*/
private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected repository service.
+ */
+ private RepositoryService _repositoryService;
/**
* Injected document service.
*/
*/
@Transactional(readOnly = true)
public Document selectDocument(long index) {
- // -------------------------------------------------
return getDocumentDAO().get(index);
}
*
* @see org.splat.service.DocumentService#selectDocument(java.lang.String, java.lang.String)
*/
+ @Transactional(readOnly = true)
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();
+ Criterion aCondition = Restrictions.and(Restrictions.eq("did", refid),
+ Restrictions.eq("version", version));
+ return getDocumentDAO().findByCriteria(aCondition);
}
/**
* @return document reference name
*/
private String generateEncodedName(Document aDoc, Study scope) {
- // ------------------------------------------------
StringBuffer encoding = new StringBuffer();
FileNaming scheme = getProjectSettings().getFileNamingScheme();
DecimalFormat tostring = new DecimalFormat(Document.suformat);
* @return file name
*/
private String getEncodedRootName(Document aDoc, Study scope) {
- // -----------------------------------------------
FileNaming scheme = getProjectSettings().getFileNamingScheme();
if (scheme == FileNaming.encoded)
public void initialize(Document aDoc, Properties dprop)
throws MissedPropertyException, InvalidPropertyException,
NotApplicableException {
- // --------------------------------------------
if (!aDoc.isUndefined())
throw new NotApplicableException(
"Cannot initialize an existing Document");
} else {
aDoc.setLastModificationDate(dprop.getDate());
}
- Database.getSession().update(aDoc);
+ getDocumentDAO().update(aDoc);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.DocumentService#getSaveDirectory(org.splat.dal.bo.som.Document)
+ */
public java.io.File getSaveDirectory(Document aDoc) {
- String mypath = Database.getRepositoryVaultPath()
+ String mypath = getRepositoryService().getRepositoryVaultPath()
+ aDoc.getSourceFile().getRelativePath();
String[] table = mypath.split("/");
_documentDAO = documentDAO;
}
+ /**
+ * Get the repositoryService.
+ *
+ * @return the repositoryService
+ */
+ public RepositoryService getRepositoryService() {
+ return _repositoryService;
+ }
+
+ /**
+ * Set the repositoryService.
+ *
+ * @param repositoryService
+ * the repositoryService to set
+ */
+ public void setRepositoryService(RepositoryService repositoryService) {
+ _repositoryService = repositoryService;
+ }
+
}
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.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
import org.splat.service.technical.IndexService;
import org.splat.som.Revision;
import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
/**
* Step service implementation.
* Injected document service.
*/
private DocumentService _documentService;
+ /**
+ * Injected document DAO.
+ */
+ private DocumentDAO _documentDAO;
/**
* Injected simulation context service.
*/
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);
// Identification and save
newdoc.buildReferenceFrom(aStep.getOwnerStudy());
- Database.getSession().save(newdoc);
+ 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;
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();
Document newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
getDocumentService().generateDocumentId(newdoc, dprop);
newdoc.buildReferenceFrom(aStep.getOwner(), previous);
- Database.getSession().save(newdoc);
+ getDocumentDAO().create(newdoc);
// Versioning
if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
+
+ /**
+ * 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;
+ }
}