Search in sources :

Example 1 with MetaSelect

use of com.axelor.meta.db.MetaSelect 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 MetaSelect

use of com.axelor.meta.db.MetaSelect 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 MetaSelect

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

the class SelectionBuilderService method updateMetaSelectFromText.

@Transactional
public String updateMetaSelectFromText(String selectionText, String name, AppBuilder appBuilder, String xmlId) {
    if (name == null && xmlId == null) {
        return null;
    }
    MetaSelect metaSelect = updateSelectItems(selectionText, name, xmlId);
    metaSelect.setIsCustom(true);
    metaSelect.setAppBuilder(appBuilder);
    metaSelect.setName(name);
    if (xmlId != null) {
        Integer priority = getPriority(name, xmlId);
        if (priority != null) {
            metaSelect.setPriority(priority);
        }
        metaSelect.setXmlId(xmlId);
    }
    metaSelectRepository.save(metaSelect);
    return name;
}
Also used : MetaSelect(com.axelor.meta.db.MetaSelect) Transactional(com.google.inject.persist.Transactional)

Example 4 with MetaSelect

use of com.axelor.meta.db.MetaSelect 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)

Example 5 with MetaSelect

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

the class SelectionBuilderController method fillSelectionText.

public void fillSelectionText(ActionRequest request, ActionResponse response) {
    MetaSelect metaSelect = (MetaSelect) request.getContext().get("metaSelect");
    if (metaSelect != null) {
        String name = metaSelect.getName();
        response.setValue("selectionText", Beans.get(SelectionBuilderService.class).createSelectionText(name));
        response.setValue("name", name);
    } else {
        response.setValue("selectionText", null);
        response.setValue("name", null);
    }
}
Also used : MetaSelect(com.axelor.meta.db.MetaSelect)

Aggregations

MetaSelect (com.axelor.meta.db.MetaSelect)6 MetaSelectItem (com.axelor.meta.db.MetaSelectItem)3 Mapper (com.axelor.db.mapper.Mapper)1 MetaSelectRepository (com.axelor.meta.db.repo.MetaSelectRepository)1 Transactional (com.google.inject.persist.Transactional)1 HashMap (java.util.HashMap)1