示例#1
0
        public void MergeWordsOneChildTest()
        {
            var thisWord = Util.RandomWord(ProjId);

            thisWord = _wordRepo.Create(thisWord).Result;

            var mergeObject = new MergeWords
            {
                Parent   = thisWord,
                Children = new List <MergeSourceWord>
                {
                    new MergeSourceWord {
                        SrcWordId = thisWord.Id
                    }
                }
            };

            var newWords = _mergeService.Merge(ProjId, new List <MergeWords> {
                mergeObject
            }).Result;

            // There should only be 1 word added and it should be identical to what we passed in
            Assert.That(newWords, Has.Count.EqualTo(1));
            Assert.That(newWords.First().ContentEquals(thisWord));

            // Check that the only word in the frontier is the new word
            var frontier = _wordRepo.GetFrontier(ProjId).Result;

            Assert.That(frontier, Has.Count.EqualTo(1));
            Assert.That(frontier.First(), Is.EqualTo(newWords.First()));

            // Check that new word has the right history
            Assert.That(newWords.First().History, Has.Count.EqualTo(1));
            Assert.That(newWords.First().History.First(), Is.EqualTo(thisWord.Id));
        }
示例#2
0
        /// <summary> Makes a new word in Frontier that has deleted tag on each sense </summary>
        /// <returns> A bool: success of operation </returns>
        public async Task <bool> Delete(string projectId, string wordId)
        {
            var wordIsInFrontier = await _wordRepo.DeleteFrontier(projectId, wordId);

            // We only want to add the deleted word if the word started in the frontier.
            if (wordIsInFrontier)
            {
                var wordToDelete = await _wordRepo.GetWord(projectId, wordId);

                if (wordToDelete is null)
                {
                    return(false);
                }

                wordToDelete.Id       = "";
                wordToDelete.Modified = "";
                wordToDelete.History  = new List <string> {
                    wordId
                };
                wordToDelete.Accessibility = State.Deleted;

                foreach (var senseAcc in wordToDelete.Senses)
                {
                    senseAcc.Accessibility = State.Deleted;
                }

                await _wordRepo.Create(wordToDelete);
            }

            return(wordIsInFrontier);
        }
        public ActionResult Create(Word word)
        {
            if (ModelState.IsValid)
            {
                db.Create(word);
                return(RedirectToAction("Index"));
            }

            return(View(word));
        }
示例#4
0
        public void TestGetAllWords()
        {
            _repo.Create(RandomWord());
            _repo.Create(RandomWord());
            _repo.Create(RandomWord());

            var words = (_wordController.Get(_projId).Result as ObjectResult).Value as List <Word>;

            Assert.That(words, Has.Count.EqualTo(3));
            _repo.GetAllWords(_projId).Result.ForEach(word => Assert.Contains(word, words));
        }
        public void TestAudioImport()
        {
            // Get path to sound in Assets folder, from debugging folder.
            var filePath = Path.Combine(Directory.GetParent(Directory.GetParent(
                                                                Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString()).ToString(),
                                        "Assets", "sound.mp3");

            // Open the file to read to controller.
            var fstream = File.OpenRead(filePath);

            // Generate parameters for controller call.
            var formFile   = new FormFile(fstream, 0, fstream.Length, "name", "sound.mp3");
            var fileUpload = new FileUpload {
                Name = "FileName", File = formFile
            };

            var word = _wordrepo.Create(RandomWord()).Result;

            // `fileUpload` contains the file stream and the name of the file.
            _ = _audioController.UploadAudioFile(_projId, word.Id, fileUpload).Result;

            var action = _wordController.Get(_projId, word.Id).Result;

            var foundWord = (action as ObjectResult).Value as Word;

            Assert.IsNotNull(foundWord.Audio);

            fstream.Close();
        }
示例#6
0
            /// <summary>
            /// <see cref="Word"/>s are added to the private field <see cref="_importEntries"/>
            /// during lift import. This saves the contents of _importEntries to the database.
            /// </summary>
            /// <returns> The words saved. </returns>
            public async Task <List <Word> > SaveImportEntries()
            {
                var savedWords = new List <Word>(await _wordRepo.Create(_importEntries));

                _importEntries.Clear();
                return(savedWords);
            }
        public void TestExportDeleted()
        {
            var proj = RandomProject();

            _projServ.Create(proj);

            var word        = RandomWord(proj.Id);
            var createdWord = _wordrepo.Create(word).Result;

            word.Id         = "";
            word.Vernacular = "updated";

            _wordService.Update(proj.Id, createdWord.Id, word);

            var result = _liftController.ExportLiftFile(proj.Id).Result;

            var util        = new Utilities();
            var combinePath = util.GenerateFilePath(Utilities.FileType.Dir, true, "", "");
            var exportPath  = Path.Combine(combinePath, proj.Id, "Export", "LiftExport",
                                           Path.Combine("Lift", "NewLiftFile.lift"));
            var text = File.ReadAllText(exportPath, Encoding.UTF8);

            // There is only one deleted word
            Assert.AreEqual(text.IndexOf("dateDeleted"), text.LastIndexOf("dateDeleted"));
        }
示例#8
0
        public async Task <IActionResult> Post(string projectId, [FromBody] Word word)
        {
            if (!_permissionService.HasProjectPermission(Permission.WordEntry, HttpContext))
            {
                return(new ForbidResult());
            }

            // Ensure project exists
            var proj = _projectService.GetProject(projectId);

            if (proj == null)
            {
                return(new NotFoundObjectResult(projectId));
            }

            word.ProjectId = projectId;

            // If word is not already in frontier, add it
            if (await _wordService.WordIsUnique(word))
            {
                await _wordRepo.Create(word);
            }
            else // Otherwise it is a duplicate
            {
                return(new OkObjectResult("Duplicate"));
            }

            return(new OkObjectResult(word.Id));
        }
示例#9
0
        public async Task <IActionResult> CreateWord(string projectId, [FromBody, BindRequired] Word word)
        {
            if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
            {
                return(Forbid());
            }
            var proj = await _projRepo.GetProject(projectId);

            if (proj is null)
            {
                return(NotFound(projectId));
            }
            word.ProjectId = projectId;

            // If word is not already in frontier, add it.
            if (await _wordService.WordIsUnique(word))
            {
                await _wordRepo.Create(word);
            }
            else
            {
                // Otherwise it is a duplicate.
                return(Ok("Duplicate"));
            }
            return(Ok(word.Id));
        }
示例#10
0
        public async Task <ActionResult <Word> > PostWords([FromBody] Word word)
        {
            // Use create method on repository to insert word in the database
            var newWord = await _wordRepository.Create(word);

            // Returns a create action result which will generate 201 http status code
            return(CreatedAtAction(nameof(GetWords), new { id = newWord.Id }, newWord));
        }
示例#11
0
        /// <summary> Makes a new word in Frontier that has deleted tag on each sense </summary>
        /// <returns> A bool: success of operation </returns>
        public async Task <bool> Delete(string projectId, string wordId)
        {
            var wordIsInFrontier = _repo.DeleteFrontier(projectId, wordId).Result;

            // We only want to add the deleted word if the word started in the frontier
            if (wordIsInFrontier)
            {
                var wordToDelete = _repo.GetWord(projectId, wordId).Result;
                wordToDelete.Id      = "";
                wordToDelete.History = new List <string>()
                {
                    wordId
                };

                foreach (var senseAcc in wordToDelete.Senses)
                {
                    senseAcc.Accessibility = (int)State.Deleted;
                }

                await _repo.Create(wordToDelete);
            }

            return(wordIsInFrontier);
        }
示例#12
0
 public Task <WordModel> Create(WordModel model)
 => _repository.Create(model);
示例#13
0
        /// <summary> The meat of lift import is done here. This reads in all necessary attributes of a word and adds it to the database. </summary>
        public async void FinishEntry(LiftEntry entry)
        {
            var newWord = new Word();
            var proj    = _projService.GetProject(_projectId).Result;

            // Only used when importing semantic domains from a lift-ranges file
            if (_sdList.Count != 0 && proj.SemanticDomains.Count == 0)
            {
                proj.SemanticDomains = _sdList;
                await _projService.Update(_projectId, proj);
            }

            // Add vernacular
            // TODO: currently we just add the first listed option, we may want to choose eventually
            if (!entry.CitationForm.IsEmpty) // Prefer citation form for vernacular
            {
                newWord.Vernacular = entry.CitationForm.FirstValue.Value.Text;
                if (proj.VernacularWritingSystem == "")
                {
                    proj.VernacularWritingSystem = entry.CitationForm.FirstValue.Key;
                    await _projService.Update(_projectId, proj);
                }
            }
            else if (!entry.LexicalForm.IsEmpty) // lexeme form for backup
            {
                newWord.Vernacular = entry.LexicalForm.FirstValue.Value.Text;
                if (proj.VernacularWritingSystem == "")
                {
                    proj.VernacularWritingSystem = entry.LexicalForm.FirstValue.Key;
                    await _projService.Update(_projectId, proj);
                }
            }
            else // this is not a word if there is no vernacular
            {
                return;
            }

            // This is not a word if there are no senses
            if (entry.Senses.Count == 0)
            {
                return;
            }

            // Add senses
            newWord.Senses = new List <Sense>();
            foreach (var sense in entry.Senses)
            {
                var newSense = new Sense {
                    SemanticDomains = new List <SemanticDomain>(), Glosses = new List <Gloss>()
                };

                // Add glosses
                foreach ((var key, var value) in sense.Gloss)
                {
                    newSense.Glosses.Add(new Gloss {
                        Language = key, Def = value.Text
                    });
                }

                // Find semantic domains
                var semanticDomainStrings = new List <string>();
                foreach (var trait in sense.Traits)
                {
                    if (trait.Name.StartsWith("semantic-domain"))
                    {
                        semanticDomainStrings.Add(trait.Value);
                    }
                }

                // Add semantic domains
                foreach (var semanticDomainString in semanticDomainStrings)
                {
                    // Splits on the space between the number and name of the semantic domain
                    var splitSemDom = semanticDomainString.Split(" ", 2);
                    newSense.SemanticDomains.Add(new SemanticDomain {
                        Id = splitSemDom[0], Name = splitSemDom[1]
                    });
                }

                newWord.Senses.Add(newSense);
            }

            // Add plural
            foreach (var field in entry.Fields)
            {
                if (field.Type == "Plural")
                {
                    foreach (var plural in field.Content)
                    {
                        var PluralForm = entry.Fields.First().Content.First().Value.Text;
                        newWord.Plural = PluralForm;
                    }
                }
            }

            // Get path to dir containing local lift package ~/{projectId}/Import/ExtractedLocation
            var util      = new Utilities();
            var importDir = util.GenerateFilePath(
                Utilities.FileType.Dir, false, "", Path.Combine(_projectId, "Import"));
            var extractedPathToImport = Path.Combine(importDir, "ExtractedLocation");

            // Get path to directory with audio files ~/{projectId}/Import/ExtractedLocation/{liftName}/audio
            var importListArr     = Directory.GetDirectories(extractedPathToImport);
            var extractedAudioDir = Path.Combine(importListArr.Single(), "audio");

            // Only add audio if the files exist
            if (Directory.Exists(extractedAudioDir))
            {
                // Add audio
                foreach (var pro in entry.Pronunciations)
                {
                    // get path to audio file in lift package at
                    // ~/{projectId}/Import/ExtractedLocation/{liftName}/audio/{audioFile}.mp3
                    var audioFile = pro.Media.First().Url;
                    newWord.Audio.Add(audioFile);
                }
            }

            newWord.ProjectId = _projectId;
            await _repo.Create(newWord);
        }
示例#14
0
        public void TestDeleteAllWords()
        {
            var inWord1    = _wordRepo.Create(Util.RandomWord(_projId)).Result;
            var inWord2    = _wordRepo.Create(Util.RandomWord(_projId)).Result;
            var diffProjId = "OTHER_PROJECT";
            var outWord    = _wordRepo.Create(Util.RandomWord(diffProjId)).Result;

            _ = _wordController.DeleteProjectWords(_projId).Result;
            Assert.That(_wordRepo.GetAllWords(_projId).Result, Has.Count.Zero);
            Assert.That(_wordRepo.GetFrontier(_projId).Result, Has.Count.Zero);
            Assert.That(_wordRepo.GetAllWords(diffProjId).Result, Has.Count.EqualTo(1));
            Assert.That(_wordRepo.GetFrontier(diffProjId).Result, Has.Count.EqualTo(1));
        }
示例#15
0
 public void Create(Word word)
 {
     word.CreatedDate = DateTime.Now;
     _repository.Create(word);
 }