Search in sources :

Example 6 with JsonContext

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());
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) HashMap(java.util.HashMap)

Example 7 with JsonContext

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());
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with JsonContext

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);
    }
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Configurator(com.axelor.apps.sale.db.Configurator) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) ConfiguratorService(com.axelor.apps.sale.service.configurator.ConfiguratorService) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 9 with JsonContext

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;
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) HashMap(java.util.HashMap) Model(com.axelor.db.Model)

Example 10 with JsonContext

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;
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) Model(com.axelor.db.Model) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JsonContext (com.axelor.rpc.JsonContext)13 Model (com.axelor.db.Model)8 HashMap (java.util.HashMap)7 MetaModel (com.axelor.meta.db.MetaModel)6 Context (com.axelor.rpc.Context)6 List (java.util.List)6 FileTab (com.axelor.apps.base.db.FileTab)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 FileField (com.axelor.apps.base.db.FileField)3 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)3 Configurator (com.axelor.apps.sale.db.Configurator)3 ConfiguratorService (com.axelor.apps.sale.service.configurator.ConfiguratorService)3 EntityHelper (com.axelor.db.EntityHelper)3 Mapper (com.axelor.db.mapper.Mapper)3 Beans (com.axelor.inject.Beans)3 MetaField (com.axelor.meta.db.MetaField)3 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)3 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 Strings (com.google.common.base.Strings)3