Accessing DataManager or EntityManager from global module?

Hi, I wondered if it is possible to access DataManager or EntityManager from the global module?
As far as I understand, it is not possible… but just wanted to confirm.

The reason I want to do this is because…

I am trying to import csv data to my Entities. I am doing this with univocity parsers, using annotations in my Entities, as this makes mapping csv data to entity attributes very easy.

Univocity Parser allows to make custom data conversion, using annotations in the Entity class, specifying the class to use for conversion. This is what I use in my Entity:


@Convert(conversionClass = EntityConversion.class, args = { "com.company.tojm.entity.ConcertUnit" , "concertUnit-ManageView" })
@Parsed
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CONCERT_ID")
protected Concert concert;

The first annotation @Convert specifies the conversion Class.
Below is the code for my conversion class. What is does is, for a related entity (here “concert”) just write its UUID as string; and when importing, use the UUID string to fetch the entity and set it for the attribute.


public class EntityConversion implements Conversion<String, BaseGenericIdEntity> {
	
	Class targetClass;
	String viewName;
	
    public EntityConversion(String... args) throws ClassNotFoundException {
    	this.targetClass = Class.forName(args[0]);
    	this.viewName = args[1];
    }

	@Override
	public BaseGenericIdEntity execute(String input) {
		UUID entityUid = UUID.fromString(input);
		
		return getEntityByUid(entityUid, this.targetClass, this.viewName);
	}

    private<T extends BaseGenericIdEntity> T getEntityByUid(UUID tojmUid, Class<T> targetClass, String viewName) {
		LoadContext<T> loadContext = LoadContext.create(targetClass).setId(tojmUid).setView(viewName);
	    return dataManager.load(loadContext);
	}

	@Override
	public String revert(BaseGenericIdEntity input) {
		return input.getId().toString();
	}
}

Now my problem is that I cannot get DataManager because I’m in global module.
In the opposite, if I put my Conversion class in core module, then my Entity (with annotation referring to the conversion class) cannot see the conversion class…

Any ideas on how this could be work?
Thanks!

Hello!

You can obtain DataManager via AppBeans:

DataManager dataManager = AppBeans.get(DataManager.class);
2 Likes

Wow, that was easy :slight_smile:
Thanks!

You are welcome!