use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class StockMoveLineController method setProductInfo.
/**
* Called from stock move line form. Fill product info using the company either from the stock
* move line, from the parent stock move or the parent manuf order.
*
* @param request
* @param response
*/
public void setProductInfo(ActionRequest request, ActionResponse response) {
StockMoveLine stockMoveLine;
try {
stockMoveLine = request.getContext().asType(StockMoveLine.class);
Company company;
StockMove stockMove = stockMoveLine.getStockMove();
if (stockMove == null) {
Context parentContext = request.getContext().getParent();
if (parentContext.getContextClass().equals(StockMove.class)) {
stockMove = parentContext.asType(StockMove.class);
company = stockMove.getCompany();
} else if (parentContext.getContextClass().equals(ManufOrder.class)) {
ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
company = manufOrder.getCompany();
} else if (parentContext.getContextClass().equals(OperationOrder.class)) {
OperationOrder operationOrder = parentContext.asType(OperationOrder.class);
if (operationOrder.getManufOrder() == null) {
return;
}
company = operationOrder.getManufOrder().getCompany();
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.STOCK_MOVE_LINE_UNKNOWN_PARENT_CONTEXT);
}
} else {
company = stockMove.getCompany();
}
if (stockMoveLine.getProduct() == null) {
stockMoveLine = new StockMoveLine();
response.setValues(Mapper.toMap(stockMoveLine));
return;
}
Beans.get(StockMoveLineService.class).setProductInfo(stockMove, stockMoveLine, company);
response.setValues(stockMoveLine);
} catch (Exception e) {
stockMoveLine = new StockMoveLine();
response.setValues(Mapper.toMap(stockMoveLine));
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class ProjectTemplateController method createProjectFromWizard.
@SuppressWarnings("unchecked")
public void createProjectFromWizard(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String projectTemplateId = ((LinkedHashMap<String, Object>) context.get("_projectTemplate")).get("id").toString();
ProjectTemplate projectTemplate = Beans.get(ProjectTemplateRepository.class).find(Long.parseLong(projectTemplateId));
String projectCode = (String) context.get("code");
Object clientPartnerContext = context.get("clientPartner");
Partner clientPartner = null;
if (clientPartnerContext != null) {
String clientPartnerId = ((LinkedHashMap<String, Object>) clientPartnerContext).get("id").toString();
clientPartner = Beans.get(PartnerRepository.class).find(Long.parseLong(clientPartnerId));
}
Project project;
try {
project = Beans.get(ProjectService.class).createProjectFromTemplate(projectTemplate, projectCode, clientPartner);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Project")).model(Project.class.getName()).add("form", "project-form").add("grid", "project-grid").param("search-filters", "project-filters").context("_showRecord", project.getId()).map());
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context 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.Context in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method computeTemplateContexts.
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> computeTemplateContexts(List<TemplateContext> templateContextList, long objectId, String model, boolean isJson, Map<String, Object> templatesContext) throws ClassNotFoundException {
if (templateContextList == null) {
return templatesContext;
}
Context context = null;
if (isJson) {
context = new com.axelor.rpc.Context(objectId, MetaJsonRecord.class);
} else {
Class<? extends Model> myClass = (Class<? extends Model>) Class.forName(model);
context = new com.axelor.rpc.Context(objectId, myClass);
}
for (TemplateContext templateContext : templateContextList) {
Object result = templateContextService.computeTemplateContext(templateContext, context);
templatesContext.put(templateContext.getName(), result);
}
return templatesContext;
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method getInvoice.
public Invoice getInvoice(Context context) {
Context parentContext = context.getParent();
Invoice invoice = parentContext.asType(Invoice.class);
if (!parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
invoice = invoiceLine.getInvoice();
}
return invoice;
}
Aggregations