Ejemplo n.º 1
0
        public JObject GetSettings([FromUri] ApiClientInfo info)
        {
            var settings = Settings.GetSettings().DeepClone() as JObject;
            var archiveplan = JsonHelper.FindTokenValue<JToken>(settings, "archiveplan");
            var entryNodes = archiveplan != null ? JsonHelper.FindTokenValue<JArray>(archiveplan, "entryNodes") : null;
            
            JsonHelper.AddOrSet(settings, "managementClientSettings", JObject.FromObject(managementClientSettings));

            var selectedLanguage = WebHelper.GetClientLanguage(Request);
            JsonHelper.AddOrSet(settings, "frontendDynamicTextSettings", JObject.FromObject(GetTranslatedFrontendDynamicTextSettings(selectedLanguage)));

            if (entryNodes != null)
            {
                try
                {
                    var access = GetUserAccess(selectedLanguage);

                    var ids = new List<int>();
                    foreach (var node in entryNodes.Children())
                    {
                        ids.Add(JsonHelper.FindTokenValue<int>(node, "archiveRecordId"));
                    }

                    var result = entityProvider.GetEntities<TreeRecord>(ids, access);
                    JsonHelper.Replace(entryNodes, JArray.FromObject(result.Items.Select(i => i.Data).ToArray()));
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "failed to decorate entry nodes");
                }
            }

            return settings;
        }
Ejemplo n.º 2
0
        public JObject GetSettings([FromUri] ApiClientInfo info)
        {
            var settings = Settings.GetSettings().DeepClone() as JObject;

            JsonHelper.AddOrSet(settings, "publicClientUrl", WebHelper.PublicClientUrl);

            return(settings);
        }
        public JObject GetAsDecoratedContext(Entity <T> entity, UserAccess access, EntityMetaOptions options = null)
        {
            var hasContext = false;

            var context = new JObject();

            entity.MetaData = GetMetadata(entity.Data, access);
            options         = options ?? EntityMetaOptions.DefaultOptions;
            var depth = options.SetDepth;

            // ancestors
            if (options.FetchAncestors)
            {
                var ancestors = GetAncestors(entity, access, out depth);
                if (ancestors.Count > 0)
                {
                    hasContext = true;
                    context.Add(ancestorsKey, JArray.FromObject(ancestors));
                    depth += 1;
                }
            }

            // own depth
            entity.Depth = depth;
            depth       += 1;

            // children
            if (options.FetchChildren)
            {
                var result = GetChildren(entity.Data, depth, access, options?.ChildrenPaging);
                if (result.Items.Count > 0)
                {
                    hasContext = true;
                    JsonHelper.AddOrSet(context, childrenKey, JArray.FromObject(result.Items), true);
                    if (result.Paging != null)
                    {
                        JsonHelper.AddOrSet(context, childrenPagingKey, JObject.FromObject(result.Paging), true);
                    }
                }
            }

            return(hasContext ? context : null);
        }
        private void InitModelData()
        {
            modelData = new JObject();

            // inject data
            var accessRoles = Reflective.GetConstants <string>(typeof(AccessRoles));
            var fieldTypes  = Reflective.GetConstants <string>(typeof(ElasticFieldTypes));

            JsonHelper.AddOrSet(modelData, "accessRoles", JObject.FromObject(accessRoles));
            JsonHelper.AddOrSet(modelData, "fieldTypes", JObject.FromObject(fieldTypes));

            // types
            var types = JsonHelper.GetTokenValue <JObject>(modelData, TypesKey, true);

            if (types != null)
            {
                foreach (JProperty property in types.Children())
                {
                    var t = ModelType.CreateFrom(property);
                    typesByNameCamelCased[t.Name.ToLowerCamelCase()] = t;
                }
            }

            // templates
            foreach (var template in TemplateDefinitions.Templates)
            {
                var t = ModelType.CreateFrom(template);
                typesByNameCamelCased[t.Name.ToLowerCamelCase()] = t;
            }

            // setup Super
            foreach (var type in typesByNameCamelCased.Values)
            {
                var superName = (type.SuperName ?? string.Empty).ToLowerCamelCase();
                if (!string.IsNullOrEmpty(superName) && typesByNameCamelCased.ContainsKey(superName))
                {
                    type.Super = typesByNameCamelCased[superName];
                }
            }
        }
        private JObject GetMetadata(TreeRecord entity, UserAccess access)
        {
            if (entity?.Level == null)
            {
                return(null);
            }

            var type = modelData.GetEntityType(entity);

            if (type == null)
            {
                Log.Information($"No type found for entiy level {entity?.Level} and external template {entity.ExternalDisplayTemplateName}");
                return(null);
            }

            var language = access.Language ?? WebHelper.DefaultLanguage;

            JObject metadata     = null;
            var     jsonEntity   = JObject.FromObject(entity);
            var     customFields = JsonHelper.GetTokenValue <JObject>(jsonEntity, customFieldKey, true) ?? new JObject();

            var categories = type.MetaCategories ?? new List <ModelTypeMetaCategory>();

            foreach (var category in categories)
            {
                var attributes = new JObject();

                // Nur wenn die Sektion (category) Felder hat und wir mindestens ein öffentliches Feld haben, oder der Benutzer ein BAR Benutzer ist, gehen wir überhaupt weiter.
                // (Fall abfangen, dass eine Kategorie nur interne Felder hat
                if (category?.Fields != null && (category.Fields.Any(f => f.Visibility == (int)DataElementVisibility.@public) ||
                                                 access.RolePublicClient == AccessRoles.RoleBAR))
                {
                    foreach (var field in category.Fields)
                    {
                        // Interne Felder sind nur für BAR Benutzer sichtbar
                        if (field.Visibility == (int)DataElementVisibility.@internal && access.RolePublicClient != AccessRoles.RoleBAR)
                        {
                            continue;
                        }

                        JToken token = null;
                        var    name  = field.Name.ToLowerCamelCase();
                        if (name.StartsWith(customFieldPrefix, StringComparison.OrdinalIgnoreCase))
                        {
                            var subKey  = field.Key.Substring(customFieldPrefix.Length);
                            var subName = name.Substring(customFieldPrefix.Length);
                            name  = subName.ToLowerCamelCase();
                            token = customFields.GetTokenByKey(subName, true) ?? customFields.GetTokenByKey(subKey, true);
                        }
                        else
                        {
                            token = jsonEntity.GetTokenByKey(name, true) ?? jsonEntity.GetTokenByKey(field.Key, true);
                        }

                        if (token != null)
                        {
                            var value = field.AsFieldValue(token, language);
                            if (value != null)
                            {
                                attributes.Add(name, value);
                            }
                        }
                    }
                }

                if (attributes.Children().Any())
                {
                    metadata = metadata ?? new JObject();

                    if (category.Labels != null && category.Labels.Any())
                    {
                        var title = category.Labels.ContainsKey(language) ? category.Labels[language] : category.Labels.Values.First();
                        JsonHelper.AddOrSet(attributes, "_title", title);
                    }

                    metadata.Add(category.Identifier.ToLowerCamelCase(), attributes);
                }
            }

            return(metadata);
        }