-
Notifications
You must be signed in to change notification settings - Fork 15
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
Gdpr notifications #48
Open
marcos-lg
wants to merge
13
commits into
master
Choose a base branch
from
gdpr-notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1ddf0c5
Gdpr notification
marcos-lg 6e9ef8d
Merge branch 'master' into gdpr-notifications
marcos-lg 188ab96
required props for gdpr
marcos-lg 4270072
typo in comment
marcos-lg 2f5c8f5
added required properties in tests
marcos-lg f87e280
Gdpr changed to data privacy
marcos-lg a8adcb0
data privacy small refactor
marcos-lg 23c005f
boolean property to string + create db notification only if email sent
marcos-lg e4876d3
logs data privacy
marcos-lg 6429313
urlTemplate for organization changed
marcos-lg e9fbd64
typo
marcos-lg 3e65257
Merge branch 'master' into gdpr-notifications
marcos-lg 4008273
Merge branch 'master' into gdpr-notifications
marcos-lg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
registry-cli/src/main/java/org/gbif/registry/cli/common/MailConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.gbif.registry.cli.common; | ||
|
||
import java.util.Properties; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import com.beust.jcommander.Parameter; | ||
|
||
/** | ||
* Configuration for sending emails. | ||
*/ | ||
@SuppressWarnings("PublicField") | ||
public class MailConfiguration { | ||
|
||
private static final String MAIL_PREFIX = "mail."; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-devmail-enabled") | ||
public String devmailEnabled; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-smtp-host") | ||
public String smtpHost; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-smtp-port") | ||
public String smtpPort; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-devemail") | ||
public String devemail; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-cc") | ||
public String cc; | ||
|
||
@NotNull | ||
@Parameter(names = "--mail-from") | ||
public String from; | ||
|
||
public Properties toMailProperties() { | ||
Properties props = new Properties(); | ||
|
||
props.put(MAIL_PREFIX + "devemail.enabled", this.devmailEnabled); | ||
props.put(MAIL_PREFIX + "smtp.host", this.smtpHost); | ||
props.put(MAIL_PREFIX + "smtp.port", this.smtpPort); | ||
props.put(MAIL_PREFIX + "devemail", this.devemail); | ||
props.put(MAIL_PREFIX + "cc", this.cc); | ||
props.put(MAIL_PREFIX + "from", this.from); | ||
|
||
return props; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...in/java/org/gbif/registry/cli/dataprivacynotification/DataPrivacyNotificationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.gbif.registry.cli.dataprivacynotification; | ||
|
||
import org.gbif.cli.Command; | ||
import org.gbif.cli.service.ServiceCommand; | ||
|
||
import com.google.common.util.concurrent.Service; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
@MetaInfServices(Command.class) | ||
public class DataPrivacyNotificationCommand extends ServiceCommand { | ||
|
||
private final DataPrivacyNotificationConfiguration configuration = new DataPrivacyNotificationConfiguration(); | ||
|
||
public DataPrivacyNotificationCommand() { | ||
super("data-privacy-notification"); | ||
} | ||
|
||
@Override | ||
protected Service getService() { | ||
return new DataPrivacyNotificationService(configuration); | ||
} | ||
|
||
@Override | ||
protected Object getConfigurationObject() { | ||
return configuration; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...a/org/gbif/registry/cli/dataprivacynotification/DataPrivacyNotificationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.gbif.registry.cli.dataprivacynotification; | ||
|
||
import org.gbif.common.messaging.config.MessagingConfiguration; | ||
import org.gbif.registry.cli.common.DbConfiguration; | ||
import org.gbif.registry.cli.common.MailConfiguration; | ||
|
||
import java.util.Properties; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.ParametersDelegate; | ||
import com.google.common.base.Objects; | ||
|
||
@SuppressWarnings("PublicField") | ||
public class DataPrivacyNotificationConfiguration { | ||
|
||
@ParametersDelegate | ||
@NotNull | ||
@Valid | ||
public MessagingConfiguration messaging = new MessagingConfiguration(); | ||
|
||
@ParametersDelegate | ||
@Valid | ||
@NotNull | ||
public DbConfiguration registry = new DbConfiguration(); | ||
|
||
@ParametersDelegate | ||
@NotNull | ||
@Valid | ||
public MailConfiguration mailConfig = new MailConfiguration(); | ||
|
||
@ParametersDelegate | ||
@NotNull | ||
@Valid | ||
public DataPrivacyConfiguration dataPrivacyConfig = new DataPrivacyConfiguration(); | ||
|
||
@Parameter(names = "--queue-name") | ||
@NotNull | ||
public String queueName; | ||
|
||
@Override | ||
public String toString() { | ||
return Objects.toStringHelper(this) | ||
.add("queueName", queueName) | ||
.add("messaging", messaging) | ||
.add("registry.serverName", registry.serverName) | ||
.add("registry.databaseName", registry.databaseName) | ||
.add("registry.user", registry.user) | ||
.add("registry.password", registry.password) | ||
.add("registry.maximumPoolSize", registry.maximumPoolSize) | ||
.add("registry.connectionTimeout", registry.connectionTimeout) | ||
.toString(); | ||
} | ||
|
||
/** | ||
* Data privacy specific configuration. | ||
*/ | ||
public static class DataPrivacyConfiguration { | ||
|
||
private static final String URL_TEMPLATE_PROP_PREFIX = "urlTemplate."; | ||
private static final String DATA_PRIVACY_PREFIX = "dataPrivacy."; | ||
private static final String MAIL_PREFIX = DATA_PRIVACY_PREFIX + "surety.mail."; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-version") | ||
public String dataPrivacyVersion; | ||
|
||
@Parameter(names = "--dataPrivacy-mail-enabled") | ||
public boolean mailEnabled = false; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-subject") | ||
public String subject; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-infoPage") | ||
public String informationPage; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-node-urlTemplate") | ||
public String nodeUrlTemplate; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-organization-urlTemplate") | ||
public String organizationUrlTemplate; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-installation-urlTemplate") | ||
public String installationUrlTemplate; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-network-urlTemplate") | ||
public String networkUrlTemplate; | ||
|
||
@NotNull | ||
@Parameter(names = "--dataPrivacy-dataset-urlTemplate") | ||
public String datasetUrlTemplate; | ||
|
||
public Properties toProperties() { | ||
Properties props = new Properties(); | ||
|
||
props.put(DATA_PRIVACY_PREFIX + "version", this.dataPrivacyVersion); | ||
props.put(MAIL_PREFIX + "enabled", String.valueOf(this.mailEnabled)); | ||
props.put(MAIL_PREFIX + "subject", this.subject); | ||
props.put(MAIL_PREFIX + "informationPage", this.informationPage); | ||
props.put(MAIL_PREFIX + URL_TEMPLATE_PROP_PREFIX + "node", this.nodeUrlTemplate); | ||
props.put(MAIL_PREFIX + URL_TEMPLATE_PROP_PREFIX + "organization", this.organizationUrlTemplate); | ||
props.put(MAIL_PREFIX + URL_TEMPLATE_PROP_PREFIX + "installation", this.installationUrlTemplate); | ||
props.put(MAIL_PREFIX + URL_TEMPLATE_PROP_PREFIX + "network", this.networkUrlTemplate); | ||
props.put(MAIL_PREFIX + URL_TEMPLATE_PROP_PREFIX + "dataset", this.datasetUrlTemplate); | ||
|
||
return props; | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...n/java/org/gbif/registry/cli/dataprivacynotification/DataPrivacyNotificationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.gbif.registry.cli.dataprivacynotification; | ||
|
||
import org.gbif.common.messaging.AbstractMessageCallback; | ||
import org.gbif.common.messaging.api.messages.DataPrivacyNotificationMessage; | ||
import org.gbif.registry.dataprivacy.DataPrivacyService; | ||
import org.gbif.registry.dataprivacy.email.DataPrivacyEmailManager; | ||
|
||
import java.util.Objects; | ||
|
||
import com.google.inject.Injector; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DataPrivacyNotificationListener extends AbstractMessageCallback<DataPrivacyNotificationMessage> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataPrivacyNotificationListener.class); | ||
|
||
private final DataPrivacyNotificationConfiguration config; | ||
private final DataPrivacyService dataPrivacyService; | ||
private final DataPrivacyEmailManager dataPrivacyEmailManager; | ||
|
||
private DataPrivacyNotificationListener(DataPrivacyNotificationConfiguration config) { | ||
this.config = config; | ||
Injector inj = new DataPrivacyNotificationModule(config).getInjector(); | ||
dataPrivacyService = inj.getInstance(DataPrivacyService.class); | ||
dataPrivacyEmailManager = inj.getInstance(DataPrivacyEmailManager.class); | ||
} | ||
|
||
static DataPrivacyNotificationListener newInstance(DataPrivacyNotificationConfiguration config) { | ||
return new DataPrivacyNotificationListener(config); | ||
} | ||
|
||
@Override | ||
public void handleMessage(DataPrivacyNotificationMessage dataPrivacyNotificationMessage) { | ||
if (!config.dataPrivacyConfig.mailEnabled) { | ||
LOG.info("Data privacy email notifications disabled"); | ||
return; | ||
} | ||
|
||
Objects.requireNonNull(dataPrivacyNotificationMessage.getEmail()); | ||
|
||
// double check that the email was not sent | ||
if (dataPrivacyService.existsNotification(dataPrivacyNotificationMessage.getEmail(), | ||
dataPrivacyNotificationMessage.getVersion())) { | ||
// email already sent | ||
LOG.info("Data privacy email notification was already sent before for {} - skipped", | ||
dataPrivacyNotificationMessage.getEmail()); | ||
return; | ||
} | ||
|
||
// send email | ||
boolean sent = dataPrivacyEmailManager.sendDataPrivacyNotification(dataPrivacyNotificationMessage.getEmail(), | ||
dataPrivacyNotificationMessage.getContext()); | ||
|
||
// create notification in DB | ||
if (sent) { | ||
LOG.info("Data privacy email sent to {}", dataPrivacyNotificationMessage.getEmail()); | ||
dataPrivacyService.createNotification(dataPrivacyNotificationMessage.getEmail(), | ||
dataPrivacyNotificationMessage.getVersion(), | ||
dataPrivacyNotificationMessage.getContext()); | ||
} | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ain/java/org/gbif/registry/cli/dataprivacynotification/DataPrivacyNotificationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gbif.registry.cli.dataprivacynotification; | ||
|
||
import org.gbif.registry.dataprivacy.DataPrivacyModule; | ||
import org.gbif.registry.dataprivacy.email.DataPrivacyEmailModule; | ||
import org.gbif.registry.persistence.guice.RegistryMyBatisModule; | ||
import org.gbif.registry.surety.email.EmailManagerModule; | ||
import org.gbif.ws.client.guice.GbifApplicationAuthModule; | ||
|
||
import java.util.Properties; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
/** | ||
* Guice module for data privacy notifications that adds all the necessary modules. | ||
*/ | ||
public class DataPrivacyNotificationModule { | ||
|
||
private final DataPrivacyNotificationConfiguration config; | ||
|
||
public DataPrivacyNotificationModule(DataPrivacyNotificationConfiguration config) { | ||
this.config = config; | ||
} | ||
|
||
public Injector getInjector() { | ||
Properties dataPrivacyProperties = config.dataPrivacyConfig.toProperties(); | ||
|
||
return Guice.createInjector(new RegistryMyBatisModule(config.registry.toRegistryProperties()), | ||
new GbifApplicationAuthModule(config.registry.user, config.registry.password), | ||
new DataPrivacyModule(dataPrivacyProperties), | ||
new DataPrivacyEmailModule(dataPrivacyProperties), | ||
new EmailManagerModule(config.mailConfig.toMailProperties())); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...in/java/org/gbif/registry/cli/dataprivacynotification/DataPrivacyNotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.gbif.registry.cli.dataprivacynotification; | ||
|
||
import org.gbif.common.messaging.MessageListener; | ||
|
||
import com.google.common.util.concurrent.AbstractIdleService; | ||
|
||
public class DataPrivacyNotificationService extends AbstractIdleService { | ||
|
||
// we use a pool size of 1 in order to avoid race conditions when consulting the DB. | ||
private static final int POOL_SIZE = 1; | ||
|
||
private final DataPrivacyNotificationConfiguration configuration; | ||
private MessageListener listener; | ||
|
||
public DataPrivacyNotificationService(DataPrivacyNotificationConfiguration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
protected void startUp() throws Exception { | ||
listener = new MessageListener(configuration.messaging.getConnectionParameters()); | ||
listener.listen(configuration.queueName, POOL_SIZE, DataPrivacyNotificationListener.newInstance(configuration)); | ||
} | ||
|
||
@Override | ||
protected void shutDown() throws Exception { | ||
if (listener != null) { | ||
listener.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
registry-liquibase/src/main/resources/liquibase/053-add-data-privacy-notification-table.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"> | ||
|
||
<changeSet id="53" author="mlopez" runInTransaction="false"> | ||
<sql splitStatements="false" stripComments="false"> | ||
CREATE TABLE data_privacy_notification ( | ||
email varchar(254) CHECK (assert_min_length(email, 5)) NOT NULL, | ||
version char(1) CHECK (assert_min_length(version, 1)) NOT NULL, | ||
timestamp_sent timestamp with time zone NOT NULL DEFAULT now(), | ||
context hstore, | ||
PRIMARY KEY (email, version) | ||
); | ||
</sql> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused