/// <summary> /// Returns a dictionary of custom fields at the LexEntry, LexSense, and LexExampleSentence levels /// From Lcm to LF. If the dictionary doesn't exist, create one. /// </summary> /// <returns>Dictionary of custom fields where the keys are the parent listCode</returns> public Dictionary <string, ICmPossibilityList> GetCustomFieldParentLists() { // Generate the dictionary of custom fields var lfCustomFieldLists = new Dictionary <string, ICmPossibilityList>(); // The three classes that are allowed to have custom fields in them are LexEntry, LexSense, and LexExampleSentence List <int> customFieldIds = new List <int>( LcmMetaData.GetFields(LexEntryTags.kClassId, false, (int)CellarPropertyTypeFilter.AllReference) .Where(flid => cache.GetIsCustomField(flid) && LcmMetaData.GetFieldListRoot(flid) != Guid.Empty)); customFieldIds.AddRange( LcmMetaData.GetFields(LexSenseTags.kClassId, false, (int)CellarPropertyTypeFilter.AllReference) .Where(flid => cache.GetIsCustomField(flid) && LcmMetaData.GetFieldListRoot(flid) != Guid.Empty)); customFieldIds.AddRange( LcmMetaData.GetFields(LexExampleSentenceTags.kClassId, false, (int)CellarPropertyTypeFilter.AllReference) .Where(flid => cache.GetIsCustomField(flid) && LcmMetaData.GetFieldListRoot(flid) != Guid.Empty)); var listRepo = servLoc.GetInstance <ICmPossibilityListRepository>(); foreach (int flid in customFieldIds) { Guid parentListGuid = LcmMetaData.GetFieldListRoot(flid); string listCode = GetParentListCode(flid); lfCustomFieldLists[listCode] = listRepo.GetObject(parentListGuid); } return(lfCustomFieldLists); }
public void SetCustomFieldsForThisCmObject(ICmObject cmObj, string objectType, BsonDocument customFieldValues, BsonDocument customFieldGuids) { if (customFieldValues == null) { return; } IEnumerable <int> customFieldIds = lcmMetaData.GetFields(cmObj.ClassID, false, (int)CellarPropertyTypeFilter.All) .Where(flid => cache.GetIsCustomField(flid)); var remainingFieldNames = new HashSet <string>(customFieldValues.Select(elem => elem.Name)); foreach (int flid in customFieldIds) { string fieldName = lcmMetaData.GetFieldNameOrNull(flid); if (fieldName == null) { return; } fieldName = ConvertUtilities.NormalizedFieldName(fieldName, objectType); BsonValue fieldValue = customFieldValues.GetValue(fieldName, BsonNull.Value); BsonValue fieldGuidOrGuids = (customFieldGuids == null) ? BsonNull.Value : customFieldGuids.GetValue(fieldName, BsonNull.Value); // Persist Guid.Empty as null to save space if (fieldGuidOrGuids.BsonType == BsonType.String && fieldGuidOrGuids.AsString == "00000000-0000-0000-0000-000000000000") { fieldGuidOrGuids = BsonNull.Value; } remainingFieldNames.Remove(fieldName); if (fieldValue != BsonNull.Value) { SetCustomFieldData(cmObj.Hvo, flid, fieldValue, fieldGuidOrGuids); } } foreach (string fieldName in remainingFieldNames) { // TODO: These are NEW CUSTOM FIELDS! Will need to create them in LCM, then do: // BsonValue fieldValue = customFieldValues.GetValue(fieldName, BsonNull.Value); // BsonValue fieldGuidOrGuids = customFieldGuids.GetValue(fieldName, BsonNull.Value); // SetCustomFieldData(cmObj.Hvo, flid, fieldValue, fieldGuidOrGuids); // Above lines commented out until we can create new custom fields correctly. 2015-11 RM logger.Warning("Custom field {0} from LF skipped, because we're not yet creating new custom fields in LCM", fieldName); } }