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;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FOntologicalRequirementEnforceRequest.java;h=3bc7295e75eb37b403523c549c60a32d296b73d5;hp=5f0df08112afac9a0c97b824bffd06bd44bf6c5e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 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..3bc7295e7 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,126 @@ -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.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) ); + + } + } \ No newline at end of file