Email notification - unwanted UI dependencies

I’m working on a multi-module application consisting two jmix applications and a custom addon used by the two of them.
One of the jmix apps is a rest application.
I want to use email notifications in the addon without including any UI dependencies in it.
Currently my dependencies look like this:

implementation(“io.jmix.email:jmix-email-starter”)
implementation(“io.jmix.emailtemplates:jmix-emailtemplates-starter”)

but there seems to be a link to these two dependencies that we don’t want to use in our rest api:

implementation("io.jmix.email:jmix-email-ui-starter")
implementation("io.jmix.emailtemplates:jmix-emailtemplates-ui-starter")

Could you advise us how to use the email notifications without using any UI dependencies?

Regards,
Nikolay

Hi,

Could you explain where are these links? In your build.gradle? If so, then you may just remove them, I think.

Hello,

When I remove the UI dependencies the email notifications stop working and I get this error:

Caused by: org.eclipse.persistence.exceptions.JPQLException:
Exception Description: Problem compiling [select e from emltmp_EmailTemplate e where e.code = :code].
[14, 34] The abstract schema type ‘emltmp_EmailTemplate’ is unknown.
[43, 49] The state field path ‘e.code’ cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:157) ~[org.eclipse.persistence.core-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:349) ~[org.eclipse.persistence.core-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:280) ~[org.eclipse.persistence.core-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:165) ~[org.eclipse.persistence.core-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144) ~[org.eclipse.persistence.jpa-2.7.9-6-jmix.jar:na]
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:

at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:118) ~[org.eclipse.persistence.jpa-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.(EJBQueryImpl.java:104) ~[org.eclipse.persistence.jpa-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.(EJBQueryImpl.java:88) ~[org.eclipse.persistence.jpa-2.7.9-6-jmix.jar:na]
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1753) ~[org.eclipse.persistence.jpa-2.7.9-6-jmix.jar:na]
… 134 common frames omitted

2022-07-13 15:51:17.385 DEBUG 18712 — [nio-8080-exec-4] i.j.w.WebdavRequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
Caused by: org.eclipse.persistence.exceptions.JPQLException:

The problem is that with only these two dependencies in build.grаdle:

implementation(“io.jmix.email:jmix-email-starter”)
implementation(“io.jmix.emailtemplates:jmix-emailtemplates-starter”)

The Jmix email notifications do not work.

Could you check why it’s not working?
Thanks

Hi Nikolay,

I couldn’t reproduce your problem in my test project.
Please look at it and try to find differences:
test-project.zip (203.6 KB)

Regards,
Konstantin

Hello, Konstantin,

I looked at your project. You have added other dependency in myaddon.gradle:

api 'io.jmix.notifications:jmix-notifications-starter'

and not these two that I sent you:

implementation(“io.jmix.email:jmix-email-starter”)
implementation(“io.jmix.emailtemplates:jmix-emailtemplates-starter”)

In order to reproduce our problem you need to add email sending service to myAddon application. Then try to call this service from myApp application from your project.

The email sending service is something like this:

@Service
public class NotificationService {

@Autowired
private EmailTemplates emailTemplates;

public void sendEmail() throws TemplateNotFoundException, EmailException, ReportParameterTypeChangedException {
    String templateCode = "test_template";
    String toAddress = "";

            EmailTemplateBuilder emailTemplateBuilder = emailTemplates.buildFromTemplate(templateCode);
            emailTemplateBuilder.setTo(toAddress);
            emailTemplateBuilder.sendEmail();
    }

}

Try to call the sendEmail() method through myApp using the dependencies defined in myAddon.

Thanks
Nikolay

Hi Nikolay,
Most probably you didn’t properly specify dependencies in your add-on like this:

@Configuration
@ComponentScan
@ConfigurationPropertiesScan
@JmixModule(dependsOn = {EclipselinkConfiguration.class, EmailConfiguration.class, EmailTemplatesConfiguration.class})
@PropertySource(name = "com.company.myaddon", value = "classpath:/com/company/myaddon/module.properties")
public class MaConfiguration {

See the documentation on @JmixModule annotation.

In the attached project, there is not problem with accessing emltmp_EmailTemplate entity.
test-project.zip (204.5 KB)