/// <summary>
/// Gets an Entity Model for a given Entity Identifier.
/// </summary>
/// <param name="id">The Entity Identifier in format ComponentID-TemplateID.</param>
/// <param name="localization">The context Localization.</param>
/// <returns>The Entity Model.</returns>
/// <exception cref="DxaItemNotFoundException">If no Entity Model exists for the given URL.</exception>
/// <remarks>
/// Since we can't obtain CT metadata for DCPs, we obtain the View Name from the CT Title.
/// </remarks>
public virtual EntityModel GetEntityModel(string id, Localization localization)
{
using (new Tracer(id, localization))
{
string[] idParts = id.Split('-');
if (idParts.Length != 2)
{
throw new DxaException(String.Format("Invalid Entity Identifier '{0}'. Must be in format ComponentID-TemplateID.", id));
}
string componentUri = string.Format("tcm:{0}-{1}", localization.LocalizationId, idParts[0]);
string templateUri = string.Format("tcm:{0}-{1}-32", localization.LocalizationId, idParts[1]);
IComponentPresentationFactory componentPresentationFactory = DD4TFactoryCache.GetComponentPresentationFactory(localization);
IComponentPresentation dcp;
if (!componentPresentationFactory.TryGetComponentPresentation(out dcp, componentUri, templateUri))
{
throw new DxaItemNotFoundException(id, localization.LocalizationId);
}
EntityModel result = ModelBuilderPipeline.CreateEntityModel(dcp, localization);
if (result.XpmMetadata != null)
{
// Entity Models requested through this method are per definition "query based" in XPM terminology.
result.XpmMetadata["IsQueryBased"] = true;
}
return(result);
}
}