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.adapters.ChangeHistoryUpdated;
15 import org.simantics.modeling.adapters.ChangeInformation;
18 * @author Antti Villberg
19 * @author Tuukka Lehtonen
21 public class OntologicalRequirementEnforceRequest extends WriteRequest {
23 private Collection<Resource> creates;
24 private Collection<Resource> modis;
25 private Collection<Resource> ids;
26 private String author;
29 public OntologicalRequirementEnforceRequest(Collection<Resource> creates, Collection<Resource> modis, Collection<Resource> ids) {
33 System.getProperty("user.name", ""),
34 System.currentTimeMillis());
37 public OntologicalRequirementEnforceRequest(Collection<Resource> creates, Collection<Resource> modis, Collection<Resource> ids, String author, long time) {
38 this.creates = creates;
46 public void perform(WriteGraph graph) throws DatabaseException {
47 update(graph, creates, modis, ids, true, author, time, true);
50 public static void update(
52 Collection<Resource> creates,
53 Collection<Resource> modis,
54 Collection<Resource> ids,
56 boolean disableDependencyIndexing) throws DatabaseException
63 System.getProperty("user.name", ""),
64 System.currentTimeMillis(),
65 disableDependencyIndexing);
69 public static void update(
71 Collection<Resource> creates,
72 Collection<Resource> modis,
73 Collection<Resource> ids,
77 boolean disableDependencyIndexing) throws DatabaseException
79 if (disableDependencyIndexing)
80 Layer0Utils.setDependenciesIndexingDisabled(graph, true);
82 ModelingResources MOD = ModelingResources.getInstance(graph);
83 Layer0 L0 = Layer0.getInstance(graph);
85 if (!creates.isEmpty()) {
86 ChangeInformation info = new ChangeInformation();
87 info.createdAt = time;
88 info.createdBy = author;
89 info.modifiedAt = time;
90 info.modifiedBy = author;
92 for (Resource c : creates) {
93 CommonDBUtils.selectClusterSet(graph, c);
94 graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
98 for (Resource m : modis) {
99 ChangeInformation info = graph.getPossibleRelatedValue(m, MOD.changeInformation, ChangeInformation.BINDING);
101 // Should not be possible but lets handle this anyway
102 info = new ChangeInformation();
103 info.createdAt = time;
104 info.createdBy = author;
106 info.modifiedAt = time;
107 info.modifiedBy = author;
108 CommonDBUtils.selectClusterSet(graph, m);
109 graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING);
112 for (Resource r : ids) {
113 if (!graph.hasStatement(r, L0.identifier)) {
114 CommonDBUtils.selectClusterSet(graph, r);
115 Layer0Utils.claimNewIdentifier(graph, r, true);
119 graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") );
121 graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) );