Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #501 from PaoloPia/fixes
Browse files Browse the repository at this point in the history
Added support for cross-tenant provisioning of taxonomy fields.
  • Loading branch information
PaoloPia committed Apr 4, 2016
2 parents 8d4d4a6 + bd0bed0 commit 0151543
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Expand Up @@ -6,6 +6,19 @@ namespace Microsoft.SharePoint.Client
{
public static class ClientObjectExtensions
{
/// <summary>
/// Checks if the ClientObject is null
/// </summary>
/// <typeparam name="T">Type of object to operate on</typeparam>
/// <param name="clientObject">Object to operate on</param>
/// <returns>True if the server object is null, otherwise false</returns>
public static bool ServerObjectIsNull<T>(this T clientObject) where T : ClientObject
{
return (clientObject.ServerObjectIsNull != null &&
clientObject.ServerObjectIsNull.HasValue &&
!clientObject.ServerObjectIsNull.Value);
}

/// <summary>
/// Check if a property is available on a object
/// </summary>
Expand Down
Expand Up @@ -381,6 +381,30 @@ public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplat
web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id);
web.Context.ExecuteQueryRetry();
taxTextFieldsToMoveUp.Add(taxField.TextField);

// Replace Taxonomy field references to SspId, TermSetId with tokens
TaxonomySession session = TaxonomySession.GetTaxonomySession(web.Context);
TermStore store = session.GetDefaultSiteCollectionTermStore();

var sspIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'SspId']/Value");
if (sspIdElement != null)
{
sspIdElement.Value = "{sitecollectiontermstoreid}";
}
var termSetIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'TermSetId']/Value");
if (termSetIdElement != null)
{
Guid termSetId = Guid.Parse(termSetIdElement.Value);
if (termSetId != Guid.Empty)
{
Microsoft.SharePoint.Client.Taxonomy.TermSet termSet = store.GetTermSet(termSetId);
if (!termSet.ServerObjectIsNull())
{
termSet.EnsureProperties(ts => ts.Name, ts => ts.Group);
termSetIdElement.Value = String.Format("{{termsetid:{0}:{1}}}", termSet.Group.Name, termSet.Name); // TODO
}
}
}
}
// Check if we have version attribute. Remove if exists
if (element.Attribute("Version") != null)
Expand Down
Expand Up @@ -39,7 +39,8 @@ public override TokenParser ProvisionObjects(Web web, Model.ProvisioningTemplate

var newGroup = false;

TermGroup group = termStore.Groups.FirstOrDefault(g => g.Id == modelTermGroup.Id);
TermGroup group = termStore.Groups.FirstOrDefault(
g => g.Id == modelTermGroup.Id || g.Name == modelTermGroup.Name);
if (group == null)
{
if (modelTermGroup.Name == "Site Collection")
Expand Down Expand Up @@ -86,12 +87,7 @@ public override TokenParser ProvisionObjects(Web web, Model.ProvisioningTemplate
var newTermSet = false;
if (!newGroup)
{
set = group.TermSets.FirstOrDefault(ts => ts.Id == modelTermSet.Id);
if (set == null)
{
set = group.TermSets.FirstOrDefault(ts => ts.Name == modelTermSet.Name);

}
set = group.TermSets.FirstOrDefault(ts => ts.Id == modelTermSet.Id || ts.Name == modelTermSet.Name);
}
if (set == null)
{
Expand Down

0 comments on commit 0151543

Please sign in to comment.