private static void SyncAllSubTeams(WBTaxonomy teams, TermCollection terms, SPSite teamsSite, SPSite site) { foreach (Term term in terms) { WBLogging.Teams.Verbose("Trying to sync the team with term name: " + term.Name); WBTeam team = new WBTeam(teams, term); try { team.SyncMembersGroup(teamsSite, site); } catch (Exception e) { WBLogging.Teams.Unexpected("Syncing failed for team: " + team.Name + " to site: " + site.Url); } WBLogging.Teams.Verbose("Next syncing all sub-teams of team: " + team.Name); SyncAllSubTeams(teams, term.Terms, teamsSite, site); } }
internal WBQuery GetQueryForTeamsPublicRecordsToArchiveInFutureWeek(WBTeam team, int weekInFuture, bool limitToJustOneWeek) { WBQuery query = new WBQuery(); if (team != null) { query.AddEqualsFilter(WBColumn.OwningTeam, team); } query.AddEqualsFilter(WBColumn.LiveOrArchived, WBColumn.LIVE_OR_ARCHIVED__LIVE); query.AddEqualsFilter(WBColumn.ProtectiveZone, WBRecordsType.PROTECTIVE_ZONE__PUBLIC); query.AddEqualsFilter(WBColumn.RecordSeriesStatus, WBColumn.RECORD_SERIES_STATUS__LATEST); query.OrderByAscending(WBColumn.ReviewDate); if (limitToJustOneWeek && weekInFuture > 1) { query.AddFilter(WBColumn.ReviewDate, WBQueryClause.Comparators.GreaterThanEquals, DateTime.Now.AddDays((-_weeksBetweenReviewDateAndAutoArchival + weekInFuture - 1) * 7)); } query.AddFilter(WBColumn.ReviewDate, WBQueryClause.Comparators.LessThan, DateTime.Now.AddDays((-_weeksBetweenReviewDateAndAutoArchival + weekInFuture) * 7)); query.RecursiveAll = true; return(query); }
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(); }
/// <summary> /// An item was added. /// </summary> public override void ItemAdded(SPItemEventProperties properties) { WBLogging.Teams.Unexpected("In WBTeamSiteCalendarChangeEventReceiver(): Requesting a new team event"); using (WBCollection collection = new WBCollection("http://workboxportals/projects")) using (SPSite teamsSite = new SPSite(properties.WebUrl)) using (SPWeb teamsWeb = teamsSite.OpenWeb()) { WBTaxonomy teams = WBTaxonomy.GetTeams(collection.Site); WBTeam team = WBTeam.GetFromTeamSite(teams, teamsWeb); if (team == null) { WBLogging.Teams.Unexpected("Didn't find a team for this calender creation event!!!"); } else { WBLogging.Teams.Unexpected("Found team: " + team.Name + " | " + team.TeamSiteUrl); } DateTime eventDate = DateTime.Now; if (properties.ListItem["EventDate"] == null) { if (properties.AfterProperties["EventDate"] == null) { WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EventDate' !!"); } else { eventDate = (DateTime)properties.AfterProperties["EventDate"]; } } else { eventDate = (DateTime)properties.ListItem["EventDate"]; } DateTime endDate = DateTime.Now.AddHours(1); if (properties.ListItem["EndDate"] == null) { if (properties.AfterProperties["EndDate"] == null) { WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EndDate' !!"); } else { endDate = (DateTime)properties.AfterProperties["EndDate"]; } } else { endDate = (DateTime)properties.ListItem["EndDate"]; } WBLogging.Teams.Unexpected(" Start End times are: " + eventDate + " and " + endDate); String title = properties.ListItem["Title"].WBxToString(); WBLogging.Teams.Unexpected(" Title is: " + title); String description = "Changed"; // properties.ListItem["Description"].WBxToString(); WBLogging.Teams.Unexpected(" description is: " + description); WorkBox workBox = collection.RequestNewEventWorkBox( properties.List.DefaultViewUrl, properties.List.ID, properties.ListItemId, title, description, eventDate, endDate, team, null, "Meeting"); workBox.Open("Opening work box triggered by new event in a calendar."); workBox.Dispose(); } base.ItemAdded(properties); }
internal WBQuery GetQueryForTeamsPublicRecordsToReview(WBTeam team) { // We can use the 'in next weeks' query generator - with the week set as the maximum gap between review and archive! return(GetQueryForTeamsPublicRecordsToArchiveInFutureWeek(team, _weeksBetweenReviewDateAndAutoArchival, false)); }
internal WBQuery GetQueryForTeamsPublicRecordsToArchive(WBTeam team) { return(GetQueryForTeamsPublicRecordsToArchiveInFutureWeek(team, 0, false)); }
internal WBQuery GetQueryForTeamsPublicRecordsToArchiveInFutureWeek(WBTeam team, int weekInFuture) { return(GetQueryForTeamsPublicRecordsToArchiveInFutureWeek(team, weekInFuture, true)); }
/// <summary> /// An item was added. /// </summary> public override void ItemAdded(SPItemEventProperties properties) { WBLogging.Teams.Unexpected("In WBLinkedCalendarUpdatesEventReceiver(): Requesting a new team event"); if (properties.List == null) { WBLogging.Teams.Unexpected("The properties.List value was null!"); return; } else { WBLogging.Teams.Unexpected("Calendar item added to list: " + properties.List.DefaultViewUrl); } String workBoxCollectionURL = properties.List.WBxGetProperty(WorkBox.LIST_PROPERTY__LINKED_CALENDAR__WORK_BOX_COLLECTION); String defaultTemplateTitle = properties.List.WBxGetProperty(WorkBox.LIST_PROPERTY__LINKED_CALENDAR__DEFAULT_TEMPLATE_TITLE); if (String.IsNullOrEmpty(workBoxCollectionURL) || String.IsNullOrEmpty(defaultTemplateTitle)) { WBLogging.Teams.Unexpected("The linked calendar configuration properties were blank: " + workBoxCollectionURL + " | " + defaultTemplateTitle); return; } using (WBCollection collection = new WBCollection(workBoxCollectionURL)) using (SPSite calendarSite = new SPSite(properties.WebUrl)) using (SPWeb calendarWeb = calendarSite.OpenWeb()) { WorkBox onWorkBox = WorkBox.GetIfWorkBox(calendarSite, calendarWeb); WBTaxonomy teams = WBTaxonomy.GetTeams(collection.Site); WBTeam eventOwningTeam = WBTeam.GetFromTeamSite(teams, calendarWeb); if (eventOwningTeam == null && onWorkBox != null) { eventOwningTeam = onWorkBox.OwningTeam; } if (eventOwningTeam == null) { WBLogging.Teams.Unexpected("Didn't find an eventOwningTeam for this calender creation event!!!"); } else { WBLogging.Teams.Unexpected("Found team: " + eventOwningTeam.Name + " | " + eventOwningTeam.TeamSiteUrl); } DateTime eventDate = DateTime.Now; if (properties.ListItem["EventDate"] == null) { if (properties.AfterProperties["EventDate"] == null) { WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EventDate' !!"); } else { eventDate = (DateTime)properties.AfterProperties["EventDate"]; } } else { eventDate = (DateTime)properties.ListItem["EventDate"]; } DateTime endDate = DateTime.Now.AddHours(1); if (properties.ListItem["EndDate"] == null) { if (properties.AfterProperties["EndDate"] == null) { WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EndDate' !!"); } else { endDate = (DateTime)properties.AfterProperties["EndDate"]; } } else { endDate = (DateTime)properties.ListItem["EndDate"]; } WBLogging.Teams.Unexpected(" Start End times are: " + eventDate + " and " + endDate); String title = properties.ListItem["Title"].WBxToString(); WBLogging.Teams.Unexpected(" Title is: " + title); String description = "Changed"; // properties.ListItem["Description"].WBxToString(); WBLogging.Teams.Unexpected(" description is: " + description); String calendarURL = calendarSite.Url + properties.List.DefaultViewUrl; WorkBox workBox = collection.RequestNewEventWorkBox( calendarURL, properties.List.ID, properties.ListItemId, title, description, eventDate, endDate, eventOwningTeam, null, defaultTemplateTitle); workBox.Open("Opening work box triggered by new event in a calendar."); workBox.Dispose(); } base.ItemAdded(properties); }