public WBTermCollection(WBTermCollection <T> collectionToCopy) { _taxonomy = collectionToCopy.Taxonomy; _UIControlValue = null; _list = new List <T>(collectionToCopy.List); }
public void Remove(WBTermCollection <T> collection) { if (collection == null) { return; } foreach (T term in collection) { Remove(term); } }
public void Add(WBTermCollection <T> collection) { if (collection == null) { return; } foreach (T term in collection) { Add(term); } }
public void CheckOwningTeamIsAlsoInvolved() { WBTermCollection <WBTeam> involvedTeams = this.InvolvedTeams; if (!involvedTeams.Contains(OwningTeam)) { involvedTeams.Add(OwningTeam); } // It's a little inefficient but we'll just call the Proerty set: this.InvolvedTeams = involvedTeams; }
public List <String> ExtranetLibrariesToRouteTo(WBTermCollection <WBSubjectTag> subjectTagsToCheck) { List <String> extranetLibraries = new List <String>(); foreach (WBSubjectTag subjectTag in subjectTagsToCheck) { foreach (WBSubjectTagRecordsRoutings routing in Routings) { if (!String.IsNullOrEmpty(routing.ExtranetDocumentsLibrary) && subjectTag.Term.GetIsDescendantOf(routing.SubjectTag.Term) && !extranetLibraries.Contains(routing.ExtranetDocumentsLibrary)) { extranetLibraries.Add(routing.ExtranetDocumentsLibrary); } } } return(extranetLibraries); }
private WBTermCollection <WBSubjectTag> AddAdditionalSubjectTags(SPSite controlSite, WBTermCollection <WBSubjectTag> subjectTags, String sourceID) { WBLogging.Migration.Verbose("Adding additional subject tags for item with Source ID = " + sourceID); WBQuery query = new WBQuery(); query.AddFilter(WBColumn.SourceID, WBQueryClause.Comparators.Equals, sourceID); SPListItemCollection items = MigrationSubjectsList.WBxGetItems(controlSite, query); if (items.Count > 0) { WBTaxonomy subjectTagsTaxonomy = subjectTags.Taxonomy; subjectTags = new WBTermCollection <WBSubjectTag>(subjectTags); foreach (SPListItem item in items) { String paths = WBUtils.NormalisePaths(item.WBxGetAsString(WBColumn.SubjectTagsPaths)); string[] pathsArray = paths.Split(';'); foreach (String path in pathsArray) { Term subjectTerm = subjectTagsTaxonomy.GetOrCreateSelectedTermByPath(path); if (subjectTerm != null) { WBLogging.Migration.Verbose("Adding additional subject: " + path); subjectTags.Add(new WBSubjectTag(subjectTagsTaxonomy, subjectTerm)); } else { WBLogging.Migration.Unexpected("Could not find or create subject: " + path); } } } } // WBLogging.Migration.Verbose("At this point the subjectTags = " + subjectTags); return(subjectTags); }
public TreeViewLocationCollection(WBRecordsManager manager, string mode, string minimumProtectiveZone, WBTermCollection <WBTerm> functionalAreas) : base() { foreach (WBTerm functionalArea in functionalAreas) { Add(new TreeViewLocation(null, manager, mode, minimumProtectiveZone, functionalArea)); } }
private void MigrateOneDocumentToLibrary( WBMigrationMapping mapping, SPSite sourceSite, SPWeb sourceWeb, SPDocumentLibrary sourceLibrary, SPSite destinationSite, SPWeb destinationWeb, SPFolder destinationRootFolder, SPSite controlSite, SPWeb controlWeb, SPList controlList, SPView controlView, SPListItem migrationItem) { WBFarm farm = WBFarm.Local; //foreach (SPField field in migrationItem.Fields) //{ // WBLogging.Migration.Verbose("Field InternalName: " + field.InternalName + " Field Title: " + field.Title + " item[field.Title] : " + migrationItem[field.Title]); //} String sourceFilePath = migrationItem.WBxGetAsString(WBColumn.SourceFilePath); String mappingPath = WBUtils.NormalisePath(migrationItem.WBxGetAsString(WBColumn.MappingPath)); WBLogging.Migration.Verbose("Trying to migrate file : " + sourceFilePath); WBLogging.Migration.Verbose("Migrating with mapping path : " + mappingPath); WBMappedPath mappedPath = mapping[mappingPath]; SPListItem controlItem = migrationItem; SPListItem mappingItem = null; SPListItem subjectItem = null; String documentumSourceID = ""; if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { documentumSourceID = controlItem.WBxGetAsString(WBColumn.SourceID); if (!String.IsNullOrEmpty(documentumSourceID)) { mappingItem = WBUtils.FindItemByColumn(controlSite, MigrationMappingList, WBColumn.SourceID, documentumSourceID); subjectItem = WBUtils.FindItemByColumn(controlSite, MigrationSubjectsList, WBColumn.SourceID, documentumSourceID); } } if (mappedPath.InErrorStatus) { WBLogging.Migration.HighLevel("WBMigrationTimerJob.MigrateOneDocumentToLibrary(): There was an error with the mapped path: " + mappedPath.ErrorStatusMessage); return; } // OK so let's first get the various WBTerms from the mapped path so that if these // fail they fail before we copy the document! WBRecordsType recordsType = null; WBTermCollection <WBTerm> functionalArea = null; WBTermCollection <WBSubjectTag> subjectTags = null; if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { string recordsTypePath = controlItem.WBxGetAsString(WBColumn.RecordsTypePath); if (String.IsNullOrEmpty(recordsTypePath) && mappingItem != null) { recordsTypePath = mappingItem.WBxGetAsString(WBColumn.RecordsTypePath); } Term rterm = mapping.RecordsTypesTaxonomy.GetSelectedTermByPath(recordsTypePath); if (rterm != null) { recordsType = new WBRecordsType(mapping.RecordsTypesTaxonomy, rterm); } string functionalAreaPath = controlItem.WBxGetAsString(WBColumn.FunctionalAreaPath); if (String.IsNullOrEmpty(functionalAreaPath) && mappingItem != null) { functionalAreaPath = mappingItem.WBxGetAsString(WBColumn.FunctionalAreaPath); } if (!String.IsNullOrEmpty(functionalAreaPath)) { string[] paths = functionalAreaPath.Split(';'); List <WBTerm> fterms = new List <WBTerm>(); foreach (string path in paths) { WBLogging.Migration.Verbose("Trying to get a Functional Area by path with: " + path); Term fterm = mapping.FunctionalAreasTaxonomy.GetOrCreateSelectedTermByPath(path); if (fterm != null) { fterms.Add(new WBTerm(mapping.FunctionalAreasTaxonomy, fterm)); } else { WBLogging.Debug("Coundn't find the functional area with path: " + path); } } if (fterms.Count > 0) { functionalArea = new WBTermCollection <WBTerm>(mapping.FunctionalAreasTaxonomy, fterms); } } string subjectTagsPaths = controlItem.WBxGetAsString(WBColumn.SubjectTagsPaths); if (String.IsNullOrEmpty(subjectTagsPaths) && mappingItem != null) { subjectTagsPaths = mappingItem.WBxGetAsString(WBColumn.SubjectTagsPaths); } if (!String.IsNullOrEmpty(subjectTagsPaths)) { List <WBSubjectTag> sterms = new List <WBSubjectTag>(); // Note that it is not necessarily an error for the subject tags to be empty. if (!String.IsNullOrEmpty(subjectTagsPaths) && subjectTagsPaths != "/") { string[] paths = subjectTagsPaths.Split(';'); foreach (string path in paths) { WBLogging.Migration.Verbose("Trying to get a Subject Tag by path with: " + path); if (path != "/") { Term sterm = mapping.SubjectTagsTaxonomy.GetOrCreateSelectedTermByPath(path); if (sterm != null) { sterms.Add(new WBSubjectTag(mapping.SubjectTagsTaxonomy, sterm)); } else { WBLogging.Debug("Coundn't find the subject tag with path: " + path); } } } } subjectTags = new WBTermCollection <WBSubjectTag>(mapping.SubjectTagsTaxonomy, sterms); } } else { recordsType = mappedPath.RecordsType; functionalArea = mappedPath.FunctionalArea; subjectTags = mappedPath.SubjectTags; } if (MigrationSubjectsList != null && MigrationSourceSystem == MIGRATION_SOURCE__HFI_INTRANET_DOCUMENTS) { //foreach (SPField field in migrationItem.Fields) //{ // WBLogging.Debug("Found field: " + field.Title + " field inner name: " + field.InternalName); //} subjectTags = AddAdditionalSubjectTags(controlSite, subjectTags, migrationItem.WBxGetAsString(WBColumn.SourceID)); } if (recordsType == null) { MigrationError(migrationItem, "The records type for this item could not be found. Looked for: " + mappedPath.RecordsTypePath); return; } if (functionalArea == null || functionalArea.Count == 0) { MigrationError(migrationItem, "The functional area for this item could not be found. Looked for: " + mappedPath.FunctionalAreaPath); return; } // OK so we can start building up our information about the document we are going to declare: WBDocument document = new WBDocument(); document.RecordsType = recordsType; document.FunctionalArea = functionalArea; document.SubjectTags = subjectTags; document[WBColumn.SourceFilePath] = sourceFilePath; string sourceSystem = migrationItem.WBxGetAsString(WBColumn.SourceSystem); if (String.IsNullOrEmpty(sourceSystem)) { sourceSystem = farm.MigrationSourceSystem; } if (String.IsNullOrEmpty(sourceSystem)) { sourceSystem = farm.MigrationControlListUrl; } document[WBColumn.SourceSystem] = sourceSystem; String sourceID = migrationItem.WBxGetAsString(WBColumn.SourceID); if (String.IsNullOrEmpty(sourceID) && MigrationSourceSystem != MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { sourceID = sourceFilePath; } document[WBColumn.SourceID] = sourceID; SPFile sourceFile = null; SPListItem sourceItem = null; if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { if (String.IsNullOrEmpty(sourceID)) { sourceItem = sourceWeb.GetListItem(sourceFilePath); document[WBColumn.SourceID] = sourceFilePath; document[WBColumn.SourceSystem] = "Initial SharePoint Web Docs"; } else { sourceItem = WBUtils.FindItemByColumn(sourceSite, (SPList)sourceLibrary, WBColumn.Source_ID, sourceID); } if (sourceItem == null) { MigrationError(migrationItem, "Could not find the doc with source id = " + sourceFilePath); return; } sourceFile = sourceItem.File; } if (migrationItem.WBxIsNotBlank(WBColumn.ReferenceDateString)) { document.ReferenceDate = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ReferenceDateString)); } if (migrationItem.WBxIsNotBlank(WBColumn.ModifiedDateString)) { document.Modified = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ModifiedDateString)); } else { if (mappingItem != null) { if (mappingItem.WBxIsNotBlank(WBColumn.ModifiedDateString)) { document.Modified = WBUtils.ParseDate(mappingItem.WBxGetAsString(WBColumn.ModifiedDateString)); } } else if (subjectItem != null) { if (subjectItem.WBxIsNotBlank(WBColumn.ModifiedDateString)) { document.Modified = WBUtils.ParseDate(subjectItem.WBxGetAsString(WBColumn.ModifiedDateString)); } } else if (sourceItem != null) { if (sourceItem.WBxHasValue(WBColumn.Modified)) { document.Modified = (DateTime)sourceItem["Modified"]; } } } if (migrationItem.WBxIsNotBlank(WBColumn.DeclaredDateString)) { document.DeclaredRecord = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.DeclaredDateString)); } if (migrationItem.WBxIsNotBlank(WBColumn.ScanDateString)) { document.ScanDate = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ScanDateString)); } if (migrationItem.WBxIsNotBlank(WBColumn.OwningTeamPath) || !String.IsNullOrEmpty(mappedPath.OwningTeamPath)) { WBTaxonomy teamsTaxonomy = mapping.TeamsTaxonomy; string owningTeamPath = migrationItem.WBxGetAsString(WBColumn.OwningTeamPath); if (owningTeamPath == "") { owningTeamPath = mappedPath.OwningTeamPath; } WBTeam foundTeam = teamsTaxonomy.GetSelectedTeam(WBUtils.NormalisePath(owningTeamPath)); if (foundTeam != null) { WBLogging.Migration.Verbose("Found the owning team: " + foundTeam.Name); document.OwningTeam = foundTeam; } else { MigrationError(migrationItem, "Could not find the owning team at: " + owningTeamPath); return; } } if (migrationItem.WBxIsNotBlank(WBColumn.Title)) { document[WBColumn.Title] = migrationItem.WBxGetAsString(WBColumn.Title); } if (MigrationSourceSystem == MIGRATION_SOURCE__HFI_INTRANET_DOCUMENTS) { document.Modified = File.GetLastWriteTime(sourceFilePath); WBLogging.Debug("Found the last modified date to be: " + document.Modified); } // We'll set the reference date for these imported files based on their existing declared date or modified date if it exists. if (!document.HasReferenceDate) { if (document.HasDeclaredRecord) { document.ReferenceDate = document.DeclaredRecord; } else if (document.HasScanDate) { document.ReferenceDate = document.ScanDate; } else if (document.HasModified) { document.ReferenceDate = document.Modified; } } if (migrationItem.WBxHasValue(WBColumn.ReferenceID)) { document.ReferenceID = migrationItem.WBxGetAsString(WBColumn.ReferenceID); } string protectiveZone = migrationItem.WBxGetAsString(WBColumn.ProtectiveZone); if (String.IsNullOrEmpty(protectiveZone)) { protectiveZone = mappedPath.ProtectiveZone; if (String.IsNullOrEmpty(protectiveZone)) { protectiveZone = WBRecordsType.PROTECTIVE_ZONE__PROTECTED; } } document[WBColumn.ProtectiveZone] = protectiveZone; string liveOrArchived = migrationItem.WBxGetAsString(WBColumn.LiveOrArchived); if (String.IsNullOrEmpty(liveOrArchived)) { liveOrArchived = mappedPath.LiveOrArchived; if (String.IsNullOrEmpty(liveOrArchived)) { liveOrArchived = WBColumn.LIVE_OR_ARCHIVED__LIVE; } } document[WBColumn.LiveOrArchived] = liveOrArchived; bool downloadFromWebSite = false; if (MigrationSourceSystem == MIGRATION_SOURCE__ALFRESCO_RECORDS) { downloadFromWebSite = true; } String originalFileName = migrationItem.WBxGetAsString(WBColumn.OriginalFilename).Trim(); if (String.IsNullOrEmpty(originalFileName)) { originalFileName = Path.GetFileName(sourceFilePath); } if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { originalFileName = sourceFile.Name; } if (downloadFromWebSite) { originalFileName = HttpUtility.UrlDecode(originalFileName); } document.OriginalFilename = originalFileName; //String extension = Path.GetExtension(filename); WBItemMessages metadataErrors = recordsType.CheckMetadataIsOK(document); if (metadataErrors.Count > 0) { string message = "There were problems with the prepared metadata. "; foreach (WBColumn column in metadataErrors.Keys) { message += "Error for column: " + column.DisplayName + " message: " + metadataErrors[column] + " "; } MigrationError(migrationItem, message); return; } Stream fileStream = null; if (downloadFromWebSite) { WebClient webClient = new WebClient(); if (!String.IsNullOrEmpty(farm.MigrationUserName) && !String.IsNullOrEmpty(farm.MigrationPassword)) { webClient.Credentials = new NetworkCredential(farm.MigrationUserName, farm.MigrationPassword); } string tempFile = @"C:\Temp\tmp.bin"; if (farm.FarmInstance == WBFarm.FARM_INSTANCE__PROTECTED_INTERNAL_FARM) { tempFile = @"E:\Temp\tmp.bin"; } webClient.DownloadFile(sourceFilePath, tempFile); WBLogging.Migration.Verbose("Downloaded to local tmp file using webClient.DownloadFile() successfully"); fileStream = File.OpenRead(tempFile); WBLogging.Migration.Verbose("Opened local tmp file using File.OpenRead() successfully"); } else if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS) { fileStream = sourceFile.OpenBinaryStream(); WBLogging.Migration.Verbose("Opened using sourceFile.OpenBinaryStream() successfully"); } else { fileStream = File.OpenRead(sourceFilePath); WBLogging.Migration.Verbose("Opened using File.OpenRead() successfully"); } SPListItem uploadedItem = null; try { uploadedItem = recordsType.PublishDocument(destinationWeb, destinationRootFolder, document, fileStream); } finally { fileStream.Close(); fileStream.Dispose(); } if (uploadedItem == null) { MigrationError(migrationItem, "There was a problem in the call to recordsType.PublishDocument() as the uploaded item is null."); return; } migrationItem.WBxSet(WBColumn.DateMigrated, DateTime.Now); migrationItem.WBxSet(WBColumn.MigratedToUrl, uploadedItem.WBxGet(WBColumn.EncodedAbsoluteURL)); migrationItem.WBxSet(WBColumn.RecordID, uploadedItem.WBxGet(WBColumn.RecordID)); migrationItem.WBxSet(WBColumn.MigrationStatus, WBColumn.MIGRATION_STATUS__DONE); migrationItem.Update(); }
internal void PopulateWithFunctionalAreas(WBLocationTreeState treeState, TreeNodeCollection treeNodeCollection, String viewMode, WBTermCollection <WBTerm> teamFunctionalAreas) { bool expandNodes = true; if (teamFunctionalAreas.Count > 2) { expandNodes = false; } List <WBTerm> sortedTerms = new List <WBTerm>(); foreach (WBTerm term in teamFunctionalAreas) { sortedTerms.Add(term); } sortedTerms = sortedTerms.OrderBy(o => o.Name).ToList(); foreach (WBTerm functionalArea in sortedTerms) { SPFolder folder = null; if (viewMode != VIEW_MODE__NEW) { folder = this.Libraries.GetMasterFolderByPath(functionalArea.Name); if (folder == null) { WBLogging.Debug("Couldn't find folder for functional area: " + functionalArea.Name); continue; } } else { WBLogging.Debug("View mode = " + viewMode); } WBFunctionalAreaTreeNode functionalAreaTreeNode = new WBFunctionalAreaTreeNode(functionalArea, folder); TreeNode node = functionalAreaTreeNode.AsTreeNode(); node.Expanded = expandNodes; node.PopulateOnDemand = false; node.SelectAction = TreeNodeSelectAction.Expand; treeNodeCollection.Add(node); WBTaxonomy recordsTypes = this.RecordsTypesTaxonomy; TermCollection terms = recordsTypes.TermSet.Terms; PopulateWithRecordsTypes(treeState, node.ChildNodes, viewMode, folder, functionalArea, recordsTypes, terms); } }
internal List <String> GetFileTypesDisallowedFromBeingPublishedToPublic(IEnumerable <String> fileTypes) { List <String> disallowedFileTypes = new List <string>(); foreach (String fileType in fileTypes) { SPListItem fileTypeInfoItem = GetFileTypeInfo(fileType); if (fileTypeInfoItem == null) { disallowedFileTypes.Add(fileType); } else { if (!fileTypeInfoItem.WBxGetAsBool(WBColumn.CanPublishToPublic)) { disallowedFileTypes.Add(fileType); } else { WBTermCollection <WBTeam> teams = fileTypeInfoItem.WBxGetMultiTermColumn <WBTeam>(this.TeamsTaxonomy, WBColumn.OnlyTeamsCanPublishToPublic); if (teams != null && teams.Count > 0) { WBLogging.RecordsTypes.Verbose("Found this many teams: " + teams.Count); // OK so if we're here then a team restriction has been set for this file type: SPUser callingUser = null; SPWeb web = null; SPSite site = null; if (SPContext.Current != null) { web = SPContext.Current.Web; site = SPContext.Current.Site; } if (web == null) { WBLogging.RecordsTypes.Verbose("SPContext.Current.Web was null !"); web = this.Libraries.ProtectedMasterLibrary.Web; site = this.Libraries.ProtectedMasterLibrary.Site; } bool isAMemberOfAtLeastOneTeam = false; if (web == null) { WBLogging.RecordsTypes.Verbose("this.Libraries.ProtectedMasterLibrary.Web was null !"); } else { WBLogging.RecordsTypes.Verbose("We have an SPWeb with web.Url = " + web.Url); if (!String.IsNullOrEmpty(this._callingUserLogin)) { callingUser = web.WBxEnsureUserOrNull(this._callingUserLogin); } if (callingUser == null) { WBLogging.RecordsTypes.Verbose("Wasn't able to find calling user: "******"Found calling user: "******"Calling user is a member of team : " + team.Name); isAMemberOfAtLeastOneTeam = true; break; } else { WBLogging.RecordsTypes.Verbose("Calling user is NOT a member of team : " + team.Name); } } } } if (!isAMemberOfAtLeastOneTeam) { disallowedFileTypes.Add(fileType + " (you're not a member of an allowed team)"); } } } } } return(disallowedFileTypes); }