Skip to content

Commit

Permalink
Remove dependency to commons.lang for Cloud Service
Browse files Browse the repository at this point in the history
  • Loading branch information
cziegeler committed Sep 3, 2024
1 parent 3589f22 commit a1db215
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 13 deletions.
8 changes: 0 additions & 8 deletions bundle-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle
<scope>provided</scope>
</dependency>
<!-- Start Test dependencies -->
<dependency>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons-bundle</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2024 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.email.impl;

import java.io.IOException;
import java.util.Map;

import javax.mail.MessagingException;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.osgi.service.component.annotations.Component;

import com.day.cq.commons.mail.MailTemplate;

@Component(service = MailTemplateManager.class)
public class MailTemplateManagerImpl implements MailTemplateManager {

@Override
public <T extends Email> T getEmail(final MailTemplate template,
final Map<String, String> params,
final Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(params, mailType);
}
}
6 changes: 6 additions & 0 deletions bundle-onprem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Fragment-Host: com.adobe.acs.acs-aem-commons-bundle
<dependencies>
<!-- ======================== -->
<!-- START build dependencies -->
<dependency>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons-bundle</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2024 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.email.impl;

import java.io.IOException;
import java.util.Map;

import javax.mail.MessagingException;

import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.osgi.service.component.annotations.Component;

import com.day.cq.commons.mail.MailTemplate;

@Component(service = MailTemplateManager.class)
public class MailTemplateManagerImpl implements MailTemplateManager {

@Override
public <T extends Email> T getEmail(final MailTemplate template,
final Map<String, String> params,
final Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.day.cq.commons.mail.MailTemplate;
import com.day.cq.mailer.MessageGateway;
import com.day.cq.mailer.MessageGatewayService;
import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
Expand Down Expand Up @@ -79,6 +78,9 @@ public final class EmailServiceImpl implements EmailService {
@Reference
private ResourceResolverFactory resourceResolverFactory;

@Reference
private MailTemplateManager mailTemplateManager;

public static final int DEFAULT_CONNECT_TIMEOUT = 30000;

public static final int DEFAULT_SOCKET_TIMEOUT = 30000;
Expand Down Expand Up @@ -229,7 +231,7 @@ private Email getEmail(final MailTemplate mailTemplate,
final Class<? extends Email> mailType,
final Map<String, String> params) throws EmailException, MessagingException, IOException {

final Email email = mailTemplate.getEmail(StrLookup.mapLookup(params), mailType);
final Email email = mailTemplateManager.getEmail(mailTemplate, params, mailType);

if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)
&& params.containsKey(EmailServiceConstants.SENDER_NAME)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* ACS AEM Commons
*
* Copyright (C) 2024 Adobe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.adobe.acs.commons.email.impl;

import java.io.IOException;
import java.util.Map;

import javax.mail.MessagingException;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;

import com.day.cq.commons.mail.MailTemplate;

public interface MailTemplateManager {

<T extends Email> T getEmail(MailTemplate template, final Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package com.adobe.acs.commons.hc.impl;

import com.adobe.acs.commons.email.impl.MailTemplateManager;
import com.adobe.acs.commons.util.RequireAem;
import com.day.cq.commons.mail.MailTemplate;
import com.day.cq.mailer.MessageGateway;
import com.day.cq.mailer.MessageGatewayService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.mail.SimpleEmail;
import org.apache.felix.scr.annotations.Activate;
Expand Down Expand Up @@ -112,6 +112,9 @@ public class SMTPMailServiceHealthCheck implements HealthCheck {
@Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policyOption = ReferencePolicyOption.GREEDY)
private MessageGatewayService messageGatewayService;

@Reference
private MailTemplateManager mailTemplateManager;

private transient ConcurrentHashMap<String, Integer> tracker = new ConcurrentHashMap<>();

@Activate
Expand Down Expand Up @@ -145,7 +148,7 @@ public Result execute() {
List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>();
emailAddresses.add(new InternetAddress(this.toEmail));
MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE, "UTF-8"), CharEncoding.UTF_8);
SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()), SimpleEmail.class);
SimpleEmail email = mailTemplateManager.getEmail(mailTemplate, null, SimpleEmail.class);

email.setSubject("AEM E-mail Service Health Check");
email.setTo(emailAddresses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
*/
package com.adobe.acs.commons.email.impl;

import com.day.cq.commons.mail.MailTemplate;
import com.day.cq.mailer.MessageGateway;
import com.day.cq.mailer.MessageGatewayService;
import junitx.util.PrivateAccessor;

import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.mail.ByteArrayDataSource;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
Expand All @@ -37,7 +42,10 @@
import org.mockito.junit.MockitoJUnitRunner;

import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -85,6 +93,13 @@ public final void setUp() throws Exception {
when(messageGatewayService.getGateway(HtmlEmail.class)).thenReturn(messageGatewayHtmlEmail);

context.registerService(MessageGatewayService.class, messageGatewayService);
context.registerService(MailTemplateManager.class, new MailTemplateManager() {
@Override
public <T extends Email> T getEmail(MailTemplate template, Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType) ;
}
});
context.registerInjectActivateService(emailService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;

import java.io.IOException;
import java.util.Map;

import javax.mail.MessagingException;

import com.adobe.acs.commons.email.impl.MailTemplateManager;
import com.adobe.acs.commons.util.RequireAem;
import com.adobe.acs.commons.util.impl.RequireAemImpl;
import com.day.cq.commons.mail.MailTemplate;
import com.day.cq.mailer.MessageGateway;
import com.day.cq.mailer.MessageGatewayService;

import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.apache.poi.ss.formula.functions.T;
import org.apache.sling.hc.api.HealthCheck;
import org.apache.sling.hc.api.Result;
import org.junit.Before;
Expand All @@ -52,6 +63,13 @@ public class SMTPMailServiceHealthCheckTest {
public void setUp() {
ctx.registerService(RequireAem.class, new RequireAemImpl(), "distribution", "classic");
ctx.registerService(MessageGatewayService.class, messageGatewayService);
ctx.registerService(MailTemplateManager.class, new MailTemplateManager() {
@Override
public <T extends Email> T getEmail(MailTemplate template, Map<String, String> params, Class<T> mailType)
throws IOException, EmailException, MessagingException {
return template.getEmail(StrLookup.mapLookup(params), mailType) ;
}
});
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<!-- the minimum AEM 6.5 version being supported -->
<aem.classic.api.version>6.5.10.0002</aem.classic.api.version>
<!-- the minimum AEMaaCS version being supported -->
<aem.sdk.api.version>2023.11.14227.20231108T162349Z-231100</aem.sdk.api.version>
<aem.sdk.api.version>2024.8.17569.20240822T203847Z-240700</aem.sdk.api.version>

<jacoco.version>0.8.11</jacoco.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version> <!-- >= 5.x requires Java 11 -->
Expand Down

0 comments on commit a1db215

Please sign in to comment.