public string GetInlineFieldId(IAssociationFacade parentFacade, IObjectFacade owner, IAssociationFacade assocFacade) { IAssociationSpec parent = parentFacade.WrappedSpec(); IAssociationSpec assoc = assocFacade.WrappedSpec(); return(parent.Id + Sep + GetObjectId(owner) + Sep + assoc.Id); }
public TestProperty(IObjectPersistor persistor, IAssociationSpec field, ITestHasActions owningObject, ITestObjectFactory factory, INakedObjectManager manager) { this.persistor = persistor; this.field = field; this.owningObject = owningObject; this.factory = factory; this.manager = manager; }
/// <summary> /// Display the identified property on the model parameter in an edit field /// </summary> public static MvcHtmlString ObjectPropertyEdit(this HtmlHelper html, object model, string propertyId) { INakedObject nakedObject = html.Framework().GetNakedObject(model); IAssociationSpec property = ((IObjectSpec)nakedObject.Spec).Properties.Where(a => a.Id == propertyId).SingleOrDefault(a => a.IsVisible(nakedObject)); return(property == null?MvcHtmlString.Create("") : html.ObjectPropertyEdit(new PropertyContext(nakedObject, property, true))); }
public virtual JsonResult ValidateProperty(string id, string value, string propertyName) { INakedObject nakedObject = NakedObjectsContext.GetNakedObjectFromId(id); if (nakedObject.ResolveState.IsTransient()) { // if transient then we cannot validate now - need to wait until save return(Jsonp(true)); } IAssociationSpec property = ((IObjectSpec)nakedObject.Spec).Properties.SingleOrDefault(p => p.Id == propertyName); string fieldId = GetFieldInputId(nakedObject, property); bool isValid = false; if (value == null) { value = Request.Params[fieldId]; } if (property != null && property is IOneToOneAssociationSpec) { ValidateAssociation(nakedObject, property as IOneToOneAssociationSpec, value); isValid = ModelState.IsValid; } if (isValid) { return(Jsonp(true)); } ModelError error = ModelState[fieldId].Errors.FirstOrDefault(); return(Jsonp(error == null ? "" : error.ErrorMessage)); }
public virtual FileContentResult GetFile(string Id, string PropertyId) { INakedObject target = NakedObjectsContext.GetNakedObjectFromId(Id); IAssociationSpec assoc = ((IObjectSpec)target.Spec).Properties.Single(a => a.Id == PropertyId); var domainObject = assoc.GetNakedObject(target).GetDomainObject(); return(AsFile(domainObject)); }
public TestProperty(IObjectPersistor persistor, IAssociationSpec field, ITestHasActions owningObject, ITestObjectFactory factory, INakedObjectManager manager) { this.persistor = persistor; this.field = field; this.owningObject = owningObject; this.factory = factory; this.manager = manager; }
private static INakedObjectAdapter RestoreInline(this INakedObjectsFramework framework, IAggregateOid aggregateOid) { IOid parentOid = aggregateOid.ParentOid; INakedObjectAdapter parent = framework.RestoreObject(parentOid); IAssociationSpec assoc = parent.GetObjectSpec().Properties.Where((p => p.Id == aggregateOid.FieldName)).Single(); return(assoc.GetNakedObject(parent)); }
public PropertyContext(INakedObject target, IAssociationSpec property, bool isEdit, PropertyContext parentContext = null) : base(target) { Property = property; IsPropertyEdit = isEdit; IsEdit = isEdit; ParentContext = parentContext; }
public void LoadField(INakedObjectAdapter nakedObjectAdapter, string field) { var spec = nakedObjectAdapter.Spec as IObjectSpec; Trace.Assert(spec != null); IAssociationSpec associationSpec = spec.Properties.Single(x => x.Id == field); ResolveField(nakedObjectAdapter, associationSpec); }
public AssociationFacade(IAssociationSpec assoc, IFrameworkFacade frameworkFacade, INakedObjectsFramework framework) { FacadeUtils.AssertNotNull(assoc, "Assoc is null"); FacadeUtils.AssertNotNull(framework, "framework is null"); FacadeUtils.AssertNotNull(frameworkFacade, "FrameworkFacade is null"); WrappedSpec = assoc; this.framework = framework; FrameworkFacade = frameworkFacade; }
public AssociationFacade(IAssociationSpec assoc, IFrameworkFacade frameworkFacade, INakedObjectsFramework framework) { FacadeUtils.AssertNotNull(assoc, "Assoc is null"); FacadeUtils.AssertNotNull(framework, "framework is null"); FacadeUtils.AssertNotNull(frameworkFacade, "FrameworkFacade is null"); this.assoc = assoc; this.framework = framework; FrameworkFacade = frameworkFacade; }
public NakedObjectAssociationWrapper(IAssociationSpec assoc, INakedObjectsSurface surface, INakedObjectsFramework framework) { SurfaceUtils.AssertNotNull(assoc, "Assoc is null"); SurfaceUtils.AssertNotNull(framework, "framework is null"); SurfaceUtils.AssertNotNull(surface, "surface is null"); this.assoc = assoc; this.framework = framework; Surface = surface; }
public void LoadField(INakedObject nakedObject, string field) { var spec = nakedObject.Spec as IObjectSpec; Trace.Assert(spec != null); Log.DebugFormat("LoadField nakedObject: {0} field: {1}", nakedObject, field); IAssociationSpec associationSpec = spec.Properties.Single(x => x.Id == field); ResolveField(nakedObject, associationSpec); }
private Tuple<IAssociationSpec, IObjectSpec> GetPropertyTypeInternal(string typeName, string propertyName) { if (string.IsNullOrWhiteSpace(typeName) || string.IsNullOrWhiteSpace(propertyName)) { throw new BadRequestNOSException(); } IObjectSpec spec = (IObjectSpec) GetDomainTypeInternal(typeName); IAssociationSpec property = spec.Properties.SingleOrDefault(p => p.Id == propertyName); if (property == null) { throw new TypePropertyResourceNotFoundNOSException(propertyName, typeName); } return new Tuple<IAssociationSpec, IObjectSpec>(property, (IObjectSpec) spec); }
public int CountField(INakedObjectAdapter nakedObjectAdapter, string field) { var spec = nakedObjectAdapter.Spec as IObjectSpec; Trace.Assert(spec != null); IAssociationSpec associationSpec = spec.Properties.Single(x => x.Id == field); if (nakedObjectAdapter.Spec.IsViewModel) { INakedObjectAdapter collection = associationSpec.GetNakedObject(nakedObjectAdapter); return(collection.GetCollectionFacetFromSpec().AsEnumerable(collection, nakedObjectManager).Count()); } return(objectStore.CountField(nakedObjectAdapter, associationSpec)); }
private static string GetFieldInputId(INakedObject nakedObject, IAssociationSpec property) { string fieldId; if (nakedObject.Oid is AggregateOid) { var aoid = ((AggregateOid)nakedObject.Oid); IAssociationSpec parent = ((IObjectSpec)aoid.ParentOid.Spec).Properties.Where(p => p.Id == aoid.FieldName).SingleOrDefault(); fieldId = IdHelper.GetInlineFieldInputId(parent, nakedObject, property); } else { fieldId = IdHelper.GetFieldInputId(nakedObject, property); } return(fieldId); }
public static object GetVersion(this INakedObjectAdapter nakedObjectAdapter, INakedObjectManager manager) { IAssociationSpec versionProperty = nakedObjectAdapter.GetVersionProperty(); if (versionProperty != null) { object version = versionProperty.GetNakedObject(nakedObjectAdapter).GetDomainObject(); if (version is DateTime) { return(((DateTime)version).StripMillis()); } return(version); } return(null); }
public int CountField(INakedObject nakedObject, string field) { Log.DebugFormat("CountField nakedObject: {0} field: {1}", nakedObject, field); var spec = nakedObject.Spec as IObjectSpec; Trace.Assert(spec != null); IAssociationSpec associationSpec = spec.Properties.Single(x => x.Id == field); if (nakedObject.Spec.IsViewModel) { INakedObject collection = associationSpec.GetNakedObject(nakedObject); return(collection.GetCollectionFacetFromSpec().AsEnumerable(collection, nakedObjectManager).Count()); } return(objectStore.CountField(nakedObject, associationSpec)); }
public string GetAggregateFieldInputId(IObjectFacade objectFacade, IAssociationFacade propertyFacade) { string fieldId; INakedObjectAdapter nakedObject = objectFacade.WrappedAdapter(); var aoid = nakedObject.Oid as IAggregateOid; if (aoid != null) { IAssociationSpec parent = ((IObjectSpec)aoid.ParentOid.Spec).Properties.SingleOrDefault(p => p.Id == aoid.FieldName); fieldId = parent.Id + Sep + GetObjectId(objectFacade) + Sep + propertyFacade.Id + Sep + InputOrSelect(propertyFacade.WrappedSpec().ReturnSpec); } else { fieldId = GetFieldInputId(objectFacade, propertyFacade); } return(fieldId); }
private IAssociationSpec GetPropertyInternal(INakedObject nakedObject, string propertyName, bool onlyVisible = true) { if (string.IsNullOrWhiteSpace(propertyName)) { throw new BadRequestNOSException(); } IEnumerable<IAssociationSpec> propertyQuery = ((IObjectSpec) nakedObject.Spec).Properties; if (onlyVisible) { propertyQuery = propertyQuery.Where(p => p.IsVisible(nakedObject)); } IAssociationSpec property = propertyQuery.SingleOrDefault(p => p.Id == propertyName); if (property == null) { throw new PropertyResourceNotFoundNOSException(propertyName); } return property; }
public void ResolveField(INakedObjectAdapter nakedObjectAdapter, IAssociationSpec field) { if (field.ReturnSpec.HasNoIdentity) { return; } INakedObjectAdapter reference = field.GetNakedObject(nakedObjectAdapter); if (reference == null || reference.ResolveState.IsResolved()) { return; } if (!reference.ResolveState.IsPersistent()) { return; } // don't log object - its ToString() may use the unresolved field or unresolved collection objectStore.ResolveField(nakedObjectAdapter, field); }
public void ResolveField(INakedObject nakedObject, IAssociationSpec field) { Log.DebugFormat("ResolveField nakedObject: {0} field: {1}", nakedObject, field); if (field.ReturnSpec.HasNoIdentity) { return; } INakedObject reference = field.GetNakedObject(nakedObject); if (reference == null || reference.ResolveState.IsResolved()) { return; } if (!reference.ResolveState.IsPersistent()) { return; } if (Log.IsInfoEnabled) { // don't log object - its ToString() may use the unresolved field or unresolved collection Log.Info("resolve field " + nakedObject.Spec.ShortName + "." + field.Id + ": " + reference.Spec.ShortName + " " + reference.ResolveState.CurrentState.Code + " " + reference.Oid); } objectStore.ResolveField(nakedObject, field); }
public AssociationFacade(IAssociationSpec assoc, IFrameworkFacade frameworkFacade, INakedObjectsFramework framework) { WrappedSpec = assoc ?? throw new NullReferenceException($"{nameof(assoc)} is null"); this.framework = framework ?? throw new NullReferenceException($"{nameof(framework)} is null"); FrameworkFacade = frameworkFacade ?? throw new NullReferenceException($"{nameof(frameworkFacade)} is null"); }
private PropertyContext GetProperty(INakedObject nakedObject, string propertyName, bool onlyVisible = true) { IAssociationSpec property = GetPropertyInternal(nakedObject, propertyName, onlyVisible); return new PropertyContext {Target = nakedObject, Property = property}; }
public static bool IsFile(this IAssociationSpec assoc, INakedObjectsFramework framework) { return(assoc.ReturnSpec.IsFile(framework)); }
public ITestProperty CreateTestProperty(IAssociationSpec field, ITestHasActions owningObject) => new TestProperty(persistor, field, owningObject, this, manager);
public string GetConcurrencyActionInputId(IAssociationSpec nakedObjectAssociation) { return(IdHelper.GetConcurrencyActionInputId(Target, Action, nakedObjectAssociation)); }
public string GetInlineFieldInputId(IAssociationFacade parent, IObjectFacade owner, IAssociationFacade assocFacade) { IAssociationSpec assoc = assocFacade.WrappedSpec(); return(GetInlineFieldId(parent, owner, assocFacade) + Sep + InputOrSelect(assoc.ReturnSpec)); }
public ITestProperty CreateTestProperty(IAssociationSpec field, ITestHasActions owningObject) => new TestProperty(framework.Persistor, field, owningObject, this, framework.NakedObjectManager);
// return true if able to navigate the complete vector of field names // successfully; false if a field could not be located or it turned // out to be a value. private bool IncludeField(Place place, IList <string> fieldNames, string annotation) { Log.DebugFormat("includeField(: {0})", DoLog("place", place) + AndLog("fieldNames", fieldNames) + AndLog("annotation", annotation)); INakedObject nakedObject = place.NakedObject; XElement xmlElement = place.XmlElement; // we use a copy of the path so that we can safely traverse collections // without side-effects fieldNames = fieldNames.ToList(); // see if we have any fields to process if (!fieldNames.Any()) { return(true); } // take the first field name from the list, and remove string fieldName = fieldNames.First(); fieldNames.Remove(fieldName); Log.Debug("includeField(Pl, Vec, Str):" + DoLog("processing field", fieldName) + AndLog("left", "" + fieldNames.Count())); // locate the field in the object's class IObjectSpec nos = (IObjectSpec)nakedObject.Spec; IAssociationSpec field = nos.Properties.SingleOrDefault(p => p.Id.ToLower() == fieldName); if (field == null) { Log.Info("includeField(Pl, Vec, Str): could not locate field, skipping"); return(false); } // locate the corresponding XML element // (the corresponding XSD element will later be attached to xmlElement // as its userData) Log.Debug("includeField(Pl, Vec, Str): locating corresponding XML element"); XElement[] xmlFieldElements = ElementsUnder(xmlElement, field.Id).ToArray(); int fieldCount = xmlFieldElements.Count(); if (fieldCount != 1) { Log.Info("includeField(Pl, Vec, Str): could not locate " + DoLog("field", field.Id) + AndLog("xmlFieldElements.size", "" + fieldCount)); return(false); } XElement xmlFieldElement = xmlFieldElements.First(); if (!fieldNames.Any() && annotation != null) { // nothing left in the path, so we will apply the annotation now NofMetaModel.SetAnnotationAttribute(xmlFieldElement, annotation); } var fieldPlace = new Place(nakedObject, xmlFieldElement); if (field.ReturnSpec.IsParseable) { Log.Debug("includeField(Pl, Vec, Str): field is value; done"); return(false); } var oneToOneAssociation = field as IOneToOneAssociationSpec; if (oneToOneAssociation != null) { Log.Debug("includeField(Pl, Vec, Str): field is 1->1"); INakedObject referencedObject = oneToOneAssociation.GetNakedObject(fieldPlace.NakedObject); if (referencedObject == null) { return(true); // not a failure if the reference was null } bool appendedXml = AppendXmlThenIncludeRemaining(fieldPlace, referencedObject, fieldNames, annotation); Log.Debug("includeField(Pl, Vec, Str): 1->1: invoked appendXmlThenIncludeRemaining for " + DoLog("referencedObj", referencedObject) + AndLog("returned", "" + appendedXml)); return(appendedXml); } var oneToManyAssociation = field as IOneToManyAssociationSpec; if (oneToManyAssociation != null) { Log.Debug("includeField(Pl, Vec, Str): field is 1->M"); INakedObject collection = oneToManyAssociation.GetNakedObject(fieldPlace.NakedObject); INakedObject[] collectionAsEnumerable = collection.GetAsEnumerable(nakedObjectManager).ToArray(); Log.Debug("includeField(Pl, Vec, Str): 1->M: " + DoLog("collection.size", "" + collectionAsEnumerable.Count())); bool allFieldsNavigated = true; foreach (INakedObject referencedObject in collectionAsEnumerable) { bool appendedXml = AppendXmlThenIncludeRemaining(fieldPlace, referencedObject, fieldNames, annotation); Log.Debug("includeField(Pl, Vec, Str): 1->M: + invoked appendXmlThenIncludeRemaining for " + DoLog("referencedObj", referencedObject) + AndLog("returned", "" + appendedXml)); allFieldsNavigated = allFieldsNavigated && appendedXml; } Log.Debug("includeField(Pl, Vec, Str): " + DoLog("returning", "" + allFieldsNavigated)); return(allFieldsNavigated); } return(false); // fall through, shouldn't get here but just in case. }
public string GetConcurrencyActionInputId(IObjectFacade owner, IActionFacade action, IAssociationFacade assocFacade) { IAssociationSpec assoc = assocFacade.WrappedSpec(); return(GetActionId(owner, action) + Sep + assoc.Id + Sep + ConcurrencyName); }
// return true if able to navigate the complete vector of field names // successfully; false if a field could not be located or it turned // out to be a value. private bool IncludeField(Place place, IList <string> fieldNames, string annotation) { INakedObjectAdapter nakedObjectAdapter = place.NakedObjectAdapter; XElement xmlElement = place.XmlElement; // we use a copy of the path so that we can safely traverse collections // without side-effects fieldNames = fieldNames.ToList(); // see if we have any fields to process if (!fieldNames.Any()) { return(true); } // take the first field name from the list, and remove string fieldName = fieldNames.First(); fieldNames.Remove(fieldName); // locate the field in the object's class var nos = (IObjectSpec)nakedObjectAdapter.Spec; IAssociationSpec field = nos.Properties.SingleOrDefault(p => p.Id.ToLower() == fieldName); if (field == null) { return(false); } // locate the corresponding XML element // (the corresponding XSD element will later be attached to xmlElement // as its userData) XElement[] xmlFieldElements = ElementsUnder(xmlElement, field.Id).ToArray(); int fieldCount = xmlFieldElements.Length; if (fieldCount != 1) { return(false); } XElement xmlFieldElement = xmlFieldElements.First(); if (!fieldNames.Any() && annotation != null) { // nothing left in the path, so we will apply the annotation now NofMetaModel.SetAnnotationAttribute(xmlFieldElement, annotation); } var fieldPlace = new Place(nakedObjectAdapter, xmlFieldElement); if (field.ReturnSpec.IsParseable) { return(false); } var oneToOneAssociation = field as IOneToOneAssociationSpec; if (oneToOneAssociation != null) { INakedObjectAdapter referencedObjectAdapter = oneToOneAssociation.GetNakedObject(fieldPlace.NakedObjectAdapter); if (referencedObjectAdapter == null) { return(true); // not a failure if the reference was null } bool appendedXml = AppendXmlThenIncludeRemaining(fieldPlace, referencedObjectAdapter, fieldNames, annotation); return(appendedXml); } var oneToManyAssociation = field as IOneToManyAssociationSpec; if (oneToManyAssociation != null) { INakedObjectAdapter collection = oneToManyAssociation.GetNakedObject(fieldPlace.NakedObjectAdapter); INakedObjectAdapter[] collectionAsEnumerable = collection.GetAsEnumerable(nakedObjectManager).ToArray(); bool allFieldsNavigated = true; foreach (INakedObjectAdapter referencedObject in collectionAsEnumerable) { bool appendedXml = AppendXmlThenIncludeRemaining(fieldPlace, referencedObject, fieldNames, annotation); allFieldsNavigated = allFieldsNavigated && appendedXml; } return(allFieldsNavigated); } return(false); // fall through, shouldn't get here but just in case. }
public ITestProperty CreateTestProperty(IAssociationSpec field, ITestHasActions owningObject) { return new TestProperty(persistor, field, owningObject, this, manager); }