Search in sources :

Example 1 with XMLBind

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;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) XMLInput(com.axelor.data.xml.XMLInput) XMLBind(com.axelor.data.xml.XMLBind)

Example 2 with XMLBind

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;
}
Also used : XMLBindJson(com.axelor.data.xml.XMLBindJson) ArrayList(java.util.ArrayList) XMLInput(com.axelor.data.xml.XMLInput) XMLBind(com.axelor.data.xml.XMLBind)

Example 3 with XMLBind

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;
}
Also used : MetaField(com.axelor.meta.db.MetaField) ArrayList(java.util.ArrayList) XMLBind(com.axelor.data.xml.XMLBind)

Example 4 with XMLBind

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;
}
Also used : XMLBind(com.axelor.data.xml.XMLBind)

Example 5 with XMLBind

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;
}
Also used : ArrayList(java.util.ArrayList) MetaJsonField(com.axelor.meta.db.MetaJsonField) XMLBind(com.axelor.data.xml.XMLBind) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

XMLBind (com.axelor.data.xml.XMLBind)5 ArrayList (java.util.ArrayList)4 XMLInput (com.axelor.data.xml.XMLInput)2 XMLBindJson (com.axelor.data.xml.XMLBindJson)1 Mapper (com.axelor.db.mapper.Mapper)1 MetaField (com.axelor.meta.db.MetaField)1 MetaJsonField (com.axelor.meta.db.MetaJsonField)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1