public void SessionAddActor_Anonymized_RemovesActorFiles() { ArchivingActor actor = new ArchivingActor { Name = "Actor Name", FullName = "Actor Full Name", Anonymize = true }; actor.Files.Add(new ArchivingFile(System.Reflection.Assembly.GetExecutingAssembly().Location)); Session session = new Session(); session.AddActor(actor); Assert.AreEqual(0, session.Resources.MediaFile.Count); Assert.AreEqual(0, session.Resources.WrittenResource.Count); }
public void SessionAddActor_Anonymized_ReturnsAnonymizedNames() { ArchivingActor actor = new ArchivingActor { Name = "Actor Name", FullName = "Actor Full Name", Anonymize = true }; Session session = new Session(); session.AddActor(actor); var imdiActor = session.MDGroup.Actors.Actor[0]; Assert.AreNotEqual("Actor Name", imdiActor.Name[0]); Assert.AreNotEqual("Actor Full Name", imdiActor.FullName); }
internal static ArchivingActor InitializeActor(ArchivingDlgViewModel model, Person person, DateTime sessionDateTime, string role) { // is this person protected var protect = bool.Parse(person.MetaDataFile.GetStringValue("privacyProtection", "false")); // display message if the birth year is not valid var birthYear = person.MetaDataFile.GetStringValue("birthYear", string.Empty).Trim(); var age = 0; if (!birthYear.IsValidBirthYear() || string.IsNullOrEmpty(birthYear)) { var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidBirthYearMsg", "The Birth Year for {0} should be a 4 digit number. It is used to calculate the age for the IMDI export."); model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning; } else { age = string.IsNullOrEmpty(birthYear) ? 0 : sessionDateTime.Year - int.Parse(birthYear); if (age < 2 || age > 130) { var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidAgeMsg", "The age for {0} must be between 2 and 130"); model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning; } } var actor = new ArchivingActor { FullName = person.Id, Name = person.MetaDataFile.GetStringValue(PersonFileType.kCode, person.Id), Code = person.MetaDataFile.GetStringValue(PersonFileType.kCode, null), BirthDate = birthYear, Age = age > 0 ? age.ToString() : "Unspecified", Gender = person.MetaDataFile.GetStringValue(PersonFileType.kGender, null), Education = person.MetaDataFile.GetStringValue(PersonFileType.kEducation, null), Occupation = person.MetaDataFile.GetStringValue(PersonFileType.kPrimaryOccupation, null), Anonymize = protect, Role = role, }; return(actor); }
public void ActorType_ArchivingActor_ValidActorType() { const string motherTongueIso3 = "spa"; const string primaryLanguageIso3 = "eng"; const string additionalLanguageIso3 = "fra"; var actrIn = new ArchivingActor { Education = "8th grade", Name = "John Smith", Age = "50 +- 10", Gender = "Male", BirthDate = 1964, Occupation = "Nerf Herder", MotherTongueLanguage = new ArchivingLanguage(motherTongueIso3), PrimaryLanguage = new ArchivingLanguage(primaryLanguageIso3) }; // additional languages actrIn.Iso3Languages.Add(new ArchivingLanguage(additionalLanguageIso3)); var actrOut = new ActorType(actrIn); Assert.AreEqual(actrIn.Name, actrOut.FullName); Assert.AreEqual(actrIn.Name, actrOut.Name[0]); Assert.AreEqual(actrIn.Gender, actrOut.Sex.Value); Assert.AreEqual(actrIn.Occupation, actrOut.Keys.Key.Find(k => k.Name == "Occupation").Value); Assert.AreEqual(actrIn.GetBirthDate(), actrOut.BirthDate); Assert.AreEqual(actrIn.Age, actrOut.Age); // language count Assert.AreEqual(3, actrOut.Languages.Language.Count); // mother tongue string motherTongueCodeFound = null; foreach (var lang in actrOut.Languages.Language) { if (lang.MotherTongue.Value == BooleanEnum.@true) motherTongueCodeFound = lang.Id; } Assert.IsNotNull(motherTongueCodeFound, "Mother tongue not found."); Assert.AreEqual(motherTongueIso3, motherTongueCodeFound.Substring(motherTongueCodeFound.Length - 3), "Wrong mother tongue returned."); // primary language string primaryLanguageCodeFound = null; foreach (var lang in actrOut.Languages.Language) { if (lang.PrimaryLanguage.Value == BooleanEnum.@true) primaryLanguageCodeFound = lang.Id; } Assert.IsNotNull(primaryLanguageCodeFound, "Primary language not found."); Assert.AreEqual(primaryLanguageIso3, primaryLanguageCodeFound.Substring(primaryLanguageCodeFound.Length - 3), "Wrong primary language returned."); // additional language var additionalLanguageFound = false; foreach (var lang in actrOut.Languages.Language) { if (lang.Id.EndsWith(additionalLanguageIso3)) additionalLanguageFound = true; } Assert.IsTrue(additionalLanguageFound, "The additional language was not found."); }
public void ActorType_ArchivingActor_ValidActorType() { const string motherTongueIso3 = "spa"; const string primaryLanguageIso3 = "eng"; const string additionalLanguageIso3 = "fra"; var actrIn = new ArchivingActor { Education = "8th grade", Name = "John Smith", Age = "50 +- 10", Gender = "Male", BirthDate = 1964, Occupation = "Nerf Herder", MotherTongueLanguage = new ArchivingLanguage(motherTongueIso3), PrimaryLanguage = new ArchivingLanguage(primaryLanguageIso3) }; // additional languages actrIn.Iso3Languages.Add(new ArchivingLanguage(additionalLanguageIso3)); var actrOut = new ActorType(actrIn); Assert.AreEqual(actrIn.Name, actrOut.FullName); Assert.AreEqual(actrIn.Name, actrOut.Name[0]); Assert.AreEqual(actrIn.Gender, actrOut.Sex.Value); Assert.AreEqual(actrIn.Occupation, actrOut.Keys.Key.Find(k => k.Name == "Occupation").Value); Assert.AreEqual(actrIn.GetBirthDate(), actrOut.BirthDate); Assert.AreEqual(actrIn.Age, actrOut.Age); // language count Assert.AreEqual(3, actrOut.Languages.Language.Count); // mother tongue string motherTongueCodeFound = null; foreach (var lang in actrOut.Languages.Language) { if (lang.MotherTongue.Value == BooleanEnum.@true) { motherTongueCodeFound = lang.Id; } } Assert.IsNotNull(motherTongueCodeFound, "Mother tongue not found."); Assert.AreEqual(motherTongueIso3, motherTongueCodeFound.Substring(motherTongueCodeFound.Length - 3), "Wrong mother tongue returned."); // primary language string primaryLanguageCodeFound = null; foreach (var lang in actrOut.Languages.Language) { if (lang.PrimaryLanguage.Value == BooleanEnum.@true) { primaryLanguageCodeFound = lang.Id; } } Assert.IsNotNull(primaryLanguageCodeFound, "Primary language not found."); Assert.AreEqual(primaryLanguageIso3, primaryLanguageCodeFound.Substring(primaryLanguageCodeFound.Length - 3), "Wrong primary language returned."); // additional language var additionalLanguageFound = false; foreach (var lang in actrOut.Languages.Language) { if (lang.Id.EndsWith(additionalLanguageIso3)) { additionalLanguageFound = true; } } Assert.IsTrue(additionalLanguageFound, "The additional language was not found."); }
private static void AddIMDISession(Session saymoreSession, ArchivingDlgViewModel model) { var sessionFile = saymoreSession.MetaDataFile; // create IMDI session var imdiSession = model.AddSession(saymoreSession.Id); imdiSession.Title = saymoreSession.Title; // session location var address = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Address", null); var region = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Region", null); var country = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Country", null); var continent = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Continent", null); if (string.IsNullOrEmpty(address)) { address = saymoreSession.MetaDataFile.GetStringValue("location", null); } imdiSession.Location = new ArchivingLocation { Address = address, Region = region, Country = country, Continent = continent }; // session description (synopsis) var stringVal = saymoreSession.MetaDataFile.GetStringValue("synopsis", null); if (!string.IsNullOrEmpty(stringVal)) { imdiSession.AddDescription(new LanguageString { Value = stringVal }); } // session date stringVal = saymoreSession.MetaDataFile.GetStringValue("date", null); if (!string.IsNullOrEmpty(stringVal)) { imdiSession.SetDate(DateTime.Parse(stringVal).ToISO8601TimeFormatDateOnlyString()); } // session situation stringVal = saymoreSession.MetaDataFile.GetStringValue("situation", null); if (!string.IsNullOrEmpty(stringVal)) { imdiSession.AddKeyValuePair("Situation", stringVal); } imdiSession.Genre = GetFieldValue(sessionFile, "genre"); imdiSession.SubGenre = GetFieldValue(sessionFile, "additional_Sub-Genre"); imdiSession.AccessCode = GetFieldValue(sessionFile, "access"); imdiSession.Interactivity = GetFieldValue(sessionFile, "additional_Interactivity"); imdiSession.Involvement = GetFieldValue(sessionFile, "additional_Involvement"); imdiSession.PlanningType = GetFieldValue(sessionFile, "additional_Planning_Type"); imdiSession.SocialContext = GetFieldValue(sessionFile, "additional_Social_Context"); imdiSession.Task = GetFieldValue(sessionFile, "additional_Task"); // custom session fields foreach (var item in saymoreSession.MetaDataFile.GetCustomFields()) { imdiSession.AddKeyValuePair(item.FieldId, item.ValueAsString); } // actors var actors = new ArchivingActorCollection(); var persons = saymoreSession.GetAllPersonsInSession(); foreach (var person in persons) { // is this person protected var protect = bool.Parse(person.MetaDataFile.GetStringValue("privacyProtection", "false")); // display message if the birth year is not valid var birthYear = person.MetaDataFile.GetStringValue("birthYear", string.Empty).Trim(); if (!birthYear.IsValidBirthYear()) { var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidBirthYearMsg", "The Birth Year for {0} should be either blank or a 4 digit number."); model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning; } ArchivingActor actor = new ArchivingActor { FullName = person.Id, Name = person.MetaDataFile.GetStringValue(PersonFileType.kCode, person.Id), BirthDate = birthYear, Gender = person.MetaDataFile.GetStringValue(PersonFileType.kGender, null), Education = person.MetaDataFile.GetStringValue(PersonFileType.kEducation, null), Occupation = person.MetaDataFile.GetStringValue(PersonFileType.kPrimaryOccupation, null), Anonymize = protect, Role = "Participant" }; // do this to get the ISO3 codes for the languages because they are not in saymore var language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("primaryLanguage", null)); if (language != null) { actor.PrimaryLanguage = new ArchivingLanguage(language.Iso3Code, language.EnglishName); } language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("mothersLanguage", null)); if (language != null) { actor.MotherTongueLanguage = new ArchivingLanguage(language.Iso3Code, language.EnglishName); } // otherLanguage0 - otherLanguage3 for (var i = 0; i < 4; i++) { language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("otherLanguage" + i, null)); if (language != null) { actor.Iso3Languages.Add(new ArchivingLanguage(language.Iso3Code, language.EnglishName)); } } // custom person fields foreach (var item in person.MetaDataFile.GetCustomFields()) { actor.AddKeyValuePair(item.FieldId, item.ValueAsString); } // actor files var actorFiles = Directory.GetFiles(person.FolderPath) .Where(f => IncludeFileInArchive(f, typeof(IMDIArchivingDlgViewModel), Settings.Default.PersonFileExtension)); foreach (var file in actorFiles) { actor.Files.Add(CreateArchivingFile(file)); } // add actor to imdi session actors.Add(actor); } // get contributors foreach (var contributor in saymoreSession.GetAllContributorsInSession()) { var actr = actors.FirstOrDefault(a => a.Name == contributor.Name); if (actr == null) { actors.Add(contributor); } else { if (actr.Role == "Participant") { actr.Role = contributor.Role; } else { if (!actr.Role.Contains(contributor.Role)) { actr.Role += ", " + contributor.Role; } } } } // add actors to imdi session foreach (var actr in actors) { imdiSession.AddActor(actr); } // session files var files = saymoreSession.GetSessionFilesToArchive(model.GetType()); foreach (var file in files) { imdiSession.AddFile(CreateArchivingFile(file)); } }
/// <remarks/> public void AddActor(ArchivingActor actor) { if (actor.Anonymize) { var nameToUse = string.IsNullOrEmpty(actor.Gender) ? "U" : actor.Gender.Substring(0, 1).ToUpper(); var suffix = "000" + _anonymizedCounter; suffix = suffix.Substring(suffix.Length - 3); nameToUse += suffix; actor.Name = nameToUse; actor.FullName = nameToUse; _anonymizedCounter++; } MDGroup.Actors.Actor.Add(new ActorType(actor)); // actor files, only if not anonymized if (!actor.Anonymize) { foreach (var file in actor.Files) AddFile(new IMDIFile(file), "Contributors"); } }
// TODO: Do we need this method? /// <remarks/> public ArchivingActor ToArchivingActor() { ArchivingActor actr = new ArchivingActor { Age = Age, Education = Education, FullName = FullName }; if (Sex != null) actr.Gender = Sex.Value; if (Name.Length > 0) actr.Name = Name[0]; if (!string.IsNullOrEmpty(Role.Value)) actr.Role = Role.Value; if (!string.IsNullOrEmpty(BirthDate)) actr.BirthDate = BirthDate; foreach (LanguageType lang in Languages.Language) { var iso3 = lang.Id.Substring(lang.Id.Length - 3); var archLanguage = new ArchivingLanguage(iso3, lang.Name[0].Value); actr.Iso3Languages.Add(archLanguage); if (lang.PrimaryLanguage.Value == BooleanEnum.@true) actr.PrimaryLanguage = archLanguage; if (lang.MotherTongue.Value == BooleanEnum.@true) actr.MotherTongueLanguage = archLanguage; } return actr; }
/// <summary></summary> public ActorType(ArchivingActor actor) : this() { Name = new[] {actor.GetName()}; FullName = actor.GetFullName(); if (!string.IsNullOrEmpty(actor.Age)) Age = actor.Age; // languages bool hasPrimary = (actor.PrimaryLanguage != null); bool hasMother = (actor.MotherTongueLanguage != null); foreach (var lang in actor.Iso3Languages) { BooleanEnum isPrimary = (hasPrimary) ? (actor.PrimaryLanguage == lang) ? BooleanEnum.@true : BooleanEnum.@false : BooleanEnum.Unspecified; BooleanEnum isMother = (hasMother) ? (actor.MotherTongueLanguage == lang) ? BooleanEnum.@true : BooleanEnum.@false : BooleanEnum.Unspecified; AddLanguage(lang, isPrimary, isMother); } // keys foreach (var kvp in actor.Keys) Keys.Key.Add(new KeyType { Name = kvp.Key, Value = kvp.Value }); // BirthDate (can be just year) var birthDate = actor.GetBirthDate(); if (!string.IsNullOrEmpty(birthDate)) SetBirthDate(birthDate); // Sex if (!string.IsNullOrEmpty(actor.Gender)) SetSex(actor.Gender); // Education if (!string.IsNullOrEmpty(actor.Education)) Education = actor.Education; // Role if (!string.IsNullOrEmpty(actor.Role)) Role = actor.Role.ToVocabularyType(false, ListType.Link(ListType.ActorRole)); ; // Occupation if (!string.IsNullOrEmpty(actor.Occupation)) Keys.Key.Add(new KeyType { Name = "Occupation", Value = actor.Occupation }); // Anonymize if (actor.Anonymize) Anonymized = new BooleanType { Value = BooleanEnum.@true }; }