1 package org.simantics.issues.common;
3 import java.util.Collections;
4 import java.util.HashSet;
7 import org.simantics.db.Issue;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
11 import org.simantics.db.common.request.WriteRequest;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.util.RemoverUtil;
14 import org.simantics.issues.common.DependencyIssueValidator2.Contexts;
15 import org.simantics.issues.common.DependencyIssueValidator2.DependencyIssueDescriptions;
16 import org.simantics.issues.ontology.IssueResource;
17 import org.simantics.layer0.Layer0;
19 public class DependencyIssueSynchronizer2 extends WriteRequest {
21 public static final boolean DEBUG = false;
23 private Resource resource;
24 private Resource source;
26 public DependencyIssueSynchronizer2(Resource resource, Resource source) {
27 this.resource = resource;
32 public void perform(WriteGraph graph) throws DatabaseException {
34 if(DEBUG) System.err.println("Running DependencySynchronizer for " + resource);
36 Set<Issue> existing = graph.syncRequest(new DependencyIssueDescriptions(source, resource), TransientCacheListener.<Set<Issue>>instance());
37 Set<Issue> contexts = Collections.emptySet();
39 if(graph.hasStatement(resource)) {
40 contexts = graph.syncRequest(new Contexts(source, resource), TransientCacheListener.<Set<Issue>>instance());
43 if(!existing.equals(contexts)) {
45 Set<Issue> added = new HashSet<Issue>(contexts);
46 Set<Issue> removed = new HashSet<Issue>(existing);
47 added.removeAll(existing);
48 removed.removeAll(contexts);
50 for(Issue add : added) {
51 add.write(graph, source);
53 for(Issue remove : removed) {
54 Resource issue = graph.sync(new IssueByList(source, remove));
56 // FIXME: when can this happen and what should be done in this case?
58 graph.deny(issue, Layer0.getInstance(graph).PartOf);
59 graph.deny(source, IssueResource.getInstance(graph).IssueSource_Manages, issue);
60 RemoverUtil.remove(graph, issue);