import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.Timestamp;
import org.splat.dal.bo.som.ValidationStep;
-import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.bo.som.Document.Properties;
+import org.splat.dal.dao.kernel.RelationDAO;
import org.splat.dal.dao.som.DocumentDAO;
import org.splat.dal.dao.som.DocumentTypeDAO;
import org.splat.dal.dao.som.FileDAO;
* Injected document DAO.
*/
private DocumentDAO _documentDAO;
+ /**
+ * Injected relation DAO.
+ */
+ private RelationDAO _relationDAO;
/**
* Injected document type DAO.
*/
*/
@Transactional
public void generateDocumentId(final Document aDoc, final Properties dprop) {
- Study owner = null;
- if (dprop.getOwner() instanceof Study) {
- owner = (Study) dprop.getOwner();
- } else {
- owner = ((Scenario) dprop.getOwner()).getOwnerStudy();
- }
+ Study owner = dprop.getOwner().getOwnerStudy();
// Synchronize the object with the current Hibernate session.
- owner = getStudyDAO().get(owner.getIndex());
+ // owner = getStudyDAO().merge(owner);
- SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); //RKV: NOPMD: TODO: Use locale here?
+ SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); // RKV: NOPMD: TODO: Use locale here?
String year = tostring.format(owner.getDate());
String filename = generateEncodedName(aDoc, owner);
String path = owner.getReference();
.append(aDoc.getFile().getFormat()) // File name and extension
.toString();
aDoc.getFile().changePath(path);
+ owner = getStudyDAO().merge(owner);
+ // getStudyDAO().update(owner);
}
/**
int number = getStudyService().generateLocalIndex(scope);
if (scheme == FileNaming.encoded) {
- encoding.append(scope.getReference()).append(".").append(
+ 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("_").append(tostring.format(number)).append(
+ aDoc.getFile().getName());
}
return encoding.toString();
}
* the format
* @return the created "Converts" relation
*/
+ @Transactional
public ConvertsRelation attach(final Document aDoc, final String format) {
return attach(aDoc, format, null);
}
ConvertsRelation attach = new ConvertsRelation(aDoc, export,
description);
- // RKV session.save(export);
- // RKV session.save(attach);
-
getFileDAO().create(export);
+ getRelationDAO().create(attach);
- // RKV aDoc.addRelation(attach); // Updates this
- aDoc.getAllRelations().add(attach); // Updates this //RKV
+ aDoc.getAllRelations().add(attach);
+ getDocumentDAO().merge(aDoc);
return attach;
}
*/
public boolean buildReferenceFrom(final Document aDoc,
final ProjectElement scope, final Document lineage) {
- if (aDoc.getProgressState() != ProgressState.inWORK) {
- return false;
- }
- Study owner = null;
- Scenario context = null;
- if (scope instanceof Study) {
- owner = (Study) scope;
- } else {
- context = ((Scenario) scope);
- owner = context.getOwnerStudy();
- }
- aDoc.setDid(lineage.getDid());
- if (context != null && (lineage.isVersioned() || owner.shares(lineage))) {
- aDoc.setVersion(new Revision(aDoc.getVersion()).setBranch(
- context.getReference()).toString());
+ boolean res = (aDoc.getProgressState() == ProgressState.inWORK);
+ if (res) {
+ Study owner = scope.getOwnerStudy();
+ Scenario context = null;
+ if (scope instanceof Scenario) {
+ context = ((Scenario) scope);
+ }
+ aDoc.setDid(lineage.getDid());
+ if (context != null
+ && (lineage.isVersioned() || owner.shares(lineage))) {
+ aDoc.setVersion(new Revision(aDoc.getVersion()).setBranch(
+ context.getReference()).toString());
+ }
}
- return true;
+ return res;
}
/**
} else {
Revision myvers = new Revision(aDoc.getVersion());
if (!myvers.isNull()) { // Versionning context
- for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
- .hasNext();) {
- Relation link = i.next();
- if (!link.getClass().equals(VersionsRelation.class)) {
- continue;
- }
- previous = (Document) link.getTo(); // Versioned document
- break;
- }
+ previous = aDoc.getPreviousVersion();
}
if (aDoc.getProgressState() != null) {
myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
}
aDoc.setVersion(myvers.toString());
}
- // Update this document and the previous version, if exit
+ // Update this document and the previous version, if exist
if (previous != null) {
previous.setHistory(previous.getHistory() + 1);
getDocumentDAO().merge(previous);
}
aDoc.setProgressState(state);
- getDocumentDAO().update(aDoc);
+ // RKV: getDocumentDAO().update(aDoc);
}
// protected void upgrade () {
_studyDAO = studyDAO;
}
+ /**
+ * Get the relationDAO.
+ *
+ * @return the relationDAO
+ */
+ public RelationDAO getRelationDAO() {
+ return _relationDAO;
+ }
+
+ /**
+ * Set the relationDAO.
+ *
+ * @param relationDAO
+ * the relationDAO to set
+ */
+ public void setRelationDAO(final RelationDAO relationDAO) {
+ _relationDAO = relationDAO;
+ }
+
}