use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class MoveTemplateController method generateMove.
@SuppressWarnings("unchecked")
public void generateMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
HashMap<String, Object> moveTemplateTypeMap = (HashMap<String, Object>) context.get("moveTemplateType");
MoveTemplateType moveTemplateType = Beans.get(MoveTemplateTypeRepository.class).find(Long.parseLong(moveTemplateTypeMap.get("id").toString()));
HashMap<String, Object> moveTemplateMap = (HashMap<String, Object>) context.get("moveTemplate");
MoveTemplate moveTemplate = null;
if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_PERCENTAGE) {
moveTemplate = Beans.get(MoveTemplateRepository.class).find(Long.parseLong(moveTemplateMap.get("id").toString()));
}
List<HashMap<String, Object>> dataList = (List<HashMap<String, Object>>) context.get("dataInputList");
List<HashMap<String, Object>> moveTemplateList = (List<HashMap<String, Object>>) context.get("moveTemplateSet");
LocalDate moveDate = null;
if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_AMOUNT) {
moveDate = LocalDate.parse((String) context.get("moveDate"), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
LOG.debug("MoveTemplate : {}", moveTemplate);
LOG.debug("Data inputlist : {}", dataList);
LOG.debug("Data inputlist : {}", moveTemplateList);
if ((dataList != null && !dataList.isEmpty()) || (moveTemplateList != null && !moveTemplateList.isEmpty())) {
List<Long> moveList = Beans.get(MoveTemplateService.class).generateMove(moveTemplateType, moveTemplate, dataList, moveDate, moveTemplateList);
if (moveList != null && !moveList.isEmpty()) {
response.setView(ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3)).model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").domain("self.id in (" + Joiner.on(",").join(moveList) + ")").map());
}
} else {
response.setFlash(I18n.get(IExceptionMessage.MOVE_TEMPLATE_4));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class AppController method bulkInstall.
public void bulkInstall(ActionRequest request, ActionResponse response) throws AxelorException, IOException {
Context context = request.getContext();
Set<Map<String, Object>> apps = new HashSet<>();
Collection<Map<String, Object>> appsSet = (Collection<Map<String, Object>>) context.get("appsSet");
if (appsSet != null) {
apps.addAll(appsSet);
}
Boolean importDemo = (Boolean) context.get("importDemoData");
String language = (String) context.get("languageSelect");
AppRepository appRepository = Beans.get(AppRepository.class);
List<App> appList = new ArrayList<>();
for (Map<String, Object> appData : apps) {
App app = appRepository.find(Long.parseLong(appData.get("id").toString()));
appList.add(app);
}
Beans.get(AppService.class).bulkInstall(appList, importDemo, language);
response.setFlash(I18n.get(IExceptionMessages.BULK_INSTALL_SUCCESS));
response.setSignal("refresh-app", true);
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class ObjectDataExportController method anonymize.
public void anonymize(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
Long recordId = Long.parseLong(context.get("modelSelectId").toString());
Long objectDataconfigId = Long.parseLong(context.get("objectDataConfigId").toString());
ObjectDataConfig objectDataConfig = Beans.get(ObjectDataConfigRepository.class).find(objectDataconfigId);
Beans.get(ObjectDataAnonymizeService.class).anonymize(objectDataConfig, recordId);
response.setFlash("Data anonymized successfully");
response.setCanClose(true);
}
use of com.axelor.rpc.Context 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.Context in project axelor-open-suite by axelor.
the class SaleOrderController method exportSaleOrder.
@SuppressWarnings("unchecked")
public void exportSaleOrder(ActionRequest request, ActionResponse response, boolean proforma, String format) {
Context context = request.getContext();
String fileLink;
String title;
SaleOrderPrintService saleOrderPrintService = Beans.get(SaleOrderPrintService.class);
try {
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = Lists.transform((List) request.getContext().get("_ids"), new Function<Object, Long>() {
@Nullable
@Override
public Long apply(@Nullable Object input) {
return Long.parseLong(input.toString());
}
});
fileLink = saleOrderPrintService.printSaleOrders(ids);
title = I18n.get("Sale orders");
} else if (context.get("id") != null) {
SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
title = Beans.get(SaleOrderService.class).getFileName(saleOrder);
fileLink = saleOrderPrintService.printSaleOrder(saleOrder, proforma, format);
response.setCanClose(true);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.SALE_ORDER_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations