コード例 #1
0
        /// <summary>
        /// Increments the versions of sdmx objects
        /// </summary>
        /// <param name="sdmxObjects">
        /// The sdmx objects.
        /// </param>
        public void IncrementVersions(ISdmxObjects sdmxObjects)
        {
            _log.Info("Update Versions of Structures if existing structures found");
            //Store a map of old versions vs the new version
            IDictionary<IStructureReference, IStructureReference> oldVsNew =
                new Dictionary<IStructureReference, IStructureReference>();
            IDictionary<IMaintainableObject, IMaintainableObject> oldMaintVsNew =
                new Dictionary<IMaintainableObject, IMaintainableObject>();
            ISet<IMaintainableObject> updatedMaintainables = new HashSet<IMaintainableObject>();
            ISet<IMaintainableObject> oldMaintainables = new HashSet<IMaintainableObject>();

            foreach (IMaintainableObject currentMaint in sdmxObjects.GetAllMaintainables())
            {
                _log.Debug("Auto Version - check latest version for maintainable: " + currentMaint);

                IMaintainableObject persistedMaintainable = this._structureVersionRetrievalManager.GetLatest(currentMaint);
                if (persistedMaintainable == null)
                {
                    persistedMaintainable = this._beanRetrievalManager.GetMaintainableObject(currentMaint.AsReference);
                }
                if (persistedMaintainable != null)
                {
                    if (VersionableUtil.IsHigherVersion(persistedMaintainable.Version, currentMaint.Version))
                    {
                        //Modify version of maintainable to be the same as persisted maintainable
                        IMaintainableMutableObject mutableInstance = currentMaint.MutableInstance;
                        mutableInstance.Version = persistedMaintainable.Version;

                        //Remove the Maintainable from the submission - as we've changed the versions
                        sdmxObjects.RemoveMaintainable(currentMaint);

                        //currentMaint = mutableInstance.ImmutableInstance;
                    }
                    if (persistedMaintainable.Version.Equals(currentMaint.Version))
                    {
                        _log.Debug("Latest version is '" + persistedMaintainable.Version + "' perform update checks");
                        if (!currentMaint.DeepEquals(persistedMaintainable, true))
                        {
                            ISet<IIdentifiableObject> allIdentifiables1 = currentMaint.IdentifiableComposites;
                            ISet<IIdentifiableObject> allIdentifiables2 = persistedMaintainable.IdentifiableComposites;

                            bool containsAll = allIdentifiables1.ContainsAll(allIdentifiables2)
                                               && allIdentifiables2.ContainsAll(allIdentifiables1);
                            if (_log.IsInfoEnabled)
                            {
                                string increment = containsAll ? "Minor" : "Major";
                                _log.Info("Perform " + increment + " Version Increment for structure:" + currentMaint.Urn);
                            }

                            //Increment the version number
                            IMaintainableObject newVersion = this.IncrmentVersion(
                                currentMaint, persistedMaintainable.Version, !containsAll);

                            //Remove the Maintainable from the submission
                            sdmxObjects.RemoveMaintainable(currentMaint);

                            //Store the newly updated maintainable in a container for further processing
                            updatedMaintainables.Add(newVersion);
                            oldMaintainables.Add(currentMaint);
                            //Store the old version number mappings to the new version number
                            oldMaintVsNew.Add(currentMaint, newVersion);
                            oldVsNew.Add(currentMaint.AsReference, newVersion.AsReference);

                            string oldVersionNumber = currentMaint.Version;
                            AddOldVsNewReferences(oldVersionNumber, newVersion, oldVsNew);
                        }
                    }
                }
            }

            //Create a set of parent sdmxObjects to not update (regardless of version)
            ISet<IMaintainableObject> filterSet = new HashSet<IMaintainableObject>(updatedMaintainables);
            filterSet.AddAll(sdmxObjects.GetAllMaintainables());

            //Get all the referencing structures to reversion them
            IEnumerable<IMaintainableObject> referencingStructures = this.RecurseUpTree(oldMaintainables, new HashSet<IMaintainableObject>(), filterSet);

            foreach (IMaintainableObject currentReferencingStructure in referencingStructures)
            {
                _log.Info("Perform Minor Version Increment on referencing structure:" + currentReferencingStructure);
                String newVersionNumber;
                if (oldMaintVsNew.ContainsKey(currentReferencingStructure))
                {
                    //The old maintainable is also in the submission and has had it's version number incremented, use this version
                    var tmp = oldMaintVsNew[currentReferencingStructure];
                    //currentReferencingStructure = oldMaintVsNew[currentReferencingStructure];
                    updatedMaintainables.Remove(tmp);
                    newVersionNumber = currentReferencingStructure.Version;
                }
                else
                {
                    newVersionNumber = VersionableUtil.IncrementVersion(currentReferencingStructure.Version, false);
                }
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, newVersionNumber);
                AddOldVsNewReferences(currentReferencingStructure.Version, updatedMaintainable, oldVsNew);

                updatedMaintainables.Add(updatedMaintainable);
            }

            foreach (IMaintainableObject currentReferencingStructure in updatedMaintainables)
            {
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, currentReferencingStructure.Version);
                sdmxObjects.AddIdentifiable(updatedMaintainable);
            }

            //Update the references of any structures that existed in the submission
            foreach (IMaintainableObject currentReferencingStructure in sdmxObjects.GetAllMaintainables())
            {
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, currentReferencingStructure.Version);
                sdmxObjects.AddIdentifiable(updatedMaintainable);
            }
        }