X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FOntologicalRequirementEnforceRequest.java;h=d8eed0a66103141a4affde596c3867b2373ec421;hp=5f0df08112afac9a0c97b824bffd06bd44bf6c5e;hb=162652c6b36097f0465c0fe13bff53b1a3b3d019;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java index 5f0df0811..d8eed0a66 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java @@ -1,126 +1,153 @@ -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; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.CommonDBUtils; -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.adapters.ChangeHistoryUpdated; -import org.simantics.modeling.adapters.ChangeInformation; - -/** - * @author Antti Villberg - * @author Tuukka Lehtonen - */ -public class OntologicalRequirementEnforceRequest extends WriteRequest { - - private Collection creates; - private Collection modis; - private Collection ids; - private String author; - private long time; - - public OntologicalRequirementEnforceRequest(Collection creates, Collection modis, Collection ids) { - this(creates, - modis, - ids, - System.getProperty("user.name", ""), - System.currentTimeMillis()); - } - - public OntologicalRequirementEnforceRequest(Collection creates, Collection modis, Collection ids, String author, long time) { - this.creates = creates; - this.modis = modis; - this.ids = ids; - this.author = author; - this.time = time; - } - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - update(graph, creates, modis, ids, true, author, time, true); - } - - public static void update( - WriteGraph graph, - Collection creates, - Collection modis, - Collection ids, - boolean addComment, - boolean disableDependencyIndexing) throws DatabaseException - { - update(graph, - creates, - modis, - ids, - addComment, - System.getProperty("user.name", ""), - System.currentTimeMillis(), - disableDependencyIndexing); - - } - - public static void update( - WriteGraph graph, - Collection creates, - Collection modis, - Collection ids, - boolean addComment, - String author, - long time, - boolean disableDependencyIndexing) throws DatabaseException - { - if (disableDependencyIndexing) - Layer0Utils.setDependenciesIndexingDisabled(graph, true); - - ModelingResources MOD = ModelingResources.getInstance(graph); - Layer0 L0 = Layer0.getInstance(graph); - - if (!creates.isEmpty()) { - ChangeInformation info = new ChangeInformation(); - info.createdAt = time; - info.createdBy = author; - info.modifiedAt = time; - info.modifiedBy = author; - - for (Resource c : creates) { - CommonDBUtils.selectClusterSet(graph, c); - graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); - } - } - - for (Resource m : modis) { - ChangeInformation info = graph.getPossibleRelatedValue(m, MOD.changeInformation, ChangeInformation.BINDING); - if (info == null) { - // Should not be possible but lets handle this anyway - info = new ChangeInformation(); - info.createdAt = time; - info.createdBy = author; - } - info.modifiedAt = time; - info.modifiedBy = author; - CommonDBUtils.selectClusterSet(graph, m); - graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); - } - - for (Resource r : ids) { - if (!graph.hasStatement(r, L0.identifier)) { - CommonDBUtils.selectClusterSet(graph, r); - graph.addLiteral(r, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING); - } - } - - graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") ); - - graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) ); - - } - +package org.simantics.modeling.utils; + +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.CommonDBUtils; +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; + +/** + * @author Antti Villberg + * @author Tuukka Lehtonen + */ +public class OntologicalRequirementEnforceRequest extends WriteRequest { + + private static final String PROP_WRITE_CHANGED_TAGS = "org.simantics.modeling.writeChangedTags"; //$NON-NLS-1$ + + private Collection creates; + private Collection modis; + private Collection 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 creates, Collection modis, Collection ids) { + this(creates, + modis, + ids, + getAuthor(), + System.currentTimeMillis()); + } + + public OntologicalRequirementEnforceRequest(Collection creates, Collection modis, Collection ids, String author, long time) { + this.creates = creates; + this.modis = modis; + this.ids = ids; + this.author = author; + this.time = time; + } + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + update(graph, creates, modis, ids, true, author, time, true, writeChangedTags()); + } + + public static void update( + WriteGraph graph, + Collection creates, + Collection modis, + Collection ids, + boolean addComment, + boolean disableDependencyIndexing) throws DatabaseException + { + update(graph, + creates, + modis, + ids, + addComment, + getAuthor(), + System.currentTimeMillis(), + disableDependencyIndexing); + + } + + public static void update( + WriteGraph graph, + Collection creates, + Collection modis, + Collection ids, + boolean addComment, + 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 creates, + Collection modis, + Collection 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); + + if (!creates.isEmpty()) { + ChangeInformation info = new ChangeInformation(); + info.createdAt = time; + info.createdBy = author; + info.modifiedAt = time; + info.modifiedBy = author; + + for (Resource c : creates) { + 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) { + ChangeInformation info = graph.getPossibleRelatedValue(m, MOD.changeInformation, ChangeInformation.BINDING); + if (info == null) { + // Should not be possible but lets handle this anyway + info = new ChangeInformation(); + info.createdAt = time; + info.createdBy = author; + } + info.modifiedAt = time; + info.modifiedBy = author; + 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.claimNewIdentifier(graph, r, true); + } + } + + 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