28
28
import javax .ws .rs .Produces ;
29
29
import javax .ws .rs .core .MediaType ;
30
30
import javax .ws .rs .core .Response ;
31
+ import javax .ws .rs .core .Response .Status ;
31
32
32
33
import org .w3c .dom .Element ;
33
34
import org .web3j .tuples .generated .Tuple4 ;
34
35
36
+ import i5 .las2peer .api .Context ;
37
+ import i5 .las2peer .api .ManualDeployment ;
35
38
import i5 .las2peer .api .security .AgentException ;
36
39
import i5 .las2peer .api .security .AgentNotFoundException ;
37
40
import i5 .las2peer .api .security .AgentOperationFailedException ;
81
84
url = "rwth-aachen.de" ,
82
85
email = "lennart.bengtson@rwth-aachen.de" )))
83
86
@ ServicePath ("/privacy" )
87
+ @ ManualDeployment
84
88
public class PrivacyControlService extends RESTService {
85
89
86
90
private final static L2pLogger logger = L2pLogger .getInstance (PrivacyControlService .class .getName ());
87
91
88
92
private final static String DEFAULT_CONFIG_FILE = "etc/consentConfiguration.xml" ;
89
93
90
- private static String lrsDomain ;
91
- private static String lrsAuth ;
94
+ private String lrsDomain ;
95
+ private String lrsAuth ;
92
96
private static ConcurrentMap <String , String > userToMoodleToken = new ConcurrentHashMap <>();
93
97
94
98
private static EthereumNode node ;
@@ -111,30 +115,20 @@ public class PrivacyControlService extends RESTService {
111
115
// ------------------------------ Initialization -----------------------------
112
116
113
117
public PrivacyControlService () {
114
- super ();
115
-
116
- // Workaround, to avoid reloading the contracts.
117
- if (!initialized ) {
118
- // Wait for service to be started before executing the initialization
119
- // Seems to be necessary because node (the service is running at) would not be known otherwise
120
- new java .util .Timer ().schedule (
121
- new java .util .TimerTask () {
122
- @ Override
123
- public void run () {
124
- init ();
125
- }
126
- },
127
- 10000
128
- );
129
- }
118
+ setFieldValues ();
130
119
}
131
120
132
- /**
133
- * Initializes the privacy control service instance.
134
- * Reads information about available consent levels from XML configuration file.
135
- * Loads/Deploys necessary smart contracts.
136
- */
137
- public void init () {
121
+ @ POST
122
+ @ Path ("/init" )
123
+ @ Produces (MediaType .TEXT_PLAIN )
124
+ @ ApiResponses (
125
+ value = { @ ApiResponse (
126
+ code = HttpURLConnection .HTTP_OK ,
127
+ message = "Privacy control service initialized" ) })
128
+ public Response init () {
129
+ if (initialized ) {
130
+ return Response .status (Status .BAD_REQUEST ).entity ("Already initialized" ).build ();
131
+ }
138
132
logger .info ("Initializing privacy control service..." );
139
133
// Read consent levels from configuration file.
140
134
try {
@@ -148,6 +142,7 @@ public void init() {
148
142
} catch (Exception e ) {
149
143
logger .warning ("Unable to read from XML. Please make sure file exists and is correctly formatted." );
150
144
e .printStackTrace ();
145
+ return Response .status (Status .BAD_REQUEST ).entity ("Unable to read consent configuration" ).build ();
151
146
}
152
147
logger .info ("Successfully read from XML consent configuration file." );
153
148
@@ -162,7 +157,7 @@ public void init() {
162
157
163
158
// Deploy smart contracts from wrapper classes
164
159
try {
165
- ServiceAgentImpl agent = (ServiceAgentImpl ) this . getAgent ();
160
+ ServiceAgentImpl agent = (ServiceAgentImpl ) Context . getCurrent (). getServiceAgent ();
166
161
node = (EthereumNode ) agent .getRunningAtNode ();
167
162
registryClient = node .getRegistryClient ();
168
163
@@ -172,9 +167,9 @@ public void init() {
172
167
} catch (Exception e ) {
173
168
logger .warning ("Initilization of smart contracts failed!" );
174
169
e .printStackTrace ();
170
+ return Response .status (Status .BAD_REQUEST ).entity ("Initilization of smart contracts failed!" ).build ();
175
171
}
176
-
177
- logger .info ("Done. Proceeding" );
172
+ return Response .status (Status .OK ).entity ("Initialization successful." ).build ();
178
173
}
179
174
180
175
// ------------------------------ Bot communication ----------------------------
0 commit comments