Skip to content

Commit 062d2af

Browse files
removed annotations that are now generated, made logToken explicit and adjusted responses accordingly
1 parent 640e583 commit 062d2af

11 files changed

+498
-479
lines changed

account/src/main/java/dk/sample/rest/bank/account/exposure/rs/AccountEventFeedMetadataServiceExposure.java

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Date;
44
import java.util.HashMap;
55
import java.util.Map;
6+
import java.util.UUID;
67

78
import javax.annotation.security.DeclareRoles;
89
import javax.annotation.security.PermitAll;
@@ -22,11 +23,8 @@
2223
import dk.sample.rest.bank.account.exposure.rs.model.EventsMetadataRepresentation;
2324
import dk.sample.rest.bank.account.persistence.AccountArchivist;
2425
import dk.sample.rest.common.core.logging.LogDuration;
25-
2626
import io.swagger.annotations.Api;
2727
import io.swagger.annotations.ApiOperation;
28-
import io.swagger.annotations.ApiResponse;
29-
import io.swagger.annotations.ApiResponses;
3028
import io.swagger.annotations.Authorization;
3129

3230
/**
@@ -37,7 +35,7 @@
3735
@Path("/account-events-metadata")
3836
@DeclareRoles("tx-system")
3937
@Api(value = "/account-events-metadata",
40-
tags = {"metadata"})
38+
tags = {"metadata"})
4139
public class AccountEventFeedMetadataServiceExposure {
4240
private final Map<String, EventMetadataProducerMethod> eventMetadataProducers = new HashMap<>();
4341

@@ -52,48 +50,53 @@ public AccountEventFeedMetadataServiceExposure() {
5250
@GET
5351
@Produces({"application/hal+json", "application/hal+json;concept=metadata;v=1"})
5452
@ApiOperation(
55-
value = "metadata for the events endpoint", response = EventsMetadataRepresentation.class,
56-
authorizations = {
57-
@Authorization(value = "oauth2", scopes = {}),
58-
@Authorization(value = "oauth2-cc", scopes = {}),
59-
@Authorization(value = "oauth2-ac", scopes = {}),
60-
@Authorization(value = "oauth2-rop", scopes = {}),
61-
@Authorization(value = "Bearer")
62-
},
63-
notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
64-
"subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
65-
"feed for the account service",
66-
tags = {"events"},
67-
produces = "application/hal+json, application/hal+json;concept=metadata;v=1",
68-
nickname = "getMetadata"
69-
)
70-
@ApiResponses(value = {
71-
@ApiResponse(code = 415, message = "Content type not supported.")
72-
})
73-
public Response getMetadata(@Context UriInfo uriInfo, @Context Request request, @HeaderParam("Accept") String accept) {
74-
return eventMetadataProducers.getOrDefault(accept, this::handleUnsupportedContentType).getResponse(uriInfo, request);
53+
value = "metadata for the events endpoint", response = EventsMetadataRepresentation.class,
54+
authorizations = {
55+
@Authorization(value = "oauth2", scopes = {}),
56+
@Authorization(value = "oauth2-cc", scopes = {}),
57+
@Authorization(value = "oauth2-ac", scopes = {}),
58+
@Authorization(value = "oauth2-rop", scopes = {}),
59+
@Authorization(value = "Bearer")
60+
},
61+
notes = " the events for accounts are signalled by this resource as this this is the authoritative resource for all events that " +
62+
"subscribers to the account service should be able to listen for and react to. In other words this is the authoritative" +
63+
"feed for the account service",
64+
tags = {"events"},
65+
produces = "application/hal+json, application/hal+json;concept=metadata, application/hal+json;concept=metadata;v=1",
66+
nickname = "getAccountEventMetadata"
67+
)
68+
public Response getMetadata(@Context UriInfo uriInfo, @Context Request request,
69+
@HeaderParam("Accept") String accept,
70+
@HeaderParam("X-Log-Token") String xLogToken) {
71+
return eventMetadataProducers.getOrDefault(accept, this::handleUnsupportedContentType).getResponse(uriInfo, request, xLogToken);
7572
}
7673

7774
@LogDuration(limit = 50)
78-
public Response getMetaDataSG1V1(UriInfo uriInfo, Request request) {
79-
EventsMetadataRepresentation em = new EventsMetadataRepresentation("", uriInfo);
75+
public Response getMetaDataSG1V1(UriInfo uriInfo, Request request, String token) {
76+
EventsMetadataRepresentation em =
77+
new EventsMetadataRepresentation("\"description\": \"This is hardcoded sample metadata for show only\"", uriInfo);
8078
CacheControl cc = new CacheControl();
8179
int maxAge = 4 * 7 * 24 * 60 * 60;
8280
cc.setMaxAge(maxAge);
83-
81+
String logToken = (token != null && !"".equals(token.trim())) ? token : UUID.randomUUID().toString();
8482
return Response.ok()
85-
.entity(em)
86-
.cacheControl(cc).expires(Date.from(CurrentTime.now().plusSeconds(maxAge)))
87-
.type("application/hal+json;concept=metadata;v=1")
88-
.build();
83+
.entity(em)
84+
.cacheControl(cc).expires(Date.from(CurrentTime.now().plusSeconds(maxAge)))
85+
.type("application/hal+json;concept=metadata;v=1")
86+
.header("X-Log-Token", logToken)
87+
.header("X-RateLimit-Limit", "-1")
88+
.header("X-RateLimit-Limit-24h", "-1")
89+
.header("X-RateLimit-Remaining", "-1")
90+
.header("X-RateLimit-Reset", "-1")
91+
.build();
8992
}
9093

91-
interface EventMetadataProducerMethod {
92-
Response getResponse(UriInfo uriInfo, Request request);
94+
Response handleUnsupportedContentType(UriInfo uriInfo, Request request, String xLogToken) {
95+
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
9396
}
9497

95-
Response handleUnsupportedContentType(UriInfo uriInfo, Request request) {
96-
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
98+
interface EventMetadataProducerMethod {
99+
Response getResponse(UriInfo uriInfo, Request request, String xLogToken);
97100
}
98101

99102

account/src/main/java/dk/sample/rest/bank/account/exposure/rs/AccountEventServiceExposure.java

Lines changed: 79 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javax.annotation.security.PermitAll;
1010
import javax.ejb.EJB;
1111
import javax.ejb.Stateless;
12+
import javax.validation.constraints.Pattern;
1213
import javax.ws.rs.GET;
1314
import javax.ws.rs.HeaderParam;
1415
import javax.ws.rs.Path;
@@ -27,11 +28,8 @@
2728
import dk.sample.rest.bank.account.persistence.AccountArchivist;
2829
import dk.sample.rest.common.core.logging.LogDuration;
2930
import dk.sample.rest.common.rs.EntityResponseBuilder;
30-
3131
import io.swagger.annotations.Api;
3232
import io.swagger.annotations.ApiOperation;
33-
import io.swagger.annotations.ApiResponse;
34-
import io.swagger.annotations.ApiResponses;
3533
import io.swagger.annotations.Authorization;
3634

3735
/**
@@ -42,7 +40,7 @@
4240
@Path("/account-events")
4341
@DeclareRoles("tx-system")
4442
@Api(value = "/account-events",
45-
tags = {"events"})
43+
tags = {"events"})
4644
public class AccountEventServiceExposure {
4745
private final Map<String, EventsProducerMethod> eventsProducers = new HashMap<>();
4846
private final Map<String, EventProducerMethod> eventProducers = new HashMap<>();
@@ -66,117 +64,121 @@ public AccountEventServiceExposure() {
6664
@GET
6765
@Produces({"application/hal+json", "application/hal+json;concept=events;v=1"})
6866
@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+
)
8782
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) {
8986
return eventsProducers.getOrDefault(accept, this::handleUnsupportedContentType)
90-
.getResponse(uriInfo, request, interval);
87+
.getResponse(uriInfo, request, interval);
9188
}
9289

9390

9491
@GET
9592
@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"})
9794
@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+
)
115109
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) {
118114
return eventCategoryProducers.getOrDefault(accept, this::handleUnsupportedContentType)
119-
.getResponse(uriInfo, request, category, interval);
115+
.getResponse(uriInfo, request, category, interval);
120116
}
121117

122118
@GET
123119
@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"})
125121
@LogDuration(limit = 50)
126122
@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")
143135
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) {
146140
return eventProducers.getOrDefault(accept, this::handleUnsupportedContentType)
147-
.getResponse(uriInfo, request, category, id);
141+
.getResponse(uriInfo, request, category, id);
148142
}
149143

150144
@LogDuration(limit = 50)
151145
public Response listAllSG1V1(UriInfo uriInfo, Request request, String interval) {
152146
Optional<Interval> withIn = Interval.getInterval(interval);
153147
List<Event> events = archivist.findEvents(withIn);
154148
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);
159153
}
160154

161155
@LogDuration(limit = 50)
162156
public Response listByCategorySG1V1(UriInfo uriInfo, Request request, String category, String interval) {
163157
Optional<Interval> withIn = Interval.getInterval(interval);
164158
List<Event> events = archivist.getEventsForCategory(category, withIn);
165159
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);
170164
}
171165

172166
@LogDuration(limit = 50)
173167
public Response getSG1V1(UriInfo uriInfo, Request request, String category, String id) {
174168
Event event = archivist.getEvent(category, id);
175169
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();
180182
}
181183

182184
interface EventsProducerMethod {
@@ -191,13 +193,5 @@ interface EventsCategoryProducerMethod {
191193
Response getResponse(UriInfo uriInfo, Request request, String interval, String category);
192194
}
193195

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-
202196

203197
}

0 commit comments

Comments
 (0)