package org.simantics.issues.common;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.Resource;
public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> typesToRecurse) {
super(resource, childRelation, typesToRecurse);
}
-
-// @Override
-// public Severity perform(ReadGraph graph) throws DatabaseException {
-// Layer0 L0 = Layer0.getInstance(graph);
-// IssueResource ISSUE = IssueResource.getInstance(graph);
-// //System.out.println("severity: " + NameUtils.getSafeName(graph, resource));
-// Collection<Resource> issues = graph.getObjects(resource, ISSUE.IsIssueContextOf);
-// if (issues.isEmpty()) {
-// // This content does not have directly attached issues, try to look
-// // for some in the child components.
-// return graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));
-// }
-//
-// Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(resource));
-// if (maxSeverity == null)
-// maxSeverity = graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));
-//
-// return maxSeverity;
-// }
-
+
@Override
public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {
+
IssueResource ISSUE = graph.getService(IssueResource.class);
- //System.out.println(getClass().getSimpleName() + ": " + parameter);
+
+ AtomicInteger issues = new AtomicInteger();
+ AtomicBoolean excepted = new AtomicBoolean(false);
graph.forEachObject(parameter, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {
- volatile int issues = 0;
@Override
public void execute(AsyncReadGraph graph, Resource result) {
- ++issues;
+ issues.incrementAndGet();
}
@Override
public void finished(AsyncReadGraph graph) {
- if (issues == 0) {
- // This content does not have directly attached issues, try to look
- // for some in the child components.
- graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
- } else {
- // Try local issues first
- graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure<Severity>() {
- @Override
- public void execute(AsyncReadGraph graph, Severity maxSeverity) {
- if (maxSeverity == null)
- // No severity for local issues, try children next.
- graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
- else
- procedure.execute(graph, maxSeverity);
- }
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- procedure.exception(graph, throwable);
- }
- });
- }
+
}
@Override
public void exception(AsyncReadGraph graph, Throwable throwable) {
- procedure.exception(graph, throwable);
+ if(excepted.compareAndSet(false, true))
+ procedure.exception(graph, throwable);
}
});
+
+ graph.forEachObject(parameter, ISSUE.Issue_ContextList_Element_Inverse, new AsyncMultiProcedure<Resource>() {
+ @Override
+ public void execute(AsyncReadGraph graph, Resource result) {
+ issues.incrementAndGet();
+ }
+ @Override
+ public void finished(AsyncReadGraph graph) {
+
+ }
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ if(excepted.compareAndSet(false, true))
+ procedure.exception(graph, throwable);
+ }
+ });
+
+ if(excepted.get()) return;
+
+ if (issues.get() == 0) {
+ // This content does not have directly attached issues, try to look
+ // for some in the child components.
+ graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
+ } else {
+ // Try local issues first
+ graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure<Severity>() {
+ @Override
+ public void execute(AsyncReadGraph graph, Severity maxSeverity) {
+ if (maxSeverity == null)
+ // No severity for local issues, try children next.
+ graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
+ else
+ procedure.execute(graph, maxSeverity);
+ }
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ if(excepted.compareAndSet(false, true))
+ procedure.exception(graph, throwable);
+ }
+ });
+ }
}
}
import java.util.concurrent.atomic.AtomicReference;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.ResourceAsyncRead;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.utils.ListUtils;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncMultiProcedure;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.issues.Severity;
@Override
public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {
+
final IssueResource ISSUE = graph.getService(IssueResource.class);
- //System.out.println(getClass().getSimpleName() + ": " + resource);
+
+ AtomicReference<Severity> maxSeverity = new AtomicReference<Severity>();
graph.forEachObject(resource, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {
- AtomicReference<Severity> maxSeverity = new AtomicReference<Severity>();
@Override
public void execute(AsyncReadGraph graph, final Resource issue) {
}
@Override
public void finished(AsyncReadGraph graph) {
- procedure.execute(graph, maxSeverity.get());
}
@Override
public void exception(AsyncReadGraph graph, Throwable throwable) {
procedure.exception(graph, throwable);
}
});
+
+ graph.forEachObject(resource, ISSUE.Issue_ContextList_Element_Inverse, new AsyncMultiProcedure<Resource>() {
+ @Override
+ public void execute(AsyncReadGraph graph, final Resource element) {
+
+ graph.asyncRequest(new ResourceRead<Resource>(element) {
+ @Override
+ public Resource perform(ReadGraph graph) throws DatabaseException {
+ Resource list = ListUtils.getListElementList(graph, resource);
+ return graph.getSingleObject(list, ISSUE.Issue_HasContexts_Inverse);
+ }
+ }, new AsyncProcedure<Resource>() {
+
+ @Override
+ public void execute(AsyncReadGraph graph, Resource issue) {
+ /*
+ * Compare severity of each related issue and find the maximum severity.
+ * The issues that are not resolved and have active issue source manager
+ * are taken into account.
+ */
+ acceptIfNotResolved(graph, procedure, ISSUE, issue, maxSeverity);
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ procedure.exception(graph, throwable);
+ }
+ });
+
+
+ }
+ @Override
+ public void finished(AsyncReadGraph graph) {
+ }
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ procedure.exception(graph, throwable);
+ }
+ });
+
+ procedure.execute(graph, maxSeverity.get());
+
}
/**