public async Task InitializeResourceInAdditionalsGraph(Resource ResourceToBeCreated, IList <MetadataProperty> allMetaData)
        {
            string revisionGraphPrefix = ResourceToBeCreated.Id + "Rev" + 1;
            string additionalGraphName = revisionGraphPrefix + "_added";

            _resourceRepository.CreateProperty(new Uri(ResourceToBeCreated.Id), new Uri(COLID.Graph.Metadata.Constants.Resource.HasRevision), revisionGraphPrefix, GetResourceInstanceGraph());
            _resourceRepository.Create(ResourceToBeCreated, allMetaData, new Uri(additionalGraphName));
        }
Ejemplo n.º 2
0
        private bool AllowedToUnlink(Resource resource, out string message)
        {
            message = string.Empty;

            string previousVersionBaseUri  = resource.PreviousVersion?.BaseUri;
            string laterVersionBaseUri     = resource.LaterVersion?.BaseUri;
            string resourceToUnlinkBaseUri = resource.BaseUri?.ToString();

            if (!string.IsNullOrWhiteSpace(resourceToUnlinkBaseUri) &&
                (resourceToUnlinkBaseUri == previousVersionBaseUri || resourceToUnlinkBaseUri == laterVersionBaseUri))
            {
                message = Common.Constants.Messages.Resource.Linking.UnlinkFailedSameBaseUri;
                return(false);
            }

            return(true);
        }
        public async Task <Resource> AddAdditionalsAndRemovals(Entity Published, Entity DraftToBePublished)
        {
            if (Published.Properties[COLID.Graph.Metadata.Constants.EnterpriseCore.PidUri][0].Id != DraftToBePublished.Properties[COLID.Graph.Metadata.Constants.EnterpriseCore.PidUri][0].Id)
            {
                throw new BusinessException("The resources to be compared do not have the same PidUri");
            }

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

            ignoredProperties.Add(COLID.Graph.Metadata.Constants.Resource.HasEntryLifecycleStatus);
            ignoredProperties.Add(COLID.Graph.Metadata.Constants.Resource.HasRevision);
            ignoredProperties.Add(COLID.Graph.Metadata.Constants.EnterpriseCore.PidUri);
            ignoredProperties.Add(COLID.Graph.Metadata.Constants.Resource.HasSourceID);

            if (DraftToBePublished.Properties.ContainsKey(COLID.Graph.Metadata.Constants.Resource.BaseUri) == Published.Properties.ContainsKey(COLID.Graph.Metadata.Constants.Resource.BaseUri))
            {
                ignoredProperties.Add(COLID.Graph.Metadata.Constants.Resource.BaseUri);
            }
            ignoredProperties.AddRange(COLID.Graph.Metadata.Constants.Resource.LinkTypes.AllLinkTypes);

            var existingRevisions = Published.Properties.TryGetValue(COLID.Graph.Metadata.Constants.Resource.HasRevision, out List <dynamic> revisionValues) ? revisionValues : new List <dynamic>();


            //IList <MetadataProperty> allMetaData = _metadataService.GetMetadataForEntityType(Published.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true));

            List <MetadataProperty> allMetaData     = _metadataService.GetMetadataForEntityTypeInConfig(Published.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true), Published.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.Resource.MetadataGraphConfiguration, true));
            List <string>           allMetaDataKeys = allMetaData.Select(x => x.Key).ToList();


            List <MetadataProperty> allMetaData2 = _metadataService.GetMetadataForEntityTypeInConfig(DraftToBePublished.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true), DraftToBePublished.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.Resource.MetadataGraphConfiguration, true));

            allMetaData.AddRange(allMetaData2.Where(x => !allMetaDataKeys.Contains(x.Key)).Select(y => y));


            Dictionary <string, List <dynamic> > additionals = new Dictionary <string, List <dynamic> >();
            Dictionary <string, List <dynamic> > removals    = new Dictionary <string, List <dynamic> >();

            foreach (var metadata in allMetaData)
            {
                if (ignoredProperties.Contains(metadata.Key))
                {
                    continue;
                }

                if (Published.Properties.TryGetValue(metadata.Key, out List <dynamic> firstValue) && DraftToBePublished.Properties.TryGetValue(metadata.Key, out List <dynamic> secondValue))
                {
                    if (ResourceValueChanged(firstValue, secondValue))
                    {
                        additionals.Add(metadata.Key, secondValue);
                        removals.Add(metadata.Key, firstValue);
                    }
                }
                else if (Published.Properties.TryGetValue(metadata.Key, out List <dynamic> OnlyfirstValue) && !DraftToBePublished.Properties.TryGetValue(metadata.Key, out List <dynamic> NotsecondValue))
                {
                    removals.Add(metadata.Key, OnlyfirstValue);
                }
                else if (!Published.Properties.TryGetValue(metadata.Key, out List <dynamic> NotfirstValue) && DraftToBePublished.Properties.TryGetValue(metadata.Key, out List <dynamic> OnlysecondValue))
                {
                    additionals.Add(metadata.Key, OnlysecondValue);
                }
                else
                {
                    continue;
                }
            }

            Resource resource = UpdateResourceProperties(additionals, removals, _mapper.Map <Resource>(Published));

            //if(additionals.Count==1 && removals.Count==1 && additionals.ContainsKey(COLID.Graph.Metadata.Constants.Resource.DateModified))

            string pattern = @"[^Rev]+$";
            Regex  rg      = new Regex(pattern);
            var    revList = existingRevisions.Select(x => Int32.Parse(rg.Match(x).Value)).ToList();
            var    max     = revList.Max();

            string revisionGraphPrefix = Published.Id + "Rev" + (max + 1);

            _resourceRepository.CreateProperty(new Uri(Published.Id), new Uri(COLID.Graph.Metadata.Constants.Resource.HasRevision), revisionGraphPrefix, GetResourceInstanceGraph());

            (additionals, removals) = GetFinalAdditionalsAndRemovals(additionals, removals);
            _resourceRepository.CreateAdditionalsAndRemovalsGraphs(additionals, removals, allMetaData, Published.Id, revisionGraphPrefix);  //letzte revisionwert rausnehmen, counter erhöhen und damit dann die graphen erstellen


            return(resource);
        }
        private Resource UpdateResourceProperties(Dictionary <string, List <dynamic> > additionals, Dictionary <string, List <dynamic> > removals, Resource published)
        {
            var newAddedValues = additionals.Where(x => !removals.ContainsKey(x.Key)).ToList();
            var removedValues  = removals.Where(x => !additionals.ContainsKey(x.Key)).ToList();
            var changedValues  = additionals.Where(x => removals.ContainsKey(x.Key)).ToList();

            if (newAddedValues.Count != 0)
            {
                foreach (var entry in newAddedValues)
                {
                    published.Properties.Add(entry.Key, entry.Value);
                }
            }
            if (removedValues.Count != 0)
            {
                foreach (var entry in removedValues)
                {
                    published.Properties.Remove(entry.Key);
                }
            }
            if (changedValues.Count != 0)
            {
                foreach (var entry in changedValues)
                {
                    published.Properties.Remove(entry.Key);
                    published.Properties.Add(entry.Key, entry.Value);
                }
            }

            return(published);
        }
Ejemplo n.º 5
0
        private IList <VersionOverviewCTO> GetPredecessorVersionList(Resource resource)
        {
            var currentVersion = Convert.ToInt32(resource.Versions.Single(x => x.PidUri == resource.PidUri.ToString())?.Version);

            return(resource.Versions.Where(x => Convert.ToInt32(x.Version) < currentVersion).ToList()); //take only predecessors
        }