public void AttributeDeleteConstructorSVTest() { AttributeValueDeleteConstructor attributeConstructor = new AttributeValueDeleteConstructor(); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("mail"); attributeConstructor.RuleGroup = new RuleGroup(); attributeConstructor.RuleGroup.Items.Add(new ObjectChangeRule() { TriggerEvents = TriggerEvents.Add }); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); sourceObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("mail"), "*****@*****.**"); sourceObject.CommitCSEntryChange(); sourceObject.DiscardPendingChanges(); sourceObject.SetObjectModificationType(ObjectModificationType.Update, false); attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("mail")); if (!value.IsNull) { Assert.Fail("The constructor did not delete the attribute value"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Expands the declaration /// </summary> /// <param name="hologram">The hologram containing the values to use in the expansion operation</param> /// <returns>A list of expanded attribute values</returns> public IList <object> ExpandDeclaration(MAObjectHologram hologram) { return(new List <object>() { this.ExpandComplexDeclaration(hologram) }); }
public override void Execute() { MAObjectHologram sourceObject = this.GetObjectFromAlias(); Rule.RuleFailedEvent += RuleBase_RuleFailedEvent; RuleGroup.RuleGroupFailedEvent += RuleGroup_RuleGroupFailedEvent; try { if (!this.SuccessCriteria.Evaluate(sourceObject)) { Logger.WriteLine("The unit test evaluation {0} failed", this.Name); Logger.WriteSeparatorLine('-'); Logger.WriteLine("MAObject drop"); Logger.WriteRaw(sourceObject.AttributeDataToString()); Logger.WriteSeparatorLine('-'); throw new EvaluationFailedException(); } } finally { Rule.RuleFailedEvent -= RuleBase_RuleFailedEvent; RuleGroup.RuleGroupFailedEvent -= RuleGroup_RuleGroupFailedEvent; } }
/// <summary> /// Gets the value of the declared attribute from the specified hologram /// </summary> /// <param name="hologram">The hologram to extract the values from</param> /// <returns>The values expanded from the hologram</returns> private IList <object> GetAttributeValues(MAObjectHologram hologram) { List <object> values = new List <object>(); AttributeValues attributeValues = hologram.GetAttributeValues(this.Attribute, this.View); //if (this.Attribute.Name == "mail" && this.View == HologramView.Current) //{ // System.Diagnostics.Debugger.Launch(); //} if (!attributeValues.IsEmptyOrNull) { foreach (AttributeValue attributeValue in attributeValues) { values.Add(attributeValue.Value); } } if (values.Count == 0 && this.Attribute.Type == ExtendedAttributeType.Boolean) { values.Add(false); } return(values); }
public void EvaluateSVStringEqualsTest() { Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); AdvancedComparisonRule target = new AdvancedComparisonRule(); target.CompareAs = ExtendedAttributeType.String; target.SourceValue = new ValueDeclaration("test1"); target.TargetValue = new ValueDeclaration("test1"); target.ValueOperator = ValueOperator.Equals; target.GroupOperator = GroupOperator.Any; if (!target.Evaluate(maObject)) { Assert.Fail("The value comparison failed"); } target.TargetValue = new ValueDeclaration("test3"); if (target.Evaluate(maObject)) { Assert.Fail("The value comparison did not fail"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void EvaluateSVAVRLongEqualsTest() { bool expected = true; bool actual; Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); ValueComparisonRule target = new ValueComparisonRule(); target.Attribute = ActiveConfig.DB.GetAttribute("sapExpiryDate"); target.ValueOperator = ValueOperator.Equals; target.ExpectedValue = new ValueDeclaration("1234567890"); // Positive Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("sapExpiryDate"), 1234567890L); actual = target.Evaluate(maObject); Assert.AreEqual(expected, actual); // Negative Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("sapExpiryDate"), 9876543210L); actual = target.Evaluate(maObject); Assert.AreNotEqual(expected, actual); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void EvaluateSVAVRBinaryEqualsTest() { bool expected = true; bool actual; Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); ValueComparisonRule target = new ValueComparisonRule(); target.Attribute = ActiveConfig.DB.GetAttribute("objectSid"); target.ValueOperator = ValueOperator.Equals; target.ExpectedValue = new ValueDeclaration("AAECAwQ="); // Positive Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("objectSid"), new byte[] { 0, 1, 2, 3, 4 }); actual = target.Evaluate(maObject); Assert.AreEqual(expected, actual); // Negative Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("objectSid"), new byte[] { 0, 0, 0, 3, 4 }); actual = target.Evaluate(maObject); Assert.AreNotEqual(expected, actual); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
internal override void OnEventRaised(RaisedEvent raisedEvent, MAObjectHologram sender) { if (sender == null) { throw new ArgumentNullException("sender"); } if (raisedEvent == null) { throw new ArgumentNullException("raisedEvent"); } IList <object> arguments = this.Arguments.Expand(sender); if (arguments.Count > 1) { throw new ArgumentException( string.Format("The command argument declaration returned too many values. Only a single value is allowed to be returned from the declaration\nDeclaration:{0}\nObject:{1}", this.Arguments.Declaration, sender.DisplayText)); } string argument = arguments.FirstOrDefault() as string; if (argument != null) { raisedEvent.RaisedEventProperties.Add("arguments", argument); } }
/// <summary> /// Calls the Execute function of all the child objects /// </summary> /// <param name="hologram">The object being processed</param> /// <returns>Returns a value indicating whether the constructor group executed</returns> private bool ExecuteConstructors(MAObjectHologram hologram, IList <string> constructorOverrides) { Logger.WriteLine("Executing: " + this.ID); bool executed = false; try { Logger.IncreaseIndent(); foreach (ExecutableConstructorObject constructor in this.Constructors) { executed = constructor.EvaluateAndExecute(hologram, constructorOverrides); if (executed) { if (this.ExecutionRule == GroupExecutionRule.ExitAfterFirstSuccess) { Logger.WriteLine("Exiting group {0} (first match found)", LogLevel.Debug, this.ID); return(executed); } } } } finally { Logger.DecreaseIndent(); } return(executed); }
/// <summary> /// Deletes an object from the database /// </summary> /// <param name="csentryChange">The CSEntryChange containing the object to delete</param> /// <param name="dc">The DBDataContext in use on this thread</param> private static void PerformCSEntryExportDelete(CSEntryChange csentryChange) { MAObjectHologram maObject = GetObjectFromDnOrAnchor(csentryChange); csentryChange.DN = maObject.ObjectID.ToString(); maObject.CommitCSEntryChange(csentryChange, false); }
/// <summary> /// Returns any deleted objects in the database that match the resurrection criteria /// </summary> /// <param name="csentryChange">The CSEntryChange object representing the object being added to the database</param> /// <param name="dc">The DBDataContext in use on this thread</param> /// <returns>An MAObject matching the resurrection criteria, or null if no matching object was found</returns> private static MAObjectHologram GetResurrectionObject(CSEntryChange csentryChange) { AcmaSchemaObjectClass objectClass = null; if (csentryChange.ObjectType != null) { objectClass = ActiveConfig.DB.GetObjectClass(csentryChange.ObjectType); } MAObjectHologram existingObject = ActiveConfig.DB.GetMAObjectOrDefault(csentryChange.DN, objectClass); if (existingObject != null) { return(existingObject); } if (!ActiveConfig.DB.GetObjectClass(csentryChange.ObjectType).AllowResurrection) { return(null); } if (!ActiveConfig.XmlConfig.ClassConstructors.Contains(csentryChange.ObjectType)) { return(null); } DBQueryGroup parameters = ActiveConfig.XmlConfig.ClassConstructors[csentryChange.ObjectType].ResurrectionParameters; if (parameters == null || parameters.DBQueries == null || parameters.DBQueries.Count == 0) { return(null); } return(ActiveConfig.DB.GetResurrectionObject(parameters, csentryChange)); }
public void ValueConstructorSequentialIntegerAllocationTest() { SequentialIntegerAllocationConstructor attributeConstructor = new SequentialIntegerAllocationConstructor(); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("unixUid"); attributeConstructor.Sequence = ActiveConfig.DB.GetSequence("unixUid"); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); long nextInt = ActiveConfig.DB.GetNextSequenceValue("unixUid") + 1; attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("unixUid")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } if (value.Value is long) { if (value.ValueLong != nextInt) { Assert.Fail("The constructor did not generate the expected value"); } } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Gets the recipients of the specified exit event /// </summary> /// <param name="exitEventRecipients">A list of reference attributes to obtain recipients from</param> /// <returns>A list of MAObjectHologram to send the specified exit event to</returns> private IList <MAObjectHologram> GetEventRecipientsFromAttributes(MAObjectHologram hologram) { List <MAObjectHologram> recipients = new List <MAObjectHologram>(); foreach (AcmaSchemaAttribute recipientAttribute in this.Recipients) { AttributeValues values = hologram.GetAttributeValues(recipientAttribute); if (!values.IsEmptyOrNull) { foreach (AttributeValue value in values) { MAObjectHologram recipient = ActiveConfig.DB.GetMAObjectOrDefault(value.ValueGuid); if (recipient == null) { hologram.MarkMissingReference(value.ValueGuid, recipientAttribute); } else { recipients.Add(recipient); } } } } return(recipients); }
private IList <MAObjectHologram> GetEventRecipientsFromQuery(MAObjectHologram hologram) { List <MAObjectHologram> recipients = new List <MAObjectHologram>(); foreach (DBQueryObject query in this.RecipientQueries) { DBQueryGroup group; if (query is DBQueryGroup) { group = query as DBQueryGroup; } else if (query is DBQueryByValue) { group = new DBQueryGroup(); group.Operator = GroupOperator.Any; group.AddChildQueryObjects(query); } else { throw new NotSupportedException(); } IEnumerable <MAObjectHologram> queryRecipients; queryRecipients = ActiveConfig.DB.GetMAObjectsFromDBQuery(group, hologram); if (queryRecipients != null) { recipients.AddRange(queryRecipients); } } return(recipients); }
/// <summary> /// Initializes a new instance of the RaisedEvent class /// </summary> /// <param name="eventObject">The event that is being raised</param> /// <param name="eventSource">The object that raised the event</param> public RaisedEvent(AcmaEvent eventObject, MAObjectHologram eventSource) : this() { this.Event = eventObject; this.Source = eventSource; this.Event.OnEventRaised(this, eventSource); }
/// <summary> /// Expands the attributes referenced in the declaration text /// </summary> /// <param name="hologram">The object containing the values to use in the expansion</param> /// <param name="isAttributeValueUnique">A function that can test if the value generated by the expansion is unique</param> /// <returns>The target attribute value with any references expanded out to their values</returns> private string ExpandComplexDeclaration(MAObjectHologram hologram, Func <string, string, bool> isAttributeValueUnique) { string constructedString = this.ExpandComplexDeclaration(hologram); if (isAttributeValueUnique == null) { return(constructedString); } if (this.HasUniqueAllocations) { return(this.ProcessUniqueAllocations(hologram, constructedString, isAttributeValueUnique)); } int count = 0; while (!isAttributeValueUnique(constructedString, null)) { constructedString = this.ExpandComplexDeclaration(hologram); if (count++ > ActiveConfig.UniqueAllocationDepth) { throw new MaximumAllocationAttemptsExceededException("The maximum number of unique allocation attempts has been exceeded"); } } return(constructedString); }
/// <summary> /// Expands the static declarations, and if any result in a value that is currently unique, that value is required /// </summary> /// <param name="hologram">The source object</param> /// <returns>A unique value expanded from the static declarations, or null if a unique value could not be found</returns> private string TryGetUniqueValueFromStaticDeclarations(MAObjectHologram hologram) { if (this.StaticDeclarations.Count == 0) { return(null); } foreach (var staticDeclaration in this.StaticDeclarations) { IList <object> values = staticDeclaration.Expand(hologram); if (values.Count == 0) { continue; } else if (values.Count > 1) { throw new TooManyValuesException(string.Format("The value declaration '{0}' returned more than one value. Only single valued attributes are supported for unique allocation", staticDeclaration)); } string value = TypeConverter.ConvertData <string>(values.First()); if (string.IsNullOrWhiteSpace(value)) { continue; } if (this.IsAttributeUnique(hologram, value)) { return(value); } } return(null); }
/// <summary> /// Creates a value that is unique against the specified UniqueAllocationAttributes /// </summary> /// <param name="hologram">The object to construct the value for</param> /// <param name="constructedValue">The value under construction</param> /// <param name="isAttributeValueUnique">A function that can test if the value generated by the expansion is unique</param> /// <returns>A value that is unique against the specified UniqueAllocationAttributes</returns> private string ProcessUniqueAllocations(MAObjectHologram hologram, string constructedValue, Func <string, string, bool> isAttributeValueUnique) { string valueToTest = string.Empty; if (isAttributeValueUnique == null) { return(constructedValue); } VariableDeclaration uniqueAllocator = this.VariableDeclarations.FirstOrDefault(t => t.IsUniqueAllocationVariable); if (uniqueAllocator == null) { throw new InvalidDeclarationStringException("The constructor requires a unique attribute allocation, but does not provide a %n% or %o% variable to use to make the value unique"); } uniqueAllocator.ResetCounter(); string wilcardDeclaration = constructedValue.Replace(uniqueAllocator.Declaration, "%"); do { IList <object> uniqueAllocatorValue = uniqueAllocator.Expand(); valueToTest = constructedValue.Replace(uniqueAllocator.Declaration, uniqueAllocatorValue.First().ToSmartStringOrNull()); }while (!isAttributeValueUnique(valueToTest, wilcardDeclaration)); return(valueToTest); }
public void EvaluateSVAVRDateTimeEqualsTest() { bool expected = true; bool actual; Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); ValueComparisonRule target = new ValueComparisonRule(); target.Attribute = ActiveConfig.DB.GetAttribute("dateTimeSV"); target.ValueOperator = ValueOperator.Equals; target.ExpectedValue = new ValueDeclaration("2010-01-01"); // Positive Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("dateTimeSV"), DateTime.Parse("2010-01-01")); actual = target.Evaluate(maObject); Assert.AreEqual(expected, actual); // Negative Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("dateTimeSV"), DateTime.Parse("2011-01-01")); actual = target.Evaluate(maObject); Assert.AreNotEqual(expected, actual); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Creates the WHERE clause for this query /// </summary> /// <param name="builder">The builder used by this query</param> /// <param name="hologram">The hologram used as the source of query values</param> /// <returns>A WhereClause object containing the terms of the query</returns> public WhereClause CreateWhereClause(DBQueryBuilder builder, MAObjectHologram hologram) { if (this.DBQueries.Count == 0) { throw new InvalidOperationException("The query group cannot generate a query when no child queries are specified"); } WhereClause parentClause; WhereClause querySubClause; if (this.Operator == GroupOperator.None) { // Workaround to stop SqlOm from dropping the operator when there is only a single term in the where clause parentClause = new WhereClause(WhereClauseRelationship.Not); parentClause.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Number(1), SqlExpression.Number(1), CompareOperator.Equal)); querySubClause = new WhereClause(WhereClauseRelationship.Or); parentClause.SubClauses.Add(querySubClause); } else { parentClause = new WhereClause(this.GetWhereClauseRelationship()); querySubClause = parentClause; } IList <DBQueryObject> queryObjects = this.ProcessChildDBQueryObjects(querySubClause, builder, hologram); if (queryObjects.Count == 0) { throw new QueryValueNullException("The query group contained no valid queries to execute"); } else { return(parentClause); } }
public void EvaluateSVAVRStringEqualsProposedTest() { bool expected = true; bool actual; Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); ValueComparisonRule target = new ValueComparisonRule(); target.Attribute = ActiveConfig.DB.GetAttribute("mail"); target.ValueOperator = ValueOperator.Equals; target.ExpectedValue = new ValueDeclaration("*****@*****.**"); target.View = HologramView.Proposed; // Positive Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("mail"), "*****@*****.**"); actual = target.Evaluate(maObject); Assert.AreEqual(expected, actual); // Negative Tests maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("mail"), "*****@*****.**"); actual = target.Evaluate(maObject); Assert.AreNotEqual(expected, actual); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void UniqueValueConstructorRequiredNumberTest() { UniqueValueConstructor attributeConstructor = new UniqueValueConstructor(); attributeConstructor.ValueDeclaration = new UniqueValueDeclaration("mytestvalue%n%"); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("personID"); attributeConstructor.UniqueAllocationAttributes.Add(attributeConstructor.Attribute); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("personID")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } if (value.Value.ToString() != "mytestvalue1") { Assert.Fail("The constructor did not generate the expected value"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Gets the object containing the attribute value to use /// </summary> /// <param name="hologram">The object that is under construction</param> /// <returns>If the declaration contains a reference to another object, then that object is returned, otherwise the original object is returned</returns> private IEnumerable <MAObjectHologram> GetSourceObjects(MAObjectHologram hologram) { if (this.ObjectEvaluationPath.Count == 0) { return(new List <MAObjectHologram>() { hologram }); } else { IEnumerable <MAObjectHologram> foundObjects = new List <MAObjectHologram>() { hologram }; foreach (AcmaSchemaAttribute pathItem in this.ObjectEvaluationPath) { List <MAObjectHologram> childObjects = new List <MAObjectHologram>(); foreach (var foundObject in foundObjects) { childObjects.AddRange(foundObject.GetReferencedObjects(pathItem)); } foundObjects = childObjects; } return(foundObjects); } }
/// <summary> /// Contributes to a CSEntryChange for the specified MA_Delta_Object by populating newly added object and its attributes /// </summary> /// <param name="maObject">The MAObject to construct the CSEntry for</param> /// <param name="csentry">The CSEntryChange object to contribute to</param> private static void GetObject(MAObjectHologram maObject, CSEntryChange csentry, IEnumerable <AcmaSchemaAttribute> requiredAttributes) { try { foreach (AcmaSchemaAttribute maAttribute in requiredAttributes) { List <object> values = new List <object>(); AttributeValues dbvalues = maObject.GetAttributeValues(maAttribute); values.AddRange(dbvalues.Where(t => !t.IsNull).Select(t => t.Value)); if (values.Count > 0) { if (maAttribute.Type == ExtendedAttributeType.Reference) { csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values.Select(t => t.ToString()).ToList <object>())); } else if (maAttribute.Type == ExtendedAttributeType.DateTime) { csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values.Select(t => ((DateTime)t).ToResourceManagementServiceDateFormat()).ToList <object>())); } else { csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values)); } } } } catch (SafetyRuleViolationException ex) { csentry.ErrorCodeImport = MAImportError.ImportErrorCustomContinueRun; csentry.ErrorName = ex.Message; csentry.ErrorDetail = ex.Message + "\n" + ex.StackTrace; } }
/// <summary> /// Expands the attributes referenced in the declaration text /// </summary> /// <param name="hologram">The object containing the values to use in the expansion</param> /// <returns>The target attribute value with any references expanded out to their values</returns> protected string ExpandComplexDeclaration(MAObjectHologram hologram) { this.ParseDeclaration(); string constructedString = this.RemoveEscapedCharacters(this.Declaration); foreach (AttributeDeclaration declaration in this.AttributeDeclarations) { if (hologram == null) { throw new ArgumentNullException("hologram"); } IList <object> values = declaration.Expand(hologram); if (values.Count == 0) { constructedString = constructedString.Replace(declaration.Declaration, string.Empty); } else if (values.Count > 1) { throw new TooManyValuesException("The declaration string returned more than one attribute value which is unsupported for a complex value declaration", null); } else { constructedString = constructedString.Replace(declaration.Declaration, values[0].ToSmartStringOrNull()); } } constructedString = this.ExpandVariables(constructedString as string); return(constructedString); }
public void EvaluateOnMVAttributePresentProposed() { Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("directReports"), new List <object> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }); // Positive Tests AttributePresenceRule target = new AttributePresenceRule(); target.Attribute = ActiveConfig.DB.GetAttribute("directReports"); target.Operator = PresenceOperator.IsPresent; target.View = HologramView.Proposed; Assert.IsTrue(target.Evaluate(maObject)); // Negative Tests target = new AttributePresenceRule(); target.Attribute = ActiveConfig.DB.GetAttribute("directReports"); target.Operator = PresenceOperator.NotPresent; target.View = HologramView.Proposed; Assert.IsFalse(target.Evaluate(maObject)); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Updates the links to the referenced objects /// </summary> /// <param name="sourceObject">The object to apply the link rule to</param> /// <returns>A list of objects that were modified</returns> private IList <MAObjectHologram> UpdateLinks(MAObjectHologram sourceObject) { List <MAObjectHologram> updatedObjects = new List <MAObjectHologram>(); List <MAObjectHologram> targetsToReference = new List <MAObjectHologram>(); List <MAObjectHologram> targetsToDereference = new List <MAObjectHologram>(); IEnumerable <MAObjectHologram> targetsProposed = sourceObject.GetReferencedObjects(this.ForwardLinkAttribute, System.Data.DataRowVersion.Proposed); IEnumerable <MAObjectHologram> targetsCurrent = sourceObject.GetReferencedObjects(this.ForwardLinkAttribute, System.Data.DataRowVersion.Current); targetsToReference.AddRange(targetsProposed.Except(targetsCurrent)); targetsToDereference.AddRange(targetsCurrent.Except(targetsProposed)); foreach (MAObjectHologram target in targetsToDereference) { Logger.WriteLine("Unlinking object {0} from {1} on object {2} referenced by {3}", LogLevel.Debug, sourceObject.DisplayText, this.BackLinkAttribute.Name, target.DisplayText, this.ForwardLinkAttribute.Name); target.SetObjectModificationType(ObjectModificationType.Update, false); this.RemoveReference(sourceObject, target); updatedObjects.Add(target); } foreach (MAObjectHologram target in targetsToReference) { Logger.WriteLine("Linking object {0} to {1} on object {2} referenced by {3}", LogLevel.Debug, sourceObject.DisplayText, this.BackLinkAttribute.Name, target.DisplayText, this.ForwardLinkAttribute.Name); target.SetObjectModificationType(ObjectModificationType.Update, false); this.AddReference(sourceObject, target); updatedObjects.Add(target); } return(updatedObjects); }
public void EvaluateOnSVAttributePresentCurrent() { Guid newId = Guid.NewGuid(); try { MAObjectHologram maObject = ActiveConfig.DB.CreateMAObject(newId, "person"); maObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("accountName"), "mytestvalue"); maObject.CommitCSEntryChange(); // Positive Tests AttributePresenceRule target = new AttributePresenceRule(); target.Attribute = ActiveConfig.DB.GetAttribute("accountName"); target.Operator = PresenceOperator.IsPresent; target.View = HologramView.Current; Assert.IsTrue(target.Evaluate(maObject)); // Negative Tests target = new AttributePresenceRule(); target.Attribute = ActiveConfig.DB.GetAttribute("accountName"); target.Operator = PresenceOperator.NotPresent; target.View = HologramView.Current; Assert.IsFalse(target.Evaluate(maObject)); } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
/// <summary> /// Calls the EvaluateAndExecute function of all the child objects /// </summary> /// <param name="hologram">The object being processed</param> /// <returns>Returns a value indicating whether the object executed</returns> public bool EvaluateAndExecute(MAObjectHologram hologram, IList <string> constructorOverrides) { bool executed = false; if (this.HasErrors) { throw new InvalidOperationException(string.Format("The constructor for object class '{0}' has the following errors that must be fixed:\n{1}", this.ObjectClass.Name, this.ErrorList.Select(t => string.Format("{0}: {1}", t.Key, t.Value)).ToNewLineSeparatedString())); } if (this.Disabled) { Logger.WriteLine("Class constructor is disabled", LogLevel.Debug, this.Name); return(false); } if (this.ObjectClass != hologram.ObjectClass) { throw new InvalidOperationException(string.Format("The class constructor for {0} was executed against object of class {1}", this.ObjectClass.Name, hologram.ObjectClass.Name)); } foreach (ExecutableConstructorObject constructor in this.Constructors) { if (constructor.EvaluateAndExecute(hologram, constructorOverrides)) { executed = true; } } return(executed); }
public void DBQueryByAttributeExceptionOnMVNull() { Guid valueSourceObjectId = Guid.NewGuid(); DBQueryByValue match1 = new DBQueryByValue(ActiveConfig.DB.GetAttribute("mailAlternateAddresses"), ValueOperator.Equals, ActiveConfig.DB.GetAttribute("mailAlternateAddresses")); DBQueryGroup group = new DBQueryGroup(GroupOperator.All); group.AddChildQueryObjects(match1); try { MAObjectHologram valueSourceObject = ActiveConfig.DB.CreateMAObject(valueSourceObjectId, "person"); valueSourceObject.CommitCSEntryChange(); try { DBQueryBuilder queryBuilder = new DBQueryBuilder(group, 0, valueSourceObject); Assert.Fail("The expected exception was not thrown"); } catch (QueryValueNullException) { } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(valueSourceObjectId); } }