use of org.motechproject.mds.service.DefaultMotechDataService in project motech by motech.
the class BaseInstanceIT method createService.
private MotechDataService createService() throws Exception {
Object repository = MDSClassLoader.getInstance().loadClass(getRepositoryClass()).newInstance();
Object service = MDSClassLoader.getInstance().loadClass(getServiceClass()).newInstance();
EntityInfoReader entityInfoReader = new EntityInfoReader() {
@Override
public EntityInfo getEntityInfo(String entityClassName) {
return buildEntityInfo();
}
@Override
public EntityInfo getEntityInfo(Long entityId) {
return buildEntityInfo();
}
@Override
public Collection<String> getEntitiesClassNames() {
List<String> classNames = new ArrayList<>();
classNames.add(entity.getClassName());
return classNames;
}
private EntityInfo buildEntityInfo() {
EntityInfo info = new EntityInfo();
info.setEntity(entity);
info.setAdvancedSettings(new AdvancedSettingsDto());
List<FieldInfo> fieldInfos = new ArrayList<>();
for (FieldDto fieldDto : getEntityFields()) {
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.setField(fieldDto);
fieldInfos.add(fieldInfo);
}
info.setFieldsInfo(fieldInfos);
return info;
}
};
PropertyUtil.safeSetProperty(repository, "persistenceManagerFactory", getDataPersistenceManagerFactory());
PropertyUtil.safeSetProperty(service, "transactionManager", getDataTransactionManager());
PropertyUtil.safeSetProperty(service, "repository", repository);
PropertyUtil.safeSetProperty(service, "entityInfoReader", entityInfoReader);
PropertyUtil.safeSetProperty(service, "historyService", getHistoryService());
PropertyUtil.safeSetProperty(service, "trashService", getTrashService());
PropertyUtil.safeSetProperty(service, "osgiEventProxy", getOsgiEventProxy());
MotechDataService mds = (MotechDataService) service;
((DefaultMotechDataService) mds).init();
return mds;
}
Aggregations