1 package org.simantics.document.linking.report.templates;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.HashSet;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.Resource;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.adapter.Instances;
14 import org.simantics.document.DocumentResource;
15 import org.simantics.document.linking.ontology.DocumentLink;
16 import org.simantics.document.linking.utils.SourceLinkUtil;
19 * Writes report of referred documents.
36 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
39 public class ReferredDocumentWriter extends ModelDocumentWriter{
42 public String getName() {
43 return "Referred Documents";
48 public List<List<Resource>> getReportItems(ReadGraph graph) throws DatabaseException {
49 DocumentResource doc = DocumentResource.getInstance(graph);
50 DocumentLink sl = DocumentLink.getInstance(graph);
51 Instances instancesQuery = graph.adapt(sl.Source, Instances.class);
52 Collection<Resource> found = instancesQuery.find(graph, model);
53 Set<Resource> referred = new HashSet<Resource>();
54 for (Resource source : found) {
55 Resource ref = SourceLinkUtil.getReferredDocument(graph, source);
60 List<List<Resource>> result = new ArrayList<List<Resource>>();
61 for (Resource ref : referred) {
62 if (!graph.isInstanceOf(ref, doc.Document))
64 result.add(SourceLinkUtil.getPath(graph,model,ref));
67 Collections.sort(result, new PathComparator(graph));