diff --git a/CONFIGURATION.md b/CONFIGURATION.md index f167e222d345095983f8047a80e218ee9f070c9a..f9902829c30320e2841bc85385858bd9651b9690 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -15,6 +15,7 @@ Configuration may be set using SpringBoot's configuration file (`application.pro | NAMING_LOGGING_STACKTRACE_LENGTH | 20 | max number of stack trace elements to log, negative value will log entire stack trace | | NAMING_MAIL_ADMINISTRATOR | | comma-separated list of administrator email addresses | | NAMING_MAIL_NOTIFICATION | false | true/false if mail notications are to be sent | +| NAMING_MAIL_NOTIFICATION_NAMES | | comma-separated list of email addresses to which to send notications about changes for names | | NAMING_NOTIFY_SCHEDULE | 0 0 5 * * * | schedule for notification job, cron expression with six or seven fields to describe individual details of the schedule | | NAMING_SMTP_HOST | mail.esss.lu.se | DNS name of server that accepts connections for SMTP | | NAMING_SMTP_PORT | 587 | port to use for SMTP, 587 for SMTP Secure | diff --git a/docker-compose-integrationtest.yml b/docker-compose-integrationtest.yml index e5969840658a7d67fcd07d130e482bbc3ce90132..ac8741a2ebb99586b55a626b6ec75d766985591f 100644 --- a/docker-compose-integrationtest.yml +++ b/docker-compose-integrationtest.yml @@ -49,6 +49,7 @@ services: - ./src/main/resources/db/migration/V4__Schema_data_migration.sql:/docker-entrypoint-initdb.d/V4__Schema_data_migration.sql - ./src/main/resources/db/migration/V5.2__Data_transformation_status_deleted.sql:/docker-entrypoint-initdb.d/V5.2__Data_transformation_status_deleted.sql - ./src/main/resources/db/migration/V6.2__Schema_data_migration_audit.sql:/docker-entrypoint-initdb.d/V6.2__Schema_data_migration_audit.sql + - ./src/main/resources/db/migration/V7__Remove_user_notification_cc_list.sql:/docker-entrypoint-initdb.d/V7__Remove_user_notification_cc_list.sql volumes: naming-data: diff --git a/docs/todo_for_first_releases.txt b/docs/todo_for_first_releases.txt index 397b2658ddeda7ccf26b2ae6857685c771030632..988be37787cb8f63546a6b8bdb542acd02e1d77a 100644 --- a/docs/todo_for_first_releases.txt +++ b/docs/todo_for_first_releases.txt @@ -174,7 +174,6 @@ Note subsystem system systemgroup - user_notification other related to wip tables -- see also V4__Schema_data_migration.sql indices @@ -184,6 +183,11 @@ Note 6. flyway - introduce 6.1 possibly use existing table flyway_schema_history or create a new table 6.2 introduce flyway and make use of new migration script V1__*.sql - see 5.1 - decide on flyway table + 6.3 update integration tests accordingly + docker-compose-integrationtest.yml + postgres: + volumes: + - ./src/main/resources/db/migration/V1__*.sql:/docker-entrypoint-initdb.d/V1__*.sql 7. release - release & deploy 8. post - open & use 8.1 open Naming (new) diff --git a/src/main/java/org/openepics/names/service/NotificationService.java b/src/main/java/org/openepics/names/service/NotificationService.java index fc6213460319a725f6a18f5ecba156060af38bc2..a0fde73c11f130001c28bf4826347bd55a0ce009 100644 --- a/src/main/java/org/openepics/names/service/NotificationService.java +++ b/src/main/java/org/openepics/names/service/NotificationService.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.compress.utils.Lists; import org.openepics.names.util.NameCommand; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.ValidateUtil; @@ -60,10 +60,13 @@ public class NotificationService { private static final String ADD_FOOTER = "addfooter"; private static final String BACKEND_URL = "backendurl"; - private static final String COMMA = ","; @Value("${naming.mail.administrator}") - String namingMailAdministrator; + List<String> namingMailAdministrator; + @Value("${naming.mail.notification.names}") + List<String> namingMailNotificationNames; + @Value("${naming.mail.notification.structures}") + List<String> namingMailNotificationStructures; @Value("${naming.swagger.url}") String namingSwaggerUrl; @@ -76,7 +79,7 @@ public class NotificationService { } /** - * Send notifications for names to affected users and administrators by email. + * Send notifications for names to administrators and affected users by email. * * @param notifications list of name notifications * @param nameCommand name command @@ -92,7 +95,7 @@ public class NotificationService { } /** - * Send notifications for names to affected users and administrators by email. + * Send notifications for names to administrators and affected users by email. * * @param created list of notifications for created names * @param updated list of notifications for updated names @@ -134,19 +137,27 @@ public class NotificationService { ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); + // email addresses for notification + // administrators + // set of users - about changes for names + List<String> toEmailAddresses = Lists.newArrayList(); + if (!namingMailAdministrator.isEmpty()) { + toEmailAddresses.addAll(namingMailAdministrator); + } + if (!namingMailNotificationNames.isEmpty()) { + toEmailAddresses.addAll(namingMailNotificationNames); + } + // send notification - String[] toEmailAddresses = !StringUtils.isEmpty(namingMailAdministrator) - ? namingMailAdministrator.split(COMMA) - : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; String subject = CHANGES_NOTIFICATION_NAMES + " - " + namingSwaggerUrl; - mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, + mailService.sendEmail(toEmailAddresses.toArray(new String[0]), ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_names.html", ctx), false, null, null); } /** - * Send notifications for structures to affected users and administrators by email. + * Send notifications for structures to administrators and affected users by email. * * @param notifications list of structure notifications * @param structureCommand structure command @@ -162,7 +173,7 @@ public class NotificationService { } /** - * Send notifications for structures to affected users and administrators by email. + * Send notifications for structures to administrators and affected users by email. * * @param created list of notifications for created structures * @param updated list of notifications for updated structures @@ -204,14 +215,22 @@ public class NotificationService { ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); + // email addresses for notification + // administrators + // set of users - about changes for structures + List<String> toEmailAddresses = Lists.newArrayList(); + if (!namingMailAdministrator.isEmpty()) { + toEmailAddresses.addAll(namingMailAdministrator); + } + if (!namingMailNotificationStructures.isEmpty()) { + toEmailAddresses.addAll(namingMailNotificationStructures); + } + // send notification - String[] toEmailAddresses = !StringUtils.isEmpty(namingMailAdministrator) - ? namingMailAdministrator.split(COMMA) - : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; String subject = CHANGES_NOTIFICATION_STRUCTURES + " - " + namingSwaggerUrl; - mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, + mailService.sendEmail(toEmailAddresses.toArray(new String[0]), ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_structures.html", ctx), false, null, null); } diff --git a/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java b/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java index ccebc8d047080956354cfbe67ddaad0be95b17e3..1d99d0e9ba85258acf4dd013d214353eda6c66d2 100644 --- a/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java +++ b/src/main/java/org/openepics/names/util/notification/NotificationScheduler.java @@ -66,24 +66,23 @@ public class NotificationScheduler { } /** - * Notify administrators about changes for names and structures. + * Notify administrators and affected users about changes for names and structures. * Intention is to inform about changes for names (create, update, delete). * It is to be checked once a day, and notifications to be generated with emails. - * Emails is to have limited size of entries and another email is to be generated with if size is greater than limit. * * <br/><br/> * Scheduling is handled with cron expression. */ @Scheduled(cron = "${naming.notify.schedule}") - public void notifyAdministrators() { - notifyAdministratorsForNames(); + public void notifyForNames() { + prepareAndNotifyForNames(); } /** * Find out which names that are created, updated or deleted the previous day - * and send notification to administrators for those names. + * and send notification to administrators and affected users for those names. */ - private void notifyAdministratorsForNames() { + private void prepareAndNotifyForNames() { // prepare // find names for previous day // find changes for names diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 96d6f369a1434179f8c1060a66ea7e2360f12d4c..7655d823cc097f1c3522300c22f53f23f814f69f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,11 +18,14 @@ logging.level.org.hibernate.SQL=INFO spring.http.log-request-details=true # mail, notification -# administrator mail is comma-separated list of email addresses +# administrator mail - comma-separated list of email addresses +# notification mail - comma-separated list of email addresses # notification job scheduled at 5 am every day by default naming.notify.schedule=${NAMING_NOTIFY_SCHEDULE:0 0 5 * * *} naming.mail.administrator=${NAMING_MAIL_ADMINISTRATOR:} naming.mail.notification=${NAMING_MAIL_NOTIFICATION:false} +naming.mail.notification.names=${NAMING_MAIL_NOTIFICATION_NAMES:} +naming.mail.notification.structures=${NAMING_MAIL_NOTIFICATION_STRUCTURES:} naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu} naming.smtp.host=${NAMING_SMTP_HOST:mail.esss.lu.se} naming.smtp.port=${NAMING_SMTP_PORT:587} diff --git a/src/main/resources/db/migration/V7__Remove_user_notification_cc_list.sql b/src/main/resources/db/migration/V7__Remove_user_notification_cc_list.sql new file mode 100644 index 0000000000000000000000000000000000000000..b5f30ef212f30de7b9b28eac02450ce18d578673 --- /dev/null +++ b/src/main/resources/db/migration/V7__Remove_user_notification_cc_list.sql @@ -0,0 +1,18 @@ +-- ---------------------------------------------------------------------------------------------------- +-- About +-- migration script +-- postgresql 9.6.7 +-- Content +-- user notification table +-- Note +-- remove table as it is no longer used +-- users to which to send notifications to be handled by configuration +-- ---------------------------------------------------------------------------------------------------- + +-- ---------------------------------------------------------------------------------------------------- +-- user notification +-- ---------------------------------------------------------------------------------------------------- +ALTER TABLE ONLY user_notification + DROP CONSTRAINT user_notification_pk; + +DROP TABLE user_notification; diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 5370eee31767f7d0c5e2d841e639caa6a3750a59..fc49f4c13c7a21160da0ed3b37bbbb9a41703334 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -18,11 +18,14 @@ logging.level.org.hibernate.SQL=INFO spring.http.log-request-details=true # mail, notification -# administrator mail is comma-separated list of email addresses +# administrator mail - comma-separated list of email addresses +# notification mail - comma-separated list of email addresses # notification job scheduled at 5 am every day by default naming.notify.schedule=${NAMING_NOTIFY_SCHEDULE:0 0 5 * * *} naming.mail.administrator=${NAMING_MAIL_ADMINISTRATOR:} naming.mail.notification=${NAMING_MAIL_NOTIFICATION:false} +naming.mail.notification.names=${NAMING_MAIL_NOTIFICATION_NAMES:} +naming.mail.notification.structures=${NAMING_MAIL_NOTIFICATION_STRUCTURES:} naming.mail.from=${NAMING_MAIL_FROM:jboss@ess.eu} naming.smtp.host=${NAMING_SMTP_HOST:mail.esss.lu.se} naming.smtp.port=${NAMING_SMTP_PORT:587} diff --git a/src/test/resources/data/db/dump-discs_names_namesit.sql b/src/test/resources/data/db/dump-discs_names_namesit.sql index bc35e38546ac00603551f048128e9e3345fbb99e..657ca34b15ce73d5e03d36a89d6647b07336c8f6 100644 --- a/src/test/resources/data/db/dump-discs_names_namesit.sql +++ b/src/test/resources/data/db/dump-discs_names_namesit.sql @@ -738,40 +738,6 @@ CREATE SEQUENCE public.systemgroup_id_seq ALTER SEQUENCE public.systemgroup_id_seq OWNED BY public.systemgroup.id; --- --- TOC entry 198 (class 1259 OID 16488) --- Name: user_notification; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.user_notification ( - id bigint NOT NULL, - notification_type character varying(32) NOT NULL, - user_login_name character varying(32) NOT NULL -); - - --- --- TOC entry 197 (class 1259 OID 16486) --- Name: user_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.user_notification_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 2364 (class 0 OID 0) --- Dependencies: 197 --- Name: user_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.user_notification_id_seq OWNED BY public.user_notification.id; - - -- -- TOC entry 195 (class 1259 OID 16420) -- Name: useraccount; Type: TABLE; Schema: public; Owner: - @@ -903,14 +869,6 @@ ALTER TABLE ONLY public.system ALTER COLUMN id SET DEFAULT nextval('public.syste ALTER TABLE ONLY public.systemgroup ALTER COLUMN id SET DEFAULT nextval('public.systemgroup_id_seq'::regclass); --- --- TOC entry 2107 (class 2604 OID 16491) --- Name: user_notification id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_notification ALTER COLUMN id SET DEFAULT nextval('public.user_notification_id_seq'::regclass); - - -- -- TOC entry 2106 (class 2604 OID 16433) -- Name: useraccount id; Type: DEFAULT; Schema: public; Owner: - @@ -1175,25 +1133,6 @@ COPY public.systemgroup (id, version, uuid, mnemonic, mnemonic_equivalence, orde SELECT pg_catalog.setval('public.systemgroup_id_seq', 1, true); --- --- TOC entry 2331 (class 0 OID 16488) --- Dependencies: 198 --- Data for Name: user_notification; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.user_notification (id, notification_type, user_login_name) FROM stdin; -\. - - --- --- TOC entry 2378 (class 0 OID 0) --- Dependencies: 197 --- Name: user_notification_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - --- - -SELECT pg_catalog.setval('public.user_notification_id_seq', 1, false); - - -- -- TOC entry 2328 (class 0 OID 16420) -- Dependencies: 195 @@ -1321,15 +1260,6 @@ ALTER TABLE ONLY public.systemgroup ADD CONSTRAINT systemgroup_pk PRIMARY KEY (id); --- --- TOC entry 2128 (class 2606 OID 16493) --- Name: user_notification user_notification_pk; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_notification - ADD CONSTRAINT user_notification_pk PRIMARY KEY (id); - - -- -- TOC entry 2126 (class 2606 OID 16445) -- Name: useraccount useraccount_pkey; Type: CONSTRAINT; Schema: public; Owner: - diff --git a/src/test/resources/data/db/dump-discs_names_subsystemit.sql b/src/test/resources/data/db/dump-discs_names_subsystemit.sql index f6d4332907fd3d20a1041ee8acb7d4a12f4ff1f4..acb1697350542097e12871ac5e89230400905d94 100644 --- a/src/test/resources/data/db/dump-discs_names_subsystemit.sql +++ b/src/test/resources/data/db/dump-discs_names_subsystemit.sql @@ -738,40 +738,6 @@ CREATE SEQUENCE public.systemgroup_id_seq ALTER SEQUENCE public.systemgroup_id_seq OWNED BY public.systemgroup.id; --- --- TOC entry 198 (class 1259 OID 16488) --- Name: user_notification; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.user_notification ( - id bigint NOT NULL, - notification_type character varying(32) NOT NULL, - user_login_name character varying(32) NOT NULL -); - - --- --- TOC entry 197 (class 1259 OID 16486) --- Name: user_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.user_notification_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 2364 (class 0 OID 0) --- Dependencies: 197 --- Name: user_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.user_notification_id_seq OWNED BY public.user_notification.id; - - -- -- TOC entry 195 (class 1259 OID 16420) -- Name: useraccount; Type: TABLE; Schema: public; Owner: - @@ -903,14 +869,6 @@ ALTER TABLE ONLY public.system ALTER COLUMN id SET DEFAULT nextval('public.syste ALTER TABLE ONLY public.systemgroup ALTER COLUMN id SET DEFAULT nextval('public.systemgroup_id_seq'::regclass); --- --- TOC entry 2107 (class 2604 OID 16491) --- Name: user_notification id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_notification ALTER COLUMN id SET DEFAULT nextval('public.user_notification_id_seq'::regclass); - - -- -- TOC entry 2106 (class 2604 OID 16433) -- Name: useraccount id; Type: DEFAULT; Schema: public; Owner: - @@ -1282,25 +1240,6 @@ COPY public.systemgroup (id, version, uuid, mnemonic, mnemonic_equivalence, orde SELECT pg_catalog.setval('public.systemgroup_id_seq', 1, true); --- --- TOC entry 2331 (class 0 OID 16488) --- Dependencies: 198 --- Data for Name: user_notification; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.user_notification (id, notification_type, user_login_name) FROM stdin; -\. - - --- --- TOC entry 2378 (class 0 OID 0) --- Dependencies: 197 --- Name: user_notification_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - --- - -SELECT pg_catalog.setval('public.user_notification_id_seq', 1, false); - - -- -- TOC entry 2328 (class 0 OID 16420) -- Dependencies: 195 @@ -1428,15 +1367,6 @@ ALTER TABLE ONLY public.systemgroup ADD CONSTRAINT systemgroup_pk PRIMARY KEY (id); --- --- TOC entry 2128 (class 2606 OID 16493) --- Name: user_notification user_notification_pk; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_notification - ADD CONSTRAINT user_notification_pk PRIMARY KEY (id); - - -- -- TOC entry 2126 (class 2606 OID 16445) -- Name: useraccount useraccount_pkey; Type: CONSTRAINT; Schema: public; Owner: -