Search in sources :

Example 26 with Model

use of com.axelor.db.Model in project axelor-open-suite by axelor.

the class WkfTaskServiceImpl method getContext.

protected Map<String, Object> getContext(WkfInstance instance) throws ClassNotFoundException {
    WkfProcess wkfProcess = instance.getWkfProcess();
    Map<String, Object> modelMap = new HashMap<>();
    for (WkfProcessConfig processConfig : wkfProcess.getWkfProcessConfigList()) {
        Model model = null;
        String klassName;
        if (processConfig.getMetaJsonModel() != null) {
            klassName = MetaJsonRecord.class.getName();
        } else {
            klassName = processConfig.getMetaModel().getFullName();
        }
        @SuppressWarnings("unchecked") final Class<? extends Model> klass = (Class<? extends Model>) Class.forName(klassName);
        String query = "self.processInstanceId = ?";
        if (processConfig.getMetaJsonModel() != null) {
            query += " AND self.jsonModel = '" + processConfig.getMetaJsonModel().getName() + "'";
        }
        if (model == null)
            model = JpaRepository.of(klass).all().filter(query, instance.getInstanceId()).order("-id").fetchOne();
        if (model != null) {
            model = EntityHelper.getEntity(model);
            String name = wkfService.getVarName(model);
            modelMap.put(name, new FullContext(model));
        } else {
            log.debug("Model not found with processInstanceId: {}", instance.getInstanceId());
        }
    }
    log.debug("Variable map used: {}", modelMap);
    return modelMap;
}
Also used : WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 27 with Model

use of com.axelor.db.Model in project axelor-open-suite by axelor.

the class WkfUserActionServiceImpl method getModelCtx.

@Override
public FullContext getModelCtx(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException {
    String modelName = null;
    Class<? extends Model> modelClass = null;
    if (wkfTaskConfig.getModelName() != null) {
        modelName = wkfTaskConfig.getModelName();
        modelClass = (Class<? extends Model>) Class.forName(Beans.get(MetaModelRepository.class).findByName(modelName).getFullName());
    } else if (wkfTaskConfig.getJsonModelName() != null) {
        modelName = wkfTaskConfig.getJsonModelName();
        modelClass = MetaJsonRecord.class;
    } else {
        return null;
    }
    String varName = wkfService.getVarName(modelName);
    Object id = execution.getVariable(varName + "Id");
    FullContext wkfContext = null;
    if (id != null && id instanceof Long) {
        Model record = JPA.find(modelClass, Long.parseLong(id.toString()));
        wkfContext = new FullContext(record);
    }
    return wkfContext;
}
Also used : MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 28 with Model

use of com.axelor.db.Model in project axelor-open-suite by axelor.

the class FullContextHelper method filter.

public static List<FullContext> filter(String modelName, String queryStr) {
    List<FullContext> wkfEntities = new ArrayList<FullContext>();
    Query<? extends Model> query = createQuery(modelName, queryStr, null, null);
    for (Model model : query.fetch()) {
        wkfEntities.add(new FullContext(model));
    }
    return wkfEntities;
}
Also used : ArrayList(java.util.ArrayList) Model(com.axelor.db.Model)

Example 29 with Model

use of com.axelor.db.Model in project axelor-open-suite by axelor.

the class ObjectDataAnonymizeServiceImpl method replaceLink.

@Transactional(rollbackOn = { Exception.class })
public void replaceLink(Mapper mapper, String path, List<? extends Model> data, String rootModel, Long recordValue) throws ClassNotFoundException, AxelorException {
    path = path.split("\\.")[0];
    Property property = mapper.getProperty(path);
    if (property == null) {
        return;
    }
    Class<? extends Model> klass = (Class<? extends Model>) Class.forName(rootModel);
    JpaRepository<? extends Model> repo = JpaRepository.of(klass);
    Model object = repo.all().filter("self.id = ?1", recordValue).fetchOne();
    if (object == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessages.OBJECT_DATA_REPLACE_MISSING), recordValue);
    }
    for (Model model : data) {
        mapper.set(model, path, object);
        JPA.save(model);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Model(com.axelor.db.Model) Property(com.axelor.db.mapper.Property) Transactional(com.google.inject.persist.Transactional)

Example 30 with Model

use of com.axelor.db.Model in project axelor-open-suite by axelor.

the class ObjectDataAnonymizeServiceImpl method deleteLink.

@Transactional
public void deleteLink(Mapper mapper, String path, List<? extends Model> data) {
    path = path.split("\\.")[0];
    Property property = mapper.getProperty(path);
    if (property == null || property.isRequired()) {
        return;
    }
    for (Model model : data) {
        mapper.set(model, path, null);
        JPA.save(model);
    }
}
Also used : Model(com.axelor.db.Model) Property(com.axelor.db.mapper.Property) Transactional(com.google.inject.persist.Transactional)

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