/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="Category"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( Category thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("SuperCategory")) { var superCategoriesId = (IEnumerable <Guid>)rawUpdateInfo["SuperCategory"]; // Check for itself in super categories list if (superCategoriesId.Contains(thing.Iid)) { throw new AcyclicValidationException( string.Format("Category {0} {1} cannot have itself as a SuperCategory", thing.Name, thing.Iid)); } // Get RDL chain and collect categories' ids var categoryIdsFromChain = this.GetCategoryIdsFromRdlChain( transaction, partition, securityContext, ((ReferenceDataLibrary)container).RequiredRdl); categoryIdsFromChain.AddRange(((ReferenceDataLibrary)container).DefinedCategory); // Check that super categories are present in the chain foreach (var superCategoryId in superCategoriesId) { if (!categoryIdsFromChain.Contains(superCategoryId)) { throw new AcyclicValidationException( string.Format( "Category {0} {1} cannot have a SuperCategory from outside the RDL chain", thing.Name, thing.Iid)); } } var categories = this.CategoryService.Get(transaction, partition, categoryIdsFromChain, securityContext) .Cast <Category>().ToList(); // Check every super category that it is acyclic foreach (var superCategoryId in superCategoriesId) { if (!this.IsSuperCategoryAcyclic(categories, superCategoryId, thing.Iid)) { throw new AcyclicValidationException( string.Format( "Category {0} {1} cannot have a SuperCategory {2} that leads to cyclic dependency", thing.Name, thing.Iid, superCategoryId)); } } } }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="SpecializedQuantityKind"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( SpecializedQuantityKind thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("General")) { var kindId = (Guid)rawUpdateInfo["General"]; // Check for itself if (kindId == thing.Iid) { throw new AcyclicValidationException( string.Format( "SpecializedQuantityKind {0} {1} cannot have itself as a general quantity kind.", thing.Name, thing.Iid)); } // Get RDL chain and collect types' ids var parameterTypeIdsFromChain = this.GetParameterTypeIdsFromRdlChain( transaction, partition, securityContext, ((ReferenceDataLibrary)container).RequiredRdl); parameterTypeIdsFromChain.AddRange(((ReferenceDataLibrary)container).ParameterType); // Check that qantity kind is from the same RDL chain if (!parameterTypeIdsFromChain.Contains(kindId)) { throw new AcyclicValidationException( string.Format( "SpecializedQuantityKind {0} {1} cannot have a general quantity kind from outside the RDL chain.", thing.Name, thing.Iid)); } // Get all SpecializedQuantityKinds var parameterTypes = this.SpecializedQuantityKindService .Get(transaction, partition, parameterTypeIdsFromChain, securityContext) .Cast <SpecializedQuantityKind>().ToList(); // Check whether containing folder is acyclic if (!this.IsSpecializedQuantityKindAcyclic(parameterTypes, kindId, thing.Iid)) { throw new AcyclicValidationException( string.Format( "Folder {0} {1} cannot have a containing Folder {2} that leads to cyclic dependency", thing.Name, thing.Iid, kindId)); } } }
public void VerifyBeforeUpdateSideEffectThrowsExceptionForNotExistingParameterType() { var rawUpdateInfo = new ClasslessDTO { { ParameterTypeTestKey, this.notExistingParameterTypeGuid } }; Assert.Throws <ArgumentException>( () => this.sideEffect.BeforeUpdate(this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo)); }
public void VerifyBeforeUpdateSideEffectPasses() { var rawUpdateInfo = new ClasslessDTO() { { ParameterTypeTestKey, this.existingNotQuantityKindParameterTypeGuid } }; this.sideEffect.BeforeUpdate( this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo); rawUpdateInfo = new ClasslessDTO() { { ParameterTypeTestKey, this.existingNotQuantityKindParameterTypeGuid }, { ScaleTestKey, null } }; this.parameter.Scale = this.scaleGuid; this.sideEffect.BeforeUpdate( this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo); rawUpdateInfo = new ClasslessDTO() { { ParameterTypeTestKey, this.existingQuantityKindParameterTypeGuid } }; this.sideEffect.BeforeUpdate( this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo); rawUpdateInfo = new ClasslessDTO() { { ParameterTypeTestKey, this.existingQuantityKindParameterTypeGuid }, { ScaleTestKey, this.scaleGuid } }; this.parameter.Scale = null; this.sideEffect.BeforeUpdate( this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo); this.parameterTypeService.Verify(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", It.IsAny <List <Guid> >(), this.securityContext.Object), Times.Exactly(4)); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="DomainFileStore"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( DomainFileStore thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { this.CheckSecurity(thing, transaction, partition); }
/// <summary> /// Execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="Thing"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw Update Info. /// </param> public override void BeforeUpdate( ParameterSubscription thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { this.CheckOwnership(thing, container); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="T"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( T thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("ReferenceUnit")) { var referenceUnitId = (Guid)rawUpdateInfo["ReferenceUnit"]; // Check for itself if (referenceUnitId == thing.Iid) { throw new AcyclicValidationException( string.Format( "ConversionBasedUnit {0} cannot have itself as a RefernceUnit", thing.Iid)); } // Get RDL chain and collect units' ids var unitIdsFromChain = this.GetUnitIdsFromRdlChain( transaction, partition, securityContext, ((ReferenceDataLibrary)container).RequiredRdl); unitIdsFromChain.AddRange(((ReferenceDataLibrary)container).Unit); // Check that reference unit is present in the chain if (!unitIdsFromChain.Contains(referenceUnitId)) { throw new AcyclicValidationException( string.Format( "ConversionBasedUnit {0} cannot have a RefernceUnit from outside the RDL chain", thing.Iid)); } // Get all ConversionBasedUnits var units = this.ConversionBasedUnitService .Get(transaction, partition, unitIdsFromChain, securityContext).Cast <ConversionBasedUnit>() .ToList(); // Check reference unit that it is acyclic if (!this.IsReferenceUnitAcyclic(units, referenceUnitId, thing.Iid)) { throw new AcyclicValidationException( string.Format( "ConversionBasedUnit {0} cannot have a RefernceUnit {1} that leads to cyclic dependency", thing.Iid, referenceUnitId)); } } }
/// <summary> /// Encapsulate the 'clear-text' password value with a password change token that is only valid for this request. /// </summary> /// <param name="passwordValue"> /// The password Value. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info. /// </param> private void EncapsulatePasswordWithChangeToken(string passwordValue, ClasslessDTO rawUpdateInfo) { // Signal the ORM layer that a password change request is being handled: // encapsulate the 'clear-text' password with the PasswordChangeToken that is valid for this request only var encapsulatedPasswordChangeRequest = string.Format( "{1}{0}{1}", passwordValue, this.PersonDao.PasswordChangeToken); // override the update info and override the rawUpdateInfo value rawUpdateInfo[PasswordKey] = encapsulatedPasswordChangeRequest; }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="T"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( T thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("Component")) { var componentsId = (IEnumerable <OrderedItem>)rawUpdateInfo["Component"]; // Get RDL chain and collect types' ids var parameterTypeIdsFromChain = this.GetParameterTypeIdsFromRdlChain( transaction, partition, securityContext, ((ReferenceDataLibrary)container).RequiredRdl); parameterTypeIdsFromChain.AddRange(((ReferenceDataLibrary)container).ParameterType); // Get all CompoundParameterTypes var parameterTypes = this.CompoundParameterTypeService .Get(transaction, partition, parameterTypeIdsFromChain, securityContext) .Cast <CompoundParameterType>().ToList(); // Add all ArrayParameterTypes parameterTypes.AddRange( this.ArrayParameterTypeService .Get(transaction, partition, parameterTypeIdsFromChain, securityContext) .Cast <ArrayParameterType>().ToList()); // Check every component foreach (var orderedItem in componentsId) { if (!this.IsParameterTypeComponentAcyclic( transaction, partition, securityContext, parameterTypes, Guid.Parse(orderedItem.V.ToString()), thing.Iid)) { throw new AcyclicValidationException( string.Format( "{0} {1} {2} cannot have a ParameterTypeComponent {3} that leads to cyclic dependency", thing.ClassKind.ToString(), thing.Name, thing.Iid, Guid.Parse(orderedItem.V.ToString()))); } } } }
public void VerifyThatExceptionIsThrownWhenRequirementsGroupLeadsToCircularDependency() { this.sideEffect = new RequirementsGroupSideEffect() { RequirementsSpecificationService = this.requirementsSpecificationService.Object }; // Leads to circular dependency this.rawUpdateInfo = new ClasslessDTO() { { TestKey, new List <Guid> { this.requirementsGroupB.Iid, this.requirementsGroupD.Iid, this.requirementsGroupF.Iid } } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.requirementsGroupA, this.requirementsSpecification, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); this.rawUpdateInfo = new ClasslessDTO() { { TestKey, new List <Guid> { this.requirementsGroupB.Iid, this.requirementsGroupD.Iid } } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.requirementsGroupF, this.requirementsSpecification, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatNoPasswordChangeIsIgnored() { this.rawUpdateinfo = new ClasslessDTO() { { TestValue, TestValue } }; this.personSideEffect.BeforeUpdate(null, null, null, null, null, this.rawUpdateinfo); // assert same number of entries in raw update info object Assert.AreEqual(1, this.rawUpdateinfo.Count); Assert.AreEqual(TestValue, this.rawUpdateinfo[TestValue].ToString()); }
public void VerifyBeforeUpdateSideEffectThrowsExceptionForNotExistingParameterType() { var rawUpdateInfo = new ClasslessDTO() { { ParameterTypeTestKey, this.notExistingParameterTypeGuid } }; Assert.Throws <ArgumentException>( () => this.sideEffect.BeforeUpdate(this.parameter, this.elementDefinition, this.npgsqlTransaction, "partition", this.securityContext.Object, rawUpdateInfo)); this.parameterTypeService.Verify(x => x.GetShallow(this.npgsqlTransaction, "SiteDirectory", It.IsAny <List <Guid> >(), this.securityContext.Object), Times.Once); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="Parameter"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( Parameter thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("ParameterType")) { this.ValidateParameterTypeUpdate(thing, transaction, securityContext, rawUpdateInfo); } }
/// <summary> /// Create a <see cref="ClasslessDTO"/> from a <see cref="JObject"/> and a partial <see cref="Dto.Thing"/> /// </summary> /// <param name="jsonObject">The <see cref="JObject"/></param> /// <param name="dto">The <see cref="Dto.Thing"/></param> /// <returns>The generated <see cref="ClasslessDTO"/></returns> private ClasslessDTO GenerateClasslessDto(JObject jsonObject, Dto.Thing dto) { var metainfo = this.metaDataProvider.GetMetaInfo(dto.ClassKind.ToString()); var classlessDto = new ClasslessDTO(); foreach (var property in jsonObject.Properties()) { var propertyName = Utils.CapitalizeFirstLetter(property.Name); classlessDto.Add(propertyName, metainfo.GetValue(propertyName, dto)); } return(classlessDto); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="MeasurementScale"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <paramref name="thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( MeasurementScale thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (!rawUpdateInfo.ContainsKey("MappingToReferenceScale")) { return; } var mappingToReferenceScaleIids = (List <Guid>)rawUpdateInfo["MappingToReferenceScale"]; var referenceDataLibrary = (ReferenceDataLibrary)container; // Check that all referenced MeasurementScales are from the same RDL chain var availableMeasurementScaleIids = this.GetMeasurementScaleIidsFromRdlChain( transaction, partition, securityContext, referenceDataLibrary.RequiredRdl); availableMeasurementScaleIids.AddRange(referenceDataLibrary.Scale); var allMeasurementScales = this.MeasurementScaleService .Get(transaction, partition, null, securityContext) .Cast <MeasurementScale>() .ToList(); var scaleValueDefinitionContainerMeasurementScales = this.GetScaleValueDefinitionContainerMeasurementScales( transaction, partition, securityContext, allMeasurementScales, mappingToReferenceScaleIids); if (scaleValueDefinitionContainerMeasurementScales.Any(x => !availableMeasurementScaleIids.Contains(x.Iid))) { throw new AcyclicValidationException($"MeasurementScale {thing.Name} {thing.Iid} cannot have " + $"a MappingToReferenceScale referencing or depending upon " + $"a ScaleValueDefinition contained by a MeasurementScale " + $"from outside the current RDL chain."); } this.CheckCycleDeep( transaction, partition, securityContext, allMeasurementScales, thing, scaleValueDefinitionContainerMeasurementScales); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="SiteReferenceDataLibrary"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( SiteReferenceDataLibrary thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("RequiredRdl")) { var requiredRdlId = (Guid)rawUpdateInfo["RequiredRdl"]; this.ValidateRequiredRdl(thing, container, transaction, partition, securityContext, requiredRdlId); } }
public void VerifyThatExceptionIsThrownWhenGeneralReferenceIsKindItself() { this.rawUpdateInfo = new ClasslessDTO { { TestKey, this.specializedQuantityKindA.Iid } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.specializedQuantityKindA, this.referenceDataLibraryA, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsThrownWhenContainingFolderIsFolderItselfOnUpdate() { this.rawUpdateInfo = new ClasslessDTO { { TestKey, this.folderA.Iid } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.folderA, this.fileStore, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyCreateWithContainerUpdateInCreateValidation() { var aliasMetaInfo = new AliasMetaInfo(); var modelReferenceDataLibraryMetaInfo = new ModelReferenceDataLibraryMetaInfo(); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.IsAny <SimpleQuantityKind>())).Returns(this.simpleQuantityKindMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.IsAny <Alias>())).Returns(aliasMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.IsAny <string>())).Returns(this.thingMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.IsAny <ModelReferenceDataLibrary>())).Returns(modelReferenceDataLibraryMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.Is <string>(y => y == SimpleQuantityKindTypeString))).Returns(this.simpleQuantityKindMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.Is <string>(y => y == "Alias"))).Returns(aliasMetaInfo); this.mockedMetaInfoProvider.Setup(x => x.GetMetaInfo(It.Is <string>(y => y == "ModelReferenceDataLibrary"))).Returns(modelReferenceDataLibraryMetaInfo); var newAlias = new Alias(Guid.NewGuid(), 0) { Content = "testContent", LanguageCode = "en-GB" }; // alias container create var newSimpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), 0) { Alias = new List <Guid> { newAlias.Iid }, Definition = new List <Guid>(), HyperLink = new List <Guid>(), PossibleScale = new List <Guid>(), Name = TestName, ShortName = TestShortName, Symbol = "testSymbol" }; // simplequantitykind container update var modelReferenceDataLibrary = new ClasslessDTO() { { IidKey, Guid.NewGuid() }, { ClasskindKey, ClassKind.ModelReferenceDataLibrary }, { "ParameterType", new[] { newSimpleQuantityKind.Iid } } }; var postOperation = new CdpPostOperation(); postOperation.Create.Add(newAlias); postOperation.Create.Add(newSimpleQuantityKind); postOperation.Update.Add(modelReferenceDataLibrary); Assert.DoesNotThrow(() => this.operationProcessor.ValidateCreateOperations(postOperation, this.fileStore)); }
public void VerifyThatExceptionIsNotThrownWhenParameterTypeComponentUpdateDoesNotLeadToCircularDependency() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.booleanParameterTypeE.Iid } }; Assert.DoesNotThrow( () => this.sideEffect.BeforeUpdate( this.parameterTypeComponentB, this.compoundParameterTypeB, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsThrownWhenParameterTypeComponentUpdateLeadsToCircularDependency() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.compoundParameterTypeC.Iid } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.parameterTypeComponentB, this.compoundParameterTypeB, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsThrownWhenUnitFactorLeadsToCircularDependency() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.derivedUnitC.Iid } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.unitFactorB, this.derivedUnitB, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsNotThrownWhenUnitFactorDoesNotLeadToCircularDependency() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.simpleUnitE.Iid } }; Assert.DoesNotThrow( () => this.sideEffect.BeforeUpdate( this.unitFactorB, this.derivedUnitB, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
/// <summary> /// Checks whether a valid selected domain is supplied <see cref="Participant"/>. /// </summary> /// <param name="thing"> /// The <see cref="Thing"/> instance that will be inspected. /// </param> /// <param name="rawUpdateInfo"> /// The update info that was serialized directly from the user request. /// The raw <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be edited likely: it can/will change the operation processor outcome. /// </param> private void ValidateSelectedDomain(Participant thing, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey(SelectedDomainKey)) { Guid selectedDomainUpdate = default; if (rawUpdateInfo[SelectedDomainKey] != null) { Guid.TryParse(rawUpdateInfo[SelectedDomainKey].ToString(), out selectedDomainUpdate); } if (!thing.Domain.Contains(selectedDomainUpdate)) { throw new InvalidOperationException("Participant selected domain must be contained in participant domain list."); } } }
public void VerifyThatExceptionIsThrownWhenTermIsTermItself() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.notD.Iid } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.notD, this.constraintA, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsNotThrownWhenTermWithoutCircularDependency() { this.rawUpdateInfo = new ClasslessDTO() { { TestKey, this.relE.Iid } }; Assert.DoesNotThrow( () => this.sideEffect.BeforeUpdate( this.notD, this.constraintA, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
public void VerifyThatExceptionIsNotThrownWhenGeneralReferenceDoesNotLeadToCircularDependency() { // There is a chain a -> b -> c this.rawUpdateInfo = new ClasslessDTO { { TestKey, this.specializedQuantityKindD.Iid } }; Assert.DoesNotThrow( () => this.sideEffect.BeforeUpdate( this.specializedQuantityKindC, this.referenceDataLibraryA, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="ParameterTypeComponent"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( ParameterTypeComponent thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("ParameterType")) { var parameterTypeId = (Guid)rawUpdateInfo["ParameterType"]; // Get RDL chain and collect types' ids var parameterTypeIdsFromChain = this.GetParameterTypeIdsFromRdlChain( transaction, partition, securityContext, container.Iid); // Get all CompoundParameterTypes var parameterTypes = this.CompoundParameterTypeService .Get(transaction, partition, parameterTypeIdsFromChain, securityContext) .Cast <CompoundParameterType>().ToList(); // Add all ArrayParameterTypes parameterTypes.AddRange( this.ArrayParameterTypeService .Get(transaction, partition, parameterTypeIdsFromChain, securityContext) .Cast <ArrayParameterType>().ToList()); if (!this.IsParameterTypeComponentAcyclic( transaction, partition, securityContext, parameterTypes, container.Iid, parameterTypeId)) { throw new AcyclicValidationException( string.Format( "{0} {1} cannot have a ParameterType {2} that leads to cyclic dependency", thing.ClassKind.ToString(), thing.Iid, parameterTypeId)); } } }
public void VerifyThatExceptionIsThrownWhenElementUsageLeadsToCircularDependency() { this.rawUpdateInfo = new ClasslessDTO { { TestKey, new List <Guid> { this.euD.Iid } } }; Assert.Throws <AcyclicValidationException>( () => this.sideEffect.BeforeUpdate( this.edC, this.iteration, this.npgsqlTransaction, "partition", this.securityContext.Object, this.rawUpdateInfo)); }
/// <summary> /// Allows derived classes to override and execute additional logic before an update operation. /// </summary> /// <param name="thing"> /// The <see cref="DerivedUnit"/> instance that will be inspected. /// </param> /// <param name="container"> /// The container instance of the <see cref="Thing"/> that is inspected. /// </param> /// <param name="transaction"> /// The current transaction to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="securityContext"> /// The security Context used for permission checking. /// </param> /// <param name="rawUpdateInfo"> /// The raw update info that was serialized from the user posted request. /// The <see cref="ClasslessDTO"/> instance only contains values for properties that are to be updated. /// It is important to note that this variable is not to be changed likely as it can/will change the operation processor outcome. /// </param> public override void BeforeUpdate( DerivedUnit thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext, ClasslessDTO rawUpdateInfo) { if (rawUpdateInfo.ContainsKey("UnitFactor")) { var unitFactorsId = (List <OrderedItem>)rawUpdateInfo["UnitFactor"]; // Get RDL chain and collect units' ids var unitIdsFromChain = this.GetUnitIdsFromRdlChain( transaction, partition, securityContext, ((ReferenceDataLibrary)container).RequiredRdl); unitIdsFromChain.AddRange(((ReferenceDataLibrary)container).Unit); // Get all Derived units var units = this.DerivedUnitService.Get(transaction, partition, unitIdsFromChain, securityContext) .Cast <DerivedUnit>().ToList(); // Check every unit factor foreach (var orderedItem in unitFactorsId) { if (!this.IsUnitFactorAcyclic( transaction, partition, securityContext, units, Guid.Parse(orderedItem.V.ToString()), thing.Iid)) { throw new AcyclicValidationException( string.Format( "DerivedUnit {0} {1} cannot have a UnitFactor {2} that leads to cyclic dependency", thing.Name, thing.Iid, Guid.Parse(orderedItem.V.ToString()))); } } } }