/// <summary> /// Update Elements in Container from Stage /// </summary> /// <param name="project">proejct</param> /// <param name="stage">stage</param> /// <param name="trxName">trx</param> protected void UpdateTTables(MWebProject project, MCStage stage, Trx trxName) { int[] tableKeys = X_CM_CStageTTable.GetAllIDs("CM_CStageTTable", "CM_CStage_ID=" + stage.Get_ID(), trxName); if (tableKeys != null && tableKeys.Length > 0) { for (int i = 0; i < tableKeys.Length; i++) { X_CM_CStageTTable thisStageTTable = new X_CM_CStageTTable( project.GetCtx(), tableKeys[i], trxName); int[] thisContainerTTableKeys = X_CM_ContainerTTable.GetAllIDs( "CM_ContainerTTable", "CM_Container_ID=" + stage.Get_ID() + " AND CM_TemplateTable_ID=" + thisStageTTable.GetCM_TemplateTable_ID(), trxName); X_CM_ContainerTTable thisContainerTTable; if (thisContainerTTableKeys != null && thisContainerTTableKeys.Length > 0) { thisContainerTTable = new X_CM_ContainerTTable(project .GetCtx(), thisContainerTTableKeys[0], trxName); } else { thisContainerTTable = new X_CM_ContainerTTable(project .GetCtx(), 0, trxName); } thisContainerTTable.SetCM_Container_ID(stage.Get_ID()); PO.CopyValues(new X_CM_CStageTTable(project.GetCtx(), tableKeys[i], trxName), thisContainerTTable); thisContainerTTable.Save(trxName); } } }
/// <summary> /// Get Stages /// </summary> /// <param name="project">project</param> /// <returns>stages</returns> public static MCStage[] GetStages(MWebProject project) { List <MCStage> list = new List <MCStage>(); SqlParameter[] param = new SqlParameter[1]; IDataReader idr = null; String sql = "SELECT * FROM CM_CStage WHERE CM_WebProject_ID=@param ORDER BY CM_CStage_ID"; try { //pstmt = DataBase.prepareStatement (sql, project.get_TrxName()); //pstmt.setInt (1, project.getCM_WebProject_ID()); param[0] = new SqlParameter("@param", project.GetCM_WebProject_ID()); idr = DataBase.DB.ExecuteReader(sql, param, project.Get_TrxName()); while (idr.Read()) { list.Add(new MCStage(project.GetCtx(), idr, project.Get_TrxName())); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } MCStage[] retValue = new MCStage[list.Count]; retValue = list.ToArray(); return(retValue); } // getStages
} // getAD_Tree_ID; /// <summary> /// Set/Copy Stage /// </summary> /// <param name="project">parent</param> /// <param name="stage">stage</param> /// <param name="path">path</param> protected void SetStage(MWebProject project, MCStage stage, String path) { _stage = stage; PO.CopyValues(stage, this); SetAD_Client_ID(project.GetAD_Client_ID()); SetAD_Org_ID(project.GetAD_Org_ID()); SetIsActive(stage.IsActive()); SetCM_ContainerLink_ID(stage.GetCM_CStageLink_ID()); // SetRelativeURL(path + stage.GetRelativeURL()); // if (GetMeta_Author() == null || GetMeta_Author().Length == 0) { SetMeta_Author(project.GetMeta_Author()); } if (GetMeta_Content() == null || GetMeta_Content().Length == 0) { SetMeta_Content(project.GetMeta_Content()); } if (GetMeta_Copyright() == null || GetMeta_Copyright().Length == 0) { SetMeta_Copyright(project.GetMeta_Copyright()); } if (GetMeta_Publisher() == null || GetMeta_Publisher().Length == 0) { SetMeta_Publisher(project.GetMeta_Publisher()); } if (GetMeta_RobotsTag() == null || GetMeta_RobotsTag().Length == 0) { SetMeta_RobotsTag(project.GetMeta_RobotsTag()); } } // setStage
/// <summary> /// getParent MCStage Object /// </summary> /// <returns>Container Stage</returns> public MCStage GetParent() { if (_parent != null) { return(_parent); } _parent = new MCStage(GetCtx(), GetCM_CStage_ID(), Get_TrxName()); return(_parent); }
} // beforeSave /// <summary> ///After Save. Insert - create tree /// </summary> /// <param name="newRecord">insert</param> /// <param name="success">success</param> /// <returns>true if inserted</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } if (newRecord) { StringBuilder sb = new StringBuilder( "INSERT INTO AD_TreeNodeCMT " + "(AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, " + "AD_Tree_ID, Node_ID, Parent_ID, SeqNo) " + "VALUES (") .Append(GetAD_Client_ID()).Append( ",0, 'Y', SysDate, 0, SysDate, 0,").Append( GetAD_Tree_ID()).Append(",").Append(Get_ID()).Append( ", 0, 999)"); int no = DataBase.DB.ExecuteQuery(sb.ToString(), null, Get_TrxName()); if (no > 0) { log.Fine("#" + no + " - TreeType=CMT"); } else { log.Warning("#" + no + " - TreeType=CMT"); } return(no > 0); } if (!newRecord) { VAdvantage.CM.CacheHandler thisHandler = new VAdvantage.CM.CacheHandler( VAdvantage.CM.CacheHandler.ConvertJNPURLToCacheURL(GetCtx() .GetContext(System.Net.Dns.GetHostName())), log, GetCtx(), Get_TrxName()); if (!IsInclude()) { // Clean Main Templates on a single level. thisHandler.CleanTemplate(this.Get_ID()); // Check the elements in the Stage Area MCStage[] theseStages = MCStage.GetStagesByTemplate(GetWebProject(), Get_ID()); for (int i = 0; i < theseStages.Length; i++) { theseStages[i].CheckElements(); } } else { // Since we not know which main templates we will clean up all! thisHandler.EmptyTemplate(); } } return(success); } // afterSave
/// <summary> ///Deploy Stage into Container /// </summary> /// <param name="project">webproject</param> /// <param name="stage">Deploy Stage into Container</param> /// <param name="path">url to it</param> /// <returns>Container</returns> public static MContainer Deploy(MWebProject project, MCStage stage, String path) { MContainer cc = GetDirect(stage.GetCtx(), stage.GetCM_CStage_ID(), stage.Get_TrxName()); if (cc == null) // new { cc = new MContainer(stage.GetCtx(), 0, stage.Get_TrxName()); } cc.SetStage(project, stage, path); cc.Save(); if (!stage.IsSummary()) { cc.UpdateElements(project, stage, stage.Get_TrxName()); cc.UpdateTTables(project, stage, stage.Get_TrxName()); } return(cc); } // copy
} // getStages /// <summary> /// Get Stage by Name /// </summary> /// <param name="project">project</param> /// <param name="RelativeURL">relurl</param> /// <param name="parent_ID">id</param> /// <returns>stages</returns> public static MCStage GetByName(MWebProject project, String RelativeURL, int parent_ID) { MCStage retValue = null; IDataReader idr = null; SqlParameter[] param = new SqlParameter[4]; String sql = "SELECT * FROM CM_CStage WHERE CM_WebProject_ID=@param1 AND RelativeURL LIKE @param2 " + //1,2 "AND CM_CStage_ID IN (SELECT Node_ID FROM AD_TreeNodeCMS WHERE " + " AD_Tree_ID=@param3 AND Parent_ID=@param4)" + // 3, 4 "ORDER BY CM_CStage_ID"; try { //pstmt = DataBase.prepareStatement (sql, project.get_TrxName()); //pstmt.setInt (1, project.getCM_WebProject_ID()); param[0] = new SqlParameter("@param1", project.GetCM_WebProject_ID()); //pstmt.setString (2, RelativeURL); param[1] = new SqlParameter("@param2", RelativeURL); //pstmt.setInt (3, project.getAD_TreeCMS_ID ()); param[2] = new SqlParameter("@param3", project.GetAD_TreeCMS_ID()); //pstmt.setInt (4, parent_ID); param[3] = new SqlParameter("@param4", parent_ID); idr = DataBase.DB.ExecuteReader(sql, param, project.Get_TrxName()); if (idr.Read()) { retValue = new MCStage(project.GetCtx(), idr, project.Get_TrxName()); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } return(retValue); } // getStages
} // setStage /// <summary> /// Update Elements in Container from Stage /// </summary> /// <param name="project">project</param> /// <param name="stage">stage</param> /// <param name="trxName">trx</param> protected void UpdateElements(MWebProject project, MCStage stage, Trx trxName) { vcon = new VConnection(); VAdvantage.CM.CacheHandler thisHandler = new VAdvantage.CM.CacheHandler( VAdvantage.CM.CacheHandler.ConvertJNPURLToCacheURL(vcon.Apps_host), log, GetCtx(), Get_Trx()); // First update the new ones... int[] tableKeys = X_CM_CStage_Element.GetAllIDs("CM_CStage_Element", "CM_CStage_ID=" + stage.Get_ID(), trxName); if (tableKeys != null && tableKeys.Length > 0) { for (int i = 0; i < tableKeys.Length; i++) { X_CM_CStage_Element thisStageElement = new X_CM_CStage_Element( project.GetCtx(), tableKeys[i], trxName); int[] thisContainerElementKeys = X_CM_Container_Element .GetAllIDs("CM_Container_Element", "CM_Container_ID=" + stage.Get_ID() + " AND Name LIKE '" + thisStageElement.GetName() + "'", trxName); X_CM_Container_Element thisContainerElement; if (thisContainerElementKeys != null && thisContainerElementKeys.Length > 0) { thisContainerElement = new X_CM_Container_Element(project .GetCtx(), thisContainerElementKeys[0], trxName); } else { thisContainerElement = new X_CM_Container_Element(project .GetCtx(), 0, trxName); } thisContainerElement.SetCM_Container_ID(stage.Get_ID()); X_CM_CStage_Element stageElement = new X_CM_CStage_Element( project.GetCtx(), tableKeys[i], trxName); thisContainerElement.SetName(stageElement.GetName()); thisContainerElement.SetDescription(stageElement.GetDescription()); thisContainerElement.SetHelp(stageElement.GetHelp()); thisContainerElement.SetIsActive(stageElement.IsActive()); thisContainerElement.SetIsValid(stageElement.IsValid()); String contentHTML = thisStageElement.GetContentHTML(); thisContainerElement.SetContentHTML(contentHTML); // PO.copyValues(new // X_CM_CStage_Element(project.getCtx(),tableKeys[i],trxName), // thisContainerElement); thisContainerElement.Save(trxName); // Remove Container from cache thisHandler.CleanContainerElement(thisContainerElement .Get_ID()); } } // Now we are checking the existing ones to delete the unneeded ones... tableKeys = X_CM_Container_Element.GetAllIDs("CM_Container_Element", "CM_Container_ID=" + stage.Get_ID(), trxName); if (tableKeys != null && tableKeys.Length > 0) { for (int i = 0; i < tableKeys.Length; i++) { X_CM_Container_Element thisContainerElement = new X_CM_Container_Element( project.GetCtx(), tableKeys[i], trxName); int[] thisCStageElementKeys = X_CM_CStage_Element .GetAllIDs("CM_CStage_Element", "CM_CStage_ID=" + stage.Get_ID() + " AND Name LIKE '" + thisContainerElement.GetName() + "'", trxName); // If we cannot find a representative in the Stage we will delete from production if (thisCStageElementKeys == null || thisCStageElementKeys.Length < 1) { // First delete it from cache, then delete the record itself thisHandler.CleanContainerElement(thisContainerElement .Get_ID()); thisContainerElement.Delete(true); } } } }