} // doIt /// <summary> /// Verify Tree /// </summary> /// <param name="tree">tree</param> /// <returns>message</returns> private String VerifyTree(MTree tree) { if (tree.GetAD_Table_ID(true) == 0) { tree.UpdateTrees(); } String nodeTableName = tree.GetNodeTableName(); String sourceTableName = tree.GetSourceTableName(true); String sourceTableKey = sourceTableName + "_ID"; int AD_Client_ID = tree.GetAD_Client_ID(); int C_Element_ID = 0; if (MTree.TREETYPE_ElementValue.Equals(tree.GetTreeType())) { String sql = "SELECT C_Element_ID FROM C_Element " + "WHERE AD_Tree_ID=" + tree.GetAD_Tree_ID(); C_Element_ID = DataBase.DB.GetSQLValue(null, sql); if (C_Element_ID <= 0) { throw new Exception("No Account Element found"); } } // Delete unused StringBuilder sql1 = new StringBuilder(); sql1.Append("DELETE FROM ").Append(nodeTableName) .Append(" WHERE AD_Tree_ID=").Append(tree.GetAD_Tree_ID()) .Append(" AND Node_ID NOT IN (SELECT ").Append(sourceTableKey) .Append(" FROM ").Append(sourceTableName) .Append(" WHERE AD_Client_ID IN (0,").Append(AD_Client_ID).Append(")"); if (C_Element_ID > 0) { sql1.Append(" AND C_Element_ID=").Append(C_Element_ID); } sql1.Append(")"); log.Finer(sql1.ToString()); // int deletes = DataBase.DB.ExecuteQuery(sql1.ToString(), null, Get_Trx()); AddLog(0, null, new Decimal(deletes), tree.GetName() + " Deleted"); if (!tree.IsAllNodes()) { return(tree.GetName() + " OK"); } // Insert new int inserts = 0; StringBuilder sql2 = new StringBuilder(); sql2.Append("SELECT ").Append(sourceTableKey) .Append(" FROM ").Append(sourceTableName) .Append(" WHERE AD_Client_ID IN (0,").Append(AD_Client_ID).Append(")"); if (C_Element_ID > 0) { sql2.Append(" AND C_Element_ID=").Append(C_Element_ID); } sql2.Append(" AND ").Append(sourceTableKey) .Append(" NOT IN (SELECT Node_ID FROM ").Append(nodeTableName) .Append(" WHERE AD_Tree_ID=").Append(tree.GetAD_Tree_ID()).Append(")") .Append(" ORDER BY Upper(name)"); log.Finer(sql2.ToString()); // Boolean ok = true; IDataReader idr = null; //PreparedStatement pstmt = null; try { //pstmt = DataBase.prepareStatement(sql.toString(), Get_Trx()); //ResultSet rs = pstmt.executeQuery(); idr = DataBase.DB.ExecuteReader(sql2.ToString(), null, Get_Trx()); //Manish 8/06/2016 int setSeqManually = -1; //End while (idr.Read()) { int Node_ID = Utility.Util.GetValueOfInt(idr[0]);// rs.getInt(1); PO node = null; if (nodeTableName.Equals("AD_TreeNode")) { // node = new MTreeNode(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNode(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeBP")) { //node = new MTreeNodeBP(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeBP(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodePR")) { //node = new MTreeNodePR(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodePR(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeCMC")) { //node = new MTreeNodeCMC(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeCMC(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeCMM")) { //node = new MTreeNodeCMM(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeCMM(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeCMS")) { // node = new MTreeNodeCMS(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeCMS(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeCMT")) { //node = new MTreeNodeCMT(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeCMT(tree, Node_ID, setSeqManually); //end } else if (nodeTableName.Equals("AD_TreeNodeMM")) { // node = new MTreeNodeMM(tree, Node_ID); //Manish setSeqManually += 1; node = new MTreeNodeMM(tree, Node_ID, setSeqManually); //end } if (node == null) { log.Log(Level.SEVERE, "No Model for " + nodeTableName); } else { if (node.Save()) { inserts++; } else { log.Log(Level.SEVERE, "Could not add to " + tree + " Node_ID=" + Node_ID); } } } } catch (Exception e) { log.Log(Level.SEVERE, sql2.ToString(), e); ok = false; } finally { idr.Close(); } AddLog(0, null, new Decimal(inserts), tree.GetName() + " Inserted"); return(tree.GetName() + (ok ? " OK" : " Error")); } // verifyTree
} // prepare /// <summary> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { _apps_host = new VConnection(); CacheHandler thisHandler = new CacheHandler //(CacheHandler.ConvertJNPURLToCacheURL(GetCtx().GetContext("java.naming.provider.url")), log, GetCtx(), Get_Trx()); (CacheHandler.ConvertJNPURLToCacheURL((String)_apps_host.Apps_host), log, GetCtx(), Get_Trx()); log.Info("CM_WebProject_ID=" + _CM_WebProject_ID); _project = new MWebProject(GetCtx(), _CM_WebProject_ID, Get_Trx()); if (_project.Get_ID() != _CM_WebProject_ID) { throw new Exception("@NotFound@ @CM_WebProject_ID@ " + _CM_WebProject_ID); } log.Log(Level.INFO, "Starting media deployment"); // Deploy Media MMediaServer[] mserver = MMediaServer.GetMediaServer(_project); for (int i = 0; i < mserver.Length; i++) { log.Log(Level.INFO, "Media Server deployment started on: " + mserver.ToString()); if (_isRedeploy) { mserver[i].ReDeployAll(); } mserver[i].Deploy(); log.Log(Level.INFO, "Media Server deployment finished on: " + mserver.ToString()); } // Stage MCStage[] stages = MCStage.GetStages(_project); for (int i = 0; i < stages.Length; i++) { _map.Add(Utility.Util.GetValueOfInt(stages[i].GetCM_CStage_ID()), stages[i]); } // Copy Stage Tree MTree treeS = new MTree(GetCtx(), _project.GetAD_TreeCMS_ID(), false, false, Get_Trx()); VTreeNode root = treeS.GetRootNode(); CopyStage(root, "/", _isRedeploy); // Delete Inactive Containers MContainer[] containers = MContainer.GetContainers(_project); for (int i = 0; i < containers.Length; i++) { MContainer container = containers[i]; if (!_idList.Contains(Utility.Util.GetValueOfInt(container.GetCM_Container_ID()))) { String name = container.GetName(); if (container.Delete(true)) { log.Fine("Deleted: " + name); } else // e.g. was referenced { log.Warning("Failed Delete: " + name); AddLog(0, null, null, "@Error@ @Delete@: " + name); } } // Remove Container from cache thisHandler.CleanContainer(container.Get_ID()); } // Delete Inactive // Sync Stage & Container Tree MTreeNodeCMS[] nodesCMS = MTreeNodeCMS.GetTree(GetCtx(), _project.GetAD_TreeCMS_ID(), Get_Trx()); MTreeNodeCMC[] nodesCMC = MTreeNodeCMC.GetTree(GetCtx(), _project.GetAD_TreeCMC_ID(), Get_Trx()); for (int s = 0; s < nodesCMS.Length; s++) { MTreeNodeCMS nodeCMS = nodesCMS[s]; int Node_ID = nodeCMS.GetNode_ID(); for (int c = 0; c < nodesCMC.Length; c++) { MTreeNodeCMC nodeCMC = nodesCMC[c]; if (nodeCMC.GetNode_ID() == Node_ID) { //if (nodeCMS.getParent_ID()!=0) nodeCMC.setParent_ID(nodeCMS.GetParent_ID()); nodeCMC.SetSeqNo(nodeCMS.GetSeqNo()); nodeCMC.Save(); break; } } } // for all stage nodes // Clean ContainerTree Cache thisHandler.CleanContainerTree(_CM_WebProject_ID); return("@Copied@ @CM_Container_ID@ #" + _idList.Count); } // doIt