1 package org.simantics.modeling.utils;
3 import java.util.Collection;
5 import org.simantics.db.Resource;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.CommentMetadata;
8 import org.simantics.db.common.request.WriteRequest;
9 import org.simantics.db.common.utils.CommonDBUtils;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.util.Layer0Utils;
12 import org.simantics.layer0.Layer0;
13 import org.simantics.modeling.ModelingResources;
14 import org.simantics.modeling.ModelingUtils;
15 import org.simantics.modeling.adapters.ChangeHistoryUpdated;
16 import org.simantics.modeling.adapters.ChangeInformation;
19 * @author Antti Villberg
20 * @author Tuukka Lehtonen
22 public class OntologicalRequirementEnforceRequest extends WriteRequest {
24 private Collection<Resource> creates;
25 private Collection<Resource> modis;
26 private Collection<Resource> ids;
27 private String author;
30 public OntologicalRequirementEnforceRequest(Collection<Resource> creates, Collection<Resource> modis, Collection<Resource> ids) {
34 System.getProperty("user.name", ""),
35 System.currentTimeMillis());
38 public OntologicalRequirementEnforceRequest(Collection<Resource> creates, Collection<Resource> modis, Collection<Resource> ids, String author, long time) {
39 this.creates = creates;
47 public void perform(WriteGraph graph) throws DatabaseException {
48 update(graph, creates, modis, ids, true, author, time, true);
51 public static void update(
53 Collection<Resource> creates,
54 Collection<Resource> modis,
55 Collection<Resource> ids,
57 boolean disableDependencyIndexing) throws DatabaseException
64 System.getProperty("user.name", ""),
65 System.currentTimeMillis(),
66 disableDependencyIndexing);
70 public static void update(
72 Collection<Resource> creates,
73 Collection<Resource> modis,
74 Collection<Resource> ids,
78 boolean disableDependencyIndexing) throws DatabaseException
80 if (disableDependencyIndexing)
81 Layer0Utils.setDependenciesIndexingDisabled(graph, true);
83 ModelingResources MOD = ModelingResources.getInstance(graph);
84 Layer0 L0 = Layer0.getInstance(graph);
86 if (!creates.isEmpty()) {
87 ChangeInformation info = new ChangeInformation();
88 info.createdAt = time;
89 info.createdBy = author;
90 info.modifiedAt = time;
91 info.modifiedBy = author;
93 for (Resource c : creates) {
94 CommonDBUtils.selectClusterSet(graph, c);
95 graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
96 ModelingUtils.markChanged(graph, c);
100 for (Resource m : modis) {
101 ChangeInformation info = graph.getPossibleRelatedValue(m, MOD.changeInformation, ChangeInformation.BINDING);
103 // Should not be possible but lets handle this anyway
104 info = new ChangeInformation();
105 info.createdAt = time;
106 info.createdBy = author;
108 info.modifiedAt = time;
109 info.modifiedBy = author;
110 CommonDBUtils.selectClusterSet(graph, m);
111 graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
112 ModelingUtils.markChanged(graph, m);
115 for (Resource r : ids) {
116 if (!graph.hasStatement(r, L0.identifier)) {
117 CommonDBUtils.selectClusterSet(graph, r);
118 Layer0Utils.claimNewIdentifier(graph, r, true);
122 graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") );
124 graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) );