Migration from CUBA to JMIX 1.3.1

I am trying again to migrate one of my largest project which was originally created in CUBA 5.x or 6.x (don’t remember) then migrated to CUBA v7. I had some interfaces which were built on CUBA V6 and now converted to v7 (Vaadin 8) as preparation for migrating to the Jmix.

I have migrated my project to JMIX 1.3.1 that looks much better than I had get many issues that has been fixed/clarified through these threads here (1.1), here (1.2), and few more…

Now I have a few more issues that need to be resolved apart from some issues I found and fixed.

  1. I do not see the “SecurityContextAwareRunnable” anymore that I used to execute tasks. What is the alternative in JMIX?
private void updatePrAsync(PurchaseRequisition purchaseRequisition) {
        // submit a task for asynchronous execution
        // use SecurityContextAwareRunnable for passing security context to the new thread
        executorService.submit(new SecurityContextAwareRunnable(() -> {
            // some artificial delay
            sleep();
            // your business logic in a new transaction

        }));
    }
  1. What is the new API in JMIX replacing CUBA?

    • FtsField

Is it “import org.springframework.context.annotation.Role” for Role? Not sure what is for other APIs

  1. In CUBA, I used the following lines of codes to put the focus on precisely. This issue is, “requestFocus()” is not recognized in JMIX.
 accountsTable.setSelected(e.getSource().getEditedEntity());
                    accountsTable.scrollTo(e.getSource().getEditedEntity());
                    accountsTable.requestFocus();
  1. I didn’t find this API, what’s new that replaces it?

com.haulmont.cuba.gui.components.mainwindow.FtsField

  1. How can I check if the current user has access to any particular screen? I have the following code in CUBA.
if (!userSessionSource.getUserSession().isScreenPermitted("erp_WorkflowTaskLineStatusInbox.browse")) {

            //action
        }
  1. SettingsWindow, no more exists?
public class ExtSettingsWindow extends SettingsWindow {

    @Inject
    private UserSettingService userSettingService;
  1. How can I get entity name list in JMIX while I used to get it in CUBA like below:

image

Do you recommend to get list of classes as follows?

> metadata.getClasses().stream()
But I didn’t find any option to exclude system-level meta-classes, thanks for suggesting.

  1. I do not see globalConfig and webConfig which was used in AppLogin screen.
    image

There are many ways I have used this, e.g. sending link:

private String buildEditorLink(String entityName, UUID entityId) {
        return globalConfig.getWebAppUrl() + "/open?screen=" + entityName + ".edit&item=" + entityName + "-" + entityId;
    }
  1. I encrypt password programmatically but I don’t see the password encrypt API anymore, any alternative available?
@Inject
    private PasswordEncryption passwordEncryption;
String passwordHash = passwordEncryption.getPasswordHash(user.getId(), password);
        user.setPassword(passwordHash);
  1. The following option to get ItemDatasource from a table to set Datasource to a textField is not working anymore as you seem them in red:

image

I used to control view only/editable dynamically as follows but what is the way in JMIX to the red highlighted field in the image above?

 demandPlanLineTable.addGeneratedColumn("quantityPd2", entity -> {
            if (entity.getDemandPerspective().getDemandPerspectiveType().equals(DemandPerspectiveType.BASE_FORECAST)
                    || entity.getDemandPerspective().getDemandPerspectiveType().equals(DemandPerspectiveType.DEMAND_PLAN)) {
                // simple text cell, non editable
                return new Table.PlainTextCell(entity.getQuantityPd2().toString());
            }

            TextField textField = componentsFactory.createComponent(TextField.class);
            textField.setWidth("100%");
            textField.setDatasource(demandPlanLineTable.getItemDatasource(entity), "quantityPd2");
            return textField;
        });
1 Like

Use DelegatingSecurityContextRunnable as described in Spring Security docs:

Runnable runnable = () -> {
    // some authenticated action
};

DelegatingSecurityContextRunnable wrappedRunnable =
        new DelegatingSecurityContextRunnable(runnable, SecurityContextHolder.getContext());

executorService.submit(wrappedRunnable);

Not sure what you mean. org.springframework.context.annotation.Role is not used in Jmix.

Use focus() method.

See Using Search in UI :: Jmix Documentation

@Autowired
private AccessManager accessManager;

private void checkIfUserBrowsePermitted() {
        UiShowScreenContext context = new UiShowScreenContext("User.browse");
        accessManager.applyRegisteredConstraints(context);
        if (context.isPermitted()) {
            log.info("Permitted");
        } else {
            log.info("Denied");
        }
}

Right, there is no predefined Settings screen in Jmix.

Inject MetadataTools bean and use its getAllJpaEntityMetaClasses() method.

Inject UiProperties and CoreProperties beans and use their getters.

Use org.springframework.security.crypto.password.PasswordEncoder:

@Autowired
private PasswordEncoder passwordEncoder;

private String encodePassword(String plain) {
    return passwordEncoder.encode(plain);
}

Looks like it’s an old API of CUBA 6. Please provide the class definition and the root element of XML descriptor.

Thank you so much Konstantin for your help.

a) I tried but didn’t find webAppUrl, see below the comparison what I am looking for and what exists.
image

b) I also noticed that the setValue() API for updating an entity’s property value with reference to the property name doesn’t not exist anymore. Is there any alternative way in JMIX?

image

c) In CUBA version, I could use the following codes to get the UUID of the entity received as a parameter.

image

However, it’s not supported in JMIX. Is the following piece of code will do the same?

UUID entityId = (UUID) entity.__getEntityEntry().getEntityId();

1 Like