Exemplo n.º 1
0
        public JsonResult GetPageItems(string q,
                                       string entityTypeFilter,
                                       int sortAttributeMappingId,
                                       bool sortAsc,
                                       int page,
                                       int itemPerPage,
                                       [Bind(Include = "mapIds[]")] int[] mapIds,
                                       bool includeImage = false, string lang = null)
        {
            int total;

            SecurityService.CreateAccessContext();
            var items = ItemService.GetPagedItems(q, entityTypeFilter, sortAttributeMappingId, sortAsc, page, itemPerPage, out total);

            List <string> mappings = new List <string>(mapIds.Length);

            foreach (int id in mapIds)
            {
                CFEntityTypeAttributeMapping am = EntityTypeService.GetEntityTypeAttributeMappingById(id);
                mappings.Add(am.Name);
            }

            IEnumerable <Tuple <int, List <string> > > result = ConvertPagedItems(items, mappings, mapIds, includeImage, lang);


            return(Json(new { total = total, result = result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        protected string SortField(int sortAttributeMappingId)
        {
            string sortField = null;
            CFEntityTypeAttributeMapping attrMap = Db.EntityTypeAttributeMappings.Where(m => m.Id == sortAttributeMappingId).FirstOrDefault();

            if (attrMap != null)
            {
                string    resultType = "en_ss";
                FormField field      = attrMap.Field;

                if (typeof(NumberField).IsAssignableFrom(field.GetType()))
                {
                    resultType = "is";
                    sortField  = string.Format("field(value_{0}_{1}_{2}, min)", attrMap.MetadataSet.Guid.Replace('-', '_'), field.Guid.Replace('-', '_'), resultType);
                }
                else
                {
                    sortField = string.Format("value_{0}_{1}_{2}", attrMap.MetadataSet.Guid.Replace('-', '_'), field.Guid.Replace('-', '_'), resultType);
                }

                //return Db.Items.FromSolr(query, out total, entityTypeFilter, start, itemsPerPage,
                //    sortField, sortAsc);
            }
            return(sortField);
        }
        public override object GetContent(object model)
        {
            foreach (var field in Fields)
            {
                CFEntityTypeAttributeMapping map = entityTypeService.GetEntityTypeAttributeMappingById(field.Id);
                Mappings.Add(map);
            }

            return(base.GetContent(model));
        }
Exemplo n.º 4
0
        public override object GetContent(object model)
        {
            if (Fields.Count > 0)
            {
                //For testing -- go to the page that use this region and add ?entity=[entityId]
                HttpContext context = HttpContext.Current;
                SolrService solrSrv = new SolrService();


                //grab the columnHeaders
                foreach (var field in Fields)
                {
                    // field = CheckDisplayOption(field);
                    CFEntityTypeAttributeMapping map = entityTypeService.GetEntityTypeAttributeMappingById(field.Id);

                    if (!typeof(Catfish.Core.Models.Forms.OptionsField).IsAssignableFrom(field.GetType()))
                    {
                        if (field.SelectedDisplayOption.Equals(eDisplayOption.DropDownList))//(field.IsDropdown)
                        {
                            string fId = "value_" + map.MetadataSet.Guid.Replace('-', '_') + "_" + map.Field.Guid.Replace('-', '_') + "_en_ss";


                            string result   = SolrService.GetPartialMatichingText(fId, "", 100);
                            var    response = Newtonsoft.Json.JsonConvert.DeserializeObject <SolrResponse>(result);

                            if (response.facet_counts.facet_fields.Count > 0)
                            {
                                foreach (var f in response.facet_counts.GetFacetsForField(fId))
                                {
                                    field.ListFields.Add(new SelectListItem {
                                        Text = f.Item1, Value = f.Item1
                                    });
                                }
                            }
                        }
                        else if (field.SelectedDisplayOption.Equals(eDisplayOption.Slider))
                        {
                            string fId = "value_" + map.MetadataSet.Guid.Replace('-', '_') + "_" + map.Field.Guid.Replace('-', '_') + "_is";

                            IDictionary <string, SolrNet.StatsResult> statsResult = solrSrv.GetStats(fId, "*:*");

                            field.Min = statsResult[fId].Min;
                            field.Max = statsResult[fId].Max;
                        }
                    }

                    Mappings.Add(map);
                }
            }

            return(base.GetContent(model));
        }
Exemplo n.º 5
0
        public override void InitManager(object model)
        {
            // get db context
            CatfishDbContext db = new CatfishDbContext();

            EntityTypeService entityTypeSrv = new EntityTypeService(db);

            FieldsMapping = new SelectList((entityTypeSrv.GetEntityTypeAttributeMappings()), "Id", "Name");

            if (Fields.Count > 0)
            {
                foreach (var field in Fields)
                {
                    CFEntityTypeAttributeMapping map = entityTypeService.GetEntityTypeAttributeMappingById(field.Id);
                    Mappings.Add(map);
                }
            }

            base.InitManager(model);
        }
        public override void InitManager(object model)
        {
            var internalId = Piranha.Config.SiteTree;
            var listModel  = ListModel.Get(internalId);

            Pages = new SelectList(listModel.Pages, "Id", "Title");

            EntityTypeService entityTypeSrv = new EntityTypeService(db);

            FieldsMapping = new SelectList((entityTypeSrv.GetEntityTypeAttributeMappings()), "Id", "Name");
            if (Fields.Count > 0)
            {
                foreach (var field in Fields)
                {
                    CFEntityTypeAttributeMapping map = entityTypeService.GetEntityTypeAttributeMappingById(field.Id);

                    Mappings.Add(map);
                }
            }

            EntityTypes = new SelectList(entityTypeService.GetEntityTypes(), "Name", "Name");

            base.InitManager(model);
        }
Exemplo n.º 7
0
        public CFItem SaveSubmission(Form form, string formSubmissionRef, int itemId, int entityTypeId, int formTemplateId, int collectionId, IDictionary <string, string> metadataAttributeMapping = null)
        {
            CFItem submissionItem;

            if (itemId == 0)
            {
                submissionItem = CreateEntity <CFItem>(entityTypeId);
                // submissionItem.m
                Db.Items.Add(submissionItem);
            }
            else
            {
                submissionItem = Db.Items.Where(m => m.Id == itemId).FirstOrDefault();
                if (submissionItem == null)
                {
                    throw new Exception("Specified item not found");
                }
                submissionItem.LogChange(submissionItem.Guid, "Updated.");
                Db.Entry(submissionItem).State = System.Data.Entity.EntityState.Modified;
            }

            CFFormSubmission storedFormSubmission = submissionItem.GetFormSubmission(formSubmissionRef);

            if (storedFormSubmission == null)
            {
                //if no stored form is available, we need to clone the template
                Form template = Db.FormTemplates.Where(m => m.Id == formTemplateId).FirstOrDefault();
                if (template == null)
                {
                    throw new Exception("Form template does not exist.");
                }

                storedFormSubmission = new CFFormSubmission();
                storedFormSubmission.ReplaceFormData(new XElement(template.Data));
                submissionItem.AddData(storedFormSubmission);
            }

            storedFormSubmission.UpdateFormData(form);

            //If any attachments have been submitted through the form and they have not yet been included in the
            //submission item, then include them and remove them from the main XMLModel table
            var attachmentFields = form.Fields.Where(f => f is Attachment).Select(f => f as Attachment);

            foreach (var att in attachmentFields)
            {
                UpdateFiles(att, submissionItem);
            }

            if (collectionId > 0)
            {
                CFCollection collection = Db.Collections.Where(c => c.Id == collectionId).FirstOrDefault();
                if (collection == null)
                {
                    throw new Exception("Specified collection not found");
                }

                collection.AppendChild(submissionItem);
            }

            //MR April 10 2018
            //update metadata field's value based on the attribute mapping
            //for example if "Name mapping" mapped to the Form's Title field, grab the value of the form title and set it to Metadata Set "Name Mapping Attribute"
            EntityTypeService entityTypeService = new EntityTypeService(Db);
            CFEntityType      entityType        = entityTypeService.GetEntityTypeById(entityTypeId);

            foreach (KeyValuePair <string, string> map in metadataAttributeMapping)
            {
                //key: attributeMapping, value Form's Field's Name
                string    attMapping  = map.Key;
                string    FieldName   = map.Value;
                FormField formField   = storedFormSubmission.FormData.Fields.Where(f => f.Name == FieldName).FirstOrDefault();
                var       FieldValues = formField.GetValues();

                CFEntityTypeAttributeMapping am = entityType.AttributeMappings.Where(a => a.Name == attMapping).FirstOrDefault();
                CFMetadataSet ms = null;
                if (am != null)
                {
                    ms = entityType.MetadataSets.Where(m => m.Id == am.MetadataSetId).FirstOrDefault();
                }

                FormField field;
                if (ms != null)
                {
                    field = ms.Fields.Where(f => f.Name == am.FieldName).FirstOrDefault();
                }

                foreach (var fVal in FieldValues)
                {
                    ms.SetFieldValue(am.FieldName, fVal.Value, fVal.LanguageCode);
                }
            }
            //end of MR

            submissionItem.Serialize();
            return(submissionItem);
        }
Exemplo n.º 8
0
        private Ingestion DeserializeEntityTypes(XElement element)
        {
            foreach (XElement entityElement in element.Elements())
            {
                CFEntityType entityType = new CFEntityType();
                entityType.Id = entityElement.Attribute("id") == null ? 0 : int.Parse(entityElement.Attribute("id").Value);

                foreach (XElement child in entityElement.Elements())
                {
                    string name = child.Name.LocalName;

                    if (name == "name")
                    {
                        entityType.Name = child.Value;
                    }
                    else if (name == "description")
                    {
                        entityType.Description = child.Value;
                    }
                    else if (name == "target-type")
                    {
                        entityType.TargetTypes = child.Value;
                    }
                    else if (name == "metadata-sets")
                    {
                        foreach (XElement metadata in child.Elements())
                        {
                            if (metadata.Name.LocalName == "metadata-set")
                            {
                                //MetadataSet set = MetadataSets.Where(m => m.Guid == metadata.Attribute("ref").Value).FirstOrDefault();
                                //if (set == null)
                                //{
                                CFMetadataSet set = new CFMetadataSet();
                                set.Guid = metadata.Attribute("ref").Value;
                                set.Id   = -1;
                                //}

                                entityType.MetadataSets.Add(set);

                                foreach (XElement attrElement in metadata.Elements())
                                {
                                    if (attrElement.Name.LocalName == "attribute-mapping")
                                    {
                                        CFEntityTypeAttributeMapping mapping = new CFEntityTypeAttributeMapping();
                                        mapping.MetadataSet = set;

                                        foreach (XElement attrChild in attrElement.Elements())
                                        {
                                            string attrName = attrChild.Name.LocalName;
                                            if (attrName == "name")
                                            {
                                                mapping.Name = attrChild.Value;
                                            }
                                            else if (attrName == "field-name")
                                            {
                                                mapping.FieldName = attrChild.Value;
                                            }
                                            else if (attrName == "label")
                                            {
                                                //When we implement the new mappings in a later sprint, we will need this field.
                                            }
                                        }

                                        entityType.AttributeMappings.Add(mapping);
                                    }
                                }
                            }
                        }
                    }
                }

                EntityTypes.Add(entityType);
            }

            return(this);
        }
        public override void UpdateDataModel(object dataModel, CatfishDbContext db)
        {
            CFEntityType model = dataModel as CFEntityType;

            model.Name        = Name;
            model.Description = Description;

            //Mr jan 15 2018

            var TargetTypesList = new List <CFEntityType.eTarget>();

            for (int i = 0; i < TargetType.Count; ++i)
            {
                if (TargetType[i])
                {
                    TargetTypesList.Add((CFEntityType.eTarget)i);
                }
            }
            model.TargetTypesList = TargetTypesList;

            List <int> dataModelMetadataSetIds = model.MetadataSets.Select(m => m.Id).ToList();
            List <int> viewModelMetadataSetIds = AssociatedMetadataSets.Select(m => m.Id).ToList();

            //Removing metadata sets that are already associated with the data model but not with the view model
            foreach (int id in dataModelMetadataSetIds)
            {
                if (!viewModelMetadataSetIds.Contains(id))
                {
                    model.MetadataSets.Remove(model.MetadataSets.Where(m => m.Id == id).FirstOrDefault());
                }
            }

            //Adding metadata sets that are in the view model but not in the data model to the data model.
            foreach (int id in viewModelMetadataSetIds)
            {
                if (!dataModelMetadataSetIds.Contains(id))
                {
                    CFMetadataSet ms = db.MetadataSets.Where(s => s.Id == id).FirstOrDefault();
                    if (ms != null)
                    {
                        model.MetadataSets.Add(ms);
                    }
                }
            }

            // Remvoe all the missing attribute mappings.
            model.AttributeMappings.Clear();
            foreach (var map in AttributeMappings)
            {
                CFEntityTypeAttributeMapping attrMapping = new CFEntityTypeAttributeMapping
                {
                    Id            = map.Id,
                    Name          = map.Name,
                    FieldName     = map.Field,
                    MetadataSetId = map.MetadataSetFieldId,
                    Label         = map.Label,
                    Deletable     = map.Deletable
                };

                if (map.Id > 0)
                {
                    CFEntityTypeAttributeMapping oldAttrMapping = db.EntityTypeAttributeMappings.Find(map.Id);

                    db.Entry(oldAttrMapping).CurrentValues.SetValues(attrMapping);

                    attrMapping = oldAttrMapping;
                }

                model.AttributeMappings.Add(attrMapping);
            }
        }