//public static WsFile DeleteDoc(string wsId, string wsLogFldrID, string docObjId, string comment = null) public static WsFile DeleteDoc(string wsId, string docObjId, string comment = null, bool toValidate = true) { IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(docObjId, isAdmin: true); if (!toValidate || WsValidation.ValidateDoc(imDoc, imDocumentOperation.imDeleteDocumentOp) == WsDocDelStatusType.Success) { //imDoc.Update(); imDoc.LockContent(false); //imDoc.UnlockContent(); IManProfileUpdateResult status = imDoc.UpdateWithResults(); if (status.Succeeded) { //Set Custom27 to true (Marked for deletion attribute) imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom27, true); //Prefix document description with “DEL_” if (!imDoc.Description.StartsWith(AmConst.CONST_DELETE_PREFIX)) { imDoc.Description = AmConst.CONST_DELETE_PREFIX + imDoc.Description; } //Add a message to IWov history (see Autonomy’s documentation) //imDoc.HistoryList.Add(imHistEvent.imHistoryDelete, 0, 0, AmConst.CONST_APP_NAME, AmConst.CONST_DELETE_COMMENT, "", "", "", null, null, null); AddImHistoryInfo(imDoc, HistoryInfoType.DELETE); //Store rollback information in the comments //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897942) //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897941) //Grant right for NRTADMIN and Service Account to file. //WsUtility.AddUserSecurity(imDoc, imAccessRight.imRightAll); -- Why? WsUtility.AddGroupSecurity(imDoc, "NRTADMIN", imAccessRight.imRightAll); imDoc.Security.DefaultVisibility = imSecurityType.imPrivate; //Set owner and creator to DELETE USER imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER)); imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER)); //Remove all security right and groups except for NRTADMIN group and Service Account -- Why? foreach (IManUserACL userRight in imDoc.Security.UserACLs) { if (userRight.User.Name != "DELETEUSER") { //WsUtility.AddUserSecurity(imDoc, userRight.User.Name, imAccessRight.imRightNone); userRight.Right = imAccessRight.imRightNone; } } foreach (IManGroupACL groupRight in imDoc.Security.GroupACLs) { if (groupRight.Group.Name != "NRTADMIN") { //WsUtility.AddGroupSecurity(imDoc, groupRight.Group.Name, imAccessRight.imRightNone); groupRight.Right = imAccessRight.imRightNone; } } imDoc.Update(); imDoc.UnlockContent(); var wsGLog = new WsGenericLog(); wsGLog.ActionBy = AmUtil.GetCurrentUser; wsGLog.Id = imDoc.Number; wsGLog.Name = imDoc.Description; wsGLog.ActionInfo = null; wsGLog.AdditionalInfo = null; wsGLog.Comment = comment; wsGLog.OldValue = null; wsGLog.NewValue = null; wsGLog.WsLogActivityType = WsLogActivityType.DeleteFile; WsUtility.CreateWsLog(wsId, wsGLog); } IManDocument imDocRet = WsUtility.GetObjectByID <IManDocument>(docObjId); return(Workspace.GetWsFile(imDocRet)); } return(null); }
public static void InitiateClosure(InitiateClosureWsModel initiateClosureWsModel) { var wsModelIn = initiateClosureWsModel.WsModel; var largeRetFiles = initiateClosureWsModel.LargeRetFiles; var comment = initiateClosureWsModel.Comment; IManWorkspace imWs = null; var wsModel = Workspace.GetWs(wsModelIn.ObjectID, out imWs, WsLoadType.ALL); //List<WsFile> wsFiles = new List<WsFile>(); //WsFldr wsFldr = new WsFldr(); //wsFldr.WsFldrs = wsModelIn.WsFldrs; //WsUtility.GetWsFiles(item => //{ // if (item.WsFiles != null && item.WsFiles.Count > 0) // { // foreach (var wsFile in item.WsFiles) // { // if (wsFile.IsIncludedInClosure) // wsFiles.Add(wsFile); // } // } //}, wsFldr); List <WsFile> wsFiles = GetAllFilesFromWs(wsModelIn); wsFiles = wsFiles.Where(x => x.IsIncludedInClosure).ToList(); var wsGLog = new WsGenericLog(); wsGLog.ActionBy = AmUtil.GetCurrentUser; wsGLog.Id = null; wsGLog.Name = null; wsGLog.ActionInfo = null; wsGLog.AdditionalInfo = null; wsGLog.Comment = comment; wsGLog.OldValue = null; wsGLog.NewValue = null; wsGLog.WsLogActivityType = WsLogActivityType.Closure; var sbFileInfo = new StringBuilder(); sbFileInfo.AppendLine("Event trigger Date for this closure: " + wsModelIn.WsProfile.EventTrgDate); sbFileInfo.AppendLine(); sbFileInfo.AppendLine(AmUtil.GetLineSeperator); sbFileInfo.AppendLine(); var sbClosureMailInfo = new StringBuilder(); foreach (var item in wsFiles) { IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(item.ObjectID, isAdmin: true); if (WsValidation.ValidateDoc(imDoc, imDocumentOperation.imFreezeDocumentOp) == WsDocDelStatusType.Success) { var wsFile = Workspace.GetWsFile(imDoc); //if (wsFile.IsLocked) { } //if (wsFile.IsCheckedOut) //{ // CheckInDoc(imDoc); //} //if (wsFile.IsDeleted) { } //if (wsFile.IsRecord) { } sbFileInfo.AppendLine("DocNum: " + wsFile.Number); sbFileInfo.AppendLine("DocName: " + wsFile.Description.FileNameWithExtn(wsFile.Extn)); sbFileInfo.AppendLine("DocPath: " + item.FilePath); sbFileInfo.AppendLine("IsLocked: " + wsFile.IsLocked); sbFileInfo.AppendLine("IsCheckedOut: " + wsFile.IsCheckedOut); sbFileInfo.AppendLine("IsDeleted: " + wsFile.IsDeleted); sbFileInfo.AppendLine("IsRecord: " + wsFile.IsRecord); sbFileInfo.AppendLine(); imDoc.SetAttributeByID(imProfileAttributeID.imProfileFrozen, true); //imDoc.HistoryList.Add(imHistEvent.imHistoryFrozen, 0, 0, "Audit Manager", "eAudit closure", String.Empty, String.Empty, String.Empty); AddImHistoryInfo(imDoc, HistoryInfoType.CLOSURE); IManProfileUpdateResult res = imDoc.UpdateWithResults(); if (res.Succeeded) { sbFileInfo.AppendLine("ClosureStatus: Success"); } else { sbFileInfo.AppendLine("ClosureStatus: Failure"); } sbFileInfo.AppendLine(); sbFileInfo.AppendLine(AmUtil.GetLineSeperator); sbFileInfo.AppendLine(); sbClosureMailInfo.Append("<tr><td align='center' valign='middle'>"); sbClosureMailInfo.Append(wsFile.Description.FileNameWithExtn(wsFile.Extn)); sbClosureMailInfo.Append("</td><td align='center' valign='middle'>"); sbClosureMailInfo.Append(item.FilePath.Remove(0, 4)); sbClosureMailInfo.Append("</td><td align='center' valign='middle'>"); if (wsFile.IsRecord) { sbClosureMailInfo.Append("X"); } sbClosureMailInfo.Append("</td></tr>"); } } if (largeRetFiles != null && largeRetFiles.Count > 0) { int idx = 0; sbFileInfo.AppendLine("Large Retention file included in the closure."); sbFileInfo.AppendLine(); largeRetFiles.ForEach(x => sbFileInfo.AppendLine(++idx + ". " + x)); foreach (var item in largeRetFiles) { sbClosureMailInfo.Append("<tr align='center'><td><p>"); sbClosureMailInfo.Append(item); sbClosureMailInfo.Append("</p></td><td><p>"); sbClosureMailInfo.Append("Large file retention server"); sbClosureMailInfo.Append("</p></td><td align='center' valign='middle'><p>"); sbClosureMailInfo.Append("</p></td></tr>"); } } wsGLog.AdditionalInfo = sbFileInfo.ToString(); WsUtility.CreateWsLog(wsModelIn.ObjectID, wsGLog); var recepients = WsUtility.GetEmailRecepients(wsModel, EmailRecepientType.MANAGER_N_PARTNER_N_ADMIN); var mailBody = AmUtil.SendMail_Closure(WsActivityType.CLOSURE_INITIATE.ToString(), wsModel.WsProfile.EngNum, wsModel.Name, recepients, sbClosureMailInfo.ToString()); wsGLog.WsLogActivityType = WsLogActivityType.ClosureConfirmEmail; WsUtility.CreateEmailLog(wsModelIn.ObjectID, mailBody, wsGLog); WsUtility.SaveClosureInfo(wsModel.WsProfile.EngNum, string.Format("{0}|{1}", string.Join(",", wsFiles.Select(x => x.Number).ToList()), ((initiateClosureWsModel.LargeRetFiles == null || initiateClosureWsModel.LargeRetFiles.Count == 0) ? string.Empty : string.Join(",", initiateClosureWsModel.LargeRetFiles)) ), string.Join(",", recepients.Select(x => x.Item2).ToList()), mailBody, initiateClosureWsModel.Comment, initiateClosureWsModel.LargeRetFiles == null ? false : (initiateClosureWsModel.LargeRetFiles.Count > 0)); //return IM.Mgr.Workspace.GetWs(wsModelIn.ObjectID); }