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());
}
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;
}
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);
}
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;
}
Aggregations