Skip to content

Commit

Permalink
EmailNotifications scaffolding with MailJet
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 19, 2022
1 parent fe71c44 commit 817c479
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
50 changes: 50 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/EmailNotification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2020-2022, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.api;

/**
* E-mail notification in Self XDSD.
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 0.0.99
*/
public interface EmailNotification {

/**
* Destination e-mail address.
* @return String.
*/
String to();

/**
* Subect text.
* @return String.
*/
String subject();

/**
* Text body.
* @return String.
*/
String body();
}
38 changes: 38 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/EmailNotifications.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2020-2022, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.api;

/**
* E-mail notifications in Self XDSD.
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 0.0.99
*/
public interface EmailNotifications {

/**
* Send a notification.
* @param emailNotification - Notification to send.
*/
void send(final EmailNotification emailNotification);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2020-2022, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core;

import com.selfxdsd.api.EmailNotification;
import com.selfxdsd.api.EmailNotifications;

/**
* Using MailJet to send e-mail notifications.
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 0.0.99
*/
public final class MailjetEmailNotifications implements EmailNotifications {

/**
* API Public Key (username).
*/
private final String apiKey;

/**
* API Private Key (password).
*/
private final String apiSecretKey;

/**
* Ctor.
* @param apiKey MailJet's API Key.
* @param apiSecretKey MailJet's API Secret Key.
*/
public MailjetEmailNotifications(
final String apiKey,
final String apiSecretKey
) {
this.apiKey = apiKey;
this.apiSecretKey = apiSecretKey;
}

@Override
public void send(final EmailNotification emailNotification) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.selfxdsd.core;

import com.selfxdsd.api.EmailNotification;
import com.selfxdsd.api.PlatformInvoice;

/**
* E-mail sent to the admin of Self XDSD when a PlatformInvoice is generated.
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 0.0.99
*/
final class PlatformInvoiceEmailNotification implements EmailNotification {

private final PlatformInvoice platformInvoice;

PlatformInvoiceEmailNotification(final PlatformInvoice platformInvoice) {
this.platformInvoice = platformInvoice;
}

@Override
public String to() {
return "[email protected]";
}

@Override
public String subject() {
return "[Self XDSD] New Platform Invoice " +
"(ID: " + this.platformInvoice.id() + ")";
}

@Override
public String body() {
return "New platform invoice (id is " + this.platformInvoice.id() +
") registered at " + this.platformInvoice.createdAt();
}
}

1 comment on commit 817c479

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've opened the Issues [#1298, #1299] for the newly added to-dos.

The to-dos may have been added in an earlier commit, but I've found them just now.

Please sign in to comment.