public void TestCrossReference(string urn)
 {
     ICodelistObject immutableInstance = CreateSampleCodelist();
     var cross = new CrossReferenceImpl(immutableInstance, urn);
     Assert.IsTrue(immutableInstance.DeepEquals(cross.ReferencedFrom, true));
 }
        public void TestStructureReferenceIsMatch(string urn, bool expectedResult)
        {
            var df = new DataflowMutableCore { AgencyId = "TFFS.ABC", Id = "EXTERNAL_DEBT", Version = "1.0" };
            df.AddName("en", "Test");
            df.DataStructureRef = new StructureReferenceImpl("TEST_AG","TST", "1.0", SdmxStructureEnumType.Dsd);
            var impl = new StructureReferenceImpl(urn);
            IDataflowObject immutableInstance = df.ImmutableInstance;
            Assert.AreEqual(expectedResult, impl.IsMatch(immutableInstance));
            if (expectedResult)
            {
                Assert.IsTrue(immutableInstance.DeepEquals(impl.GetMatch(immutableInstance), true));
            }
            else
            {
                Assert.IsNull(impl.GetMatch(immutableInstance));
            }

            var cross = new CrossReferenceImpl(immutableInstance, impl);
            Assert.IsTrue(cross.ReferencedFrom.DeepEquals(immutableInstance, true));
            Assert.AreEqual(cross.CreateMutableInstance().TargetUrn, impl.TargetUrn);
        }
 public void TestCrossReference2(string agency, string id, string version)
 {
     ICodelistObject immutableInstance = CreateSampleCodelist();
     foreach (SdmxStructureType sdmxStructureType in SdmxStructureType.Values)
     {
         if (sdmxStructureType.IsMaintainable)
         {
             string maintainableId = GetID(sdmxStructureType, id);
             var cross = new CrossReferenceImpl(immutableInstance, agency, maintainableId, version, sdmxStructureType);
             Assert.AreEqual(agency, cross.AgencyId);
             Assert.AreEqual(maintainableId, cross.MaintainableId);
             string versionToTest = string.IsNullOrWhiteSpace(version) ? "1.0" : version;
             Assert.AreEqual(versionToTest, cross.Version);
         }
         else if (sdmxStructureType.IsIdentifiable && !sdmxStructureType.HasFixedId)
         {
             var cross = new CrossReferenceImpl(
                 immutableInstance, agency, id, version, sdmxStructureType.EnumType, "ENA", "DYO", "TRIA");
             Assert.AreEqual(agency, cross.AgencyId);
             Assert.AreEqual(id, cross.MaintainableId);
             string versionToTest = string.IsNullOrWhiteSpace(version) ? "1.0" : version;
             Assert.AreEqual(versionToTest, cross.Version);
             CollectionAssert.IsNotEmpty(cross.IdentifiableIds);
         }
     }
 }
 /// <summary>
 /// Adds code references.
 /// </summary>
 /// <param name="constraintBean">
 /// The constraint object.
 /// </param>
 /// <param name="returnReferences">
 /// The returned references.
 /// </param>
 /// <param name="codelistRef">
 /// The code list reference object.
 /// </param>
 /// <param name="codeIds">
 /// The code ids.
 /// </param>
 private void AddCodeReferences(IContentConstraintObject constraintBean, ISet<ICrossReference> returnReferences, ICrossReference codelistRef, ICollection<string> codeIds)
 {
     string agencyId = codelistRef.AgencyId;
     string codelistId = codelistRef.MaintainableId;
     string version = codelistRef.Version;
     foreach (string codeId in codeIds)
     {
         ICrossReference codeRef = new CrossReferenceImpl(constraintBean, agencyId, codelistId, version, SdmxStructureEnumType.Code, codeId);
         returnReferences.Add(codeRef);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CrossSectionalDataStructureObjectCore"/> class.
        /// </summary>
        /// <param name="keyFamilyType">
        /// The itemMutableObject.
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CrossSectionalDataStructureObjectCore(KeyFamilyType keyFamilyType)
            : base(keyFamilyType)
        {
            this._crossSectionalMeasures = new List<ICrossSectionalMeasure>();
            this._crossSectionalAttachDataSet = new List<IComponent>();
            this._crossSectionalAttachGroup = new List<IComponent>();
            this._crossSectionalAttachSection = new List<IComponent>();
            this._crossSectionalAttachObservation = new List<IComponent>();
            this._attributeToMeasuresMap = new Dictionary<string, IList<ICrossSectionalMeasure>>();
            this._measureDimensions = new List<string>();
            this._codelistMap = new Dictionary<string, ICrossReference>();

            //// TODO java 0.9.9 bug. XS DSD may not have any XS Measures
            //// Reverted changes that were made during sync
            //// Please do not change unless you are sure.
            if (keyFamilyType.Components == null || !CrossSectionalUtil.IsCrossSectional(keyFamilyType))
            {
                throw new SdmxSemmanticException("Can not create ICrossSectionalDataStructureObject as there are no CrossSectional Measures defined");
            }

            foreach (CrossSectionalMeasureType xsMeasureType in keyFamilyType.Components.CrossSectionalMeasure)
            {
                this._crossSectionalMeasures.Add(new CrossSectionalMeasureCore(xsMeasureType, this));
            }

            foreach (DimensionType currentComponent in keyFamilyType.Components.Dimension)
            {
                string componentId = currentComponent.conceptRef;
                if (currentComponent.isMeasureDimension)
                {
                    this._measureDimensions.Add(componentId);
                    string codelistAgency = currentComponent.codelistAgency;
                    if (string.IsNullOrWhiteSpace(codelistAgency))
                    {
                        codelistAgency = this.BaseAgencyId;
                    }

                    ICrossReference codelistRef = new CrossReferenceImpl(
                        this, codelistAgency, currentComponent.codelist, currentComponent.codelistVersion, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList));
                    this._codelistMap.Add(componentId, codelistRef);
                }

                if (currentComponent.crossSectionalAttachDataSet != null && currentComponent.crossSectionalAttachDataSet.Value)
                {
                    this.AddComponentToList(componentId, this._crossSectionalAttachDataSet);
                }

                if (currentComponent.crossSectionalAttachGroup != null && currentComponent.crossSectionalAttachGroup.Value)
                {
                    this.AddComponentToList(componentId, this._crossSectionalAttachGroup);
                }

                if (currentComponent.crossSectionalAttachObservation != null && currentComponent.crossSectionalAttachObservation.Value)
                {
                    this.AddComponentToList(componentId, this._crossSectionalAttachObservation);
                }

                if (currentComponent.crossSectionalAttachSection != null && currentComponent.crossSectionalAttachSection.Value)
                {
                    this.AddComponentToList(componentId, this._crossSectionalAttachSection);
                }
            }

            foreach (AttributeType currentComponent0 in keyFamilyType.Components.Attribute)
            {
                string componentId1 = currentComponent0.conceptRef;

                if (currentComponent0.crossSectionalAttachDataSet != null && currentComponent0.crossSectionalAttachDataSet.Value)
                {
                    this.AddComponentToList(componentId1, this._crossSectionalAttachDataSet);
                }

                if (currentComponent0.crossSectionalAttachGroup != null && currentComponent0.crossSectionalAttachGroup.Value)
                {
                    this.AddComponentToList(componentId1, this._crossSectionalAttachGroup);
                }

                if (currentComponent0.crossSectionalAttachObservation != null && currentComponent0.crossSectionalAttachObservation.Value)
                {
                    this.AddComponentToList(componentId1, this._crossSectionalAttachObservation);
                }

                if (currentComponent0.crossSectionalAttachSection != null && currentComponent0.crossSectionalAttachSection.Value)
                {
                    this.AddComponentToList(componentId1, this._crossSectionalAttachSection);
                }

                this.SetAttributeMeasures(componentId1, currentComponent0.AttachmentMeasure);
            }

            if (keyFamilyType.Components.TimeDimension != null)
            {
                TimeDimensionType timeDimensionType = keyFamilyType.Components.TimeDimension;
                if (timeDimensionType.crossSectionalAttachDataSet != null && timeDimensionType.crossSectionalAttachDataSet.Value)
                {
                    this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachDataSet);
                }

                if (timeDimensionType.crossSectionalAttachGroup != null && timeDimensionType.crossSectionalAttachGroup.Value)
                {
                    this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachGroup);
                }

                if (timeDimensionType.crossSectionalAttachObservation != null && timeDimensionType.crossSectionalAttachObservation.Value)
                {
                    this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachObservation);
                }

                if (timeDimensionType.crossSectionalAttachSection != null && timeDimensionType.crossSectionalAttachSection.Value)
                {
                    this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachSection);
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException ex)
            {
                throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }
            catch (Exception th)
            {
                throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }
        }
        public void TestResolveCrossReference(string file)
        {

            ICrossReferenceResolverEngine crossReferenceResolverEngine = new CrossReferenceResolverEngineCore();
            ISdmxObjects structureBeans;
            using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                IStructureWorkspace structureWorkspace = this.parsingManager.ParseStructures(fileReadableDataLocation);
                Assert.NotNull(structureWorkspace);
                structureBeans = structureWorkspace.GetStructureObjects(false);
            }

            var retrievalManager = new InMemoryRetrievalManager(structureBeans);
            ICodelistObject immutableInstance = CreateSampleCodelist();
            var cross = new CrossReferenceImpl(immutableInstance, "urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=TFFS:CRED_EXT_DEBT(1.0)");

            int i = 0;

            foreach (IMaintainableObject maintainableObject in this.maintainableObjectSet)
            {
                beanRetrivalManager.Setup(m => m.GetMaintainableObject(It.IsAny<IStructureReference>(), false, false)).Returns(maintainableObject);
                beanRetrivalManager.Setup(m => m.GetIdentifiableObject(It.IsAny<ICrossReference>())).Returns(maintainableObject);
                IIdentifiableObject ret = crossReferenceResolverEngine.ResolveCrossReference(cross, beanRetrivalManager.Object);
                Assert.IsNotNull(ret);
                Assert.AreEqual(maintainableObject.Urn, ret.Urn);
                i++;
            } 
        }