Skip to content

Commit

Permalink
Composite Clash checking #46
Browse files Browse the repository at this point in the history
Checking on the creation of a property type that it isn't in the child
property types. need to do a little bit of performance testing on this
one, because we call GetAllContentTypes or GetAllMediaTypes depending on
the import, want to minimise the impact of those calls if i can.
  • Loading branch information
KevinJump committed May 4, 2016
1 parent 73091c2 commit 9d21010
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
72 changes: 66 additions & 6 deletions Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ abstract public class ContentTypeBaseSerializer<T> : SyncBaseSerializer<T>, ISyn
internal IContentTypeService _contentTypeService;
internal IDataTypeService _dataTypeService;
internal IMemberTypeService _memberTypeService;
internal IEntityService _entityService;
internal IEntityService _entityService;

// all content/media cached lists - they are used when
// creating new properties to make sure we don't YSOD the site.
//
private List<IContentType> _allContentTypes;
private List<IMediaType> _allMediaTypes;


public ContentTypeBaseSerializer(string itemType): base(itemType)
{
Expand Down Expand Up @@ -138,8 +145,13 @@ internal void DeserializeStructure(IContentTypeBase item, XElement node)
item.AllowedContentTypes = allowedTypes;
}

internal void DeserializeProperties(IContentTypeBase item, XElement node)
internal string DeserializeProperties(IContentTypeBase item, XElement node)
{
string message = "";
// clear our type cache, we use it to check for clashes in compistions.
_allMediaTypes = null;
_allContentTypes = null;

List<string> propertiesToRemove = new List<string>();
Dictionary<string, string> propertiesToMove = new Dictionary<string, string>();
Dictionary<PropertyGroup, string> tabsToBlank = new Dictionary<PropertyGroup, string>();
Expand Down Expand Up @@ -191,10 +203,20 @@ internal void DeserializeProperties(IContentTypeBase item, XElement node)

if (property == null)
{
// create the property
LogHelper.Debug<Events>("Creating new Property: {0} {1}", ()=> item.Alias, ()=> alias);
property = new PropertyType(dataTypeDefinition, alias);
newProperty = true;
// for doctypes we need to check the compositions, we cant create a property here
// that exists further down the composition tree.

if (CanCreateProperty(item, alias))
{
LogHelper.Debug<Events>("Creating new Property: {0} {1}", () => item.Alias, () => alias);
property = new PropertyType(dataTypeDefinition, alias);
newProperty = true;
}
else
{
message = string.Format("Property: {0} was not created because of clash (try running import again)", alias);
}

}

if (property != null)
Expand Down Expand Up @@ -353,6 +375,8 @@ internal void DeserializeProperties(IContentTypeBase item, XElement node)
}
}

return message;

}

internal void DeserializeTabSortOrder(IContentTypeBase item, XElement node)
Expand Down Expand Up @@ -616,6 +640,42 @@ private IContentTypeBase LookupByAlias(string alias)

return item;
}


/// <summary>
/// does a check to see that no doctype/media type below
/// what we are looking at has the property we want to
/// create, if it doesn, we warn and carry on. a double
/// import fixes this
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
private bool CanCreateProperty(IContentTypeBase item, string alias)
{
bool canCreate = true;

switch (_itemType)
{
case Constants.Packaging.DocumentTypeNodeName:
if (_allContentTypes == null)
_allContentTypes = _contentTypeService.GetAllContentTypes().ToList();

var allProperties = _allContentTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == item.Id)).Select(x => x.PropertyTypes);
if (allProperties.Any(x => x.Any(y => y.Alias == alias)))
canCreate = false;
break;
case "MediaType":
if (_allMediaTypes == null)
_allMediaTypes = _contentTypeService.GetAllMediaTypes().ToList();

var allMediaProperties = _allMediaTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == item.Id)).Select(x => x.PropertyTypes);
if (allMediaProperties.Any(x => x.Any(y => y.Alias == alias)))
canCreate = false;
break;
}
return canCreate;

}
#endregion

}
Expand Down
4 changes: 2 additions & 2 deletions Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal override SyncAttempt<IContentType> DeserializeCore(XElement node)
// _contentTypeService.Save(item);

// Update Properties
DeserializeProperties((IContentTypeBase)item, node);
var msg = DeserializeProperties((IContentTypeBase)item, node);

// Update Tabs
DeserializeTabSortOrder((IContentTypeBase)item, node);
Expand Down Expand Up @@ -143,7 +143,7 @@ internal override SyncAttempt<IContentType> DeserializeCore(XElement node)
// structure twice.
// DeserializeStructure((IContentTypeBase)item, node);

return SyncAttempt<IContentType>.Succeed(item.Name, item, ChangeType.Import);
return SyncAttempt<IContentType>.Succeed(item.Name, item, ChangeType.Import, msg);
}

private int GetContentFolders(XElement info, IContentType item)
Expand Down
4 changes: 2 additions & 2 deletions Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal override SyncAttempt<IMediaType> DeserializeCore(XElement node)
item.SetLazyParentId(new Lazy<int>(() => parentId));
}

DeserializeProperties(item, node);
var msg = DeserializeProperties(item, node);

DeserializeTabSortOrder(item, node);

Expand All @@ -103,7 +103,7 @@ internal override SyncAttempt<IMediaType> DeserializeCore(XElement node)

_contentTypeService.Save(item);

return SyncAttempt<IMediaType>.Succeed(item.Name, item, ChangeType.Import);
return SyncAttempt<IMediaType>.Succeed(item.Name, item, ChangeType.Import, msg);
}

private int GetMediaFolders(XElement info, IMediaType item)
Expand Down
4 changes: 2 additions & 2 deletions Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ internal override SyncAttempt<IMemberType> DeserializeCore(XElement node)

DeserializeBase(item, info);

DeserializeProperties(item, node);
var msg = DeserializeProperties(item, node);

DeserializeTabSortOrder(item, node);

_memberTypeService.Save(item);

return SyncAttempt<IMemberType>.Succeed(item.Name, item, ChangeType.Import);
return SyncAttempt<IMemberType>.Succeed(item.Name, item, ChangeType.Import, msg);
}

internal override SyncAttempt<XElement> SerializeCore(IMemberType item)
Expand Down
Binary file modified umbPackage/uSync.BackOffice/Jumoo.uSync.Core.dll
Binary file not shown.
Binary file modified umbPackage/uSync.Core/Jumoo.uSync.Core.dll
Binary file not shown.

0 comments on commit 9d21010

Please sign in to comment.