use of com.axelor.rpc.JsonContext in project axelor-open-suite by axelor.
the class ProjectInvoicingAssistantBatchService method updateJsonObject.
@SuppressWarnings("unchecked")
public static void updateJsonObject(Batch batch, List<Object> recordList, String field, Map<String, Object> contextValues) {
JsonContext jsonContext = (JsonContext) contextValues.get("jsonContext");
List<Object> dataList = recordList;
if (jsonContext.containsKey(field)) {
dataList = ((List<Object>) jsonContext.get(field)).stream().map(obj -> {
if (Mapper.toMap(EntityHelper.getEntity(obj)).get("id") != null) {
Map<String, Object> idMap = new HashMap<String, Object>();
idMap.put("id", Mapper.toMap(EntityHelper.getEntity(obj)).get("id"));
return idMap;
}
return obj;
}).collect(Collectors.toList());
dataList.addAll(recordList);
}
jsonContext.put(field, dataList);
Context context = (Context) contextValues.get("context");
batch.setAttrs(context.get("attrs").toString());
}
use of com.axelor.rpc.JsonContext in project axelor-open-suite by axelor.
the class ImportAdvancedImport method addJsonObjectRecord.
@SuppressWarnings("unchecked")
private void addJsonObjectRecord(Object bean, FileTab fileTab, String fieldName, Map<String, Object> values) {
String field = Inflector.getInstance().camelize(fieldName, true) + "Set";
List<Object> recordList;
Map<String, Object> recordMap = new HashMap<String, Object>();
recordMap.put("id", ((Model) bean).getId());
Map<String, Object> jsonContextValues = (Map<String, Object>) values.get("jsonContextValues" + fileTab.getId());
JsonContext jsonContext = (JsonContext) jsonContextValues.get("jsonContext");
Context context = (Context) jsonContextValues.get("context");
if (!jsonContext.containsKey(field)) {
recordList = new ArrayList<Object>();
} else {
recordList = ((List<Object>) jsonContext.get(field)).stream().map(obj -> {
if (Mapper.toMap(EntityHelper.getEntity(obj)).get("id") != null) {
Map<String, Object> idMap = new HashMap<String, Object>();
idMap.put("id", Mapper.toMap(EntityHelper.getEntity(obj)).get("id"));
return idMap;
}
return obj;
}).collect(Collectors.toList());
}
recordList.add(recordMap);
jsonContext.put(field, recordList);
fileTab.setAttrs(context.get("attrs").toString());
}
use of com.axelor.rpc.JsonContext in project axelor-open-suite by axelor.
the class ConfiguratorController method generateForSaleOrder.
/**
* Called from configurator wizard form view, call {@link
* ConfiguratorService#addLineToSaleOrder(Configurator, SaleOrder, JsonContext, JsonContext)}
*
* @param request
* @param response
*/
public void generateForSaleOrder(ActionRequest request, ActionResponse response) {
Configurator configurator = request.getContext().asType(Configurator.class);
long saleOrderId = ((Integer) request.getContext().get("_saleOrderId")).longValue();
JsonContext jsonAttributes = (JsonContext) request.getContext().get("$attributes");
JsonContext jsonIndicators = (JsonContext) request.getContext().get("$indicators");
configurator = Beans.get(ConfiguratorRepository.class).find(configurator.getId());
SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrderId);
try {
Beans.get(ConfiguratorService.class).addLineToSaleOrder(configurator, saleOrder, jsonAttributes, jsonIndicators);
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.JsonContext in project axelor-open-suite by axelor.
the class ProjectInvoicingAssistantBatchService method createJsonContext.
@SuppressWarnings("unchecked")
public static Map<String, Object> createJsonContext(Batch batch) throws ClassNotFoundException {
Context context = new Context(batch.getClass());
Class<? extends Model> klass = (Class<? extends Model>) Class.forName(batch.getClass().getName());
JsonContext jsonContext = new JsonContext(context, Mapper.of(klass).getProperty("attrs"), batch.getAttrs());
Map<String, Object> _map = new HashMap<String, Object>();
_map.put("context", context);
_map.put("jsonContext", jsonContext);
return _map;
}
use of com.axelor.rpc.JsonContext in project axelor-open-suite by axelor.
the class ProjectInvoicingAssistantBatchService method getShowRecordIds.
@SuppressWarnings("unchecked")
public String getShowRecordIds(Batch batch, String field) throws ClassNotFoundException {
Context context = new Context(batch.getClass());
Class<? extends Model> klass = (Class<? extends Model>) Class.forName(batch.getClass().getName());
JsonContext jsonContext = new JsonContext(context, Mapper.of(klass).getProperty("attrs"), batch.getAttrs());
List<Map<String, Object>> recordList = (List<Map<String, Object>>) jsonContext.get(field);
String ids = !CollectionUtils.isEmpty(recordList) ? recordList.stream().map(_map -> _map.get("id").toString()).collect(Collectors.joining(",")) : null;
return ids;
}
Aggregations