Email Templates Assume Parameter Entity ID is UUID?

Jmix v 1.4.4

I am just beginning to work with the Email Templates add on. It appears as if the add on assumes your entity parameters will always have an ID that is a UUID type. My entities have integer IDs. Also, one of my parameters is an AppSettingsEntity which always has an integer ID of 1.

The error I receive when I try to preview an email template is:

java.lang.IllegalArgumentException: Invalid UUID string: 1
	at java.base/java.util.UUID.fromString1(UUID.java:280)
	at java.base/java.util.UUID.fromString(UUID.java:258)
	at io.jmix.reports.libintegration.JmixObjectToStringConverter.convertFromString(JmixObjectToStringConverter.java:69)
	at io.jmix.emailtemplates.TemplateParametersExtractor.convertFromString(TemplateParametersExtractor.java:192)
	at io.jmix.emailtemplatesui.screen.emailtemplate.parameters.EmailTemplateParametersFragment.createComponent(EmailTemplateParametersFragment.java:242)
	at io.jmix.emailtemplatesui.screen.emailtemplate.parameters.EmailTemplateParametersFragment.createComponents(EmailTemplateParametersFragment.java:162)
	at io.jmix.emailtemplatesui.screen.emailtemplate.send.EmailTemplateSendScreen.onAfterInit(EmailTemplateSendScreen.java:155)
	at io.jmix.core.common.event.EventHub.publish(EventHub.java:170)
	at io.jmix.ui.screen.Screen.fireEvent(Screen.java:124)
	at io.jmix.ui.screen.UiControllerUtils.fireEvent(UiControllerUtils.java:58)
	at io.jmix.ui.sys.ScreensImpl.fireScreenAfterInitEvent(ScreensImpl.java:1359)
	at io.jmix.ui.sys.ScreensImpl.createScreen(ScreensImpl.java:232)
	at io.jmix.ui.sys.ScreensImpl.create(ScreensImpl.java:133)
	at io.jmix.emailtemplatesui.screen.emailtemplate.browse.EmailTemplateBrowse.onSendEmailClick(EmailTemplateBrowse.java:119)

This seems to be supported by the code in JmixObjectToStringConverter:

public Object convertFromString(Class parameterClass, @Nullable String paramValueStr) {
        if (paramValueStr == null) {
            return null;
        } else if (String.class.isAssignableFrom(parameterClass)) {
            return paramValueStr;
        } else if (Entity.class.isAssignableFrom(parameterClass)) {
            UUID id = UUID.fromString(paramValueStr);
            Optional entityOpt = dataManager.load(parameterClass)
                    .id(id)
                    .fetchPlan(FetchPlan.BASE)
                    .optional();
            return entityOpt.isPresent() ? entityOpt.get() : null;

I cannot see any workaround from my end.

Hi,

I’ve created an issue for supporting non-UUID entities as template parameters.

As a workaround you may try to create a primary bean instead of the problematic one and override the method that cause problems:

import io.jmix.reports.libintegration.JmixObjectToStringConverter;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;

@Primary
@Component
public class MyJmixObjectToStringConverter extends JmixObjectToStringConverter {

    @Nullable
    @Override
    public Object convertFromString(Class parameterClass, @Nullable String paramValueStr) {
        return super.convertFromString(parameterClass, paramValueStr);
    }
}

Thanks for creating the issue and suggesting a work around. It seems to be a problem only when generating a preview of the template, so I have been able to keep developing and will look for the fixed preview in a later version.