/// <summary>
        /// Inserts related fields to results.
        /// </summary>
        /// <param name="listOfNodes">The k a list.</param>
        /// <param name="relatedField">Related Fields</param>
        private void InsertRelatedFields(Dictionary <string, XElement> listOfNodes, RelatedField relatedField)
        {
            foreach (var relationship in relatedField.ListOfFields)
            {
                if (relationship.Value.Split(',').Length <= 1)
                {
                    continue;
                }

                var relatedEntitiesIds = relationship.Value.Split(',');
                var node = listOfNodes[relationship.Key];

                var field = node.Descendants(relatedField.FieldName).FirstOrDefault();
                if (field != null)
                {
                    field.Remove();
                }

                foreach (var id in relatedEntitiesIds)
                {
                    node.Add(new XElement(relatedField.FieldName, id));
                }
                listOfNodes[relationship.Key] = node;
            }
        }
Ejemplo n.º 2
0
        public void it_returns_full_build_field_2()
        {
            var                            tempBuildConfig                = m_client.BuildConfigs.All().First();
            ItemsField                     itemsField                     = ItemsField.WithFields(item: true);
            BuildsField                    buildsField                    = BuildsField.WithFields();
            RelatedField                   relatedField                   = RelatedField.WithFields(builds: buildsField);
            RelatedIssuesField             relatedIssuesField             = RelatedIssuesField.WithFields(href: true);
            ArtifactDependenciesField      artifactDependenciesField      = ArtifactDependenciesField.WithFields();
            BuildArtifactDependenciesField buildArtifactDependenciesField = BuildArtifactDependenciesField.WithFields();
            BuildSnapshotDependenciesField buildSnapshotDependenciesField = BuildSnapshotDependenciesField.WithFields();
            DatasField                     datasField                     = DatasField.WithFields();
            StatisticsField                statisticsField                = StatisticsField.WithFields();
            EntriesField                   entriesField                   = EntriesField.WithFields();
            PropertiesField                propertiesField                = PropertiesField.WithFields();
            ArtifactsField                 artifactsField                 = ArtifactsField.WithFields(href: true);
            ProblemOccurrencesField        problemOccurrences             = ProblemOccurrencesField.WithFields();
            TestOccurrencesField           testOccurrencesField           = TestOccurrencesField.WithFields();
            AgentField                     agentField                     = AgentField.WithFields(id: true);
            CompatibleAgentsField          compatibleAgentsField          = CompatibleAgentsField.WithFields(agent: agentField, href: true);
            BuildField                     buildField1                    = BuildField.WithFields(id: true);
            BuildChangeField               buildChangeField               = BuildChangeField.WithFields(nextBuild: buildField1, prevBuild: buildField1);
            BuildChangesField              buildChangesField              = BuildChangesField.WithFields(buildChange: buildChangeField);
            RevisionField                  revisionField                  = RevisionField.WithFields(version: true);
            RevisionsField                 revisionsField                 = RevisionsField.WithFields();
            LastChangesField               lastChangesField               = LastChangesField.WithFields();
            ChangesField                   changesField                   = ChangesField.WithFields();
            TriggeredField                 triggeredField                 = TriggeredField.WithFields(type: true);
            ProgressInfoField              progressInfoField              = ProgressInfoField.WithFields(currentStageText: true);
            TagsField                      tagsField             = TagsField.WithFields();
            UserField                      userField             = UserField.WithFields(id: true);
            CommentField                   commentField          = CommentField.WithFields(text: true);
            BuildTypeField                 buildTypeField        = BuildTypeField.WithFields(id: true);
            BuildTypeWrapperField          buildTypeWrapperField = BuildTypeWrapperField.WithFields(buildType: buildTypeField);
            LinkField                      linkField             = LinkField.WithFields(type: true);
            LinksField                     linksField            = LinksField.WithFields(link: linkField);
            var                            buildField            = BuildField.WithFields(links: linksField, buildType: buildTypeField, comment: commentField,
                                                                                         tags: tagsField, pinInfo: commentField, user: userField, running_info: progressInfoField,
                                                                                         canceledInfo: commentField, triggered: triggeredField, lastChanges: lastChangesField, changes: changesField,
                                                                                         revisions: revisionsField, versionedSettingsRevision: revisionField,
                                                                                         artifactDependencyChanges: buildChangesField, agent: agentField, compatibleAgents: compatibleAgentsField,
                                                                                         testOccurrences: testOccurrencesField, problemOccurrences: problemOccurrences, artifacts: artifactsField,
                                                                                         properties: propertiesField, resultingProperties: propertiesField, attributes: entriesField,
                                                                                         statistics: statisticsField, metadata: datasField, snapshotDependencies: buildSnapshotDependenciesField,
                                                                                         artifactDependencies: buildArtifactDependenciesField, customArtifactDependencies: artifactDependenciesField,
                                                                                         statusChangeComment: commentField, relatedIssues: relatedIssuesField, replacementIds: itemsField,
                                                                                         related: relatedField);

            var tempBuild = m_client.Builds.LastBuildByBuildConfigId(tempBuildConfig.Id);
            var build     = m_client.Builds.GetFields(buildField.ToString()).ById(tempBuild.Id);

            Assert.IsNotNull(build);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <RelatedField> > > Edit([FromBody] RelatedField request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsStyleRelatedField))
            {
                return(Unauthorized());
            }

            await _relatedFieldRepository.UpdateAsync(request);

            await _authManager.AddSiteLogAsync(request.SiteId, "编辑联动字段");

            return(await _relatedFieldRepository.GetRelatedFieldsAsync(request.SiteId));
        }
Ejemplo n.º 4
0
        public async Task ExportRelatedFieldAsync(RelatedField relatedField)
        {
            var filePath = _directoryPath + PathUtils.SeparatorChar + relatedField.Id + ".xml";

            var feed = ExportRelatedFieldInfo(relatedField);

            var relatedFieldItemInfoList = await _databaseManager.RelatedFieldItemRepository.GetRelatedFieldItemsAsync(_site.Id, relatedField.Id, 0);

            foreach (var relatedFieldItemInfo in relatedFieldItemInfoList)
            {
                await AddAtomEntryAsync(_databaseManager, feed, _site.Id, relatedFieldItemInfo, 1);
            }
            feed.Save(filePath);
        }
Ejemplo n.º 5
0
        private static AtomFeed ExportRelatedFieldInfo(RelatedField relatedField)
        {
            var feed = AtomUtility.GetEmptyFeed();

            AtomUtility.AddDcElement(feed.AdditionalElements, new List <string> {
                nameof(RelatedField.Id), "RelatedFieldID"
            }, relatedField.Id.ToString());
            AtomUtility.AddDcElement(feed.AdditionalElements, new List <string> {
                nameof(RelatedField.Title), "RelatedFieldName"
            }, relatedField.Title);
            AtomUtility.AddDcElement(feed.AdditionalElements, new List <string> {
                nameof(RelatedField.SiteId), "PublishmentSystemID"
            }, relatedField.SiteId.ToString());

            return(feed);
        }
        /// <summary>
        /// Gets related fields
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="relatedField">The related fields.</param>
        /// <param name="entityId">Entity Id.</param>
        private void GetRelatedFields(XElement node, RelatedField relatedField, string entityId)
        {
            var relation = node.Descendants(relatedField.FieldName).FirstOrDefault();

            if (relation == null)
            {
                return;
            }

            var relationId = relation.Value;

            if (relatedField.ListOfFields.ContainsKey(entityId))
            {
                if (!relatedField.ListOfFields[entityId].Contains(relationId))
                {
                    relatedField.ListOfFields[entityId] += ',' + relationId;
                }
            }
            else
            {
                relatedField.ListOfFields.Add(entityId, relationId);
            }
        }
Ejemplo n.º 7
0
        public async Task ImportRelatedFieldAsync(bool overwrite)
        {
            if (!DirectoryUtils.IsDirectoryExists(_directoryPath))
            {
                return;
            }
            var filePaths = DirectoryUtils.GetFilePaths(_directoryPath);

            foreach (var filePath in filePaths)
            {
                var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(filePath));

                var title = AtomUtility.GetDcElementContent(feed.AdditionalElements, new List <string> {
                    nameof(RelatedField.Title), "RelatedFieldName"
                });

                var relatedFieldInfo = new RelatedField
                {
                    Id     = 0,
                    Title  = title,
                    SiteId = _site.Id
                };

                var srcRelatedFieldInfo = await _databaseManager.RelatedFieldRepository.GetRelatedFieldAsync(_site.Id, title);

                if (srcRelatedFieldInfo != null)
                {
                    if (overwrite)
                    {
                        await _databaseManager.RelatedFieldRepository.DeleteAsync(srcRelatedFieldInfo.Id);
                    }
                    else
                    {
                        relatedFieldInfo.Title = await _databaseManager.RelatedFieldRepository.GetImportTitleAsync(_site.Id, relatedFieldInfo.Title);
                    }
                }

                var relatedFieldId = await _databaseManager.RelatedFieldRepository.InsertAsync(relatedFieldInfo);

                var lastInertedLevel     = 1;
                var lastInsertedParentId = 0;
                var lastInsertedId       = 0;
                foreach (AtomEntry entry in feed.Entries)
                {
                    var itemName  = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(RelatedFieldItem.Label));
                    var itemValue = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(RelatedFieldItem.Value));
                    var level     = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Level"));
                    var parentId  = 0;
                    if (level > 1)
                    {
                        parentId = level != lastInertedLevel ? lastInsertedId : lastInsertedParentId;
                    }

                    var relatedFieldItemInfo = new RelatedFieldItem
                    {
                        Id             = 0,
                        RelatedFieldId = relatedFieldId,
                        Label          = itemName,
                        Value          = itemValue,
                        ParentId       = parentId,
                        Taxis          = 0
                    };
                    lastInsertedId = await _databaseManager.RelatedFieldItemRepository.InsertAsync(relatedFieldItemInfo);

                    lastInsertedParentId = parentId;
                    lastInertedLevel     = level;
                }
            }
        }
Ejemplo n.º 8
0
 public async Task <bool> UpdateAsync(RelatedField relatedField)
 {
     return(await _repository.UpdateAsync(relatedField));
 }
Ejemplo n.º 9
0
 public async Task <int> InsertAsync(RelatedField relatedField)
 {
     return(await _repository.InsertAsync(relatedField));
 }