Search in sources :

Example 1 with MetaSelectItem

use of com.axelor.meta.db.MetaSelectItem in project axelor-open-suite by axelor.

the class DataImportServiceImpl method getSelectionValue.

private String getSelectionValue(String selection, String value, int forSelectUse) {
    if (forSelectUse != FileFieldRepository.SELECT_USE_VALUES) {
        String title = null;
        if (forSelectUse == FileFieldRepository.SELECT_USE_TRANSLATED_TITLES) {
            title = translationService.getTranslationKey(value, language);
        } else {
            title = value;
        }
        MetaSelect metaSelect = metaSelectRepo.findByName(selection);
        if (metaSelect == null) {
            return null;
        }
        MetaSelectItem metaSelectItem = metaSelectItemRepo.all().filter("self.title = ?1 AND self.select.id = ?2", title, metaSelect.getId()).fetchOne();
        if (metaSelectItem != null) {
            return metaSelectItem.getValue();
        } else {
            return value;
        }
    } else {
        return value;
    }
}
Also used : MetaSelectItem(com.axelor.meta.db.MetaSelectItem) MetaSelect(com.axelor.meta.db.MetaSelect)

Example 2 with MetaSelectItem

use of com.axelor.meta.db.MetaSelectItem in project axelor-open-suite by axelor.

the class PrintTemplateLineServiceImpl method addItemToReferenceSelection.

@Override
public void addItemToReferenceSelection(MetaModel model) {
    MetaSelect metaSelect = Beans.get(MetaSelectRepository.class).findByName("print.template.line.test.reference.select");
    List<MetaSelectItem> items = metaSelect.getItems();
    if (items != null && !items.stream().anyMatch(x -> x.getValue().equals(model.getFullName()))) {
        MetaSelectItem metaSelectItem = new MetaSelectItem();
        metaSelectItem.setTitle(model.getName());
        metaSelectItem.setValue(model.getFullName());
        metaSelectItem.setSelect(metaSelect);
        saveMetaSelectItem(metaSelectItem);
    }
}
Also used : MetaSelectRepository(com.axelor.meta.db.repo.MetaSelectRepository) MetaSelectItem(com.axelor.meta.db.MetaSelectItem) MetaSelect(com.axelor.meta.db.MetaSelect)

Example 3 with MetaSelectItem

use of com.axelor.meta.db.MetaSelectItem in project axelor-open-suite by axelor.

the class SelectionBuilderService method updateItem.

private MetaSelectItem updateItem(Map<String, MetaSelectItem> itemMap, int order, final String title, final String value) {
    MetaSelectItem metaSelectItem = itemMap.get(value);
    if (metaSelectItem == null) {
        metaSelectItem = new MetaSelectItem();
    }
    metaSelectItem.setTitle(title);
    metaSelectItem.setValue(value);
    metaSelectItem.setOrder(order);
    return metaSelectItem;
}
Also used : MetaSelectItem(com.axelor.meta.db.MetaSelectItem)

Example 4 with MetaSelectItem

use of com.axelor.meta.db.MetaSelectItem in project axelor-open-suite by axelor.

the class SelectionBuilderService method updateSelectItems.

private MetaSelect updateSelectItems(String selectionText, String name, String xmlId) {
    String[] selection = selectionText.trim().split("\n");
    MetaSelect metaSelect = xmlId != null ? findMetaSelectById(xmlId) : findMetaSelectByName(name);
    Map<String, MetaSelectItem> itemMap = new HashMap<String, MetaSelectItem>();
    if (metaSelect == null) {
        metaSelect = new MetaSelect(name);
    } else {
        for (MetaSelectItem item : metaSelect.getItems()) {
            itemMap.put(item.getValue(), item);
        }
    }
    metaSelect.clearItems();
    int order = 1;
    for (String option : selection) {
        option = option.trim();
        if (option.isEmpty()) {
            continue;
        }
        final String title;
        final String value;
        if (option.contains(":") && option.indexOf(":") != option.length() - 1) {
            title = option.substring(option.indexOf(":") + 1);
            value = option.substring(0, option.indexOf(":"));
        } else {
            title = option;
            value = option;
        }
        MetaSelectItem metaSelectItem = updateItem(itemMap, order, title, value);
        order++;
        metaSelect.addItem(metaSelectItem);
    }
    return metaSelect;
}
Also used : MetaSelectItem(com.axelor.meta.db.MetaSelectItem) HashMap(java.util.HashMap) MetaSelect(com.axelor.meta.db.MetaSelect)

Aggregations

MetaSelectItem (com.axelor.meta.db.MetaSelectItem)4 MetaSelect (com.axelor.meta.db.MetaSelect)3 MetaSelectRepository (com.axelor.meta.db.repo.MetaSelectRepository)1 HashMap (java.util.HashMap)1