Search in sources :

Example 61 with Model

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;
}
Also used : TimerHistoryRepository(com.axelor.apps.base.db.repo.TimerHistoryRepository) AbstractTimerService(com.axelor.apps.base.service.timer.AbstractTimerService) ProjectTask(com.axelor.apps.project.db.ProjectTask) Timer(com.axelor.apps.base.db.Timer) Model(com.axelor.db.Model) UserService(com.axelor.apps.base.service.user.UserService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) Transactional(com.google.inject.persist.Transactional) List(java.util.List) AxelorException(com.axelor.exception.AxelorException) Duration(java.time.Duration) TimerRepository(com.axelor.apps.base.db.repo.TimerRepository) TimerHistory(com.axelor.apps.base.db.TimerHistory) User(com.axelor.auth.db.User) User(com.axelor.auth.db.User) Timer(com.axelor.apps.base.db.Timer) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 62 with Model

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);
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Context(com.axelor.rpc.Context) ValueMapper(com.axelor.studio.db.ValueMapper) ValueMapperRepository(com.axelor.studio.db.repo.ValueMapperRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) ValueMapperService(com.axelor.studio.service.mapper.ValueMapperService) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 63 with Model

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;
}
Also used : Listener(com.axelor.data.Listener) Model(com.axelor.db.Model) XMLImporter(com.axelor.data.xml.XMLImporter) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 64 with Model

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;
}
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 65 with Model

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;
}
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

Model (com.axelor.db.Model)77 MetaModel (com.axelor.meta.db.MetaModel)22 AxelorException (com.axelor.exception.AxelorException)19 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)16 Context (com.axelor.rpc.Context)15 Transactional (com.google.inject.persist.Transactional)15 List (java.util.List)14 Mapper (com.axelor.db.mapper.Mapper)13 IOException (java.io.IOException)13 File (java.io.File)12 Map (java.util.Map)12 Property (com.axelor.db.mapper.Property)11 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)9 JsonContext (com.axelor.rpc.JsonContext)8 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)7 Strings (com.google.common.base.Strings)7 HashSet (java.util.HashSet)7 FullContext (com.axelor.apps.tool.context.FullContext)6 Beans (com.axelor.inject.Beans)6