mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(ses): paginate template lists and align ListExportJobs paging (#4465)
* feat(ses): paginate template lists and align ListExportJobs paging Add a namespaced Pagination.paginate overload and SesListPaging, which holds the probed per-operation page-size bounds, default page sizes, error messages and empty-token handling. ListTemplates (v1) and ListEmailTemplates (v2) now page newest first and share one token namespace, so a token from either continues the other. Without a page size the template lists serve 10, as SES does. ListExportJobs refuses a PageSize above 100 instead of clamping it, returns a null NextToken on the last page, and uses SES's own error messages. * refactor(ses): inject the template service clock and drop the paging test sleeps * test(ses): tick the clock between template create and update
This commit is contained in:
1 parent
53de56f487
commit
3441532a9d
15 files changed
+807
-86
No files matched your search
@@ -39,9 +39,30 @@ public final class Pagination {
|
||||
"maxResults must be between 1 and " + maxResultsLimit, 400);
|
||||
}
|
||||
int limit = maxResults != null ? maxResults : defaultPageSize;
|
||||
return slice(all, cursorOf, limit,
|
||||
decodeCursor(nextToken, "", token -> new AwsException(errorCode, "Invalid nextToken.", 400)), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* For callers that validate the page size and render token errors themselves, because the
|
||||
* wording differs per operation. Every cursor is prefixed with {@code namespace}, so a token
|
||||
* minted for another namespace is refused instead of being read as a position in this list,
|
||||
* while two operations listing the same resources can share one namespace and accept each
|
||||
* other's tokens.
|
||||
*/
|
||||
public static <T> PaginatedResult<T> paginate(List<T> all, Function<T, String> cursorOf,
|
||||
int limit, String nextToken, String namespace,
|
||||
Function<String, AwsException> invalidToken) {
|
||||
if (limit < 1) {
|
||||
throw new IllegalArgumentException("limit must be at least 1, was " + limit);
|
||||
}
|
||||
String prefix = namespace + ":";
|
||||
return slice(all, cursorOf, limit, decodeCursor(nextToken, prefix, invalidToken), prefix);
|
||||
}
|
||||
|
||||
private static <T> PaginatedResult<T> slice(List<T> all, Function<T, String> cursorOf, int limit,
|
||||
String after, String tokenPrefix) {
|
||||
List<T> sorted = all.stream().sorted(Comparator.comparing(cursorOf)).collect(Collectors.toList());
|
||||
String after = decodeToken(nextToken, errorCode);
|
||||
int start = 0;
|
||||
if (after != null) {
|
||||
for (int i = 0; i < sorted.size(); i++) {
|
||||
@@ -54,8 +75,8 @@ public final class Pagination {
|
||||
}
|
||||
List<T> page = sorted.stream().skip(start).limit(limit).collect(Collectors.toList());
|
||||
String token = null;
|
||||
if (start + limit < sorted.size() && !page.isEmpty()) {
|
||||
token = encodeToken(cursorOf.apply(page.get(page.size() - 1)));
|
||||
if (limit < sorted.size() - start && !page.isEmpty()) {
|
||||
token = encodeToken(tokenPrefix + cursorOf.apply(page.get(page.size() - 1)));
|
||||
}
|
||||
return new PaginatedResult<>(page, token);
|
||||
}
|
||||
@@ -82,14 +103,20 @@ public final class Pagination {
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(cursor.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static String decodeToken(String token, String errorCode) {
|
||||
private static String decodeCursor(String token, String prefix,
|
||||
Function<String, AwsException> invalidToken) {
|
||||
if (token == null || token.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String decoded;
|
||||
try {
|
||||
return new String(Base64.getUrlDecoder().decode(token), StandardCharsets.UTF_8);
|
||||
decoded = new String(Base64.getUrlDecoder().decode(token), StandardCharsets.UTF_8);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException(errorCode, "Invalid nextToken.", 400);
|
||||
throw invalidToken.apply(token);
|
||||
}
|
||||
if (!decoded.startsWith(prefix)) {
|
||||
throw invalidToken.apply(token);
|
||||
}
|
||||
return decoded.substring(prefix.length());
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.ses.model.ExportJob;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -21,8 +20,6 @@ import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
@@ -42,14 +39,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAb
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class SesExportJobController {
|
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 100;
|
||||
/**
|
||||
* A page no emulator will ever fill, so a larger {@code PageSize} can be clamped instead of
|
||||
* refused. The paginator adds this to the page offset as an int, so {@code Integer.MAX_VALUE}
|
||||
* would overflow that sum and report a further page that does not exist.
|
||||
*/
|
||||
private static final int MAX_PAGE_SIZE = 1_000_000;
|
||||
|
||||
private final SesExportJobService exportJobService;
|
||||
private final SesAccountService accountService;
|
||||
private final RegionResolver regionResolver;
|
||||
@@ -116,18 +105,12 @@ public class SesExportJobController {
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String sourceType = stringMemberOrAbsent(request, "ExportSourceType");
|
||||
String jobStatus = stringMemberOrAbsent(request, "JobStatus");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
// PageSize carries no bound in the model, so a large one is clamped rather than refused;
|
||||
// only a value below 1 is an error, and the default applies when it is absent.
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
if (pageSize != null && pageSize > MAX_PAGE_SIZE) {
|
||||
pageSize = MAX_PAGE_SIZE;
|
||||
}
|
||||
|
||||
PaginatedResult<ExportJob> page = Pagination.paginate(
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
PaginatedResult<ExportJob> page = SesListPaging.V2_LIST_EXPORT_JOBS.page(
|
||||
exportJobService.listExportJobs(region, sourceType, jobStatus),
|
||||
SesExportJobController::cursor, pageSize, nextToken, DEFAULT_PAGE_SIZE,
|
||||
MAX_PAGE_SIZE, "BadRequestException");
|
||||
job -> SesListPaging.newestFirst(job.getCreatedTimestamp(), job.getJobId()),
|
||||
pageSize, nextToken);
|
||||
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode jobs = result.putArray("ExportJobs");
|
||||
@@ -139,9 +122,7 @@ public class SesExportJobController {
|
||||
putTimestamp(node, "CreatedTimestamp", job.getCreatedTimestamp());
|
||||
putTimestamp(node, "CompletedTimestamp", job.getCompletedTimestamp());
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
result.put("NextToken", page.nextToken());
|
||||
}
|
||||
result.put("NextToken", page.nextToken());
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@@ -152,15 +133,4 @@ public class SesExportJobController {
|
||||
exportJobService.cancelExportJob(region, jobId);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared paginator orders by the cursor ascending, and AWS returns the newest job first, so
|
||||
* the cursor counts time backwards. The job id breaks ties between jobs created in the same
|
||||
* millisecond.
|
||||
*/
|
||||
private static String cursor(ExportJob job) {
|
||||
Instant created = job.getCreatedTimestamp();
|
||||
long descending = Long.MAX_VALUE - (created == null ? 0L : created.toEpochMilli());
|
||||
return String.format("%019d#%s", descending, job.getJobId());
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -393,9 +392,6 @@ public class SesExportJobService implements Resettable {
|
||||
return exportJobStore.scan(k -> k.startsWith(keyPrefix(region))).stream()
|
||||
.filter(job -> sourceType == null || sourceType.equals(job.getExportSourceType()))
|
||||
.filter(job -> jobStatus == null || jobStatus.equals(job.getJobStatus()))
|
||||
// Newest first, as AWS returns them.
|
||||
.sorted(Comparator.comparing(ExportJob::getCreatedTimestamp).reversed()
|
||||
.thenComparing(ExportJob::getJobId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Paging rules of the SES list operations. Probe-confirmed against real SES (2026-09-25): the
|
||||
* page-size bound, both error messages and the treatment of an empty token differ per operation,
|
||||
* while the token itself belongs to the kind of resource listed, so the v1 and v2 lists of the
|
||||
* same resources accept each other's tokens and refuse any other list's. Without a page size the
|
||||
* template lists serve 10 (probed 2026-09-26); the export-job default is not documented or
|
||||
* measured and is taken to be the bound.
|
||||
*/
|
||||
enum SesListPaging {
|
||||
|
||||
V2_LIST_EMAIL_TEMPLATES(Namespace.TEMPLATE, 10, 100,
|
||||
size -> badRequest("The page size must be between 1 and 100"),
|
||||
token -> badRequest("Invalid PageToken <" + token + ">."),
|
||||
false),
|
||||
|
||||
/** v1 serves a page of the bound for an out-of-range {@code MaxItems} instead of refusing it. */
|
||||
V1_LIST_TEMPLATES(Namespace.TEMPLATE, 10, 100,
|
||||
null,
|
||||
token -> invalidParameterValue("Invalid PageToken <" + token + ">."),
|
||||
false),
|
||||
|
||||
V2_LIST_EXPORT_JOBS(Namespace.EXPORT_JOB, 100, 100,
|
||||
size -> badRequest("PageSize must be between 1 and 100"),
|
||||
token -> badRequest("Failed to deserialize token. "),
|
||||
true);
|
||||
|
||||
private static final class Namespace {
|
||||
static final String TEMPLATE = "template";
|
||||
static final String EXPORT_JOB = "export-job";
|
||||
}
|
||||
|
||||
private final String namespace;
|
||||
private final int defaultPageSize;
|
||||
private final int maxPageSize;
|
||||
private final Function<Integer, AwsException> outOfRange;
|
||||
private final Function<String, AwsException> invalidToken;
|
||||
private final boolean emptyTokenInvalid;
|
||||
|
||||
SesListPaging(String namespace, int defaultPageSize, int maxPageSize,
|
||||
Function<Integer, AwsException> outOfRange, Function<String, AwsException> invalidToken,
|
||||
boolean emptyTokenInvalid) {
|
||||
this.namespace = namespace;
|
||||
this.defaultPageSize = defaultPageSize;
|
||||
this.maxPageSize = maxPageSize;
|
||||
this.outOfRange = outOfRange;
|
||||
this.invalidToken = invalidToken;
|
||||
this.emptyTokenInvalid = emptyTokenInvalid;
|
||||
}
|
||||
|
||||
<T> PaginatedResult<T> page(List<T> all, Function<T, String> cursorOf, Integer pageSize,
|
||||
String nextToken) {
|
||||
int limit = pageSize(pageSize);
|
||||
if (nextToken != null && nextToken.isEmpty() && emptyTokenInvalid) {
|
||||
throw invalidToken.apply(nextToken);
|
||||
}
|
||||
return Pagination.paginate(all, cursorOf, limit, nextToken, namespace, invalidToken);
|
||||
}
|
||||
|
||||
int pageSize(Integer requested) {
|
||||
if (requested == null) {
|
||||
return defaultPageSize;
|
||||
}
|
||||
if (requested < 1 || requested > maxPageSize) {
|
||||
if (outOfRange == null) {
|
||||
return maxPageSize;
|
||||
}
|
||||
throw outOfRange.apply(requested);
|
||||
}
|
||||
return requested;
|
||||
}
|
||||
|
||||
/** Newest first, as SES lists templates and export jobs; the id orders equal timestamps. */
|
||||
static String newestFirst(Instant created, String id) {
|
||||
long descending = Long.MAX_VALUE - (created == null ? 0L : created.toEpochMilli());
|
||||
return descending + "#" + id;
|
||||
}
|
||||
|
||||
static String templateCursor(EmailTemplate template) {
|
||||
return newestFirst(template.getCreatedTimestamp(), template.getTemplateName());
|
||||
}
|
||||
|
||||
/** A REST JSON query-string page size; a value that is not an int is a serialization error. */
|
||||
static Integer parseQueryPageSize(String raw) {
|
||||
if (raw == null || raw.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.valueOf(raw);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("SerializationException",
|
||||
"'" + raw + "' can not be converted to Integer", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Query-protocol page size. Unlike the REST JSON query string, a present but empty value is
|
||||
* refused, and a value that is not an int is refused without a message.
|
||||
*/
|
||||
static Integer parseQueryProtocolPageSize(String raw) {
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
if (raw.isEmpty()) {
|
||||
throw new AwsException("MalformedInput", "missing value for decimal type", 400);
|
||||
}
|
||||
try {
|
||||
return Integer.valueOf(raw);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("MalformedInput", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException badRequest(String message) {
|
||||
return new AwsException("BadRequestException", message, 400);
|
||||
}
|
||||
|
||||
private static AwsException invalidParameterValue(String message) {
|
||||
return new AwsException("InvalidParameterValue", message, 400);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
@@ -110,7 +111,7 @@ public class SesQueryHandler {
|
||||
case "UpdateTemplate" -> handleUpdateTemplate(params, region);
|
||||
case "GetTemplate" -> handleGetTemplate(params, region);
|
||||
case "DeleteTemplate" -> handleDeleteTemplate(params, region);
|
||||
case "ListTemplates" -> handleListTemplates(region);
|
||||
case "ListTemplates" -> handleListTemplates(params, region);
|
||||
case "SendTemplatedEmail" -> handleSendTemplatedEmail(params, region);
|
||||
case "SendBulkTemplatedEmail" -> handleSendBulkTemplatedEmail(params, region);
|
||||
case "TestRenderTemplate" -> handleTestRenderTemplate(params, region);
|
||||
@@ -563,10 +564,13 @@ public class SesQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("DeleteTemplate", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleListTemplates(String region) {
|
||||
List<EmailTemplate> templates = templateService.listTemplates(region);
|
||||
var xml = new XmlBuilder().start("TemplatesMetadata");
|
||||
for (EmailTemplate t : templates) {
|
||||
private Response handleListTemplates(MultivaluedMap<String, String> params, String region) {
|
||||
PaginatedResult<EmailTemplate> page = SesListPaging.V1_LIST_TEMPLATES.page(
|
||||
templateService.listTemplates(region), SesListPaging::templateCursor,
|
||||
SesListPaging.parseQueryProtocolPageSize(getParam(params, "MaxItems")),
|
||||
getParam(params, "NextToken"));
|
||||
XmlBuilder xml = new XmlBuilder().start("TemplatesMetadata");
|
||||
for (EmailTemplate t : page.items()) {
|
||||
xml.start("member")
|
||||
.elem("Name", t.getTemplateName());
|
||||
if (t.getCreatedTimestamp() != null) {
|
||||
@@ -575,6 +579,7 @@ public class SesQueryHandler {
|
||||
xml.end("member");
|
||||
}
|
||||
xml.end("TemplatesMetadata");
|
||||
xml.elem("NextToken", page.nextToken());
|
||||
return Response.ok(AwsQueryResponse.envelope("ListTemplates", AwsNamespaces.SES, xml.build())).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
@@ -18,6 +19,7 @@ import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
@@ -85,17 +87,22 @@ public class SesTemplateController {
|
||||
|
||||
@GET
|
||||
@Path("/templates")
|
||||
public Response listEmailTemplates(@Context HttpHeaders headers) {
|
||||
public Response listEmailTemplates(@Context HttpHeaders headers,
|
||||
@QueryParam("PageSize") String pageSize,
|
||||
@QueryParam("NextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<EmailTemplate> templates = templateService.listTemplates(region);
|
||||
PaginatedResult<EmailTemplate> page = SesListPaging.V2_LIST_EMAIL_TEMPLATES.page(
|
||||
templateService.listTemplates(region), SesListPaging::templateCursor,
|
||||
SesListPaging.parseQueryPageSize(pageSize), nextToken);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode items = result.putArray("TemplatesMetadata");
|
||||
for (EmailTemplate t : templates) {
|
||||
for (EmailTemplate t : page.items()) {
|
||||
ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("TemplateName", t.getTemplateName());
|
||||
putTimestamp(item, "CreatedTimestamp", t.getCreatedTimestamp());
|
||||
items.add(item);
|
||||
}
|
||||
result.put("NextToken", page.nextToken());
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
@@ -52,18 +52,20 @@ public class SesTemplateService {
|
||||
private final StorageBackend<String, EmailTemplate> templateStore;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final SecureRandom boundaryRandom;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
public SesTemplateService(StorageFactory storageFactory, ObjectMapper objectMapper) {
|
||||
public SesTemplateService(StorageFactory storageFactory, ObjectMapper objectMapper, Clock clock) {
|
||||
this(storageFactory.create("ses", "ses-templates.json",
|
||||
new TypeReference<Map<String, EmailTemplate>>() {}), objectMapper, new SecureRandom());
|
||||
new TypeReference<Map<String, EmailTemplate>>() {}), objectMapper, new SecureRandom(), clock);
|
||||
}
|
||||
|
||||
SesTemplateService(StorageBackend<String, EmailTemplate> templateStore,
|
||||
ObjectMapper objectMapper, SecureRandom boundaryRandom) {
|
||||
ObjectMapper objectMapper, SecureRandom boundaryRandom, Clock clock) {
|
||||
this.templateStore = templateStore;
|
||||
this.objectMapper = objectMapper;
|
||||
this.boundaryRandom = boundaryRandom;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
public EmailTemplate createTemplate(EmailTemplate template, String region) {
|
||||
@@ -74,7 +76,7 @@ public class SesTemplateService {
|
||||
throw new AwsException("AlreadyExists",
|
||||
"Template " + template.getTemplateName() + " already exists.", 400);
|
||||
}
|
||||
Instant now = Instant.now();
|
||||
Instant now = Instant.now(clock);
|
||||
template.setCreatedTimestamp(now);
|
||||
template.setLastUpdatedTimestamp(now);
|
||||
templateStore.put(key, template);
|
||||
@@ -95,7 +97,7 @@ public class SesTemplateService {
|
||||
.orElseThrow(() -> new AwsException("TemplateDoesNotExist",
|
||||
"Template " + template.getTemplateName() + " does not exist.", 400));
|
||||
template.setCreatedTimestamp(existing.getCreatedTimestamp());
|
||||
template.setLastUpdatedTimestamp(Instant.now());
|
||||
template.setLastUpdatedTimestamp(Instant.now(clock));
|
||||
// Tags are managed exclusively via Tag/UntagResource — preserve them on update (copied,
|
||||
// so the two objects never share a list instance).
|
||||
template.setTags(new ArrayList<>(existing.getTags()));
|
||||
@@ -116,12 +118,7 @@ public class SesTemplateService {
|
||||
|
||||
public List<EmailTemplate> listTemplates(String region) {
|
||||
String prefix = "template::" + region + "::";
|
||||
List<EmailTemplate> all = new ArrayList<>(templateStore.scan(k -> k.startsWith(prefix)));
|
||||
all.sort(Comparator.comparing(EmailTemplate::getCreatedTimestamp,
|
||||
Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.thenComparing(EmailTemplate::getTemplateName,
|
||||
Comparator.nullsLast(Comparator.naturalOrder())));
|
||||
return all;
|
||||
return templateStore.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user