Skip to content

Commit db540ae

Browse files
Merge pull request #32 from aquality-automation/feature/bug_link_view_on_AT_is_broken
Fix for Email URL
2 parents 205b1cf + a3611e9 commit db540ae

File tree

10 files changed

+270
-78
lines changed

10 files changed

+270
-78
lines changed

src/main/java/main/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Importer getImporter(List<String> filePaths, TestRunDto testRunTemplate,
6363
return new Importer(filePaths, testRunTemplate, pattern, format, nodeType, singleTestRun, user);
6464
}
6565

66-
public TestRunEmails getTestRunEmails(){
66+
public TestRunEmails getTestRunEmails() throws AqualityException {
6767
return new TestRunEmails();
6868
}
6969

src/main/java/main/model/db/dao/DAO.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ public List<T> searchAll(T entity) throws AqualityException {
8686
* @return entity
8787
*/
8888
public T getEntityById(T entity) throws AqualityException {
89-
return searchAll(entity).get(0);
89+
List<T> all = searchAll(entity);
90+
if(all.size() > 0) {
91+
return all.get(0);
92+
}
93+
else{
94+
throw new AqualityException("No Entities was found by %s", entity.getIDParameters());
95+
}
9096
}
9197

9298

src/main/java/main/model/db/dao/settings/EmailSettingsDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class EmailSettingsDao extends DAO<EmailSettingsDto> {
1414

1515
public EmailSettingsDao() {
1616
super(EmailSettingsDto.class);
17-
insert = "{call INSERT_EMAIL_SETTINGS(?,?,?,?,?,?,?,?,?)}";
17+
insert = "{call INSERT_EMAIL_SETTINGS(?,?,?,?,?,?,?,?,?,?)}";
1818
select = "{call SELECT_EMAIL_SETTINGS(?)}";
1919
}
2020

src/main/java/main/model/dto/EmailSettingsDto.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ public class EmailSettingsDto extends BaseDto {
3434
@DataBaseName(name="request_default_email_pattern")
3535
@DataBaseInsert
3636
private String default_email_pattern;
37+
@DataBaseName(name="request_base_url")
38+
@DataBaseInsert
39+
private String base_url;
3740
}

src/main/java/main/model/email/AuditEmails.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public class AuditEmails extends Emails {
1818
private AuditStatisticDao auditStatisticController;
1919
private AppProperties appProperties = new AppProperties();
2020

21-
public AuditEmails() {
21+
public AuditEmails() throws AqualityException {
22+
super();
2223
auditStatisticController = new AuditStatisticDao();
2324
}
24-
public List<EmailDto> GetUpcomingEmails() throws AqualityException {
25+
26+
public List<EmailDto> getUpcomingEmails() throws AqualityException {
2527
List<AuditStatisticDto> audits = auditStatisticController.getAll();
2628
List<String> recipients = getRecipients();
2729

@@ -32,7 +34,8 @@ public List<EmailDto> GetUpcomingEmails() throws AqualityException {
3234

3335
return emails;
3436
}
35-
public List<EmailDto> GetOverdueEmails() throws AqualityException {
37+
38+
public List<EmailDto> getOverdueEmails() throws AqualityException {
3639
List<AuditStatisticDto> audits = auditStatisticController.getAll();
3740
List<String> recipients = getRecipients();
3841
List<AuditStatisticDto> overdueAudits = audits.stream()
@@ -45,9 +48,9 @@ public List<EmailDto> GetOverdueEmails() throws AqualityException {
4548
EmailDto email = new EmailDto();
4649
email.setSubject(String.format("[%s] Overdue Project Audit - %s", appProperties.getName(), overdueAudit.getName()));
4750
email.setContent("<p style=\"font-family: Calibri, sans-serif; font-size: 11pt; line-height: 4px;\">Next Audit Date for the <strong><a style=\"color: #6b6b6b;\" href=\""
48-
+ hostUri() +"#/project/" + overdueAudit.getId()+"\">" + overdueAudit.getName() +"</a>&nbsp; </strong>project is overdue and requires your attention.</p>\n" +
51+
+ baseURL +"#/project/" + overdueAudit.getId()+"\">" + overdueAudit.getName() +"</a>&nbsp; </strong>project is overdue and requires your attention.</p>\n" +
4952
"<p style=\"font-family: Calibri, sans-serif; font-size: 11pt; line-height: 4px;\">Please follow this <a style=\"color: #6b6b6b;\" href=\""
50-
+ hostUri() + "#/audit\">link</a> to access Audits Dashboard.</p>\n" +
53+
+ baseURL + "#/audit\">link</a> to access Audits Dashboard.</p>\n" +
5154
"<p>&nbsp;</p>" +
5255
"<p style=\"font-family: Calibri, sans-serif; font-size: 10pt; line-height: 2px;\">Best Regards,</p>\n" +
5356
"<p style=\"font-family: Calibri, sans-serif; font-size: 10pt; line-height: 2px;\">" + appProperties.getName() + " Administration</p>\n" +
@@ -78,10 +81,10 @@ private List<EmailDto> getUpcomingAudits(int daysFromToday, List<AuditStatisticD
7881
EmailDto email = new EmailDto();
7982
email.setSubject(String.format("[%s] Upcoming Project Audit - %s", appProperties.getName(), upcAudit.getName()));
8083
email.setContent("<p style=\"font-family: Calibri, sans-serif; font-size: 11pt; line-height: 4px;\">Next Audit for the <strong><a style=\"color: #6b6b6b;\" href=\""
81-
+ hostUri() +"#/project/" + upcAudit.getId()+"\">" + upcAudit.getName() + "</a> </strong>project should be submitted within<strong> "
84+
+ baseURL +"#/project/" + upcAudit.getId()+"\">" + upcAudit.getName() + "</a> </strong>project should be submitted within<strong> "
8285
+ days + " days.</strong></p>\n" +
8386
"<p style=\"font-family: Calibri, sans-serif; font-size: 11pt; line-height: 4px;\">Please follow this <a style=\"color: #6b6b6b;\" href=\""
84-
+ hostUri() + "#/audit\">link</a> to access Audits Dashboard and create a new Audit.</p>\n" +
87+
+ baseURL + "#/audit\">link</a> to access Audits Dashboard and create a new Audit.</p>\n" +
8588
"<p>&nbsp;</p>\n" +
8689
"<p style=\"font-family: Calibri, sans-serif; font-size: 10pt; line-height: 2px;\">Best Regards,</p>\n" +
8790
"<p style=\"font-family: Calibri, sans-serif; font-size: 10pt; line-height: 2px;\">" + appProperties.getName() + " Administration</p>\n" +
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
package main.model.email;
22

33
import main.exceptions.AqualityException;
4+
import main.model.db.dao.settings.EmailSettingsDao;
5+
import main.model.dto.EmailDto;
6+
import main.model.dto.EmailSettingsDto;
47
import main.utils.DateUtils;
5-
6-
import java.io.IOException;
7-
import java.io.InputStream;
8-
import java.util.Properties;
8+
import main.utils.EmailUtil;
99

1010
abstract class Emails {
11+
String baseURL;
1112
DateUtils dateUtils = new DateUtils();
1213

13-
String hostUri() throws AqualityException {
14-
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
15-
Properties prop = new Properties();
16-
17-
InputStream resource = classloader.getResourceAsStream("hostinfo.properties");
18-
try {
19-
prop.load(resource);
20-
} catch (IOException e) {
21-
throw new AqualityException("Not able to load properties");
22-
}
14+
Emails() throws AqualityException {
15+
EmailSettingsDao emailSettingsDao = new EmailSettingsDao();
16+
EmailSettingsDto settings = emailSettingsDao.getEntityById(new EmailSettingsDto());
17+
baseURL = settings.getBase_url();
18+
}
2319

24-
return String.format("http://%s/", prop.getProperty("frontURI"));
20+
boolean sendEmail(EmailDto email) throws AqualityException {
21+
EmailSettingsDao emailSettingsDao = new EmailSettingsDao();
22+
EmailSettingsDto settings = emailSettingsDao.getAll().get(0);
23+
settings.setPassword(emailSettingsDao.getAdminSecret(settings.getPassword()));
24+
EmailUtil emailUtil = new EmailUtil(settings);
25+
return emailUtil.sendHtmlEmail(email.getRecipients(), email.getSubject(), email.getContent());
2526
}
2627
}

src/main/java/main/model/email/TestRunEmails.java

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,26 @@
1818
import java.util.stream.Collectors;
1919

2020
public class TestRunEmails extends Emails{
21+
public TestRunEmails() throws AqualityException {
22+
super();
23+
}
24+
2125
private AppProperties appProperties = new AppProperties();
26+
public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) throws AqualityException, MessagingException, IOException, URISyntaxException {
27+
ProjectDto project = getProject(testRun.getProject_id());
2228

23-
public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) throws IOException, JSONException, SQLException, NamingException, IllegalAccessException, InstantiationException, MessagingException, URISyntaxException, AqualityException {
24-
ProjectDao projectDao = new ProjectDao();
25-
ProjectDto projectDto = new ProjectDto();
26-
projectDto.setId(testRun.getProject_id());
27-
projectDto = projectDao.searchAll(projectDto).get(0);
28-
List<TestResultDto> testResults = testRun.getTestResults();
29-
double totalResultsNum = testResults.size();
30-
double passedResultsNum = (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 5).count();
31-
double failedResultsNum = (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 1).count();
32-
double notExecutedResultsNum = (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 3 || x.getFinal_result().getColor() == 2 || x.getFinal_result().getColor() == 4).count();
33-
List<TestResultDto> failedResults = testResults.stream().filter(x -> x.getFinal_result().getColor() != 5).collect(Collectors.toList());
34-
List<TestResultDto> appIssues = failedResults.stream().filter(x -> x.getTest_resolution().getColor() == 1).collect(Collectors.toList());
35-
List<TestResultDto> otherIssues = failedResults.stream().filter(x -> x.getTest_resolution().getColor() != 1 && x.getTest_resolution().getColor() != 2 && x.getTest_resolution().getColor() != 3).collect(Collectors.toList());
36-
double successRate = passedResultsNum/totalResultsNum*100;
37-
String rateColor = successRate > 85 ? "#009900" : successRate > 65 ? "#ff6601" : "#cc2100";
38-
StringBuilder overview = new StringBuilder(appIssues.size() > 0 ? " <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\">Application Issues Overview:</p>\n" : "");
39-
for (TestResultDto testResult : appIssues) {
40-
overview.append(" <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;\">").append(testResult.getTest().getName()).append(": ").append(testResult.getComment() != null ? testResult.getComment() : "No comment for This Failure.").append("</p>\n");
41-
}
29+
double failedCount = getFailedResultsCount(testRun.getTestResults());
30+
double passedCount = getPassedResultsCount(testRun.getTestResults());
31+
double totalCount = getTotalResultsCount(testRun.getTestResults());
32+
double notExecutedCount = getNotExecutedResultsCount(testRun.getTestResults());
33+
double successRate = getSuccessRate(passedCount, totalCount);
34+
35+
List<TestResultDto> failed = getFailedResults(testRun.getTestResults());
36+
List<TestResultDto> appIssues = getAppIssues(failed);
37+
List<TestResultDto> otherIssues = getOtherIssues(failed);
4238

4339
EmailDto email = new EmailDto();
44-
email.setSubject("[RP]:" + projectDto.getName() + " - " + new DecimalFormat("##.##").format(successRate) + "% - " + testRun.getBuild_name());
40+
email.setSubject("[RP]:" + project.getName() + " - " + new DecimalFormat("##.##").format(successRate) + "% - " + testRun.getBuild_name());
4541
email.setContent("<div style=\"\n" +
4642
"margin-left: 20px;\n" +
4743
"padding-left: 20px;\">\n" +
@@ -60,32 +56,32 @@ public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) th
6056
" font-weight: bold;\n" +
6157
" font-family: Calibri, sans-serif;\n" +
6258
" font-size: 15px;\n" +
63-
" line-height: 10px;\" href=\"" + hostUri() + "#/project/" + projectDto.getId() + "/testrun/" + testRun.getId() + "\">View on " + appProperties.getName() + "</a>\n" +
59+
" line-height: 10px;\" href=\"" + baseURL + "#/project/" + project.getId() + "/testrun/" + testRun.getId() + "\">View on " + appProperties.getName() + "</a>\n" +
6460
" </div>\n" +
6561
" <hr>\n" +
66-
" <div style=\"margin: 0;font-family: Calibri, sans-serif;height:50px; padding-top:20px; color:" + rateColor + ";font-size: 30px;\">\n" +
62+
" <div style=\"margin: 0;font-family: Calibri, sans-serif;height:50px; padding-top:20px; color:" + getRateColor(successRate) + ";font-size: 30px;\">\n" +
6763
" Success Rate: " + new DecimalFormat("##.##").format(successRate) + "%\n" +
6864
" </div>\n" +
6965
" <br/>\n" +
7066
" <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\">Test Results:</p>\n" +
7167
" <p style=\"margin: 0; color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
72-
" Passed | " + new DecimalFormat("##").format(passedResultsNum) + " | " + new DecimalFormat("##.##").format(passedResultsNum/totalResultsNum*100) + "% </p>\n" +
68+
" Passed | " + new DecimalFormat("##").format(passedCount) + " | " + new DecimalFormat("##.##").format(passedCount/totalCount*100) + "% </p>\n" +
7369
" <p style=\"margin: 0;color:#e27070;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
74-
" Failed | " + new DecimalFormat("##").format(failedResultsNum) + " | " + new DecimalFormat("##.##").format(failedResultsNum/totalResultsNum*100) +"% </p>\n" +
70+
" Failed | " + new DecimalFormat("##").format(failedCount) + " | " + new DecimalFormat("##.##").format(failedCount/totalCount*100) +"% </p>\n" +
7571
" <p style=\"margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
76-
" Not Executed | " + new DecimalFormat("##").format(notExecutedResultsNum) + " | " + new DecimalFormat("##.##").format(notExecutedResultsNum/totalResultsNum*100) +"% </p>\n" +
72+
" Not Executed | " + new DecimalFormat("##").format(notExecutedCount) + " | " + new DecimalFormat("##.##").format(notExecutedCount/totalCount*100) +"% </p>\n" +
7773
" <br/>\n" +
7874
" <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\">Failed Test Resolutions:</p>\n" +
7975
" <p style=\"margin: 0;color:#e27070;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
8076
" Application Issues | " + appIssues.size() + " </p>\n" +
8177
" <p style=\"margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
82-
" Test Issues | " + (int) failedResults.stream().filter(x -> x.getTest_resolution().getColor() == 2).count() + " </p>\n" +
78+
" Test Issues | " + (int) failed.stream().filter(x -> x.getTest_resolution().getColor() == 2).count() + " </p>\n" +
8379
" <p style=\"margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
84-
" Not Assigned | " + (int) failedResults.stream().filter(x -> x.getTest_resolution().getColor() == 3).count() + " </p>\n" +
80+
" Not Assigned | " + (int) failed.stream().filter(x -> x.getTest_resolution().getColor() == 3).count() + " </p>\n" +
8581
" <p style=\"margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\">\n" +
8682
" Other Issues | " + otherIssues.size() + " </p>\n" +
8783
" <br/>\n" +
88-
overview +
84+
buildIssuesOverview(appIssues) +
8985
" <br/>\n" +
9086
" <hr>\n" +
9187
" <br/>\n" +
@@ -100,15 +96,73 @@ public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) th
10096
" </p>\n" +
10197
"</div>");
10298
email.setRecipients(getProjectMemberRecipients(users));
103-
EmailSettingsDao emailSettingsDao = new EmailSettingsDao();
104-
EmailSettingsDto settings = emailSettingsDao.getAll().get(0);
105-
settings.setPassword(emailSettingsDao.getAdminSecret(settings.getPassword()));
106-
EmailUtil emailUtil = new EmailUtil(settings);
107-
emailUtil.SendHtmlEmail(email.getRecipients(), email.getSubject(), email.getContent());
99+
if(!sendEmail(email)) {
100+
throw new AqualityException("Was not able to send Email!");
101+
}
102+
}
103+
104+
private ProjectDto getProject(Integer id) throws AqualityException {
105+
ProjectDao projectDao = new ProjectDao();
106+
ProjectDto projectDto = new ProjectDto();
107+
projectDto.setId(id);
108+
return projectDao.getEntityById(projectDto);
108109
}
109110

110111
private List<String> getProjectMemberRecipients(List<UserDto> users) {
111112
return users.stream().map(UserDto::getEmail).collect(Collectors.toList());
112113
}
113114

115+
private double getSuccessRate(double passedCount, double totalCount) {
116+
return passedCount/totalCount*100;
117+
}
118+
119+
private List<TestResultDto> getAppIssues(List<TestResultDto> testResults) {
120+
return testResults.stream().filter(x -> x.getTest_resolution().getColor() == 1).collect(Collectors.toList());
121+
}
122+
123+
private List<TestResultDto> getFailedResults(List<TestResultDto> testResults) {
124+
return testResults.stream().filter(x -> x.getFinal_result().getColor() != 5).collect(Collectors.toList());
125+
}
126+
127+
private List<TestResultDto> getOtherIssues(List<TestResultDto> testResults) {
128+
return testResults.stream().filter(x -> x.getTest_resolution().getColor() != 1 && x.getTest_resolution().getColor() != 2 && x.getTest_resolution().getColor() != 3).collect(Collectors.toList());
129+
}
130+
131+
private double getTotalResultsCount(List<TestResultDto> testResults) {
132+
return testResults.size();
133+
}
134+
135+
private double getNotExecutedResultsCount(List<TestResultDto> testResults) {
136+
return (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 3 || x.getFinal_result().getColor() == 2 || x.getFinal_result().getColor() == 4).count();
137+
}
138+
139+
private double getPassedResultsCount(List<TestResultDto> testResults) {
140+
return (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 5).count();
141+
}
142+
143+
private double getFailedResultsCount(List<TestResultDto> testResults) {
144+
return (int) testResults.stream().filter(x -> x.getFinal_result().getColor() == 1).count();
145+
}
146+
147+
private String getRateColor(double successRate) {
148+
return successRate > 85 ? "#009900" : successRate > 65 ? "#ff6601" : "#cc2100";
149+
}
150+
151+
private StringBuilder buildIssuesOverview(List<TestResultDto> appIssues){
152+
StringBuilder overview = new StringBuilder(appIssues.size() > 0 ? " <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\">Application Issues Overview:</p>\n" : "");
153+
154+
for (TestResultDto testResult : appIssues) {
155+
overview
156+
.append(" <p style=\"font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;\">")
157+
.append(testResult.getTest().getName())
158+
.append(": ")
159+
.append(
160+
testResult.getComment() != null
161+
? testResult.getComment()
162+
: "No comment for This Failure.")
163+
.append("</p>\n");
164+
}
165+
166+
return overview;
167+
}
114168
}

0 commit comments

Comments
 (0)