1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.graphql.execution.context;
23
24 import org.opencastproject.graphql.config.GraphQLConfiguration;
25 import org.opencastproject.security.api.Organization;
26 import org.opencastproject.security.api.User;
27
28 import org.osgi.framework.BundleContext;
29
30 import java.util.Map;
31 import java.util.Objects;
32
33 public class OpencastContext {
34
35 private BundleContext bundleContext;
36
37 private Map<String, Object> arguments;
38
39 private Organization organization;
40
41 private User user;
42
43 public <T> T getService(Class<T> clazz) {
44 return bundleContext.getService(bundleContext.getServiceReference(clazz));
45 }
46
47 public GraphQLConfiguration getConfiguration() {
48 return getService(GraphQLConfiguration.class);
49 }
50
51 public static OpencastContext newContext(BundleContext bundleContext) {
52 var context = new OpencastContext();
53 context.setBundleContext(bundleContext);
54 return context;
55 }
56
57 protected void setBundleContext(BundleContext bundleContext) {
58 Objects.requireNonNull(bundleContext, "OSGi bundle context cannot be null");
59 this.bundleContext = bundleContext;
60 }
61
62 public Organization getOrganization() {
63 return organization;
64 }
65
66 public void setOrganization(Organization organization) {
67 this.organization = organization;
68 }
69
70 public User getUser() {
71 return user;
72 }
73
74 public void setUser(User user) {
75 this.user = user;
76 }
77
78 }