use of com.axelor.data.xml.XMLBind in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method createMetaModelInput.
protected XMLInput createMetaModelInput(AppDataLoader dataLoader, boolean relationalInput) throws ClassNotFoundException {
XMLInput xmlInput = createXmlInput(dataLoader);
Mapper modelMapper = Mapper.of(Class.forName(dataLoader.getMetaModel().getFullName()));
String nodeName = getBindNodeName(xmlInput.getRoot());
XMLBind xmlBind = new XMLBind();
xmlBind.setTypeName(dataLoader.getMetaModel().getFullName());
xmlBind.setNode(nodeName);
if (!CollectionUtils.isEmpty(dataLoader.getSearchMetaFieldSet())) {
xmlBind.setSearch(getMetaSearchFields(modelMapper, dataLoader));
xmlBind.setUpdate(true);
}
if (relationalInput) {
xmlBind.setCreate(false);
}
xmlBind.setBindings(getMetaFieldBinding(modelMapper, dataLoader, relationalInput));
List<XMLBind> rootBindings = new ArrayList<XMLBind>();
rootBindings.add(xmlBind);
xmlInput.setBindings(rootBindings);
return xmlInput;
}
use of com.axelor.data.xml.XMLBind in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method createJsonModelInput.
protected XMLInput createJsonModelInput(AppDataLoader dataLoader, boolean relationalInput) {
XMLInput xmlInput = createXmlInput(dataLoader);
Map<String, Object> jsonFieldMap = MetaStore.findJsonFields(dataLoader.getModelName());
fixTargetName(jsonFieldMap);
String nodeName = getBindNodeName(xmlInput.getRoot());
XMLBindJson xmlBindJson = new XMLBindJson();
xmlBindJson.setNode(nodeName);
xmlBindJson.setJsonModel(dataLoader.getModelName());
if (!CollectionUtils.isEmpty(dataLoader.getSearchJsonFieldSet())) {
xmlBindJson.setSearch(getJsonSearchFields(dataLoader, jsonFieldMap));
xmlBindJson.setUpdate(true);
}
if (relationalInput) {
xmlBindJson.setCreate(false);
}
xmlBindJson.setBindings(geJsonFieldBinding(jsonFieldMap, dataLoader, relationalInput));
List<XMLBind> rootBindings = new ArrayList<XMLBind>();
rootBindings.add(xmlBindJson);
xmlInput.setBindings(rootBindings);
return xmlInput;
}
use of com.axelor.data.xml.XMLBind in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method getMetaFieldBinding.
private List<XMLBind> getMetaFieldBinding(Mapper modelMapper, AppDataLoader dataLoader, boolean relationalInput) {
List<XMLBind> fieldBindings = new ArrayList<XMLBind>();
for (MetaField field : dataLoader.getMetaFieldSet()) {
fieldBindings.add(createDummyFieldBinding(field.getName()));
if (relationalInput && field.getRelationship() == null) {
continue;
}
XMLBind fieldBind = new XMLBind();
fieldBind.setField(field.getName());
fieldBind.setNode(field.getName());
if (field.getRelationship() != null) {
addRelationalMetaFieldBind(modelMapper, field, fieldBind);
} else if (field.getTypeName().equals("Boolean")) {
fieldBind.setAdapter("Boolean");
}
fieldBindings.add(fieldBind);
}
return fieldBindings;
}
use of com.axelor.data.xml.XMLBind in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method createDummyFieldBinding.
private XMLBind createDummyFieldBinding(String name) {
XMLBind dummyBind = new XMLBind();
dummyBind.setNode(name);
dummyBind.setField("_" + name);
return dummyBind;
}
use of com.axelor.data.xml.XMLBind in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method geJsonFieldBinding.
protected List<XMLBind> geJsonFieldBinding(Map<String, Object> jsonFieldMap, AppDataLoader dataLoader, boolean relationalInput) {
List<XMLBind> fieldBindings = new ArrayList<>();
for (MetaJsonField jsonField : dataLoader.getJsonFieldSet()) {
Map<String, Object> fieldAttrs = (Map<String, Object>) jsonFieldMap.get(jsonField.getName());
log.debug("Json Field name: {}, Field attrs: {}", jsonField, fieldAttrs);
String fieldType = jsonField.getType();
fieldBindings.add(createDummyFieldBinding(jsonField.getName()));
if (relationalInput && jsonField.getTargetJsonModel() == null && jsonField.getTargetModel() == null) {
continue;
}
XMLBind xmlBind = new XMLBind();
xmlBind.setNode(jsonField.getName());
xmlBind.setField("$attrs." + jsonField.getName());
if (jsonField.getTargetJsonModel() != null || jsonField.getTargetModel() != null) {
addRelationaJsonFieldBind(jsonField, fieldAttrs, xmlBind);
} else if (fieldType.equals("boolean")) {
xmlBind.setAdapter("Boolean");
}
fieldBindings.add(xmlBind);
}
return fieldBindings;
}
Aggregations