use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.
the class WkfEmailServiceImpl method createUrl.
@Override
public String createUrl(FullContext wkfContext, String formName) {
if (wkfContext == null) {
return "";
}
String url = AppSettings.get().getBaseURL();
Model model = (Model) EntityHelper.getEntity(wkfContext.getTarget());
if (formName == null) {
if (model instanceof MetaJsonRecord) {
formName = "custom-model-" + ((MetaJsonRecord) model).getJsonModel() + "-form";
} else {
formName = inflector.dasherize(model.getClass().getSimpleName());
}
}
String action = getAction(formName);
if (action == null) {
url += "/#ds/form::" + model.getClass().getName() + "/edit/" + wkfContext.get("id");
} else {
url += "/#ds/" + action + "/edit/" + wkfContext.get("id");
}
return url;
}
use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.
the class WkfInstanceServiceImpl method checkSubProcess.
protected void checkSubProcess(Model model) {
String chldModel = model instanceof MetaJsonRecord ? ((MetaJsonRecord) model).getJsonModel() : model.getClass().getSimpleName();
List<WkfTaskConfig> taskConfigs = wkfTaskConfigRepository.all().filter("self.callModel = ?1 AND self.callLink IS NOT NULL", chldModel).fetch();
if (taskConfigs.isEmpty()) {
return;
}
FullContext modelCtx = WkfContextHelper.create(model);
Map<String, Object> ctxMap = ImmutableMap.of(wkfService.getVarName(model), modelCtx);
for (WkfTaskConfig taskConfig : taskConfigs) {
if (!evalCondition(ctxMap, taskConfig.getCallLinkCondition())) {
continue;
}
Object parentModel = modelCtx.get(taskConfig.getCallLink());
if (parentModel != null && parentModel instanceof FullContext) {
Model parent = (Model) ((FullContext) parentModel).getTarget();
if (parent.getProcessInstanceId() != null) {
addChildProcessInstanceId(parent.getProcessInstanceId(), modelCtx, ctxMap);
break;
}
}
}
}
use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.
the class WkfDisplayServiceImpl method getWkfStatus.
@Override
public List<Map<String, Object>> getWkfStatus(Class<?> klass, Long id) {
List<Map<String, Object>> statusList = new ArrayList<>();
if (klass == null || id == null) {
return statusList;
}
Model model = (Model) JPA.em().find(klass, id);
if (model == null) {
return statusList;
}
String processInstanceId = model.getProcessInstanceId();
log.debug("Display wkf nodes of processInstanceId: {}", processInstanceId);
if (processInstanceId != null) {
WkfInstance wkfInstance = Beans.get(WkfInstanceRepository.class).findByInstnaceId(processInstanceId);
if (wkfInstance == null) {
return statusList;
}
String klassName = klass.getSimpleName();
if (model instanceof MetaJsonRecord) {
klassName = ((MetaJsonRecord) model).getJsonModel();
}
boolean valid = isValidDisplayModel(klassName, wkfInstance);
log.debug("Is valid model to display wkf nodes : {}", valid);
if (!valid) {
return statusList;
}
addActiveNodes(statusList, wkfInstance, klassName);
}
return statusList;
}
use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.
the class BamlModelController method execute.
public void execute(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String model = (String) context.get("modelName");
Model entity = null;
if (context.get("recordId") != null && model != null) {
Long recordId = Long.parseLong(context.get("recordId").toString());
entity = WkfContextHelper.getRepository(model).find(recordId);
}
Map<String, Object> bamlModelMap = (Map<String, Object>) context.get("bamlModel");
BamlModel bamlModel = Beans.get(BamlModelRepository.class).find(Long.parseLong(bamlModelMap.get("id").toString()));
Model object = Beans.get(BamlService.class).execute(bamlModel, entity);
String modelName = object.getClass().getSimpleName();
String dasherizeModel = Inflector.getInstance().dasherize(modelName);
String title = object.getClass().getSimpleName();
String formView = dasherizeModel + "-form";
String gridView = dasherizeModel + "-grid";
String jsonModel = null;
if (object instanceof MetaJsonRecord) {
jsonModel = ((MetaJsonRecord) object).getJsonModel();
title = Beans.get(MetaJsonModelRepository.class).findByName(jsonModel).getTitle();
if (Strings.isNullOrEmpty(title)) {
title = jsonModel;
}
formView = "custom-model-" + jsonModel + "-form";
gridView = "custom-model-" + jsonModel + "-grid";
}
response.setCanClose(true);
ActionViewBuilder builder = ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form", formView).add("grid", gridView).context("_showRecord", object.getId());
if (jsonModel != null) {
builder.context("jsonModel", jsonModel);
builder.domain("self.jsonModel = :jsonModel");
}
response.setView(builder.map());
}
use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.
the class ValueMapperController method execute.
public void execute(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
Map<String, Object> valueMapperMap = (Map<String, Object>) context.get("valueMapper");
ValueMapper mapper = Beans.get(ValueMapperRepository.class).find(Long.parseLong(valueMapperMap.get("id").toString()));
if (mapper == null || mapper.getScript() == null) {
return;
}
String modelName = (String) context.get("modelName");
Model model = null;
if (context.get("recordId") != null && modelName != null) {
Long recordId = Long.parseLong(context.get("recordId").toString());
model = FullContextHelper.getRepository(modelName).find(recordId);
}
Object result = Beans.get(ValueMapperService.class).execute(mapper, model);
if (result != null && result instanceof FullContext && mapper.getScript().startsWith("def rec = $ctx.create(")) {
FullContext fullContext = (FullContext) result;
Object object = fullContext.getTarget();
String title = object.getClass().getSimpleName();
if (object instanceof MetaJsonRecord) {
title = ((MetaJsonRecord) object).getJsonModel();
}
response.setView(ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form").add("grid").context("_showRecord", fullContext.get("id")).map());
}
response.setCanClose(true);
}
Aggregations