1   package eu.fbk.knowledgestore.internal.jaxrs;
2   
3   import eu.fbk.knowledgestore.Outcome;
4   import eu.fbk.knowledgestore.data.Record;
5   import eu.fbk.knowledgestore.data.Stream;
6   import eu.fbk.knowledgestore.internal.rdf.HtmlRDF;
7   import eu.fbk.knowledgestore.internal.rdf.HtmlSparql;
8   import eu.fbk.knowledgestore.vocabulary.KS;
9   import eu.fbk.rdfpro.tql.TQL;
10  import org.openrdf.model.Statement;
11  import org.openrdf.model.URI;
12  import org.openrdf.query.BindingSet;
13  
14  import javax.ws.rs.core.GenericType;
15  
16  public final class Protocol {
17  
18      // Type declarations
19  
20      public static final GenericType<Stream<Record>> STREAM_OF_RECORDS //
21      = new GenericType<Stream<Record>>() { /* empty */};
22  
23      public static final GenericType<Stream<Outcome>> STREAM_OF_OUTCOMES //
24      = new GenericType<Stream<Outcome>>() { /* empty */};
25  
26      public static final GenericType<Stream<Statement>> STREAM_OF_STATEMENTS //
27      = new GenericType<Stream<Statement>>() { /* empty */};
28  
29      public static final GenericType<Stream<BindingSet>> STREAM_OF_TUPLES //
30      = new GenericType<Stream<BindingSet>>() { /* empty */};
31  
32      public static final GenericType<Stream<Boolean>> STREAM_OF_BOOLEANS //
33      = new GenericType<Stream<Boolean>>() { /* empty */};
34  
35      // MIME types
36  
37      public static final String MIME_TYPES_RDF = "" //
38              + "application/ld+json;charset=UTF-8," //
39              + "application/rdf+xml;charset=UTF-8," //
40              + "application/n-triples;charset=UTF-8," //
41              + "text/x-nquads;charset=UTF-8," //
42              + "application/x-tql;charset=UTF-8," //
43              + "text/turtle;charset=UTF-8," //
44              + "text/n3;charset=UTF-8," //
45              + "application/trix;charset=UTF-8," //
46              + "application/x-trig;charset=UTF-8," //
47              + "application/x-binary-rdf," //
48              + "application/rdf+json;charset=UTF-8," //
49              + "text/html;charset=UTF-8";
50  
51      public static final String MIME_TYPES_SPARQL_TUPLE = "" //
52              + "application/sparql-results+json;charset=UTF-8," //
53              + "application/sparql-results+xml;charset=UTF-8," //
54              + "text/csv;charset=UTF-8," //
55              + "text/tab-separated-values;charset=UTF-8," //
56              + "application/x-binary-rdf-results-table," //
57              + "text/html;charset=UTF-8";
58  
59      public static final String MIME_TYPES_SPARQL_BOOLEAN = "" //
60              + "application/sparql-results+json;charset=UTF-8,"
61              + "application/sparql-results+xml;charset=UTF-8," //
62              + "text/boolean;charset=UTF-8," //
63              + "text/html;charset=UTF-8";
64  
65      public static final String MIME_TYPES_ALL = MIME_TYPES_RDF + "," + MIME_TYPES_SPARQL_TUPLE
66              + "," + MIME_TYPES_SPARQL_BOOLEAN;
67  
68      // Paths
69  
70      public static final String PATH_REPRESENTATIONS = "files";
71  
72      public static final String PATH_RESOURCES = "resources";
73  
74      public static final String PATH_MENTIONS = "mentions";
75  
76      public static final String PATH_ENTITIES = "entities";
77  
78      public static final String PATH_AXIOMS = "axioms";
79  
80      public static final String PATH_MATCH = "match";
81  
82      public static final String PATH_UPDATE = "triplestoreupdate";
83      public static final String PATH_DELETE = "triplestoredelete";
84  
85      public static final String PATH_CUSTOM = "custom";
86  
87      public static final String PATH_SPARQL = "sparql";
88  
89      public static final String SUBPATH_COUNT = "count";
90  
91      public static final String SUBPATH_CREATE = "create";
92  
93      public static final String SUBPATH_MERGE = "merge";
94  
95      public static final String SUBPATH_UPDATE = "update";
96  
97      public static final String SUBPATH_DELETE = "delete";
98  
99      public static final String PARAMETER_PROBE = "probe";
100 
101     public static final String PARAMETER_ACCEPT = "accept";
102 
103     public static final String PARAMETER_TIMEOUT = "timeout";
104 
105     public static final String PARAMETER_ID = "id";
106 
107     public static final String PARAMETER_CONDITION = "condition";
108 
109     public static final String PARAMETER_PROPERTY = "property";
110 
111     public static final String PARAMETER_OFFSET = "offset";
112 
113     public static final String PARAMETER_LIMIT = "limit";
114 
115     public static final String PARAMETER_CRITERIA = "criteria";
116 
117     public static final String PARAMETER_QUERY = "query";
118 
119     public static final String PARAMETER_DEFAULT_GRAPH = "default-graph-uri";
120 
121     public static final String PARAMETER_NAMED_GRAPH = "named-graph-uri";
122 
123     public static final String HEADER_INVOCATION = "X-KS-Invocation";
124 
125     public static final String HEADER_CHUNKED = "X-KS-Chunked";
126 
127     public static final String HEADER_META = "X-KS-Content-Meta";
128 
129     public static final String[] HTTPS_PROTOCOLS = new String[] { "TLSv1" };
130 
131     public static final String[] HTTPS_CIPHER_SUITES = new String[] {
132             "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
133             "TLS_RSA_WITH_AES_128_CBC_SHA", "SSL_RSA_WITH_3DES_EDE_CBC_SHA",
134             "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA" };
135 
136     public static String pathFor(final URI type) {
137         if (KS.RESOURCE.equals(type)) {
138             return PATH_RESOURCES;
139         } else if (KS.MENTION.equals(type)) {
140             return PATH_MENTIONS;
141         } else if (KS.ENTITY.equals(type)) {
142             return PATH_ENTITIES;
143         } else if (KS.AXIOM.equals(type)) {
144             return PATH_AXIOMS;
145         } else if (KS.REPRESENTATION.equals(type)) {
146             return PATH_REPRESENTATIONS;
147         }
148         throw new IllegalArgumentException("Invalid type " + type);
149     }
150 
151     public static URI typeFor(final String path) {
152         if (path.equals(PATH_RESOURCES)) {
153             return KS.RESOURCE;
154         } else if (path.equals(PATH_MENTIONS)) {
155             return KS.MENTION;
156         } else if (path.equals(PATH_ENTITIES)) {
157             return KS.ENTITY;
158         } else if (path.equals(PATH_AXIOMS)) {
159             return KS.AXIOM;
160         } else if (path.equals(PATH_REPRESENTATIONS)) {
161             return KS.REPRESENTATION;
162         }
163         throw new IllegalArgumentException("Invalid path " + path);
164     }
165 
166     static {
167         try {
168             TQL.register();
169         } catch (Throwable ex) {
170             // ignore: RDFpro TQL lib not available
171         }
172         HtmlRDF.register();
173         HtmlSparql.register();
174     }
175 
176 }