use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.
the class JarGeneratorServiceImpl method getFieldsInfo.
private List<FieldInfo> getFieldsInfo(EntityDto entity, List<FieldDto> fields, AdvancedSettingsDto advancedSettings) {
List<FieldInfo> fieldsInfo = new ArrayList<>();
Collections.sort(fields, new UIDisplayFieldComparator(advancedSettings.getBrowsing().getDisplayedFields()));
for (FieldDto field : fields) {
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.setField(field);
boolean exposedByRest = advancedSettings.isFieldExposedByRest(field.getBasic().getName());
fieldInfo.setRestExposed(exposedByRest);
FieldInfo.TypeInfo typeInfo = fieldInfo.getTypeInfo();
typeInfo.setType(field.getType().getTypeClass());
typeInfo.setTaskType(ActionParameterTypeResolver.resolveType(entity, field));
// combobox values
typeInfo.setCombobox(field.getType().isCombobox());
if (field.getType().isCombobox()) {
ComboboxHolder cbHolder = new ComboboxHolder(entity, field);
String[] items = cbHolder.getValues();
if (ArrayUtils.isNotEmpty(items)) {
typeInfo.setItems(Arrays.asList(items));
}
typeInfo.setAllowsMultipleSelection(cbHolder.isCollection());
typeInfo.setAllowUserSupplied(cbHolder.isAllowUserSupplied());
}
fieldsInfo.add(fieldInfo);
}
return fieldsInfo;
}
use of org.motechproject.mds.entityinfo.FieldInfo 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.FieldInfo in project motech by motech.
the class FieldTestHelper method fieldInfo.
public static FieldInfo fieldInfo(String name, Class typeClass, boolean required, boolean restExposed, boolean autoGenerated) {
FieldInfo field = new FieldInfo();
FieldDto fieldDto = new FieldDto();
fieldDto.setBasic(new FieldBasicDto());
fieldDto.getBasic().setName(name);
fieldDto.getBasic().setDisplayName(name + " disp");
fieldDto.getBasic().setRequired(required);
TypeDto type = new TypeDto();
type.setTypeClass(typeClass.getName());
fieldDto.setType(type);
field.setRestExposed(restExposed);
if (autoGenerated) {
fieldDto.addMetadata(new MetadataDto(Constants.Util.AUTO_GENERATED, Constants.Util.TRUE));
}
field.setField(fieldDto);
field.getTypeInfo().setType(typeClass.getName());
return field;
}
use of org.motechproject.mds.entityinfo.FieldInfo 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;
}
use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.
the class RevertConverter method convert.
@Override
public Object convert(Object value, PropertyDescriptor descriptor) {
FieldInfo field = entityInfo.getField(descriptor.getName());
FieldDto fieldDto = field.getField();
if (value == null || field == null || !fieldDto.getType().isRelationship()) {
return value;
} else {
RelationshipHolder relHolder = new RelationshipHolder(fieldDto);
String relatedClass = relHolder.getRelatedClass();
MotechDataService relatedDataService = ServiceUtil.getServiceFromAppContext(applicationContext, relatedClass);
if (value instanceof Collection) {
Collection<Long> idColl = (Collection<Long>) value;
return idCollToRelColl(idColl, relatedDataService);
} else {
Long id = (Long) value;
return relatedDataService.findById(id);
}
}
}
Aggregations