1 package org.simantics.modeling.utils;
3 import java.util.Collection;
5 import org.simantics.datatypes.literal.GUID;
6 import org.simantics.db.Resource;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.common.CommentMetadata;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.common.utils.CommonDBUtils;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.util.Layer0Utils;
13 import org.simantics.layer0.Layer0;
14 import org.simantics.modeling.ModelingResources;
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);
99 for (Resource m : modis) {
100 ChangeInformation info = graph.getPossibleRelatedValue(m, MOD.changeInformation, ChangeInformation.BINDING);
102 // Should not be possible but lets handle this anyway
103 info = new ChangeInformation();
104 info.createdAt = time;
105 info.createdBy = author;
107 info.modifiedAt = time;
108 info.modifiedBy = author;
109 CommonDBUtils.selectClusterSet(graph, m);
110 graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
113 for (Resource r : ids) {
114 if (!graph.hasStatement(r, L0.identifier)) {
115 CommonDBUtils.selectClusterSet(graph, r);
116 Layer0Utils.addL0Identifier(graph, r);
120 graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") );
122 graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) );