9
9
import javax .annotation .security .PermitAll ;
10
10
import javax .ejb .EJB ;
11
11
import javax .ejb .Stateless ;
12
+ import javax .validation .constraints .Pattern ;
12
13
import javax .ws .rs .GET ;
13
14
import javax .ws .rs .HeaderParam ;
14
15
import javax .ws .rs .Path ;
27
28
import dk .sample .rest .bank .account .persistence .AccountArchivist ;
28
29
import dk .sample .rest .common .core .logging .LogDuration ;
29
30
import dk .sample .rest .common .rs .EntityResponseBuilder ;
30
-
31
31
import io .swagger .annotations .Api ;
32
32
import io .swagger .annotations .ApiOperation ;
33
- import io .swagger .annotations .ApiResponse ;
34
- import io .swagger .annotations .ApiResponses ;
35
33
import io .swagger .annotations .Authorization ;
36
34
37
35
/**
42
40
@ Path ("/account-events" )
43
41
@ DeclareRoles ("tx-system" )
44
42
@ Api (value = "/account-events" ,
45
- tags = {"events" })
43
+ tags = {"events" })
46
44
public class AccountEventServiceExposure {
47
45
private final Map <String , EventsProducerMethod > eventsProducers = new HashMap <>();
48
46
private final Map <String , EventProducerMethod > eventProducers = new HashMap <>();
@@ -66,117 +64,121 @@ public AccountEventServiceExposure() {
66
64
@ GET
67
65
@ Produces ({"application/hal+json" , "application/hal+json;concept=events;v=1" })
68
66
@ ApiOperation (
69
- value = "obtain all events emitted by the account-event service" , response = EventsRepresentation .class ,
70
- notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
71
- "subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
72
- "feed for the account service" ,
73
- authorizations = {
74
- @ Authorization (value = "oauth2" , scopes = {}),
75
- @ Authorization (value = "oauth2-cc" , scopes = {}),
76
- @ Authorization (value = "oauth2-ac" , scopes = {}),
77
- @ Authorization (value = "oauth2-rop" , scopes = {}),
78
- @ Authorization (value = "Bearer" )
79
- },
80
- tags = {"interval" , "events" },
81
- produces = "application/hal+json, application/hal+json;concept=events;v=1" ,
82
- nickname = "listAllEvents"
83
- )
84
- @ ApiResponses (value = {
85
- @ ApiResponse (code = 415 , message = "Content type not supported." )
86
- })
67
+ value = "obtain all events emitted by the account-event service" , response = EventsRepresentation .class ,
68
+ notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
69
+ "subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
70
+ "feed for the account service" ,
71
+ authorizations = {
72
+ @ Authorization (value = "oauth2" , scopes = {}),
73
+ @ Authorization (value = "oauth2-cc" , scopes = {}),
74
+ @ Authorization (value = "oauth2-ac" , scopes = {}),
75
+ @ Authorization (value = "oauth2-rop" , scopes = {}),
76
+ @ Authorization (value = "Bearer" )
77
+ },
78
+ tags = {"interval" , "events" },
79
+ produces = "application/hal+json, application/hal+json;concept=events;v=1" ,
80
+ nickname = "listAllAccountEvents"
81
+ )
87
82
public Response listAll (@ Context UriInfo uriInfo , @ Context Request request ,
88
- @ HeaderParam ("Accept" ) String accept , @ QueryParam ("interval" ) String interval ) {
83
+ @ HeaderParam ("Accept" ) String accept ,
84
+ @ HeaderParam ("X-Log-Token" ) String xLogToken ,
85
+ @ QueryParam ("interval" ) String interval ) {
89
86
return eventsProducers .getOrDefault (accept , this ::handleUnsupportedContentType )
90
- .getResponse (uriInfo , request , interval );
87
+ .getResponse (uriInfo , request , interval );
91
88
}
92
89
93
90
94
91
@ GET
95
92
@ Path ("{category}" )
96
- @ Produces ({ "application/hal+json" , "application/hal+json;concept=eventcategory;v=1" })
93
+ @ Produces ({"application/hal+json" , "application/hal+json;concept=eventcategory;v=1" })
97
94
@ ApiOperation (value = "obtain all events scoped to a certain category" , response = EventsRepresentation .class ,
98
- notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
99
- "subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
100
- "feed for the account service, allowing for subscribers to have these grouped into categories" ,
101
- authorizations = {
102
- @ Authorization (value = "oauth2" , scopes = {}),
103
- @ Authorization (value = "oauth2-cc" , scopes = {}),
104
- @ Authorization (value = "oauth2-ac" , scopes = {}),
105
- @ Authorization (value = "oauth2-rop" , scopes = {}),
106
- @ Authorization (value = "Bearer" )
107
- },
108
- tags = {"interval" , "events" },
109
- produces = "application/hal+json, application/hal+json;concept=eventcategory;v=1" ,
110
- nickname = "getEventsByCategory"
111
- )
112
- @ ApiResponses (value = {
113
- @ ApiResponse (code = 415 , message = "Content type not supported." )
114
- })
95
+ notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
96
+ "subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
97
+ "feed for the account service, allowing for subscribers to have these grouped into categories" ,
98
+ authorizations = {
99
+ @ Authorization (value = "oauth2" , scopes = {}),
100
+ @ Authorization (value = "oauth2-cc" , scopes = {}),
101
+ @ Authorization (value = "oauth2-ac" , scopes = {}),
102
+ @ Authorization (value = "oauth2-rop" , scopes = {}),
103
+ @ Authorization (value = "Bearer" )
104
+ },
105
+ tags = {"interval" , "events" },
106
+ produces = "application/hal+json, application/hal+json;concept=eventcategory;v=1" ,
107
+ nickname = "getAccountEventsByCategory"
108
+ )
115
109
public Response getByCategory (@ Context UriInfo uriInfo , @ Context Request request ,
116
- @ HeaderParam ("Accept" ) String accept , @ PathParam ("category" ) String category ,
117
- @ QueryParam ("interval" ) String interval ) {
110
+ @ HeaderParam ("Accept" ) String accept ,
111
+ @ HeaderParam ("X-Log-Token" ) String xLogToken ,
112
+ @ PathParam ("category" ) @ Pattern (regexp = "^[a-zA-Z0-9-]{36}]" ) String category ,
113
+ @ QueryParam ("interval" ) String interval ) {
118
114
return eventCategoryProducers .getOrDefault (accept , this ::handleUnsupportedContentType )
119
- .getResponse (uriInfo , request , category , interval );
115
+ .getResponse (uriInfo , request , category , interval );
120
116
}
121
117
122
118
@ GET
123
119
@ Path ("{category}/{id}" )
124
- @ Produces ({ "application/hal+json" , "application/hal+json;concept=event;v=1" })
120
+ @ Produces ({"application/hal+json" , "application/hal+json;concept=event;v=1" })
125
121
@ LogDuration (limit = 50 )
126
122
@ ApiOperation (
127
- value = "obtain the individual events from an account" , response = EventRepresentation .class ,
128
- notes = "the event her is immutable and thus can be cached for a long time" ,
129
- authorizations = {
130
- @ Authorization (value = "oauth2" , scopes = {}),
131
- @ Authorization (value = "oauth2-cc" , scopes = {}),
132
- @ Authorization (value = "oauth2-ac" , scopes = {}),
133
- @ Authorization (value = "oauth2-rop" , scopes = {}),
134
- @ Authorization (value = "Bearer" )
135
- },
136
- tags = {"immutable" , "events" },
137
- produces = "application/hal+json, application/hal+json;concept=event;v=1" ,
138
- nickname = "getEvent" )
139
- @ ApiResponses (value = {
140
- @ ApiResponse (code = 404 , message = "No event found." ),
141
- @ ApiResponse (code = 415 , message = "Content type not supported." )
142
- })
123
+ value = "obtain the individual events from an account" , response = EventRepresentation .class ,
124
+ notes = "the event her is immutable and thus can be cached for a long time" ,
125
+ authorizations = {
126
+ @ Authorization (value = "oauth2" , scopes = {}),
127
+ @ Authorization (value = "oauth2-cc" , scopes = {}),
128
+ @ Authorization (value = "oauth2-ac" , scopes = {}),
129
+ @ Authorization (value = "oauth2-rop" , scopes = {}),
130
+ @ Authorization (value = "Bearer" )
131
+ },
132
+ tags = {"immutable" , "events" },
133
+ produces = "application/hal+json, application/hal+json;concept=event;v=1" ,
134
+ nickname = "getAccountEvent" )
143
135
public Response getSingle (@ Context UriInfo uriInfo , @ Context Request request ,
144
- @ HeaderParam ("Accept" ) String accept , @ PathParam ("category" )String category ,
145
- @ PathParam ("id" )String id ) {
136
+ @ HeaderParam ("Accept" ) String accept ,
137
+ @ HeaderParam ("X-Log-Token" ) String xLogToken ,
138
+ @ PathParam ("category" ) @ Pattern (regexp = "^[a-zA-Z0-9-]{36}]" ) String category ,
139
+ @ PathParam ("id" ) String id ) {
146
140
return eventProducers .getOrDefault (accept , this ::handleUnsupportedContentType )
147
- .getResponse (uriInfo , request , category , id );
141
+ .getResponse (uriInfo , request , category , id );
148
142
}
149
143
150
144
@ LogDuration (limit = 50 )
151
145
public Response listAllSG1V1 (UriInfo uriInfo , Request request , String interval ) {
152
146
Optional <Interval > withIn = Interval .getInterval (interval );
153
147
List <Event > events = archivist .findEvents (withIn );
154
148
return new EntityResponseBuilder <>(events , txs -> new EventsRepresentation (events , uriInfo ))
155
- .name ("events" )
156
- .version ("1" )
157
- .maxAge (60 )
158
- .build (request );
149
+ .name ("events" )
150
+ .version ("1" )
151
+ .maxAge (60 )
152
+ .build (request );
159
153
}
160
154
161
155
@ LogDuration (limit = 50 )
162
156
public Response listByCategorySG1V1 (UriInfo uriInfo , Request request , String category , String interval ) {
163
157
Optional <Interval > withIn = Interval .getInterval (interval );
164
158
List <Event > events = archivist .getEventsForCategory (category , withIn );
165
159
return new EntityResponseBuilder <>(events , txs -> new EventsRepresentation (events , uriInfo ))
166
- .name ("eventcategory" )
167
- .version ("1" )
168
- .maxAge (60 )
169
- .build (request );
160
+ .name ("eventcategory" )
161
+ .version ("1" )
162
+ .maxAge (60 )
163
+ .build (request );
170
164
}
171
165
172
166
@ LogDuration (limit = 50 )
173
167
public Response getSG1V1 (UriInfo uriInfo , Request request , String category , String id ) {
174
168
Event event = archivist .getEvent (category , id );
175
169
return new EntityResponseBuilder <>(event , e -> new EventRepresentation (e , uriInfo ))
176
- .maxAge (7 * 24 * 60 * 60 )
177
- .name ("event" )
178
- .version ("1" )
179
- .build (request );
170
+ .maxAge (7 * 24 * 60 * 60 )
171
+ .name ("event" )
172
+ .version ("1" )
173
+ .build (request );
174
+ }
175
+
176
+ Response handleUnsupportedContentType (UriInfo uriInfo , Request request , String interval ) {
177
+ return Response .status (Response .Status .UNSUPPORTED_MEDIA_TYPE ).build ();
178
+ }
179
+
180
+ Response handleUnsupportedContentType (UriInfo uriInfo , Request request , String category , String id ) {
181
+ return Response .status (Response .Status .UNSUPPORTED_MEDIA_TYPE ).build ();
180
182
}
181
183
182
184
interface EventsProducerMethod {
@@ -191,13 +193,5 @@ interface EventsCategoryProducerMethod {
191
193
Response getResponse (UriInfo uriInfo , Request request , String interval , String category );
192
194
}
193
195
194
- Response handleUnsupportedContentType (UriInfo uriInfo , Request request , String interval ) {
195
- return Response .status (Response .Status .UNSUPPORTED_MEDIA_TYPE ).build ();
196
- }
197
-
198
- Response handleUnsupportedContentType (UriInfo uriInfo , Request request , String category , String id ) {
199
- return Response .status (Response .Status .UNSUPPORTED_MEDIA_TYPE ).build ();
200
- }
201
-
202
196
203
197
}
0 commit comments