Skip to content
Snippets Groups Projects
Commit cbf2b73e authored by Lars Johansson's avatar Lars Johansson
Browse files

Fix to send email notifications only when there are changes to notify about

parent e3f12b5e
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
import org.openepics.names.util.NameCommand;
import org.openepics.names.util.StructureCommand;
import org.openepics.names.util.ValidateUtil;
import org.openepics.names.util.notification.NotificationName;
import org.openepics.names.util.notification.NotificationStructure;
import org.openepics.names.util.notification.NotificationUtil;
......@@ -114,6 +115,10 @@ public class NotificationService {
numberUpdated,
numberDeleted));
if (ValidateUtil.areAllZero(numberCreated, numberUpdated, numberDeleted)) {
return;
}
// email content
final Context ctx = new Context();
ctx.setVariable("numberCreated", numberCreated);
......@@ -201,6 +206,10 @@ public class NotificationService {
numberCancelled,
numberRejected));
if (ValidateUtil.areAllZero(numberCreated, numberUpdated, numberDeleted, numberApproved, numberCancelled, numberRejected)) {
return;
}
// email content
final Context ctx = new Context();
ctx.setVariable("numberCreated", numberCreated);
......
......@@ -336,4 +336,23 @@ public class ValidateUtil {
return false;
}
/**
* Validate given ints such that <tt>true</tt> is returned if all ints are zero (0).
* This may be used to validate that given ints are not zero.
*
* @param values values
* @return boolean if validation is ok
*/
public static boolean areAllZero(int... values) {
if (values == null) {
return false;
}
for (int value : values) {
if (value != 0) {
return false;
}
}
return true;
}
}
......@@ -661,6 +661,31 @@ class ValidateUtilTest {
assertEquals(expected, ValidateUtil.isAnyTrue(b1, b2, b3));
}
/**
* Test of validate an array if all ints in array are zero.
*/
@Test
void areAllZero() {
assertFalse(ValidateUtil.areAllZero(null));
assertTrue (ValidateUtil.areAllZero(0));
assertFalse(ValidateUtil.areAllZero(1));
assertTrue (ValidateUtil.areAllZero(0, 0));
assertFalse(ValidateUtil.areAllZero(0, 1));
assertFalse(ValidateUtil.areAllZero(1, 0));
assertFalse(ValidateUtil.areAllZero(1, 1));
assertTrue (ValidateUtil.areAllZero(0, 0, 0));
assertFalse(ValidateUtil.areAllZero(0, 0, 1));
assertFalse(ValidateUtil.areAllZero(0, 1, 0));
assertFalse(ValidateUtil.areAllZero(0, 1, 1));
assertFalse(ValidateUtil.areAllZero(1, 0, 0));
assertFalse(ValidateUtil.areAllZero(1, 0, 1));
assertFalse(ValidateUtil.areAllZero(1, 1, 0));
assertFalse(ValidateUtil.areAllZero(1, 1, 1));
}
// ----------------------------------------------------------------------------------------------------
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment