Example #1
0
        /// <summary>
        /// Normalizes the SDMXV20 data structure.
        /// </summary>
        /// <param name="dataStructure">The data structure.</param>
        public static void NormalizeSdmxv20DataStructure(this IDataStructureMutableObject dataStructure)
        {
            ApplyCodedTimeDimensionNormalization(dataStructure);

            var crossDsd = dataStructure as ICrossSectionalDataStructureMutableObject;

            if (crossDsd != null)
            {
                crossDsd.NormalizeSdmxv20DataStructure();
            }
        }
Example #2
0
        /// <summary>
        /// Applies the coded time dimension normalization.
        /// </summary>
        /// <param name="dataStructure">The data structure.</param>
        private static void ApplyCodedTimeDimensionNormalization(IDataStructureMutableObject dataStructure)
        {
            var timeDimension = dataStructure.GetDimension(DimensionObject.TimeDimensionFixedId);

            if (timeDimension != null)
            {
                var codelist = timeDimension.GetEnumeratedRepresentation();
                if (codelist != null)
                {
                    timeDimension.Representation.Representation = null;
                    if (timeDimension.Representation.TextFormat == null)
                    {
                        timeDimension.Representation = null;
                    }

                    IAnnotationBuilder <IMaintainableRefObject> codedTimeAnnotationBuilder = new CodedTimeDimensionAnnotationBuilder <AnnotationMutableCore>();
                    var annotation = codedTimeAnnotationBuilder.Build(codelist);
                    timeDimension.AddAnnotation(annotation);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Add references to <paramref name="structureReferences"/>
        /// </summary>
        /// <param name="dsd">
        /// The DSD.
        /// </param>
        /// <param name="structureReferences">
        /// The structure references.
        /// </param>
        private static void AddReferences(IDataStructureMutableObject dsd, ISet <IStructureReference> structureReferences)
        {
            if (dsd != null && !dsd.Stub)
            {
                AddReferences(dsd.Dimensions, structureReferences);

                if (dsd.AttributeList != null)
                {
                    AddReferences(dsd.AttributeList.Attributes, structureReferences);
                }

                AddReferences(dsd.PrimaryMeasure, structureReferences);

                var crossDsd = dsd as ICrossSectionalDataStructureMutableObject;
                if (crossDsd != null)
                {
                    AddReferences(crossDsd.CrossSectionalMeasures, structureReferences);
                    structureReferences.UnionWith(crossDsd.MeasureDimensionCodelistMapping.Values);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Gets the component.
        /// </summary>
        /// <param name="dsd">The DSD.</param>
        /// <param name="id">The component unique identifier.</param>
        /// <returns>The matched <see cref="IComponentMutableObject"/>; otherwise <c>null</c></returns>
        public static IComponentMutableObject GetComponent(this IDataStructureMutableObject dsd, string id)
        {
            switch (id)
            {
            case DimensionObject.TimeDimensionFixedId:
                return(dsd.Dimensions.FirstOrDefault(o => o.TimeDimension));

            case PrimaryMeasure.FixedId:
                return(dsd.PrimaryMeasure);
            }

            Func <IComponentMutableObject, bool> func = o => id.Equals(o.Id) || id.Equals(o.ConceptRef.ChildReference.Id);
            var dimension = dsd.Dimensions.FirstOrDefault(func);

            if (dimension != null)
            {
                return(dimension);
            }

            if (dsd.AttributeList != null)
            {
                var attribute = dsd.AttributeList.Attributes.FirstOrDefault(func);
                if (attribute != null)
                {
                    return(attribute);
                }
            }

            var crossDsd = dsd as ICrossSectionalDataStructureMutableObject;

            if (crossDsd != null)
            {
                return(crossDsd.CrossSectionalMeasures.FirstOrDefault(func));
            }

            return(null);
        }
 private void PopulateAttachedGroup(IDataStructureMutableObject dsd)
 {
     if (dsd.Groups != null && dsd.Groups.Count > 0)
     {
         cmbAttachedGroupID.Items.Clear();
         cmbAttachedGroupID.Items.Add("");
         foreach (IGroupMutableObject group in dsd.Groups)
         {
             cmbAttachedGroupID.Items.Add(group.Id);
         }
     }
 }
 /// <summary>
 /// 
 /// </summary>
 private void GetDsdFromSession()
 {
     if (Session[_snInsDSD] != null)
         _dsdMutable = (IDataStructureMutableObject)Session[_snInsDSD];
 }
        private void CreateEmptyDSD()
        {
            IDataStructureMutableObject dsdMutable;

            dsdMutable = _sdmxUtils.buildDataStructure(_ntdString + "DSD_ID", _ntdString + "AGENCY", _ntdDSDVersion);
            dsdMutable.AddName("en", _ntdString + "DSD_NAME");

            //AnnotationGeneralControl.ClearAnnotationsSession();

            #region NormalDimension

            IDimensionMutableObject dim = new DimensionMutableCore();
            dim.Id = _ntdNRName;

            IStructureReference conceptRef = new StructureReferenceImpl(_ntdNRName,
                                        _ntdNRName, "1.0",
                                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept),
                                        new string[] { _ntdNRName });

            dim.ConceptRef = conceptRef;

            dsdMutable.AddDimension(dim);

            #endregion

            #region TimeDimension

            IDimensionMutableObject dim2 = new DimensionMutableCore();
            dim2.Id = _ntdTDName;
            dim2.TimeDimension = true;

            IStructureReference conceptRef2 = new StructureReferenceImpl(_ntdTDName,
                                        _ntdTDName, "1.0",
                                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept),
                                        new string[] { _ntdTDName });

            dim2.ConceptRef = conceptRef2;

            dsdMutable.AddDimension(dim2);

            #endregion

            dsdMutable.AddPrimaryMeasure(new StructureReferenceImpl(_ntdPMName, _ntdPMName, "1.0", SdmxStructureEnumType.Concept, _ntdPMName));

            _dsdMutable = dsdMutable;

            SetDsdToSession();
        }
        private void BindData()
        {
            IDataStructureObject ds = _sdmxObjects.DataStructures.FirstOrDefault();

            if (ds == null)
                return;

            if (_action == Action.VIEW)
            {
                _dsdMutable = ds.MutableInstance;
                SetDsdToSession();
            }

            SetGeneralTab(ds);
            SetPMTab(ds);
            SetDimensionTab(ds);
            SetGroupTab(ds);
            SetAttributeTab(ds);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Org.Sdmxsource.Sdmx.Api.Exception.SdmxException.SetMessageResolver(new Org.Sdmxsource.Util.ResourceBundle.MessageDecoder());

            _dsdMutable = null;

            _sdmxUtils = new SDMXUtils();
            _localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);
            _entityMapper = new EntityMapper(Utils.LocalizedLanguage);
            _artIdentity = Utils.GetIdentityFromRequest(Request);

            SetAction();

            CommonInitUserControl();

            if (!IsPostBack)
            {
                CommonInit();
            }

            switch (_action)
            {
                case Action.INSERT:
                    SetInsertForm();
                    break;
                case Action.UPDATE:
                    SetEditForm();
                    break;
                case Action.VIEW:
                    SetViewForm();
                    Utils.ResetBeforeUnload();
                    break;
            }

            DuplicateArtefact1.ucStructureType = SdmxStructureEnumType.Dsd;
            DuplicateArtefact1.ucMaintanableArtefact = _dsdMutable;

            lblDSDDescription.DataBind();
            lblDSDName.DataBind();
            lblDSDID.DataBind();
            lblAgency.DataBind();
            lblVersion.DataBind();
            lblIsFinal.DataBind();
            lblDSDURI.DataBind();
            lblValidTo.DataBind();
            lblValidFrom.DataBind();
            lblDSDURN.DataBind();
            lblDSDURI.DataBind();
            lblPMID.DataBind();
            lblCodelist.DataBind();
            lblConcept.DataBind();
            lblTitle.DataBind();
            lblDimType.DataBind();
            lblDimID.DataBind();
            lblDimConceptReference.DataBind();
            lblDimConcept.DataBind();
            lblCodeConceptScheme.DataBind();
            lblCodeCodelist.DataBind();
            lblCodeCodeRappresentation.DataBind();
            btnAddDimension.DataBind();
            btnSaveDSD.DataBind();
            lblAddGroupTitle.DataBind();
            lblGroupID.DataBind();
            lblGroupDimension.DataBind();
            btnAddGroup.DataBind();
            lbl_annotation.DataBind();
            lblAnnotaionPM.DataBind();
        }
        private IDataStructureMutableObject RestylingDSD(IDataStructureMutableObject workingDSD, List<string> lCubeColumns, SDMXIdentifier sdmxDFKey)
        {
            // Mi ciclo tutte le dimensioni e gli attributi della DSD di origine, se non sono presenti nella lista componentList li elimino

            List<IDimensionMutableObject> dimsToDelete = new List<IDimensionMutableObject>();
            List<IAttributeMutableObject> attsToDelete = new List<IAttributeMutableObject>();

            List<string> lCubeColumnsName = new List<string>();

            foreach (string col in lCubeColumns)
            {
                lCubeColumnsName.Add(RemoveFirstUnderscore(col));
            }

            foreach (IDimensionMutableObject dim in workingDSD.Dimensions)
            {
                if (!lCubeColumnsName.Contains(dim.Id.ToUpper()))
                {
                    dimsToDelete.Add(dim);
                }
                else
                    _dimensionList.Add(dim.Id);

            }

            if (workingDSD.Attributes != null)
                foreach (IAttributeMutableObject att in workingDSD.Attributes)
                {
                    if (!lCubeColumnsName.Contains(att.Id.ToUpper()))
                    {
                        attsToDelete.Add(att);
                    }
                    else if (att.AttachmentLevel == Org.Sdmxsource.Sdmx.Api.Constants.AttributeAttachmentLevel.Group)
                    {
                        IGroupMutableObject grp = workingDSD.Groups.Where(g => g.Id == att.AttachmentGroup).FirstOrDefault();

                        List<string> lDim = new List<string>();

                        if (grp != null)
                            foreach (string dimName in grp.DimensionRef)
                                if (lCubeColumnsName.Contains(dimName.ToUpper()))
                                    lDim.Add(dimName.ToUpper());

                        //if (grp == null || lDim.Count == 0)
                        //{
                        //    attsToDelete.Add(att);
                        //    continue;
                        //}

                        if (grp == null || lDim.Count == 0)
                        {
                            //se 1 modifico l'attachmentLevel a Dataset
                            att.AttachmentLevel = Org.Sdmxsource.Sdmx.Api.Constants.AttributeAttachmentLevel.DataSet;
                            //continue;
                        }

                        if (lDim.Count >= 1)
                        {
                            foreach (string dimName in lDim)
                                att.DimensionReferences.Add(dimName);

                            att.AttachmentLevel = AttributeAttachmentLevel.DimensionGroup;
                        }

                        att.AttachmentGroup = null;
                        _attributeList.Add(att.Id);
                    }
                    else if (att.AttachmentLevel == Org.Sdmxsource.Sdmx.Api.Constants.AttributeAttachmentLevel.DimensionGroup)
                    {

                        List<string> lDelDim = new List<string>();

                        foreach (string dimName in att.DimensionReferences)
                            if (!lCubeColumnsName.Contains(dimName.ToUpper()))
                                lDelDim.Add(dimName.ToUpper());

                        foreach (string delDimName in lDelDim)
                            att.DimensionReferences.Remove(delDimName);

                        if (att.DimensionReferences.Count == 0)
                        {
                            attsToDelete.Add(att);
                            continue;
                        }
                        //else if (att.DimensionReferences.Count == 1)
                        //{
                        //    att.AttachmentLevel = Org.Sdmxsource.Sdmx.Api.Constants.AttributeAttachmentLevel.DataSet;
                        //    continue;
                        //}
                        _attributeList.Add(att.Id);
                    }
                    else
                        _attributeList.Add(att.Id);
                }

            foreach (IDimensionMutableObject dd in dimsToDelete)
            {
                workingDSD.Dimensions.Remove(dd);
            }

            foreach (IAttributeMutableObject ad in attsToDelete)
            {
                workingDSD.Attributes.Remove(ad);
            }

            workingDSD.Id = sdmxDFKey.id;
            workingDSD.AgencyId = sdmxDFKey.agencyid;
            workingDSD.Version = sdmxDFKey.version;

            if (workingDSD.Groups != null)
                workingDSD.Groups.Clear();

            return workingDSD;
        }
        private IDataStructureMutableObject ReOrderDimension(IDataStructureMutableObject dsMut, IDimensionMutableObject dimMut, int inputOrder)
        {
            var sortedDimension = dsMut.DimensionList.Dimensions.OrderBy(
            o =>
            {
                var corder = o.Annotations.FirstOrDefault(mutableObject => string.Equals(mutableObject.Type, "@ORDER@"));
                return corder != null ? int.Parse(corder.Text[0].Value) : 0;
            }).ToArray();

            dsMut.Dimensions.Clear();

            int orderID = 1;

            IAnnotationMutableObject annOrder;

            foreach (IDimensionMutableObject dim in sortedDimension)
            {
                if (orderID == inputOrder)
                {
                    annOrder = dimMut.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault();

                    if (annOrder != null)
                        dimMut.Annotations.Remove(annOrder);

                    dimMut.Annotations.Add(CreateAnnotation("order" + orderID.ToString(),
                                                        "",
                                                        "@ORDER@",
                                                        "", new List<ITextTypeWrapperMutableObject>(){
                                                            new TextTypeWrapperMutableCore("en",orderID.ToString()) }
                                                         )
                                        );
                    dsMut.AddDimension(dimMut);

                    ++orderID;
                }

                annOrder = dim.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault();

                if (annOrder != null)
                    dim.Annotations.Remove(annOrder);

                dim.Annotations.Add(CreateAnnotation("order" + orderID.ToString(),
                                                    "",
                                                    "@ORDER@",
                                                    "", new List<ITextTypeWrapperMutableObject>(){
                                                            new TextTypeWrapperMutableCore("en",orderID.ToString()) }
                                                     )
                                    );
                dsMut.AddDimension(dim);

                ++orderID;
            }

            if (orderID <= inputOrder)
            {
                annOrder = dimMut.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault();

                if (annOrder != null)
                    dimMut.Annotations.Remove(annOrder);

                dimMut.Annotations.Add(CreateAnnotation("order" + orderID.ToString(),
                                                    "",
                                                    "@ORDER@",
                                                    "", new List<ITextTypeWrapperMutableObject>(){
                                                            new TextTypeWrapperMutableCore("en",orderID.ToString()) }
                                                     )
                                    );
                dsMut.AddDimension(dimMut);
            }

            return dsMut;
        }
Example #12
0
        /// <summary>
        /// Gets the enumerated representation.
        /// </summary>
        /// <param name="dimension">The dimension.</param>
        /// <param name="dsd">The DSD.</param>
        /// <returns>The representation <see cref="IStructureReference"/> of the <paramref name="dimension"/>; otherwise null.</returns>
        public static IStructureReference GetEnumeratedRepresentation(this IDimensionMutableObject dimension, IDataStructureMutableObject dsd)
        {
            if (dimension.MeasureDimension)
            {
                var crossDsd = dsd as ICrossSectionalDataStructureMutableObject;
                if (crossDsd != null)
                {
                    IStructureReference reference = crossDsd.MeasureDimensionCodelistMapping[dimension.Id];
                    return(reference);
                }
            }

            return(dimension.GetEnumeratedRepresentation());
        }
 private static void AddUnCodedAttribute(IDataStructureMutableObject dsdMutableObject, string conceptId)
 {
     var attributeMutableObject =
         dsdMutableObject.AddAttribute(new StructureReferenceImpl(agencyId: dsdMutableObject.AgencyId, maintainableId: "TEST_CS", version: "1.0", targetStructureEnum: SdmxStructureEnumType.Concept, identfiableIds: conceptId), null);
     attributeMutableObject.AttachmentLevel = AttributeAttachmentLevel.Group;
     attributeMutableObject.AttachmentGroup = "Sibling";
     attributeMutableObject.AssignmentStatus = "Conditional";
 }
        /// <summary>
        /// Requests the partial codelist.
        /// </summary>
        /// <param name="dataflow">The dataflow.</param>
        /// <param name="firstDsd">The first DSD.</param>
        /// <param name="mutableSearchManager">The mutable search manager.</param>
        /// <returns>The criteria used.</returns>
        private static IEnumerable<IKeyValuesMutable> RequestPartialCodelist(IDataflowMutableObject dataflow, IDataStructureMutableObject firstDsd, IMutableStructureSearchManager mutableSearchManager)
        {
            var currentDataflowReference = _fromMutableBuilder.Build(dataflow);

            var previousMembers = new List<IKeyValuesMutable>();
            foreach (var dimension in firstDsd.Dimensions)
            {
                var representation = dimension.GetEnumeratedRepresentation(firstDsd);
                if (representation != null)
                {
                    IStructureReference codelistRef = new StructureReferenceImpl(representation.MaintainableReference, SdmxStructureEnumType.CodeList);

                    var id = dimension.Id;
                    var agencyId = firstDsd.AgencyId;
                    var version = firstDsd.Version;
                    var name = dimension.ConceptRef.ChildReference.Id;
                    var specialRequest = BuildConstrainableStructureReference(id, agencyId, version, name, previousMembers, currentDataflowReference);
                    var queries = new[] { specialRequest, codelistRef };
                    var objects = mutableSearchManager.RetrieveStructures(queries, false, false);
                    var message = string.Format("DataflowRef : {0}, CodelistRef : {1}", specialRequest, codelistRef);
                    Assert.IsNotNull(objects, message);
                    Assert.IsNotEmpty(objects.Codelists, message);
                    Assert.AreEqual(1, objects.Codelists.Count, message);

                    var codeIds = objects.Codelists.First().Items.TakeWhile(o => _random.Next() % 2 == 0).Select(o => o.Id).ToArray();

                    if (codeIds.Length > 0)
                    {
                        var criteria = new KeyValuesMutableImpl { Id = id };
                        criteria.KeyValues.AddAll(codeIds);
                        previousMembers.Add(criteria);
                    }
                }
                else if (dimension.TimeDimension)
                {
                    var id = dimension.Id;
                    var agencyId = firstDsd.AgencyId;
                    var version = firstDsd.Version;
                    var name = dimension.ConceptRef.ChildReference.Id;
                    IStructureReference specialRequest = BuildConstrainableStructureReference(id, agencyId, version, name, previousMembers, currentDataflowReference);
                    IStructureReference timeCodelistReference = new StructureReferenceImpl(
                        CustomCodelistConstants.Agency, 
                        CustomCodelistConstants.TimePeriodCodeList, 
                        CustomCodelistConstants.Version, 
                        SdmxStructureEnumType.CodeList);
                    var queries = new[] { specialRequest, timeCodelistReference };
                    var objects = mutableSearchManager.RetrieveStructures(queries, false, false);
                    var message = string.Format("DataflowRef : {0}, CodelistRef : {1}", specialRequest, timeCodelistReference);
                    Assert.IsNotNull(objects);
                    Assert.IsNotEmpty(objects.Codelists, message);
                    Assert.AreEqual(1, objects.Codelists.Count, message);
                    var timeCodelist = objects.Codelists.First();
                    Assert.GreaterOrEqual(timeCodelist.Items.Count, 1, message);
                    Assert.LessOrEqual(timeCodelist.Items.Count, 2, message);
                    foreach (var item in timeCodelist.Items)
                    {
                        DateTime date;
                        Assert.IsTrue(DateTime.TryParseExact(item.Id, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date), "Invalid date : '{0}' for {1}", item.Id, specialRequest);
                    }
                    
                    if (timeCodelist.Items.Count > 0)
                    {
                        var criteria = new KeyValuesMutableImpl { Id = id };
                        criteria.KeyValues.AddAll(timeCodelist.Items.Select(o => o.Id));
                        previousMembers.Add(criteria);
                    }
                }
            }

            return previousMembers;
        }
 /// <summary>
 /// Requests the concept scheme.
 /// </summary>
 /// <param name="firstDsd">The first DSD.</param>
 /// <param name="conceptFunc">The concept function.</param>
 private static void RequestConceptScheme(IDataStructureMutableObject firstDsd, Func<IDataStructureMutableObject, IMutableObjects> conceptFunc)
 {
     var conceptSchemeContainer = conceptFunc(firstDsd);
     Assert.IsNotNull(conceptSchemeContainer);
     Assert.IsNotEmpty(conceptSchemeContainer.ConceptSchemes);
 }
        protected void btnAddDimension_Click(object sender, EventArgs e)
        {
            if (!ValidateDimensionData())
            {
                OpenAddDimensionPopUp();
                return;
            }

            IDimensionMutableObject dim = new DimensionMutableCore();
            dim.Id = txtDimID.Text;

            switch (cmbDimType.SelectedValue)
            {
                case "FREQUENCY":
                    dim.FrequencyDimension = true;
                    break;
                case "MEASURE":
                    dim.MeasureDimension = true;
                    break;
                case "TIME":
                    dim.TimeDimension = true;
                    break;
            }

            #region "***** Concept Reference ******"

            ArtefactIdentity csIdentity = new ArtefactIdentity();
            string[] conceptData = txtDimConcept.Text.Split(',');

            if (conceptData.Length > 0)
            {
                csIdentity.ID = conceptData[0];
                csIdentity.Agency = conceptData[1];
                csIdentity.Version = conceptData[2].Substring(0, conceptData[2].IndexOf(' '));

                string conceptID = conceptData[2].Substring(conceptData[2].LastIndexOf(' ') + 1);

                IStructureReference conceptRef = new StructureReferenceImpl(csIdentity.Agency,
                                                                            csIdentity.ID,
                                                                            csIdentity.Version,
                                                                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept),
                                                                            new string[] { conceptID });

                dim.ConceptRef = conceptRef;
            }
            #endregion

            switch (cmbDimType.SelectedValue)
            {
                case "NORMAL":
                case "FREQUENCY":

                    // Remove NTD Dimension
                    if (_dsdMutable.Dimensions != null)
                        foreach (IDimensionMutableObject dimF in _dsdMutable.Dimensions)
                        {
                            if (dimF.ConceptRef.MaintainableId == _ntdNRName)
                            {
                                _dsdMutable.Dimensions.Remove(dimF);
                                break;
                            }
                        }

                    #region "***** Codelist Reference ******"

                    if (txtDimCodelist.Text != string.Empty)
                    {
                        ArtefactIdentity clIdentity = new ArtefactIdentity();
                        string[] clData = txtDimCodelist.Text.Split(',');

                        clIdentity.ID = clData[0];
                        clIdentity.Agency = clData[1];
                        clIdentity.Version = clData[2];

                        IStructureReference codelistRef = new StructureReferenceImpl(clIdentity.Agency,
                                                                                        clIdentity.ID,
                                                                                        clIdentity.Version,
                                                                                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList),
                                                                                        null);

                        IRepresentationMutableObject representationRef = new RepresentationMutableCore();
                        representationRef.Representation = codelistRef;

                        dim.Representation = representationRef;

                    }

                    #endregion

                    break;
                case "MEASURE":

                    #region "***** ConceptScheme Reference ******"

                    if (txtDimConceptScheme.Text != string.Empty)
                    {
                        ArtefactIdentity cSchemeIdentity = new ArtefactIdentity();
                        string[] clData = txtDimConceptScheme.Text.Split(',');

                        cSchemeIdentity.ID = clData[0];
                        cSchemeIdentity.Agency = clData[1];
                        cSchemeIdentity.Version = clData[2];

                        IStructureReference cSchemeRef = new StructureReferenceImpl(cSchemeIdentity.Agency,
                                                                                    cSchemeIdentity.ID,
                                                                                    cSchemeIdentity.Version,
                                                                                    SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme),
                                                                                    null);

                        IRepresentationMutableObject representationRef = new RepresentationMutableCore();
                        representationRef.Representation = cSchemeRef;

                        dim.Representation = representationRef;

                    }

                    #endregion

                    break;
                case "TIME":

                    // Remove NTD Time Dimensione
                    //foreach (IDimensionMutableObject dimF in _dsdMutable.Dimensions)
                    //{
                    //    if (dimF.ConceptRef.MaintainableId == _ntdTDName)
                    //    {
                    //        _dsdMutable.Dimensions.Remove(dimF);
                    //        break;
                    //    }
                    //}

                    break;
            }

            try
            {
                if (hdnEditDimension.Value == "true")
                {
                    foreach (IDimensionMutableObject dimDel in _dsdMutable.Dimensions)
                    {
                        if (dimDel.Id == txtDimID.Text)
                        {
                            _dsdMutable.Dimensions.Remove(dimDel);
                            break;
                        }
                    }
                }

                int orderID = 0;

                if (Int32.TryParse(txtDimOrder.Text, out orderID))
                {
                    _dsdMutable = ReOrderDimension(_dsdMutable, dim, orderID);
                }
                else
                    _dsdMutable.AddDimension(dim);

                SetDsdToSession();
                SetDimensionTab(_dsdMutable.ImmutableInstance);
                PopulateLBDimensionList(_dsdMutable, lbAttachmentDimension);
                PopulateLBDimensionList(_dsdMutable, lbGroupDimension);

                txtDimID.Text = "";
                txtDimConcept.Text = "";
                txtDimCodelist.Text = "";
                txtDimConceptScheme.Text = "";
                cmbDimType.SelectedIndex = 0;
                txtDimID.Enabled = true;

                Utils.ForceBlackClosing();
            }
            catch (Exception ex)
            {
                _dsdMutable.Dimensions.Remove(dim);
                OpenAddDimensionPopUp();
                Utils.ShowDialog(ex.Message, 600, Resources.Messages.err_add_dimension);
            }
        }
 private void PopulateLBDimensionList(IDataStructureMutableObject dsd, ListBox lb)
 {
     if (dsd.Dimensions != null && dsd.Dimensions.Count > 0)
     {
         lb.Items.Clear();
         foreach (IDimensionMutableObject dim in dsd.Dimensions)
         {
             if (!dim.ConceptRef.FullId.Contains(_ntdString))
                 lb.Items.Add(dim.Id);
         }
     }
 }
 /// <summary>
 /// Returns true if the specified <paramref name="artefact"/> has components.
 /// </summary>
 /// <param name="artefact">
 /// The DSD
 /// </param>
 /// <returns>
 /// The true if the specified <paramref name="artefact"/> has components; otherwise false.
 /// </returns>
 private static bool HasComponents(IDataStructureMutableObject artefact)
 {
     return (artefact.Dimensions.Count > 0)
            || (artefact.AttributeList != null && artefact.AttributeList.Attributes.Count > 0)
            || artefact.MeasureList != null || artefact.Groups.Count > 0;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CrossSectionalDsdHelper"/> class.
 /// </summary>
 /// <param name="dsd">
 /// The DSD.
 /// </param>
 public CrossSectionalDsdHelper(IDataStructureMutableObject dsd)
 {
     this._crossSectional = dsd as ICrossSectionalDataStructureMutableObject;
     if (this._crossSectional != null)
     {
         this._crossDataSet = new HashSet<string>(
             this._crossSectional.CrossSectionalAttachDataSet, StringComparer.Ordinal);
         this._crossGroup = new HashSet<string>(
             this._crossSectional.CrossSectionalAttachGroup, StringComparer.Ordinal);
         this._crossSection = new HashSet<string>(
             this._crossSectional.CrossSectionalAttachSection, StringComparer.Ordinal);
         this._crossObs = new HashSet<string>(
             this._crossSectional.CrossSectionalAttachObservation, StringComparer.Ordinal);
         this._attributeMap = this._crossSectional.AttributeToMeasureMap;
     }
 }
        protected void btnAddAttribute_Click(object sender, EventArgs e)
        {
            if (!ValidateAttributeData())
            {
                OpenAddAttributePopUp();
                return;
            }

            /*
             * Creo l'attribute
             * ID
             * Concept
             * Eventuale Codelist
             * Assignment status
             * Attachmentlevel
             *      DimensionGroup
             *          Attachment Dimension
             *      Group
             *          Attached Group ID
             * */

            IAttributeMutableObject attr = new AttributeMutableCore();
            attr.Id = txtAttributeID.Text;

            #region "***** Concept Reference ******"

            ArtefactIdentity csIdentity = new ArtefactIdentity();
            string[] conceptData = txtAttributeConcept.Text.Split(',');

            if (conceptData.Length > 0)
            {
                csIdentity.ID = conceptData[0];
                csIdentity.Agency = conceptData[1];
                csIdentity.Version = conceptData[2].Substring(0, conceptData[2].IndexOf(' '));

                string conceptID = conceptData[2].Substring(conceptData[2].LastIndexOf(' ') + 1);

                IStructureReference conceptRef = new StructureReferenceImpl(csIdentity.Agency,
                                                                            csIdentity.ID,
                                                                            csIdentity.Version,
                                                                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept),
                                                                            new string[] { conceptID });

                attr.ConceptRef = conceptRef;
            }

            #endregion

            #region "***** Codelist Reference ******"

            if (txtAttributeCodelist.Text != string.Empty)
            {
                ArtefactIdentity clIdentity = new ArtefactIdentity();
                string[] clData = txtAttributeCodelist.Text.Split(',');

                clIdentity.ID = clData[0];
                clIdentity.Agency = clData[1];
                clIdentity.Version = clData[2];

                IStructureReference codelistRef = new StructureReferenceImpl(clIdentity.Agency,
                                                                                clIdentity.ID,
                                                                                clIdentity.Version,
                                                                                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList),
                                                                                null);

                IRepresentationMutableObject representationRef = new RepresentationMutableCore();
                representationRef.Representation = codelistRef;

                attr.Representation = representationRef;
            }

            #endregion

            attr.AssignmentStatus = cmbAssignmentStatus.SelectedValue;
            attr.AttachmentLevel = (AttributeAttachmentLevel)Enum.Parse(typeof(AttributeAttachmentLevel), cmbAttachLevel.SelectedValue);

            switch (attr.AttachmentLevel)
            {
                case AttributeAttachmentLevel.DataSet:
                    break;
                case AttributeAttachmentLevel.DimensionGroup:
                    // Aggiungo le dimensioni selezionate nella list box
                    IList<string> lDim = new List<string>();

                    foreach (ListItem li in lbAttachmentDimension.Items)
                    {
                        if (li.Selected)
                            attr.DimensionReferences.Add(li.Value);
                    }

                    break;
                case AttributeAttachmentLevel.Group:
                    // Aggiungo il gruppo selezionato nella combo
                    attr.AttachmentGroup = cmbAttachedGroupID.SelectedValue;
                    break;
                case AttributeAttachmentLevel.Null:
                    break;
                case AttributeAttachmentLevel.Observation:
                    break;
                default:
                    break;
            }

            try
            {
                if (hdnEditAttribute.Value == "true")
                {
                    foreach (IAttributeMutableObject attrDel in _dsdMutable.Attributes)
                    {
                        if (attrDel.Id == txtAttributeID.Text)
                        {
                            _dsdMutable.Attributes.Remove(attrDel);
                            break;
                        }
                    }
                }

                int orderID = 0;

                if (Int32.TryParse(txtAttOrder.Text, out orderID))
                {
                    _dsdMutable = ReOrderAttribute(_dsdMutable, attr, orderID);
                }
                else
                    _dsdMutable.Attributes.Add(attr);

                SetDsdToSession();
                SetAttributeTab(_dsdMutable.ImmutableInstance);

                txtAttributeID.Text = "";
                txtAttributeConcept.Text = "";
                txtAttributeCodelist.Text = "";
                cmbAssignmentStatus.SelectedIndex = 0;
                cmbAttachLevel.SelectedIndex = 0;

                lbAttachmentDimension.ClearSelection();
                if (cmbAttachedGroupID.Items.Count > 0)
                    cmbAttachedGroupID.SelectedIndex = 0;
                pnlAttachedGroupID.Visible = false;
                pnlAttachmentDimension.Visible = false;

                Utils.ForceBlackClosing();
            }
            catch (Exception ex)
            {
                _dsdMutable.Attributes.Remove(attr);
                OpenAddAttributePopUp();
                Utils.ShowDialog(ex.Message, 600, Resources.Messages.err_add_attribute);
            }
        }