Search in sources :

Example 1 with Option

use of com.axelor.meta.schema.views.Selection.Option in project axelor-open-suite by axelor.

the class EbicsCertificateService method computeFullName.

public void computeFullName(EbicsCertificate entity) {
    StringBuilder fullName = new StringBuilder();
    Option item = MetaStore.getSelectionItem("bankpayment.ebics.certificate.type.select", entity.getTypeSelect());
    if (item != null) {
        fullName.append(I18n.get(item.getTitle()));
    }
    LocalDate date = entity.getValidFrom();
    if (date != null) {
        fullName.append(":" + date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        date = entity.getValidTo();
        if (date != null) {
            fullName.append("-" + date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        }
    }
    String issuer = entity.getIssuer();
    if (issuer != null) {
        fullName.append(":" + issuer);
    }
    entity.setFullName(fullName.toString());
}
Also used : Option(com.axelor.meta.schema.views.Selection.Option) LocalDate(java.time.LocalDate)

Example 2 with Option

use of com.axelor.meta.schema.views.Selection.Option in project axelor-open-suite by axelor.

the class ObjectDataExportServiceImpl method fetchData.

private List<String[]> fetchData(String[][] fieldsData, Query<? extends Model> query, Map<String, String> selectMap, ResourceBundle bundle) {
    List<String[]> dataList = new ArrayList<>();
    dataList.add(fieldsData[1]);
    List<Map> records = query.select(fieldsData[0]).fetch(0, 0);
    for (Map<String, Object> recordMap : records) {
        List<String> datas = new ArrayList<>();
        for (String field : fieldsData[0]) {
            Object object = recordMap.get(field);
            if (object == null) {
                datas.add("");
                continue;
            }
            if (selectMap.containsKey(field)) {
                String selection = selectMap.get(field);
                Option option = MetaStore.getSelectionItem(selection, object.toString());
                if (option == null) {
                    datas.add("");
                    continue;
                }
                String optionTitle = option.getTitle();
                optionTitle = bundle.getString(optionTitle);
                if (optionTitle != null) {
                    datas.add(optionTitle);
                } else {
                    datas.add(option.getTitle());
                }
            } else {
                datas.add(object.toString());
            }
        }
        dataList.add(datas.toArray(new String[fieldsData[0].length]));
    }
    return dataList;
}
Also used : ArrayList(java.util.ArrayList) Option(com.axelor.meta.schema.views.Selection.Option) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Option

use of com.axelor.meta.schema.views.Selection.Option in project axelor-open-suite by axelor.

the class SelectionBuilderService method createSelectionText.

public String createSelectionText(String selectionName) {
    List<Option> options = MetaStore.getSelectionList(selectionName);
    boolean allSame = true;
    List<String> values = new ArrayList<>();
    List<String> valuesWithTitles = new ArrayList<String>();
    for (Option option : options) {
        if (option.getHidden() != null && option.getHidden()) {
            continue;
        }
        valuesWithTitles.add(option.getValue() + ":" + option.getTitle());
        if (allSame && !option.getValue().equals(option.getTitle())) {
            allSame = false;
        } else {
            values.add(option.getValue());
        }
    }
    return Joiner.on("\n").join(allSame ? values : valuesWithTitles);
}
Also used : ArrayList(java.util.ArrayList) Option(com.axelor.meta.schema.views.Selection.Option)

Example 4 with Option

use of com.axelor.meta.schema.views.Selection.Option in project axelor-open-suite by axelor.

the class ChartRecordViewServiceImpl method getSelectionFieldValue.

protected Object getSelectionFieldValue(ChartBuilder chartBuilder, Object titleParam, Boolean isForGroup) throws AxelorException {
    Object value = null;
    String selection = null;
    Class<?> targetType = String.class;
    Boolean isJson = chartBuilder.getIsJson() || (isForGroup ? chartBuilder.getIsJsonGroupOn() : chartBuilder.getIsJsonAggregateOn());
    MetaField target = chartBuilder.getGroupOn();
    MetaJsonField jsonField = chartBuilder.getGroupOnJson();
    if (!isForGroup) {
        target = chartBuilder.getAggregateOn();
        jsonField = chartBuilder.getAggregateOnJson();
    }
    if (isJson && ObjectUtils.notEmpty(jsonField.getSelection()) && (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType()) || String.class.getSimpleName().toLowerCase().equals(jsonField.getType()))) {
        selection = jsonField.getSelection();
        if (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType())) {
            targetType = Integer.class;
        }
    } else {
        try {
            Mapper mapper = Mapper.of(Class.forName(chartBuilder.getModel()));
            Property p = mapper.getProperty(target.getName());
            if (ObjectUtils.notEmpty(p.getSelection())) {
                selection = p.getSelection();
                targetType = p.getJavaType();
            }
        } catch (ClassNotFoundException e) {
            throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
        }
    }
    if (ObjectUtils.isEmpty(selection)) {
        return value;
    }
    List<Option> selectionList = MetaStore.getSelectionList(selection);
    for (Option option : selectionList) {
        if (option.getLocalizedTitle().equals(titleParam)) {
            return ConvertUtils.convert(option.getValue(), targetType);
        }
    }
    return value;
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaField(com.axelor.meta.db.MetaField) BigInteger(java.math.BigInteger) Mapper(com.axelor.db.mapper.Mapper) MetaJsonField(com.axelor.meta.db.MetaJsonField) Option(com.axelor.meta.schema.views.Selection.Option) Property(com.axelor.db.mapper.Property)

Aggregations

Option (com.axelor.meta.schema.views.Selection.Option)4 ArrayList (java.util.ArrayList)2 Mapper (com.axelor.db.mapper.Mapper)1 Property (com.axelor.db.mapper.Property)1 AxelorException (com.axelor.exception.AxelorException)1 MetaField (com.axelor.meta.db.MetaField)1 MetaJsonField (com.axelor.meta.db.MetaJsonField)1 BigInteger (java.math.BigInteger)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1