Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce B2B Resolving Capabilities to Email/SMS Template Mgt APIs #755

Merged
merged 7 commits into from
Dec 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ public Response getAllEmailTemplateTypes( @Valid @Min(0)@ApiParam(value = "Ma
@ApiResponse(code = 404, message = "The specified resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal Server Error.", response = Error.class)
})
public Response getAppEmailTemplate(@ApiParam(value = "Email Template Type ID.",required=true) @PathParam("template-type-id") String templateTypeId, @ApiParam(value = "Application UUID.",required=true) @PathParam("app-uuid") String appUuid, @ApiParam(value = "This should be a valid locale.",required=true) @PathParam("locale") String locale, @Valid @Min(0)@ApiParam(value = "Maximum number of records to return. _<b>This option is not yet supported.<b>_") @QueryParam("limit") Integer limit, @Valid @Min(0)@ApiParam(value = "Number of records to skip for pagination. _<b>This option is not yet supported.<b>_") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_", allowableValues="asc, desc") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_") @QueryParam("sortBy") String sortBy) {
public Response getAppEmailTemplate(@ApiParam(value = "Email Template Type ID.",required=true) @PathParam("template-type-id") String templateTypeId, @ApiParam(value = "Application UUID.",required=true) @PathParam("app-uuid") String appUuid, @ApiParam(value = "This should be a valid locale.",required=true) @PathParam("locale") String locale, @Valid@ApiParam(value = "Specifies whether to return resolved template/s throughout the ancestor organization hierarchy.", defaultValue="false") @DefaultValue("false") @QueryParam("resolve") Boolean resolve, @Valid @Min(0)@ApiParam(value = "Maximum number of records to return. _<b>This option is not yet supported.<b>_") @QueryParam("limit") Integer limit, @Valid @Min(0)@ApiParam(value = "Number of records to skip for pagination. _<b>This option is not yet supported.<b>_") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_", allowableValues="asc, desc") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_") @QueryParam("sortBy") String sortBy) {

return delegate.getAppEmailTemplate(templateTypeId, appUuid, locale, limit, offset, sortOrder, sortBy );
return delegate.getAppEmailTemplate(templateTypeId, appUuid, locale, resolve, limit, offset, sortOrder, sortBy );
}

@Valid
Expand All @@ -257,9 +257,9 @@ public Response getAppEmailTemplate(@ApiParam(value = "Email Template Type ID.",
@ApiResponse(code = 404, message = "The specified resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal Server Error.", response = Error.class)
})
public Response getAppTemplatesListOfEmailTemplateType(@ApiParam(value = "Email Template Type ID.",required=true) @PathParam("template-type-id") String templateTypeId, @ApiParam(value = "Application UUID.",required=true) @PathParam("app-uuid") String appUuid, @Valid @Min(0)@ApiParam(value = "Maximum number of records to return. _<b>This option is not yet supported.<b>_") @QueryParam("limit") Integer limit, @Valid @Min(0)@ApiParam(value = "Number of records to skip for pagination. _<b>This option is not yet supported.<b>_") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_", allowableValues="asc, desc") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_") @QueryParam("sortBy") String sortBy) {
public Response getAppTemplatesListOfEmailTemplateType(@ApiParam(value = "Email Template Type ID.",required=true) @PathParam("template-type-id") String templateTypeId, @ApiParam(value = "Application UUID.",required=true) @PathParam("app-uuid") String appUuid, @Valid@ApiParam(value = "Specifies whether to return resolved template/s throughout the ancestor organization hierarchy.", defaultValue="false") @DefaultValue("false") @QueryParam("resolve") Boolean resolve, @Valid @Min(0)@ApiParam(value = "Maximum number of records to return. _<b>This option is not yet supported.<b>_") @QueryParam("limit") Integer limit, @Valid @Min(0)@ApiParam(value = "Number of records to skip for pagination. _<b>This option is not yet supported.<b>_") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_", allowableValues="asc, desc") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _<b>This option is not yet supported.<b>_") @QueryParam("sortBy") String sortBy) {

return delegate.getAppTemplatesListOfEmailTemplateType(templateTypeId, appUuid, limit, offset, sortOrder, sortBy );
return delegate.getAppTemplatesListOfEmailTemplateType(templateTypeId, appUuid, resolve, limit, offset, sortOrder, sortBy );
}

@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public interface EmailApiService {

public Response getAllEmailTemplateTypes(Integer limit, Integer offset, String sortOrder, String sortBy);

public Response getAppEmailTemplate(String templateTypeId, String appUuid, String locale, Integer limit, Integer offset, String sortOrder, String sortBy);
public Response getAppEmailTemplate(String templateTypeId, String appUuid, String locale, Boolean resolve, Integer limit, Integer offset, String sortOrder, String sortBy);

public Response getAppTemplatesListOfEmailTemplateType(String templateTypeId, String appUuid, Integer limit, Integer offset, String sortOrder, String sortBy);
public Response getAppTemplatesListOfEmailTemplateType(String templateTypeId, String appUuid, Boolean resolve, Integer limit, Integer offset, String sortOrder, String sortBy);

public Response getEmailTemplateType(String templateTypeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ public class ApplicationEmailTemplatesService {
* @param templateTypeId Email template type id.
* @param templateId Email template id.
* @param applicationUuid Application UUID.
* @param resolve Whether to retrieve the template resolved through the ancestor organization hierarchy.
* @param limit Limit the number of email template types in the response. **Not supported at the moment**
* @param offset Offset to be used with the limit parameter. **Not supported at the moment**
* @param sortOrder Sort the response in ascending order or descending order. **Not supported at the moment**
* @param sortBy Element to sort the responses. **Not supported at the moment**
* @return Email template identified by the given template-type-id and the template-id, 404 if not found.
*/
public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templateId, String applicationUuid,
Integer limit, Integer offset,
boolean resolve, Integer limit, Integer offset,
String sortOrder, String sortBy) {

handleNotSupportedParameters(limit, offset, sortOrder, sortBy);
Expand All @@ -79,7 +80,7 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa
templateId = I18nEmailUtil.normalizeLocaleFormat(templateId);
EmailTemplate internalEmailTemplate = EmailTemplatesServiceHolder.getEmailTemplateManager().
getEmailTemplate(templateTypeDisplayName, templateId,
getTenantDomainFromContext(), applicationUuid);
getTenantDomainFromContext(), applicationUuid, resolve);
// EmailTemplateManager sends the default template if no matching template found. We need to check for
// the locale specifically.
if (!internalEmailTemplate.getLocale().equals(templateId)) {
Expand All @@ -97,22 +98,26 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa
*
* @param templateTypeId Email template type id.
* @param applicationUuid Application UUID.
* @param resolve Whether to retrieve templates resolved through the ancestor organization hierarchy,
* returning templates that are applicable across the tenant's organizational structure.
* @param limit Limit the number of email template types in the response. **Not supported at the moment**
* @param offset Offset to be used with the limit parameter. **Not supported at the moment**
* @param sortOrder Sort the response in ascending order or descending order. **Not supported at the moment**
* @param sortBy Element to sort the responses. **Not supported at the moment**
* @return List of SimpleEmailTemplate objects in the template type identified by the given id, 404 if not found.
*/
public List<SimpleEmailTemplate> getTemplatesListOfEmailTemplateType(String templateTypeId, String applicationUuid,
boolean resolve,
Integer limit, Integer offset,
String sortOrder, String sortBy) {

handleNotSupportedParameters(limit, offset, sortOrder, sortBy);

String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId);
try {
List<EmailTemplate> internalEmailTemplates = EmailTemplatesServiceHolder.getEmailTemplateManager().
getEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext(), applicationUuid);
List<EmailTemplate> internalEmailTemplates =
EmailTemplatesServiceHolder.getEmailTemplateManager().getEmailTemplateType(
templateTypeDisplayName, getTenantDomainFromContext(), applicationUuid, resolve);
return buildSimpleEmailTemplatesList(internalEmailTemplates, templateTypeId, applicationUuid);
} catch (I18nEmailMgtException e) {
if (StringUtils.equals(I18nMgtConstants.ErrorCodes.EMAIL_TEMPLATE_TYPE_NOT_FOUND, e.getErrorCode())) {
Expand All @@ -137,7 +142,7 @@ public SimpleEmailTemplate addEmailTemplate(
try {
boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager()
.isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getLocale(),
getTenantDomainFromContext(), applicationUuid);
getTenantDomainFromContext(), applicationUuid, false);
if (!isTemplateExists) {
// Email template is new, hence add to the system.
addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID, applicationUuid);
Expand Down Expand Up @@ -174,7 +179,7 @@ public void deleteEmailTemplate(String templateTypeId, String templateId, String
}
try {
boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists(
templateTypeDisplayName, templateId, getTenantDomainFromContext(), applicationUuid);
templateTypeDisplayName, templateId, getTenantDomainFromContext(), applicationUuid, false);
if (isTemplateExists) {
EmailTemplatesServiceHolder.getEmailTemplateManager().deleteEmailTemplate(templateTypeDisplayName,
templateId, getTenantDomainFromContext(), applicationUuid);
Expand Down Expand Up @@ -224,9 +229,11 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT

String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId);
try {
// Check whether the email template exists, first.
/* Check whether the email template exists, first. Here, resolve param is specified as true since
resolved org templates are returned in GET endpoint, by default. Therefore, resolved template existence
is checked before updating. */
boolean isTemplateExists = EmailTemplatesServiceHolder.getEmailTemplateManager().isEmailTemplateExists(
templateTypeDisplayName, templateId, getTenantDomainFromContext(), applicationUuid);
templateTypeDisplayName, templateId, getTenantDomainFromContext(), applicationUuid, true);
if (isTemplateExists) {
addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID, applicationUuid);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,22 @@ public Response getAllEmailTemplateTypes(Integer limit, Integer offset, String s
}

@Override
public Response getAppEmailTemplate(String templateTypeId, String appUuid, String locale,
public Response getAppEmailTemplate(String templateTypeId, String appUuid, String locale, Boolean resolve,
Integer limit, Integer offset, String sortOrder, String sortBy) {

return Response.ok().entity(applicationEmailTemplatesService.
getEmailTemplate(templateTypeId, locale, appUuid, limit, offset, sortOrder, sortBy)).build();
return Response.ok()
.entity(applicationEmailTemplatesService.getEmailTemplate(templateTypeId, locale, appUuid, resolve,
limit, offset, sortOrder, sortBy)).build();
}

@Override
public Response getAppTemplatesListOfEmailTemplateType(
String templateTypeId, String appUuid, Integer limit, Integer offset, String sortOrder, String sortBy) {
public Response getAppTemplatesListOfEmailTemplateType(String templateTypeId, String appUuid, Boolean resolve,
Integer limit, Integer offset, String sortOrder,
String sortBy) {

return Response.ok().entity(applicationEmailTemplatesService.
getTemplatesListOfEmailTemplateType(templateTypeId, appUuid, limit, offset, sortOrder, sortBy)).build();
return Response.ok()
.entity(applicationEmailTemplatesService.getTemplatesListOfEmailTemplateType(templateTypeId, appUuid,
resolve, limit, offset, sortOrder, sortBy)).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ paths:
parameters:
- $ref: '#/components/parameters/templateTypeIdPathParam'
- $ref: '#/components/parameters/appUuidPathParam'
- $ref: '#/components/parameters/resolveQueryParam'
- $ref: '#/components/parameters/limitQueryParam'
- $ref: '#/components/parameters/offsetQueryParam'
- $ref: '#/components/parameters/sortOrderQueryParam'
Expand Down Expand Up @@ -442,6 +443,7 @@ paths:
- $ref: '#/components/parameters/templateTypeIdPathParam'
- $ref: '#/components/parameters/appUuidPathParam'
- $ref: '#/components/parameters/localePathParam'
- $ref: '#/components/parameters/resolveQueryParam'
- $ref: '#/components/parameters/limitQueryParam'
- $ref: '#/components/parameters/offsetQueryParam'
- $ref: '#/components/parameters/sortOrderQueryParam'
Expand Down Expand Up @@ -556,6 +558,14 @@ components:
description: Application UUID.
schema:
type: string
resolveQueryParam:
in: query
name: resolve
required: false
description: Specifies whether to return resolved template/s throughout the ancestor organization hierarchy.
schema:
type: boolean
default: false
offsetQueryParam:
in: query
name: offset
Expand Down
Loading
Loading