]> gerrit.simantics Code Review - simantics/platform.git/blob
7c79e639ef98445bde2ff53b651e1550004a1aca
[simantics/platform.git] /
1 package org.simantics.document.server.request;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
6 import java.util.List;
7
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.common.request.UnaryRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.db.layer0.variable.Variables;
13 import org.simantics.document.server.JSONObject;
14
15 public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
16
17     public URIDocumentRequest(String var) {
18         super(var);
19         }
20
21         @Override
22         public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
23                 
24                 Variable var = Variables.getPossibleVariable(graph, parameter);
25                 if(var == null) {
26                         Variables.getPossibleVariable(graph, parameter);
27                         return Collections.emptyList();
28                 }
29                 
30                 ArrayList<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
31                 Collections.sort(result, new Comparator<JSONObject>() {
32
33                         @Override
34                         public int compare(JSONObject o1, JSONObject o2) {
35                                 return o1.id.compareTo(o2.id);
36                         }
37                         
38                 });
39                 return result;
40                                 
41         }
42         
43 }