]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Keep file format when versioning a document if the new format is appropriate for...
authorrkv <rkv@opencascade.com>
Wed, 5 Dec 2012 11:49:21 +0000 (11:49 +0000)
committerrkv <rkv@opencascade.com>
Wed, 5 Dec 2012 11:49:21 +0000 (11:49 +0000)
Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java

index 1713dc2e8bf7c96498433b64f1596d2af1ac7df8..aa9b6ddaaa031542e36cdf696eedadae92a4d608 100644 (file)
@@ -300,6 +300,14 @@ public class Document extends Entity {
                                }
                        }
                }
+
+               /**
+                * Get the format.
+                * @return the format
+                */
+               public String getFormat() {
+                       return format;
+               }
        }
 
        /**
index f66ef9a17e1f938899a95afffd4e59e43172f26c..b230749b58b98cea9bb13f0ed29a2e789f2c4731 100644 (file)
@@ -570,7 +570,7 @@ public class ScenarioServiceImpl implements ScenarioService {
                                        upfile.getName().lastIndexOf('.') + 1);
 
                        // Create a new document or a new version of the document
-                       dprop.setAuthor(aUser).setDate(aDate);
+                       dprop.setAuthor(aUser).setDate(aDate).setFormat(fileFormat);
                        Publication pub, newPub;
 
                        if (doc.getId() > 0) {
@@ -610,8 +610,7 @@ public class ScenarioServiceImpl implements ScenarioService {
                                }
                                docname += "_" + i; // The generated new document title
 
-                               dprop.setDescription("Checked in").setName(docname).setFormat(
-                                               fileFormat);
+                               dprop.setDescription("Checked in").setName(docname);
                                newPub = getStepService().createDocument(step, dprop);
 
                                // Remeber the new document
index 934b29682797e9ec6cd932545dbef15426eeca77..9c2458daec7d4ffadb38381a4d2c202c74166c9d 100644 (file)
@@ -104,8 +104,9 @@ public class StepServiceImpl implements StepService {
         * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties)
         */
        public SimulationContext addSimulationContext(final Step aStep,
-                       final SimulationContext.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException {
+                       final SimulationContext.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
                SimulationContext context = new SimulationContext(dprop.setStep(aStep
                                .getStep()));
                return addSimulationContext(aStep, context);
@@ -169,8 +170,7 @@ public class StepServiceImpl implements StepService {
                                updateScenarioIndex(scene);
                        }
                } catch (Exception error) {
-                       LOG.error("Unable to re-index Knowledge Elements, reason:",
-                                       error);
+                       LOG.error("Unable to re-index Knowledge Elements, reason:", error);
                }
        }
 
@@ -203,7 +203,8 @@ public class StepServiceImpl implements StepService {
         * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
         */
        @Transactional
-       public boolean removeSimulationContext(final Step aStep, final SimulationContext context) {
+       public boolean removeSimulationContext(final Step aStep,
+                       final SimulationContext context) {
                SimulationContext torem = aStep
                                .getSimulationContext(context.getIndex());
 
@@ -228,9 +229,9 @@ public class StepServiceImpl implements StepService {
         * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
         */
        @Transactional
-       public Publication createDocument(final Step aStep, final Document.Properties dprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException, IOException {
+       public Publication createDocument(final Step aStep,
+                       final Document.Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException {
                Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
                                .setStep(aStep.getStep()));
                getDocumentService().generateDocumentId(newdoc, dprop);
@@ -317,10 +318,10 @@ public class StepServiceImpl implements StepService {
         * @throws MismatchException
         *             if the document is not applicable to the given study step
         */
-       public Publication versionDocument(final Step aStep, final Publication base,
-                       final String reason) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException, IOException,
-                       MismatchException {
+       public Publication versionDocument(final Step aStep,
+                       final Publication base, final String reason)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException, MismatchException {
                return versionDocument(aStep, base, new Document.Properties()
                                .setDescription(reason));
        }
@@ -347,17 +348,28 @@ public class StepServiceImpl implements StepService {
         *             if the document is not applicable to the given study step
         */
        @Transactional
-       public Publication versionDocument(final Step aStep, final Publication base,
-                       final Document.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException, IOException,
-                       MismatchException {
+       public Publication versionDocument(final Step aStep,
+                       final Publication base, final Document.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException, MismatchException {
                Document previous = base.value();
 
-               dprop.setDocument(previous, getProjectSettings().getStep(base.getStep().getNumber())); // Initializes the Step property
+               // RKV: Keep the new file format if it is related to the same document type on this step.
+               String newFormat = dprop.getFormat();
+
+               dprop.setDocument(previous, getProjectSettings().getStep(
+                               base.getStep().getNumber())); // Initializes the Step property
                if (dprop.getStep().getNumber() != aStep.getNumber()) {
                        throw new MismatchException();
                }
 
+               if (newFormat != null
+                               && previous.getTitle().equals(
+                                               getProjectSettings().getDefaultDocumentType(
+                                                               aStep.getStep(), newFormat))) {
+                       dprop.setFormat(newFormat);
+               }
+               
                if (dprop.getAuthor() == null) {
                        dprop.setAuthor(previous.getAuthor());
                }
@@ -374,24 +386,16 @@ public class StepServiceImpl implements StepService {
                // Versioning
                VersionsRelation aRel;
                aRel = new VersionsRelation(newdoc, previous, summary);
-//             getVersionsRelationDAO().create(aRel);
+               // getVersionsRelationDAO().create(aRel);
                newdoc.addRelation(aRel);
-               
+
                // Update of usedby relations, if exist
-/* RKV: Consider the new version as not used by old dependent documents. 
- * So these documents must be marked as outdated then.
-               List<Relation> relist = previous.getRelations(UsedByRelation.class);
-               Study scope = aStep.getOwnerStudy();
-               for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
-                       UsedByRelation relation = (UsedByRelation) i.next();
-                       Document relatedoc = relation.getTo();
-                       if (scope.shares(relatedoc)) {
-                               relatedoc.addRelation(new UsesRelation(relatedoc, newdoc));
-                       } else {
-                               relation.moveTo(newdoc);
-                       }
-               }
-*/
+               /*
+                * RKV: Consider the new version as not used by old dependent documents. So these documents must be marked as outdated then. List<Relation>
+                * relist = previous.getRelations(UsedByRelation.class); Study scope = aStep.getOwnerStudy(); for (Iterator<Relation> i =
+                * relist.iterator(); i.hasNext();) { UsedByRelation relation = (UsedByRelation) i.next(); Document relatedoc = relation.getTo(); if
+                * (scope.shares(relatedoc)) { relatedoc.addRelation(new UsesRelation(relatedoc, newdoc)); } else { relation.moveTo(newdoc); } }
+                */
                return new Publication(newdoc, aStep.getOwner());
        }
 
@@ -638,12 +642,14 @@ public class StepServiceImpl implements StepService {
         * @param documentTypeService
         *            the documentTypeService to set
         */
-       public void setDocumentTypeService(final DocumentTypeService documentTypeService) {
+       public void setDocumentTypeService(
+                       final DocumentTypeService documentTypeService) {
                _documentTypeService = documentTypeService;
        }
 
        /**
         * Get the versionsRelationDAO.
+        * 
         * @return the versionsRelationDAO
         */
        public VersionsRelationDAO getVersionsRelationDAO() {
@@ -652,9 +658,12 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the versionsRelationDAO.
-        * @param versionsRelationDAO the versionsRelationDAO to set
+        * 
+        * @param versionsRelationDAO
+        *            the versionsRelationDAO to set
         */
-       public void setVersionsRelationDAO(final VersionsRelationDAO versionsRelationDAO) {
+       public void setVersionsRelationDAO(
+                       final VersionsRelationDAO versionsRelationDAO) {
                _versionsRelationDAO = versionsRelationDAO;
        }