]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java
Added system property for controlling writing of MOD.changed tags
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / utils / OntologicalRequirementEnforceRequest.java
index 905305bc3087f657ec6e70739eafdcf8eb4867cb..d8eed0a66103141a4affde596c3867b2373ec421 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.modeling.utils;
 
 import java.util.Collection;
 
-import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.CommentMetadata;
@@ -12,6 +11,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ModelingUtils;
 import org.simantics.modeling.adapters.ChangeHistoryUpdated;
 import org.simantics.modeling.adapters.ChangeInformation;
 
@@ -21,17 +21,28 @@ import org.simantics.modeling.adapters.ChangeInformation;
  */
 public class OntologicalRequirementEnforceRequest extends WriteRequest {
 
+       private static final String PROP_WRITE_CHANGED_TAGS = "org.simantics.modeling.writeChangedTags"; //$NON-NLS-1$
+
        private Collection<Resource> creates;
        private Collection<Resource> modis;
        private Collection<Resource> ids;
        private String author;
        private long time;
 
+       private static String getAuthor() {
+               return System.getProperty("user.name", ""); //$NON-NLS-1$ //$NON-NLS-2$
+       }
+
+       private static boolean writeChangedTags() {
+               return !System.getProperty(PROP_WRITE_CHANGED_TAGS, "") //$NON-NLS-1$
+                               .equalsIgnoreCase("false"); //$NON-NLS-1$
+       }
+
        public OntologicalRequirementEnforceRequest(Collection<Resource> creates, Collection<Resource> modis, Collection<Resource> ids) {
                this(creates,
                                modis,
                                ids,
-                               System.getProperty("user.name", ""),
+                               getAuthor(),
                                System.currentTimeMillis());
        }
 
@@ -45,7 +56,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
 
        @Override
        public void perform(WriteGraph graph) throws DatabaseException {
-               update(graph, creates, modis, ids, true, author, time, true);
+               update(graph, creates, modis, ids, true, author, time, true, writeChangedTags());
        }
 
        public static void update(
@@ -61,7 +72,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                                modis,
                                ids,
                                addComment,
-                               System.getProperty("user.name", ""),
+                               getAuthor(),
                                System.currentTimeMillis(),
                                disableDependencyIndexing);
 
@@ -76,10 +87,24 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                        String author,
                        long time,
                        boolean disableDependencyIndexing) throws DatabaseException
+       {
+               update(graph, creates, modis, ids, addComment, author, time, disableDependencyIndexing, writeChangedTags());
+       }
+
+       public static void update(
+                       WriteGraph graph,
+                       Collection<Resource> creates,
+                       Collection<Resource> modis,
+                       Collection<Resource> ids,
+                       boolean addComment,
+                       String author,
+                       long time,
+                       boolean disableDependencyIndexing,
+                       boolean writeChangedTags) throws DatabaseException
        {
                if (disableDependencyIndexing)
                        Layer0Utils.setDependenciesIndexingDisabled(graph, true);
-               
+
                ModelingResources MOD = ModelingResources.getInstance(graph);
                Layer0 L0 = Layer0.getInstance(graph);
 
@@ -94,6 +119,8 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                                CommonDBUtils.selectClusterSet(graph, c);
                                graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
                        }
+                       if (writeChangedTags)
+                               ModelingUtils.markChanged(graph, creates);
                }
 
                for (Resource m : modis) {
@@ -109,18 +136,18 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                        CommonDBUtils.selectClusterSet(graph, m);
                        graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
                }
-               
+               if (writeChangedTags)
+                       ModelingUtils.markChanged(graph, modis);
+
                for (Resource r : ids) {
                        if (!graph.hasStatement(r, L0.identifier)) {
                                CommonDBUtils.selectClusterSet(graph, r);
-                               Layer0Utils.addL0Identifier(graph, r);
+                               Layer0Utils.claimNewIdentifier(graph, r, true);
                        }
                }
 
-               graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") );
-               
+               graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") ); //$NON-NLS-1$
                graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) );
-               
        }
 
 }
\ No newline at end of file