Skip to content

Commit

Permalink
adding constact for variable
Browse files Browse the repository at this point in the history
  • Loading branch information
nvvi committed Nov 1, 2024
1 parent cc73dc8 commit d137676
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@

public class DemoService {
private static final Logger LOG = Ivy.log();
private static final String INBOX = "INBOX";
private static final String USER_PASSWORD_PROVIDER = "userPasswordProvider";
private static final String LOCALHOST_IMAP = "localhost-imap";
private static final String LOCALHOST_IMAP_BASIC_AUTHENTICATION = "localhost-imap-basic-authentication";
private static final String LOCALHOST_IMAP_AZURE_OAUTH2_AUTHENTICATION = "localhost-imap-azure-oauth2-authentication";

public static void handleMessages() throws MessagingException, IOException {
MessageIterator iterator = MailStoreService.messageIterator("localhost-imap", "INBOX", null, false, MailStoreService.subjectMatches(".*test [0-9]+.*"), new MessageComparator());
MessageIterator iterator = MailStoreService.messageIterator(LOCALHOST_IMAP, INBOX, null, false, MailStoreService.subjectMatches(".*test [0-9]+.*"), new MessageComparator());

while (iterator.hasNext()) {
Message message = iterator.next();
Expand Down Expand Up @@ -52,7 +57,7 @@ public static boolean handleMessage(Message message) throws MessagingException,
}

public static void handleMessagesMultiDestinationFolder() throws MessagingException, IOException {
MessageIterator iterator = MailStoreService.messageIterator("localhost-imap", "INBOX", true, MailStoreService.subjectMatches(".*test [0-9]+.*"), new MessageComparator(), Arrays.asList("Processed", "ErrorFolder"));
MessageIterator iterator = MailStoreService.messageIterator(LOCALHOST_IMAP, INBOX, true, MailStoreService.subjectMatches(".*test [0-9]+.*"), new MessageComparator(), Arrays.asList("Processed", "ErrorFolder"));
int runner = 0;

while (iterator.hasNext()) {
Expand All @@ -65,13 +70,11 @@ public static void handleMessagesMultiDestinationFolder() throws MessagingExcept
}

public static void connectMailStoreWithBasicAuth() throws MessagingException, IOException {
String storeName = "localhost-imap-basic-authentication";

// get from variable mailstore-connector.localhost-imap.userPasswordProvider
String authProviderPath = MailStoreService.getVar(storeName, "userPasswordProvider");
initAuthProvider(storeName, authProviderPath);
String authProviderPath = MailStoreService.getVar(LOCALHOST_IMAP_BASIC_AUTHENTICATION, USER_PASSWORD_PROVIDER);
initAuthProvider(LOCALHOST_IMAP_BASIC_AUTHENTICATION, authProviderPath);

MessageIterator iterator = MailStoreService.messageIterator(storeName, "INBOX", null, false, MailStoreService.subjectMatches(".*"), new MessageComparator());
MessageIterator iterator = MailStoreService.messageIterator(LOCALHOST_IMAP_BASIC_AUTHENTICATION, INBOX, null, false, MailStoreService.subjectMatches(".*"), new MessageComparator());

while (iterator.hasNext()) {
Message message = iterator.next();
Expand All @@ -81,13 +84,11 @@ public static void connectMailStoreWithBasicAuth() throws MessagingException, IO
}

public static void connectMailStoreWithAzureOauth2() throws MessagingException, IOException {
String storeName = "localhost-imap-azure-oauth2-authentication";

// get from variable mailstore-connector.localhost-imap.userPasswordProvider
String authProviderPath = MailStoreService.getVar(storeName, "userPasswordProvider");
initAuthProvider(storeName, authProviderPath);
String authProviderPath = MailStoreService.getVar(LOCALHOST_IMAP_AZURE_OAUTH2_AUTHENTICATION, USER_PASSWORD_PROVIDER);
initAuthProvider(LOCALHOST_IMAP_AZURE_OAUTH2_AUTHENTICATION, authProviderPath);

MessageIterator iterator = MailStoreService.messageIterator(storeName, "INBOX", null, false, MailStoreService.subjectMatches(".*"), new MessageComparator());
MessageIterator iterator = MailStoreService.messageIterator(LOCALHOST_IMAP_AZURE_OAUTH2_AUTHENTICATION, INBOX, null, false, MailStoreService.subjectMatches(".*"), new MessageComparator());

while (iterator.hasNext()) {
Message message = iterator.next();
Expand All @@ -98,8 +99,8 @@ public static void connectMailStoreWithAzureOauth2() throws MessagingException,

public static void handleAttachmentMessages() throws MessagingException, IOException {
MessageIterator iterator = MailStoreService.messageIterator(
"localhost-imap",
"INBOX",
LOCALHOST_IMAP,
INBOX,
null,
false,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public static interface FormProperty {
String GRANT_TYPE = "grant_type";
String USERNAME = "username";
String PASSWORD = "password";

}

public static interface ResponseProperty {
String ACCESS_TOKEN = "access_token";
}

/**
Expand Down Expand Up @@ -131,7 +134,7 @@ private String extractToken(Response response) {
GenericType<Map<String, Object>> map = new GenericType<>(Map.class);
Map<String, Object> values = response.readEntity(map);

return Optional.ofNullable(values).map(value -> values.get("access_token").toString()).orElse(null);
return Optional.ofNullable(values).map(value -> values.get(ResponseProperty.ACCESS_TOKEN).toString()).orElse(null);
}

private static enum GrantType {
Expand Down

0 comments on commit d137676

Please sign in to comment.