public async Task <IActionResult> DeleteProjectWords(string projectId) { if (!await _permissionService.HasProjectPermission(HttpContext, Permission.DatabaseAdmin)) { return(Forbid()); } var proj = await _projRepo.GetProject(projectId); if (proj is null) { return(NotFound(projectId)); } return(Ok(await _wordRepo.DeleteAllWords(projectId))); }
public async Task <IActionResult> Delete(string projectId) { if (!_permissionService.HasProjectPermission(Permission.DatabaseAdmin, HttpContext)) { return(new ForbidResult()); } // Ensure project exists var proj = _projectService.GetProject(projectId); if (proj == null) { return(new NotFoundObjectResult(projectId)); } return(new ObjectResult(await _wordRepo.DeleteAllWords(projectId))); }
public void TestRoundtrip() { // This test assumes you have the starting .zip included in your project files. // Get path to the starting dir var pathToStartZips = Path.Combine(Directory.GetParent(Directory.GetParent( Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString()).ToString(), "Assets"); var testZips = Directory.GetFiles(pathToStartZips, "*.zip"); var fileMapping = new Dictionary <string, RoundTripObj>(); // Add new .zip file information here var gusillaay = new RoundTripObj("gsl-Qaaa-x-orth", new List <string>(), 8045 /*number of words*/); fileMapping.Add("Gusillaay.zip", gusillaay); var lotad = new RoundTripObj("dtr", new List <string>(), 5400); fileMapping.Add("Lotad.zip", lotad); var natqgu = new RoundTripObj("qaa-x-stc-natqgu", new List <string>(), 11570 /*number of words*/); fileMapping.Add("Natqgu.zip", natqgu); var resembli = new RoundTripObj("ags", new List <string>(), 255 /*number of words*/); fileMapping.Add("Resembli.zip", resembli); var rwc = new RoundTripObj("es", new List <string>(), 132 /*number of words*/); fileMapping.Add("RWC.zip", rwc); var sena = new RoundTripObj("seh", new List <string>(), 1462 /*number of words*/); fileMapping.Add("Sena.zip", sena); var singleEntryLiftWithSound = new RoundTripObj( "ptn", new List <string> { "short.mp3" }, 1 /*number of words*/); fileMapping.Add("SingleEntryLiftWithSound.zip", singleEntryLiftWithSound); var singleEntryLiftWithTwoSound = new RoundTripObj( "ptn", new List <string> { "short.mp3", "short1.mp3" }, 1 /*number of words*/); fileMapping.Add("SingleEntryLiftWithTwoSound.zip", singleEntryLiftWithTwoSound); foreach (var dataSet in fileMapping) { var actualFilename = dataSet.Key; var pathToStartZip = Path.Combine(pathToStartZips, actualFilename); // Upload the zip file // Init the project the .zip info is added to var proj = RandomProject(); _projServ.Create(proj); // Generate api parameter with filestream if (File.Exists(pathToStartZip)) { var fstream = File.OpenRead(pathToStartZip); var fileUpload = InitFile(fstream, actualFilename); // Make api call var result = _liftController.UploadLiftFile(proj.Id, fileUpload).Result; Assert.That(!(result is BadRequestObjectResult)); proj = _projServ.GetProject(proj.Id).Result; Assert.AreEqual(proj.VernacularWritingSystem, dataSet.Value.Language); fstream.Close(); var allWords = _wordrepo.GetAllWords(proj.Id); // Export var exportedFilePath = _liftController.CreateLiftExport(proj.Id); var exportedDirectory = Path.GetDirectoryName(exportedFilePath); // Assert the file was created with desired heirarchy Assert.That(Directory.Exists(exportedDirectory)); Assert.That(Directory.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "audio"))); foreach (var audioFile in dataSet.Value.AudioFiles) { Assert.That(File.Exists(Path.Combine( exportedDirectory, "LiftExport", "Lift", "audio", audioFile))); } Assert.That(Directory.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "WritingSystems"))); Assert.That(File.Exists(Path.Combine( exportedDirectory, "LiftExport", "Lift", "WritingSystems", dataSet.Value.Language + ".ldml"))); Assert.That(File.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "NewLiftFile.lift"))); var dirList = new List <string>( Directory.GetDirectories(Path.GetDirectoryName(exportedDirectory))); dirList.Remove(exportedDirectory); Assert.That(Directory.Exists(Path.Combine(Path.GetDirectoryName(exportedDirectory), dirList.Single()))); _wordrepo.DeleteAllWords(proj.Id); // Roundtrip Part 2 // Upload the exported words again // Init the project the .zip info is added to var proj2 = RandomProject(); _projServ.Create(proj2); // Generate api parameter with filestream fstream = File.OpenRead(exportedFilePath); fileUpload = InitFile(fstream, actualFilename); // Make api call var result2 = _liftController.UploadLiftFile(proj2.Id, fileUpload).Result; Assert.That(!(result is BadRequestObjectResult)); proj2 = _projServ.GetProject(proj2.Id).Result; Assert.AreEqual(proj2.VernacularWritingSystem, dataSet.Value.Language); fstream.Close(); allWords = _wordrepo.GetAllWords(proj2.Id); Assert.AreEqual(allWords.Result.Count, dataSet.Value.NumOfWords); // Export exportedFilePath = _liftController.CreateLiftExport(proj2.Id); exportedDirectory = Path.GetDirectoryName(exportedFilePath); // Assert the file was created with desired hierarchy Assert.That(Directory.Exists(exportedDirectory)); Assert.That(Directory.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "audio"))); foreach (var audioFile in dataSet.Value.AudioFiles) { var path = Path.Combine(exportedDirectory, "LiftExport", "Lift", "audio", audioFile); Assert.That(File.Exists(path), "The file " + audioFile + " can not be found at this path: " + path); } Assert.That(Directory.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "WritingSystems"))); Assert.That(File.Exists(Path.Combine( exportedDirectory, "LiftExport", "Lift", "WritingSystems", dataSet.Value.Language + ".ldml"))); Assert.That(File.Exists(Path.Combine(exportedDirectory, "LiftExport", "Lift", "NewLiftFile.lift"))); dirList = new List <string>(Directory.GetDirectories(Path.GetDirectoryName(exportedDirectory))); dirList.Remove(exportedDirectory); Assert.That(Directory.Exists(Path.Combine(Path.GetDirectoryName(exportedDirectory), dirList.Single()))); _wordrepo.DeleteAllWords(proj.Id); } } }