use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class TimerProjectTaskServiceImpl method find.
@Override
public Timer find(Model model) {
User user = userService.getUser();
ProjectTask task = (ProjectTask) model;
List<Timer> timers = task.getTimerList();
return timers != null && !timers.isEmpty() ? timers.stream().filter(t -> t.getAssignedToUser() == user).findFirst().orElse(null) : null;
}
use of com.axelor.db.Model 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);
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class AppLoaderImportServiceImpl method importApp.
protected File importApp(AppLoader appLoader, File dataDir) throws IOException, FileNotFoundException {
File logFile = appLoader.getImportLog() != null ? MetaFiles.getPath(appLoader.getImportLog()).toFile() : MetaFiles.createTempFile("import-", "log").toFile();
PrintWriter pw = new PrintWriter(logFile);
for (File confiFile : getAppImportConfigFiles(dataDir)) {
XMLImporter xmlImporter = new XMLImporter(confiFile.getAbsolutePath(), dataDir.getAbsolutePath());
xmlImporter.setContext(getImportContext(appLoader));
xmlImporter.addListener(new Listener() {
@Override
public void imported(Integer total, Integer success) {
}
@Override
public void imported(Model bean) {
}
@Override
public void handle(Model bean, Exception e) {
pw.write("Error Importing: " + bean);
e.printStackTrace(pw);
}
});
xmlImporter.run();
}
pw.flush();
pw.close();
return logFile;
}
use of com.axelor.db.Model 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.db.Model 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