if(!hibList.isEmpty()) {
return;
}
// main attributes
SbiKpiModelInst hibMi = new SbiKpiModelInst();
hibMi.setKpiModelInst(mi.getId());
hibMi.setName(mi.getName());
hibMi.setLabel(mi.getLabel());
hibMi.setDescription(mi.getDescription());
hibMi.setStartDate(mi.getStartDate());
hibMi.setEndDate(mi.getEndDate());
hibMi.setModelUUID(mi.getModelUUID());
// insert Parent
if(mi.getParentId()!=null){
SbiKpiModelInst hibKpiModelInstParent = (SbiKpiModelInst) session.load(SbiKpiModelInst.class, mi.getParentId());
hibMi.setSbiKpiModelInst(hibKpiModelInstParent);
}
// model
if(mi.getModel()!=null){
SbiKpiModel hibModel = (SbiKpiModel) session.load(SbiKpiModel.class, mi.getModel().getId());
hibMi.setSbiKpiModel(hibModel);
}
// Load tKpi Instance
if (mi.getKpiInstance() != null) {
KpiInstance kpiInstance=mi.getKpiInstance();
insertKpiInstance(kpiInstance.getKpiInstanceId(), session);
SbiKpiInstance hibKpiInst = (SbiKpiInstance) session.load(SbiKpiInstance.class, kpiInstance.getKpiInstanceId());
hibMi.setSbiKpiInstance(hibKpiInst);
}
//load all organizational units
List<OrganizationalUnitGrantNode> grants = DAOFactory.getOrganizationalUnitDAO().getGrants(mi.getId());
if(grants != null){
for (OrganizationalUnitGrantNode organizationalUnitGrantNode : grants) {
OrganizationalUnitGrant organizationalUnitGrant = organizationalUnitGrantNode.getGrant();
insertOrgUnitGrant(organizationalUnitGrant, session);
insertOrgUnitGrantNodes(organizationalUnitGrantNode, session);
}
}
Transaction tx = session.beginTransaction();
session.save(hibMi);
tx.commit();
// Load all the model resources of the current instance model
// after having inserted model instance
IModelResourceDAO modelResourceDao=DAOFactory.getModelResourcesDAO();
List modelResources=modelResourceDao.loadModelResourceByModelId(mi.getId());
for (Iterator iterator = modelResources.iterator(); iterator.hasNext();) {
ModelResources modRes = (ModelResources) iterator.next();
insertModelResources(modRes, session);
// TODO: maybe insert also the set
}
Set modelInstanceChildren=new HashSet();
logger.debug("insert current model instance children");
// get the Model Instance children
IModelInstanceDAO modelInstDao=DAOFactory.getModelInstanceDAO();
ModelInstance modInstWithChildren=modelInstDao.loadModelInstanceWithChildrenById(mi.getId());
List childrenList=modInstWithChildren.getChildrenNodes();
if(childrenList!=null){
for (Iterator iterator = childrenList.iterator(); iterator.hasNext();) {
ModelInstance childNode = (ModelInstance) iterator.next();
logger.debug("insert child "+childNode.getLabel());
insertModelInstanceTree(childNode,session);
SbiKpiModelInst hibKpiModelInst = (SbiKpiModelInst) session.load(SbiKpiModelInst.class, childNode.getId());
modelInstanceChildren.add(hibKpiModelInst);
}
}
hibMi.setSbiKpiModelInsts(modelInstanceChildren); // serve?