use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class ComboboxValueServiceImpl method getAllValuesForCombobox.
@Override
@Transactional
public List<String> getAllValuesForCombobox(String entityClassName, String fieldName) {
EntityInfo entityInfo = entityInfoReader.getEntityInfo(entityClassName);
if (entityInfo == null) {
throw new EntityNotFoundException(entityClassName);
}
FieldDto field = entityInfo.getField(fieldName).getField();
if (field == null) {
throw new FieldNotFoundException(entityClassName, fieldName);
} else if (!field.getType().isCombobox()) {
throw new IllegalArgumentException("Field " + fieldName + "in entity " + entityClassName + " is not a combobx field");
}
return getAllValuesForCombobox(entityInfo.getEntity(), field);
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class DefaultMotechDataService method copyValuesFromRecord.
protected void copyValuesFromRecord(T target, Object record) {
EntityInfo entityInfo = entityInfoReader.getEntityInfo(getClassType().getName());
RevertConverter revertConverter = new RevertConverter(entityInfo, applicationContext);
PropertyUtil.copyProperties(target, record, revertConverter);
PropertyUtil.copyProperties(target, record, revertConverter, Constants.Util.RECORD_FIELDS_TO_COPY);
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class DefaultMotechDataService method init.
@PostConstruct
public void init() {
debug("Initializing {}", getClass().getName());
EntityInfo entityInfo = entityInfoReader.getEntityInfo(repository.getClassType().getName());
securityMode = entityInfo.getSecurityMode();
schemaVersion = entityInfo.getSchemaVersion();
recordHistory = entityInfo.isRecordHistory();
allowCreateEvent = entityInfo.isCreateEventFired();
allowUpdateEvent = entityInfo.isUpdateEventFired();
allowDeleteEvent = entityInfo.isDeleteEventFired();
module = entityInfo.getModule();
entityName = entityInfo.getEntityName();
namespace = entityInfo.getNamespace();
// we need the field types for handling lookups with null values
Map<String, String> fieldTypeMap = new HashMap<>();
for (FieldInfo field : entityInfo.getFieldsInfo()) {
fieldTypeMap.put(field.getName(), field.getType());
if (field.isVersionField()) {
versionFieldName = field.getName();
}
}
repository.setFieldTypeMap(fieldTypeMap);
debug("{} ready", getClass().getName());
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class MdsRestFacadeImpl method getLookupFieldsMapping.
private Map<String, FieldDto> getLookupFieldsMapping(EntityInfo entity, LookupDto lookup) {
Map<String, FieldDto> fieldMap = new HashMap<>();
for (LookupFieldDto lookupField : lookup.getLookupFields()) {
FieldDto field;
if (StringUtils.isNotBlank(lookupField.getRelatedName())) {
RelationshipHolder relHolder = new RelationshipHolder(entity.getField(lookupField.getName()).getField());
EntityInfo relatedEntity = entityInfoReader.getEntityInfo(relHolder.getRelatedClass());
field = relatedEntity.getField(lookupField.getRelatedName()).getField();
} else {
field = entity.getField(lookupField.getName()).getField();
}
fieldMap.put(lookupField.getLookupFieldName(), field);
}
return fieldMap;
}
use of org.motechproject.mds.entityinfo.EntityInfo 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