Ejemplo n.º 1
0
        internal WBFolderTreeNode GetFolderTreeNode(String path)
        {
            List <String> steps          = WBUtils.GetPathStepsFromNormalisedPath(path);
            String        normalisedPath = String.Join("/", steps.ToArray());

            SPFolder folder = this.Libraries.GetMasterFolderByPath(normalisedPath);

            WBLogging.Debug("In GetFolderTreeNode(): steps.Count = " + steps.Count);
            if (folder == null)
            {
                WBLogging.Debug("In GetFolderTreeNode(): folder is NULL");
            }
            else
            {
                WBLogging.Debug("In GetFolderTreeNode(): folder = " + folder.Name);
            }

            if (steps.Count == 0)
            {
                return(null);
            }

            WBTerm functionalArea = this.FunctionalAreasTaxonomy.GetSelectedWBTermByPath(steps[0]);

            if (steps.Count == 1)
            {
                return(new WBFunctionalAreaTreeNode(functionalArea, folder));
            }

            // Now let's remove the functional area bit from the list of steps so that we just have a potential records type path:
            steps.RemoveAt(0);

            Term deepestRecordsTypeTerm = this.RecordsTypesTaxonomy.GetDeepestTermBySteps(steps);

            if (deepestRecordsTypeTerm == null)
            {
                return(null);
            }

            String deepestRecordsTypeLocationPath = functionalArea.Name + "/" + deepestRecordsTypeTerm.WBxFullPath();

            if (deepestRecordsTypeLocationPath == normalisedPath)
            {
                // OK so the path was to a records type - not a folder below the records type:
                return(new WBRecordsTypeTreeNode(functionalArea, new WBRecordsType(this.RecordsTypesTaxonomy, deepestRecordsTypeTerm), folder));
            }

            // Otherwise - if we've got here then the path is to an actual folder within the master records library:
            return(new WBFolderTreeNode(folder));
        }
Ejemplo n.º 2
0
        public bool Contains(WBTerm term)
        {
            if (term == null)
            {
                return(false);
            }
            string termGUIDString = term.Id.WBxToString();

            if (termGUIDString == "")
            {
                return(false);
            }

            return(UIControlValue.Contains(termGUIDString));
        }
Ejemplo n.º 3
0
        public bool Equals(WBTerm other)
        {
            if (other == null)
            {
                return(false);
            }

            if (this.Id == other.Id)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            WBTerm term = obj as WBTerm;

            if (term == null)
            {
                return(false);
            }
            else
            {
                return(Equals(term));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Public constructor
        /// </summary>
        /// <param name="term">The underlying Term object that is being wrapped</param>
        public TreeViewLocation(TreeViewLocation parent, WBRecordsManager manager, string mode, string minimumProtectiveZone, WBTerm functionalArea)
        {
            _type = LOCATION_TYPE__FUNCTIONAL_AREA;

            _parent  = parent;
            _manager = manager;
            _mode    = mode;
            _minimumProtectiveZone = minimumProtectiveZone;

            _functionalArea = functionalArea;
            _name           = functionalArea.Name;
            _guidString     = functionalArea.Id.ToString();

            if (_mode != VIEW_MODE__NEW)
            {
                _folder = manager.Libraries.GetMasterFolderByPath(functionalArea.Name);
            }
        }
Ejemplo n.º 6
0
        public TreeViewLocation(TreeViewLocation parent, WBRecordsManager manager, string mode, string minimumProtectiveZone, WBTerm functionalArea, WBRecordsType recordsType)
        {
            _type = LOCATION_TYPE__RECORDS_TYPE;

            _parent  = parent;
            _manager = manager;
            _mode    = mode;
            _minimumProtectiveZone = minimumProtectiveZone;

            _functionalArea = functionalArea;
            _recordsType    = recordsType;
            _name           = _recordsType.Name;
            _guidString     = _recordsType.Id.ToString();

            if (_mode != VIEW_MODE__NEW)
            {
                _folder = _parent._folder.WBxGetSubFolder(recordsType.Name);
                if (_folder == null)
                {
                    WBLogging.Debug("Did not find folder for: " + recordsType.Name);
                }
            }
        }
Ejemplo n.º 7
0
        public WBTermCollection <WBTerm> FunctionalArea(WBTaxonomy functionalAreas)
        {
            if (UseAllFunctionalAreas)
            {
                List <WBTerm> allTerms = new List <WBTerm>();
                foreach (Term term in functionalAreas.TermSet.Terms)
                {
                    WBTerm functionalArea = new WBTerm(functionalAreas, term);
                    allTerms.Add(functionalArea);
                }

                return(new WBTermCollection <WBTerm>(functionalAreas, allTerms));
            }

            // Otherwise if we get here then this team has specific terms set:
            string UIControlValue = FunctionalAreaUIControlValue;

            if ((UIControlValue == null || UIControlValue == "") && Parent != null)
            {
                return(Parent.FunctionalArea(functionalAreas));
            }

            return(new WBTermCollection <WBTerm>(functionalAreas, FunctionalAreaUIControlValue));
        }
Ejemplo n.º 8
0
 public WBFunctionalAreaTreeNode(WBTerm functionalArea, SPFolder folder)
     : base(folder)
 {
     FunctionalArea = functionalArea;
 }
Ejemplo n.º 9
0
 public WBRecordsTypeTreeNode(WBTerm functionalArea, WBRecordsType recordsType, SPFolder folder)
     : base(folder)
 {
     FunctionalArea = functionalArea;
     RecordsType    = recordsType;
 }
Ejemplo n.º 10
0
        public WBRecord DeclareNewRecord(WBTaskFeedback feedback, String callingUserLogin, WBDocument document, WBRecord recordToReplace, String replacingAction, WBItem extraMetadata)
        {
            WBTerm        functionalArea = document.FunctionalArea[0];
            WBRecordsType recordsType    = document.RecordsType;

            string fullClassPath = WBUtils.NormalisePath(functionalArea.Name + "/" + recordsType.FullPath);

            WBLogging.RecordsTypes.HighLevel("Declaring a document to the library with path: " + fullClassPath);

            string datePath      = "NO DATE SET";
            string dateForName   = "YYYY-MM-DD";
            string oldDateFormat = "YYYYMMDD-";

            // If nothing else we'll use the time now (which will be roughly the date / time declared as the date for the naming convention:
            DateTime referenceDate = DateTime.Now;

            if (document.HasReferenceDate && recordsType.DocumentReferenceDateRequirement != WBRecordsType.METADATA_REQUIREMENT__HIDDEN)
            {
                referenceDate = document.ReferenceDate;
            }
            else
            {
                document.ReferenceDate = referenceDate;
            }

            int year  = referenceDate.Year;
            int month = referenceDate.Month;

            if (month >= 4)
            {
                datePath = String.Format("{0}-{1}", year.ToString("D4"), (year + 1).ToString("D4"));
            }
            else
            {
                datePath = String.Format("{0}-{1}", (year - 1).ToString("D4"), year.ToString("D4"));
            }

            dateForName = String.Format("{0}-{1}-{2}",

                                        referenceDate.Year.ToString("D4"),
                                        referenceDate.Month.ToString("D2"),
                                        referenceDate.Day.ToString("D2"));

            oldDateFormat = String.Format("{0}{1}{2}-",
                                          referenceDate.Year.ToString("D4"),
                                          referenceDate.Month.ToString("D2"),
                                          referenceDate.Day.ToString("D2"));


            string fullFilingPath = String.Join("/", recordsType.FilingPathForDocument(document).ToArray());

            WBLogging.Debug("The original filename is set as: " + document.OriginalFilename);

            String extension = Path.GetExtension(document.OriginalFilename);
            String filename  = WBUtils.RemoveDisallowedCharactersFromFilename(document.OriginalFilename);

            String titleForFilename = document[WBColumn.Title].WBxToString();
            String referenceID      = document.ReferenceID;

            // We don't want to use a title that is too long:
            if (String.IsNullOrEmpty(titleForFilename) || titleForFilename.Length > 50)
            {
                titleForFilename = "";
            }

            if (String.IsNullOrEmpty(titleForFilename) && String.IsNullOrEmpty(referenceID))
            {
                titleForFilename = Path.GetFileNameWithoutExtension(filename);

                // Let's now remove the old date format if the date is the same as the one
                // that is going to be used for the new date format:
                titleForFilename = titleForFilename.Replace(oldDateFormat, "");
            }

            if (String.IsNullOrEmpty(referenceID))
            {
                filename = "(" + dateForName + ") " + titleForFilename + extension;
            }
            else
            {
                if (String.IsNullOrEmpty(titleForFilename))
                {
                    filename = "(" + dateForName + ") " + referenceID + extension;
                }
                else
                {
                    filename = "(" + dateForName + ") " + referenceID + " - " + titleForFilename + extension;
                }
            }

            filename = WBUtils.RemoveDisallowedCharactersFromFilename(filename);

            SPContentType classFolderType    = null;
            SPContentType filePartFolderType = null;

            try
            {
                classFolderType    = ProtectedMasterLibrary.Site.RootWeb.ContentTypes[WBRecordsType.RECORDS_LIBRARY__CLASS_FOLDER_CONTENT_TYPE];
                filePartFolderType = ProtectedMasterLibrary.Site.RootWeb.ContentTypes[WBRecordsType.RECORDS_LIBRARY__FILE_PART_FOLDER_CONTENT_TYPE];
            }
            catch (Exception exception)
            {
                WBLogging.RecordsTypes.Unexpected("Couldn't find the class and/or file part folder content types.");
                throw new Exception("Couldn't find the class and/or file part folder content types.", exception);
            }

            if (classFolderType == null)
            {
                classFolderType = ProtectedMasterLibrary.Site.RootWeb.ContentTypes[WBRecordsType.RECORDS_LIBRARY__FALL_BACK_FOLDER_CONTENT_TYPE];
            }

            if (filePartFolderType == null)
            {
                filePartFolderType = ProtectedMasterLibrary.Site.RootWeb.ContentTypes[WBRecordsType.RECORDS_LIBRARY__FALL_BACK_FOLDER_CONTENT_TYPE];
            }

            SPFolder protectedLibraryRootFolder = ProtectedMasterLibrary.List.RootFolder;

            protectedLibraryRootFolder.WBxGetOrCreateFolderPath(fullClassPath, classFolderType.Id);
            SPFolder actualDestinationFolder = protectedLibraryRootFolder.WBxGetOrCreateFolderPath(fullFilingPath, filePartFolderType.Id);

            /*
             * // This next bit is all because we've been having problems when new folders had to be created:
             * if (actualDestinationFolder == null)
             * {
             *  WBLogging.RecordsTypes.HighLevel("We have to create part of the folder path: " + fullFilingPath);
             *  actualDestinationFolder = protectedLibraryRootFolder.WBxGetOrCreateFolderPath(fullFilingPath, filePartFolderType.Id);
             *
             *  WBLogging.RecordsTypes.HighLevel("Now we're going to add a dummy first file:");
             *
             *  MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("Please ignore this file."));
             *  SPFile dummyFile = actualDestinationFolder.Files.Add("FirstFile.txt", memoryStream);
             *
             *  WBLogging.RecordsTypes.HighLevel("Now we're going to try to update the file");
             *  try
             *  {
             *      dummyFile.Item.Update();
             *  }
             *  catch (Exception e)
             *  {
             *      WBLogging.RecordsTypes.Unexpected("And exception did occur while updating the dummy item", e);
             *  }
             *
             *  memoryStream.Dispose();
             *
             *  WBLogging.RecordsTypes.HighLevel("Now re-opening the whole ProtectedMasterLibrary object");
             *
             *  ProtectedMasterLibrary.ReOpen();
             *
             *  WBLogging.RecordsTypes.HighLevel("Have re-opened the whole ProtectedMasterLibrary object - now re-getting the SPFolder:");
             *
             *  protectedLibraryRootFolder = ProtectedMasterLibrary.List.RootFolder;
             *  actualDestinationFolder = protectedLibraryRootFolder.WBxGetFolderPath(fullFilingPath);
             * }
             */


            if (ProtectedMasterLibrary.Web.WBxFileExists(actualDestinationFolder, filename))
            {
                filename = ProtectedMasterLibrary.Web.WBxMakeFilenameUnique(actualDestinationFolder, filename);
            }

            SPFile uploadedFile = actualDestinationFolder.Files.Add(filename, document.OpenBinaryStream());

            SPListItem uploadedItem = uploadedFile.Item;

            if (extraMetadata == null)
            {
                extraMetadata = new WBItem();
            }
            if (!extraMetadata.IsUsingColumn(WBColumn.DatePublished))
            {
                extraMetadata[WBColumn.DatePublished] = DateTime.Now;
            }
            if (!extraMetadata.IsUsingColumn(WBColumn.PublishedBy) && SPContext.Current != null)
            {
                extraMetadata[WBColumn.PublishedBy] = SPContext.Current.Web.CurrentUser;
            }

            WBRecord newRecord = new WBRecord(this, uploadedItem, uploadedItem.ID.ToString(), document, extraMetadata);

            if (feedback != null)
            {
                String urlToFolder = newRecord.ProtectedMasterRecord.AbsoluteURL.Replace(newRecord.Name, "");

                feedback.AddFeedback("Uploaded file to protected, master records library");
                feedback.AddFeedback("Master record: <a href='" + newRecord.ProtectedMasterRecord.AbsoluteURL + "' target='_blank'>" + newRecord.ProtectedMasterRecord.AbsoluteURL + "</a>");
                feedback.AddFeedback("In folder: <a href='" + urlToFolder + "' target='_blank'>" + urlToFolder + "</a>");
            }

            if (recordToReplace != null)
            {
                // OK so actually we need to do the replacement actions with elevated priviledges:

                //bool digestOK = SPContext.Current.Web.ValidateFormDigest();
                //if (digestOK)
                //{
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (WBRecordsManager manager = new WBRecordsManager(callingUserLogin))
                    {
                        WBRecord elevatedRecordToReplace = manager.Libraries.GetRecordByID(recordToReplace.RecordID);

                        if (replacingAction == WBPublishingProcess.REPLACE_ACTION__ARCHIVE_FROM_IZZI)
                        {
                            elevatedRecordToReplace.LiveOrArchived     = WBColumn.LIVE_OR_ARCHIVED__ARCHIVED;
                            elevatedRecordToReplace.RecordSeriesStatus = WBColumn.RECORD_SERIES_STATUS__ARCHIVED;
                        }
                        else
                        {
                            elevatedRecordToReplace.RecordSeriesStatus = WBColumn.RECORD_SERIES_STATUS__RETIRED;
                        }

                        elevatedRecordToReplace.Update(callingUserLogin, "Record was " + elevatedRecordToReplace.RecordSeriesStatus + " because it was replaced through publishing process");

                        if (feedback != null)
                        {
                            feedback.AddFeedback("Archived record being replaced");
                        }
                        WBLogging.Debug("WBRecordsLibraries.DeclareNewRecord(): Archived the record being replaced Record ID = " + recordToReplace.RecordID);
                    }
                });

                newRecord.ReplacesRecordID   = recordToReplace.RecordID;
                newRecord.RecordSeriesID     = recordToReplace.RecordSeriesID;
                newRecord.RecordSeriesIssue  = "" + (recordToReplace.RecordSeriesIssue.WBxToInt() + 1);
                newRecord.RecordSeriesStatus = WBColumn.RECORD_SERIES_STATUS__LATEST;
            }
            else
            {
                newRecord.ReplacesRecordID   = null;
                newRecord.RecordSeriesID     = newRecord.RecordID;
                newRecord.RecordSeriesIssue  = "1";
                newRecord.RecordSeriesStatus = WBColumn.RECORD_SERIES_STATUS__LATEST;
            }

            newRecord.LiveOrArchived = WBColumn.LIVE_OR_ARCHIVED__LIVE;

            newRecord.UpdateMasterAndCreateCopies(feedback, callingUserLogin);

            bool beforeForDocument = document.Web.AllowUnsafeUpdates;

            document.Web.AllowUnsafeUpdates = true;

            // And now just copy back to the original document any metadata changes:
            document.MaybeCopyColumns(newRecord.Metadata, WBRecord.DefaultColumnsToCopy);

            // And let's make sure that the original document is using the work box document content type:
            if (document.IsSPListItem)
            {
                SPContentType workBoxDocumentType = document.Item.ParentList.ContentTypes[WBFarm.Local.WorkBoxDocumentContentTypeName];
                if (workBoxDocumentType != null)
                {
                    document.Item["ContentTypeId"] = workBoxDocumentType.Id;
                }
            }

            document.Update();

//            uploadedItem.Update();
//          uploadedFile.Update();

            bool beforeForUploadedFile = uploadedFile.Web.AllowUnsafeUpdates;

            uploadedFile.Web.AllowUnsafeUpdates = true;

            if (uploadedFile.CheckOutType != SPFile.SPCheckOutType.None)
            {
                uploadedFile.WBxCheckInAs("Declared new major version of record.", SPCheckinType.MajorCheckIn, callingUserLogin);
            }
            else
            {
                WBLogging.Migration.Verbose("There was no need to check in file: " + uploadedFile.Name);
            }

            uploadedFile.Web.AllowUnsafeUpdates = beforeForUploadedFile;
            document.Web.AllowUnsafeUpdates     = beforeForDocument;

            return(newRecord);
        }
Ejemplo n.º 11
0
        public StringBuilder AppendMMCAMLClause(StringBuilder builder, SPSite site, string fieldName, WBTerm term, bool includeDescendants)
        {
            if (term == null)
            {
                return(builder);
            }
            if (Comparator != Comparators.Equals)
            {
                return(builder);
            }

            WBLogging.Queries.Verbose("Looking for term: " + term.Name + " in site: " + site.HostName + site.ServerRelativeUrl + " for field: " + fieldName);

            int[] wssIds = site.WBxGetWssIdsOfTerm(term, includeDescendants);

            // If the site had no matching WssIds that means the term isn't being used in the site
            // so it can't possibly match - hence returning a filter clause that should always fail:
            if (wssIds.Length == 0)
            {
                return(AppendNoResultsClause(builder));
            }

            if (wssIds.Length == 1)
            {
                builder.Append("<Eq><FieldRef Name='").Append(fieldName).Append("' LookupId='TRUE'/>");

                foreach (int wssId in wssIds)
                {
                    builder.Append("<Value Type='Lookup'>").Append(wssId).Append("</Value>");
                }

                builder.Append("</Eq>");
            }
            else
            {
                builder.Append("<In><FieldRef Name='").Append(fieldName).Append("'  LookupId='TRUE'/><Values>");

                foreach (int wssId in wssIds)
                {
                    builder.Append("<Value Type='Lookup'>").Append(wssId).Append("</Value>");
                }

                builder.Append("</Values></In>");
            }

            return(builder);
        }
Ejemplo n.º 12
0
 public static int[] GetWssIdsOfTerm(SPSite site, WBTerm term, bool includeDescendants)
 {
     return(TaxonomyField.GetWssIdsOfTerm(site, term.Taxonomy.TermStore.Id, term.Taxonomy.TermSet.Id, term.Id, includeDescendants, 500));
 }
Ejemplo n.º 13
0
        internal void PopulateWithRecordsTypes(WBLocationTreeState treeState, TreeNodeCollection treeNodeCollection, String viewMode, SPFolder parentFolder, WBTerm functionalArea, WBTaxonomy recordsTypesTaxonomy, TermCollection recordsTypeTerms)
        {
            List <Term> sortedTerms = new List <Term>();

            foreach (Term term in recordsTypeTerms)
            {
                sortedTerms.Add(term);
            }
            sortedTerms = sortedTerms.OrderBy(o => o.Name).ToList();

            foreach (Term term in sortedTerms)
            {
                WBRecordsType recordsType = new WBRecordsType(recordsTypesTaxonomy, term);

                bool protectiveZoneOK = true;
                if (!String.IsNullOrEmpty(treeState.MinimumProtectiveZone))
                {
                    protectiveZoneOK = (recordsType.IsZoneAtLeastMinimum(treeState.MinimumProtectiveZone));
                }

                if (recordsType.BranchCanHaveDocuments() && recordsType.IsRelevantToFunctionalArea(functionalArea) && protectiveZoneOK)
                {
                    SPFolder folder = null;
                    if (viewMode != VIEW_MODE__NEW && parentFolder != null)
                    {
                        folder = parentFolder.WBxGetSubFolder(recordsType.Name);
                        if (folder == null)
                        {
                            WBLogging.Debug("Did not find folder for: " + recordsType.Name);
                        }
                    }

                    if (viewMode == VIEW_MODE__NEW || folder != null)
                    {
                        WBRecordsTypeTreeNode recordsTypeTreeNode = new WBRecordsTypeTreeNode(functionalArea, recordsType, folder);
                        TreeNode node = recordsTypeTreeNode.AsTreeNode();

                        if (recordsType.Term.TermsCount > 0 || viewMode != VIEW_MODE__NEW)
                        {
                            if (viewMode == VIEW_MODE__BROWSE_FOLDERS && recordsType.Term.TermsCount == 0)
                            {
                                node.SelectAction = TreeNodeSelectAction.Select;
                            }
                            else
                            {
                                node.SelectAction = TreeNodeSelectAction.Expand;
                            }
                            node.Expanded         = false;
                            node.PopulateOnDemand = true;
                        }
                        else
                        {
                            node.SelectAction     = TreeNodeSelectAction.Select;
                            node.Expanded         = true;
                            node.PopulateOnDemand = false;
                        }

                        treeNodeCollection.Add(node);
                    }
                }
            }
        }