*
* @throws EMFUserError the EMF user error
*/
public void insertModelTree(Model mod, Session session) throws EMFUserError {
logger.debug("IN");
IModelDAO modelDao=DAOFactory.getModelDAO();
try {
Query hibQuery = session.createQuery(" from SbiKpiModel where kpiModelId = " + mod.getId());
List hibList = hibQuery.list();
if(!hibList.isEmpty()) {
return;
}
// main attributes
SbiKpiModel hibMod = new SbiKpiModel();
hibMod.setKpiModelId(mod.getId());
hibMod.setKpiModelLabel(mod.getLabel());
hibMod.setKpiModelCd(mod.getCode());
hibMod.setKpiModelDesc(mod.getDescription());
hibMod.setKpiModelNm(mod.getName());
// insert Parent
if(mod.getParentId()!=null){
SbiKpiModel hibKpiModelParent = (SbiKpiModel) session.load(SbiKpiModel.class, mod.getParentId());
hibMod.setSbiKpiModel(hibKpiModelParent);
}
// sbiDomain
Criterion nameCriterrion = Expression.eq("valueCd", mod.getTypeCd());
Criteria criteria = session.createCriteria(SbiDomains.class);
criteria.add(nameCriterrion);
SbiDomains domainType = (SbiDomains) criteria.uniqueResult();
hibMod.setModelType(domainType);
// load kpi
if (mod.getKpiId() != null) {
Integer kpiId=mod.getKpiId();
insertKpi(kpiId,session);
SbiKpi sbiKpi= (SbiKpi) session.load(SbiKpi.class, mod.getKpiId());
hibMod.setSbiKpi(sbiKpi);
}
// save current Model
Transaction tx = session.beginTransaction();
session.save(hibMod);
tx.commit();
logger.debug("current model "+mod.getCode()+" inserted");
//manage insert of udp values
List udpValues = DAOFactory.getUdpDAOValue().findByReferenceId(mod.getId(), "Model");
if(udpValues != null && !udpValues.isEmpty()){
for (Iterator iterator = udpValues.iterator(); iterator.hasNext();) {
UdpValue udpValue = (UdpValue) iterator.next();
insertUdpValue(udpValue, session);
}
}
Set modelChildren=new HashSet();
logger.debug("insert current model children");
//Load model childred
Model modWithChildren=modelDao.loadModelWithChildrenById(mod.getId());
List childrenList=modWithChildren.getChildrenNodes();
if(childrenList!=null){
for (Iterator iterator = childrenList.iterator(); iterator.hasNext();) {
Model childNode = (Model) iterator.next();