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

Issue promote topic email #1349

Merged
merged 8 commits into from
Jun 14, 2023
Merged
4 changes: 3 additions & 1 deletion core/src/main/java/io/aiven/klaw/config/ManageDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ public Map<String, Map<String, String>> getKwPropertiesMap(int tenantId) {

public String getKwPropertyValue(String kwKey, int tenantId) {
if (kwPropertiesMapPerTenant.get(tenantId) != null) {
return kwPropertiesMapPerTenant.get(tenantId).get(kwKey).get("kwvalue");
return kwPropertiesMapPerTenant.get(tenantId).get(kwKey) != null
? kwPropertiesMapPerTenant.get(tenantId).get(kwKey).get("kwvalue")
: "";
} else {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@Configuration // Spring will automatically scan and instantiate this class for retrieval.
public class MigrateData2x4x0 {

public static final String OLD_PWD_RESET_TEMPLATE =
"Dear User, \\nYou have requested for reset password on your Klaw account. \\n\\nUser name : %s \\nYour new Password : %s ";
@Autowired private SelectDataJdbc selectDataJdbc;

@Autowired private InsertDataJdbc insertDataJdbc;
Expand All @@ -42,7 +44,9 @@ public boolean migrate() {

for (int tenantId : tenantIds) {
migrateKwProperties(tenantId);
addKwProperties(tenantId);
manageDatabase.loadEnvMapForOneTenant(tenantId);
manageDatabase.loadKwPropsPerOneTenant(null, tenantId);
}

return true;
Expand All @@ -53,28 +57,32 @@ private void migrateKwProperties(Integer tenantId) {
List<KwProperties> properties = selectDataJdbc.selectAllKwPropertiesPerTenant(tenantId);

try {

KwProperties kwProperty =
new KwProperties(
"klaw.mail.passwordchanged.content",
tenantId,
KwConstants.MAIL_PASSWORDCHANGED_CONTENT,
"Email notification body for password update.");
properties.add(kwProperty);

if (manageDatabase
.getKwPropertyValue("klaw.mail.passwordchanged.content", tenantId)
.equals("")) {
KwProperties kwProperty =
new KwProperties(
"klaw.mail.passwordchanged.content",
tenantId,
KwConstants.MAIL_PASSWORDCHANGED_CONTENT,
"Email notification body for password update.");
properties.add(kwProperty);
}
String propertyToUpdate =
manageDatabase.getKwPropertyValue("klaw.mail.passwordreset.content", tenantId);
// If it has been customized do not update automatically.
if (propertyToUpdate.equals(
"Dear User, \\nYou have requested for reset password on your Klaw account. \\n\\nUser name : %s \\nYour new Password : %s ")) {
if (propertyToUpdate.equals(OLD_PWD_RESET_TEMPLATE)) {
log.info("Updated Password Reset email.");
KwProperties passwordResetProperty =
new KwProperties(
"klaw.mail.passwordreset.content",
tenantId,
KwConstants.MAIL_PASSWORDRESET_CONTENT,
"Email notification body for password reset");
properties.remove(propertyToUpdate);
properties =
properties.stream()
.filter(prop -> !prop.getKwKey().equals("klaw.mail.passwordreset.content"))
.toList();
properties.add(passwordResetProperty);
} else {
log.info("Password Reset Property not updated.");
Expand All @@ -86,4 +94,46 @@ private void migrateKwProperties(Integer tenantId) {
log.error("Exception caught: ", ex);
}
}

aindriu-aiven marked this conversation as resolved.
Show resolved Hide resolved
private void addKwProperties(Integer tenantId) {
log.info("Update promotion and update email KwProperties for tenant {}", tenantId);
List<KwProperties> properties = selectDataJdbc.selectAllKwPropertiesPerTenant(tenantId);

try {
KwProperties kwProperties37 = null, kwProperties36 = null;
if (manageDatabase
.getKwPropertyValue("klaw.mail.topicpromotionrequest.content", tenantId)
.equals("")) {
kwProperties36 =
new KwProperties(
"klaw.mail.topicpromotionrequest.content",
tenantId,
KwConstants.MAIL_TOPICPROMOTIONREQUEST_CONTENT,
"Email notification body for a new Topic Promotion Request");
properties.add(kwProperties36);
}
if (manageDatabase
.getKwPropertyValue("klaw.mail.topicupdaterequest.content", tenantId)
.equals("")) {
kwProperties37 =
new KwProperties(
"klaw.mail.topicupdaterequest.content",
tenantId,
KwConstants.MAIL_TOPICUPDATEREQUEST_CONTENT,
"Email notification body for a new Topic Update Request");
log.info("loaded kw properties");
properties.add(kwProperties37);
}

if (kwProperties37 != null || kwProperties36 != null) {
log.info("Updated email messages for Promotion and Update topic requests.");
insertDataJdbc.insertDefaultKwProperties(properties);
} else {
log.info("Did not update email messages for Promotion and Update topic requests.");
}

} catch (Exception ex) {
log.error("Exception caught: ", ex);
}
}
}
6 changes: 6 additions & 0 deletions core/src/main/java/io/aiven/klaw/helpers/KwConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class KwConstants {
public static final String STAGINGTEAM = "STAGINGTEAM";
public static final String MAIL_TOPICREQUEST_CONTENT =
"Dear User, \\nA request for a create topic %s has been requested in Klaw.";

public static final String MAIL_TOPICPROMOTIONREQUEST_CONTENT =
"Dear User, \\nA request to promote topic %s to the next environment has been requested in Klaw.";

public static final String MAIL_TOPICUPDATEREQUEST_CONTENT =
"Dear User, \\nA request to update the topic %s has been requested in Klaw.";
public static final String MAIL_TOPICDELETEREQUEST_CONTENT =
"Dear User, \\nA request for a delete topic %s has been requested in Klaw.";
public static final String MAIL_TOPICCLAIMREQUEST_CONTENT =
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/io/aiven/klaw/model/enums/MailType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum MailType {
TOPIC_CREATE_REQUESTED,
TOPIC_PROMOTION_REQUESTED,
CONNECTOR_CREATE_REQUESTED,
TOPIC_DELETE_REQUESTED,
CONNECTOR_DELETE_REQUESTED,
Expand All @@ -20,5 +21,7 @@ public enum MailType {
SCHEMA_REQUEST_APPROVED,
SCHEMA_REQUEST_DENIED,
REGISTER_USER_REQUEST,
TOPIC_UPDATE_REQUESTED,
SCHEMA_PROMOTION_REQUESTED,
NEW_USER_ADDED
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@

@Data
public class SchemaDetailsPerEnv {
// This is the id of the Schema as it relates to this topic
private int id;

// This is the version of this Schema that is returned for this topic
private int version;

// If a newer version of the schema exsists its version will be here
private int nextVersion;

// If an older version of the schema exsists its version will be here
private int prevVersion;

// This is the compatibility set in the Schema Registry e.g. NOT_SET/BACKWARD/FORWARD/FULL/NONE
// This can return 'Couldn't retrieve' if it is unable to retrieve that information from the
// schema registry. Or there is an issue with the data saved in the DB.
private String compatibility;

// The content is the actual schema
private String content;

// This is the Schema Registry env that the schema relates to
private String env;

// lets the UI know if it should show a next button
private boolean showNext;

// lets the UI know if it should show a next button
private boolean showPrev;

// simple boolean to identify if this is the latest schema on the topic for that environment.
private boolean latest;
}
16 changes: 16 additions & 0 deletions core/src/main/java/io/aiven/klaw/service/DefaultDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,22 @@ public List<KwProperties> createDefaultProperties(int tenantId, String mailId) {
KwConstants.MAIL_PASSWORDCHANGED_CONTENT,
"Email notification body for password update.");
kwPropertiesList.add(kwProperties35);

KwProperties kwProperties36 =
new KwProperties(
"klaw.mail.topicpromotionrequest.content",
tenantId,
KwConstants.MAIL_TOPICPROMOTIONREQUEST_CONTENT,
"Email notification body for a new Topic Promotion Request");
kwPropertiesList.add(kwProperties36);

KwProperties kwProperties37 =
new KwProperties(
"klaw.mail.topicupdaterequest.content",
tenantId,
KwConstants.MAIL_TOPICUPDATEREQUEST_CONTENT,
"Email notification body for a new Topic Update Request");
kwPropertiesList.add(kwProperties37);
return kwPropertiesList;
}

Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/io/aiven/klaw/service/MailUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class MailUtils {
private String preferredUsername;

private static final String TOPIC_REQ_KEY = "klaw.mail.topicrequest.content";
private static final String TOPIC_PROMOTION_REQ_KEY = "klaw.mail.topicpromotionrequest.content";
private static final String TOPIC_UPDATE_REQ_KEY = "klaw.mail.topicupdaterequest.content";
private static final String TOPIC_REQ_DEL_KEY = "klaw.mail.topicdeleterequest.content";
private static final String TOPIC_REQ_CLAIM_KEY = "klaw.mail.topicclaimrequest.content";
private static final String TOPIC_REQ_APPRVL_KEY = "klaw.mail.topicrequestapproval.content";
Expand All @@ -64,6 +66,9 @@ public class MailUtils {
"klaw.mail.registerusertouser.saasadmin.content";
private static final String RECONCILIATION_TOPICS_KEY = "klaw.mail.recontopics.content";
private String topicRequestMail;

private String topicPromotionRequestMail;
private String topicUpdateRequestMail;
private String topicDeleteRequestMail;
private String topicClaimRequestMail;
private String topicRequestApproved;
Expand All @@ -75,6 +80,10 @@ public class MailUtils {

private void loadKwProps(int tenantId) {
this.topicRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_KEY, tenantId);

this.topicUpdateRequestMail = manageDatabase.getKwPropertyValue(TOPIC_UPDATE_REQ_KEY, tenantId);
this.topicPromotionRequestMail =
manageDatabase.getKwPropertyValue(TOPIC_PROMOTION_REQ_KEY, tenantId);
this.topicDeleteRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_DEL_KEY, tenantId);
this.topicClaimRequestMail = manageDatabase.getKwPropertyValue(TOPIC_REQ_CLAIM_KEY, tenantId);
this.topicRequestApproved = manageDatabase.getKwPropertyValue(TOPIC_REQ_APPRVL_KEY, tenantId);
Expand Down Expand Up @@ -122,6 +131,16 @@ void sendMail(
subject = "Create Topic Request";
requiresApproval = true;
}
case TOPIC_PROMOTION_REQUESTED -> {
formattedStr = String.format(topicPromotionRequestMail, "'" + topicName + "'");
subject = "Topic Promotion Request";
requiresApproval = true;
}
case TOPIC_UPDATE_REQUESTED -> {
formattedStr = String.format(topicUpdateRequestMail, "'" + topicName + "'");
subject = "Topic Update Request";
requiresApproval = true;
}
case TOPIC_DELETE_REQUESTED -> {
formattedStr = String.format(topicDeleteRequestMail, "'" + topicName + "'");
subject = "Delete Topic Request";
Expand Down Expand Up @@ -173,6 +192,11 @@ void sendMail(
subject = "New Schema Request";
formattedStr = "New Schema Request on " + topicName;
}
case SCHEMA_PROMOTION_REQUESTED -> {
requiresApproval = true;
subject = "New Schema Promotion Request";
formattedStr = "New Schema Promotion Request on " + topicName;
}
case CONNECTOR_DELETE_REQUESTED, CONNECTOR_CREATE_REQUESTED -> {
// all remaining requests that require approvals are grouped here.
requiresApproval = true;
Expand Down
Loading