import org.splat.dal.bo.kernel.User;
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.ProgressState;
import org.splat.dal.bo.som.ProjectElement;
*/
ConvertsRelation attach(Publication aPublication, String format,
String description);
+
+ /**
+ * Searches for a document which is connected by chain of versioning operations with the given
+ * and belongs to a publication from given project element.
+ * If the given document is the last version, it will be returned.
+ * @param doc the document
+ * @param owner the project element
+ * @return the document if found, null otherwise
+ */
+ Document getLastVersion(final Document doc, final ProjectElement owner);
/**
* Undo the out-date operation.
import java.util.List;
import org.apache.log4j.Logger;
+import org.hibernate.criterion.Restrictions;
import org.splat.common.properties.MessageKeyEnum;
+import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.Timestamp;
import org.splat.dal.bo.som.UsedByRelation;
+import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationStep;
+import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.dao.som.ProjectElementDAO;
import org.splat.dal.dao.som.PublicationDAO;
import org.splat.dal.dao.som.TimestampDAO;
+import org.splat.dal.dao.som.VersionsRelationDAO;
import org.splat.exception.IncompatibleDataException;
import org.splat.exception.InvalidParameterException;
import org.splat.kernel.InvalidPropertyException;
* Injected repository service.
*/
private RepositoryService _repositoryService;
+ /**
+ * Injected versions relation DAO.
+ */
+ private VersionsRelationDAO _versionsRelationDAO;
/**
* {@inheritDoc}
return aPublication.getStep();
}
+ /**
+ * {@inheritDoc}
+ * @see org.splat.service.PublicationService#getLastVersion(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.ProjectElement)
+ */
+ @Transactional(readOnly=true)
+ public Document getLastVersion(final Document doc, final ProjectElement owner) {
+ Document theLastVersion = _documentService.selectDocument(doc.getIndex()); //get document attached to hibernate session
+ ProjectElement trueOwner = _projectElementDAO.merge(owner);
+ if(trueOwner.getPublication(theLastVersion) == null) { //start recursive search
+ List<VersionsRelation> relations = _versionsRelationDAO
+ .getFilteredList(Restrictions.eq("refer", theLastVersion));
+ //there may be several next versions if document is shared between scenarios,
+ //but only one leads to a publication from given project elements.
+ for(Relation relation : relations) {
+ Document candidate = getLastVersion((Document)(relation.getFrom()), trueOwner);
+ if(candidate != null ) {
+ theLastVersion = candidate;
+ }
+ }
+ }
+ if(theLastVersion != null && trueOwner.getPublication(theLastVersion) == null) {
+ theLastVersion = null;
+ }
+ return theLastVersion;
+ }
+
+ /**
+ * Check if this publication is outdated and other publications used by it are up-to-date.
+ *
+ * @param aPublication
+ * the publication
+ * @return true if succeeded
+ */
+ @Transactional(readOnly=true)
+ private boolean canBeActualized(final Publication aPublication) {
+ boolean res = aPublication.isOutdated();
+ for(Publication used : aPublication.getRelations(UsesRelation.class)) {
+ if(used.isOutdated()) {
+ res = false;
+ }
+ }
+ return res;
+ }
+
/**
* Undo the out-date operation.
*
*/
@Transactional
public boolean actualize(final Publication aPublication) {
- boolean res = aPublication.isOutdated();
+ boolean res = aPublication.isOutdated() && canBeActualized(aPublication);
if (res) {
+ //Replace dependencies to old versions of documents with dependencies to the latest versions.
+ for(Relation rel : aPublication.value().getRelations(UsesRelation.class)) {
+ Document used = (Document)rel.getTo();
+ if(aPublication.getOwnerStudy().getPublication(used) == null) {
+ aPublication.value().removeRelation(UsesRelation.class, used);
+ //There is always a last version
+ Document theLastVersion = getLastVersion(used, aPublication.getOwner());
+ aPublication.addDependency(theLastVersion);
+ }
+ }
+
aPublication.setIsnew('Y');
getPublicationDAO().update(aPublication);
+
+ //recursively actualize all documents that don't use any more outdated documents.
+ for(Publication using : aPublication.getRelations(UsedByRelation.class)) {
+ actualize(using);
+ }
}
return res;
}
}
return res;
}
+
+ /**
+ * Get the versionsRelationDAO.
+ * @return the versionsRelationDAO
+ */
+ public VersionsRelationDAO getVersionsRelationDAO() {
+ return _versionsRelationDAO;
+ }
+
+ /**
+ * Set the versionsRelationDAO.
+ * @param versionsRelationDAO the versionsRelationDAO to set
+ */
+ public void setVersionsRelationDAO(final VersionsRelationDAO versionsRelationDAO) {
+ _versionsRelationDAO = versionsRelationDAO;
+ }
}
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
_display = State.deepopen;
} else { // Opening the document
if (_uses == null) {
- List<Publication> relist = _me.getRelations(UsesRelation.class);
-
- _uses = new ArrayList<DocumentFacade>(relist.size());
- for (Iterator<Publication> i = relist.iterator(); i.hasNext();) {
- Publication used = i.next();
- long index = used.getIndex();
- DocumentFacade facade = _owner._docpres.get(index);
- if (facade == null) {
- facade = new DocumentFacade(_owner, used,
+ List<Relation> used = _me.value().getRelations(UsesRelation.class);
+
+ _uses = new ArrayList<DocumentFacade>();
+ for(Relation relation : used) {
+ Document doc = (Document)relation.getTo();
+ Publication pub = _me.getOwner().getPublication(
+ _publicationService.getLastVersion(doc, _me.getOwner()));
+ DocumentFacade facade = _owner._docpres.get(pub.getIndex());
+ if (facade == null && pub != null) {
+ facade = new DocumentFacade(_owner, pub,
getProjectSettings(), getPublicationService(),
getApplicationSettings());
- _owner._docpres.put(index, facade);
+ _owner._docpres.put(pub.getIndex(), facade);
}
_uses.add(facade);
}
_sharing = "image.share.png";
_updated = "icon.hold.png";
}
- if (_me.isOutdated()) {
- _state = ProgressState.inWORK; // Overrides the document state
- }
+ //if (_me.isOutdated()) {
+ // _state = ProgressState.inWORK; // Overrides the document state
+ //}
}
}