Salome HOME
VPV implementation of the new checking algorithm and the unit test (getNewDocumentId())
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / PublicationServiceImpl.java
index dfb90ddf211102aad6af5ecc716e614245f262f9..91f2c25dfed6bd9480aecee19049c3bd33d30640 100644 (file)
@@ -44,7 +44,6 @@ 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.BusinessException;
 import org.splat.exception.IncompatibleDataException;
 import org.splat.exception.InvalidParameterException;
 import org.splat.exception.UserRightsException;
@@ -694,19 +693,20 @@ public class PublicationServiceImpl implements PublicationService {
                Document document = _documentService.selectDocument(doc.getIndex());    //get document attached to hibernate session
                ProjectElement trueOwner = _projectElementDAO.merge(owner);
                Document theLastVersion = null;
-               if(trueOwner.getPublication(document) != null) {
-                       theLastVersion = document;
-               } else {        //start recursive search
+               if (trueOwner.getPublication(document) == null) {
                        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 ) {
+                       // 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;
                                }
                        }
+               } else { // start recursive search
+                       theLastVersion = document;
                }
                if(theLastVersion == null && owner instanceof Scenario) {
                        theLastVersion = getLastVersion(doc, ((Scenario)owner).getOwnerStudy());