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