Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use java.nio.file.Path instead of java.io.File (DSP-1124) #1770

Merged
merged 4 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.knora.webapi

import java.io.File
import java.nio.file.{Files, Path, Paths}

import akka.actor.{ActorRef, ActorSystem, Props}
import akka.event.LoggingAdapter
Expand Down Expand Up @@ -228,13 +228,13 @@ class ITKnoraLiveSpec(_system: ActorSystem)
// Make a multipart/form-data request containing the files.

val formDataParts: Seq[Multipart.FormData.BodyPart] = filesToUpload.map { fileToUpload =>
val fileToSend = new File(fileToUpload.path)
assert(fileToSend.exists(), s"File ${fileToUpload.path} does not exist")
val fileToSend: Path = Paths.get(fileToUpload.path)
assert(Files.exists(fileToSend), s"File ${fileToUpload.path} does not exist")

Multipart.FormData.BodyPart(
"file",
HttpEntity.fromPath(fileToUpload.mimeType, fileToSend.toPath),
Map("filename" -> fileToSend.getName)
HttpEntity.fromPath(fileToUpload.mimeType, fileToSend),
Map("filename" -> fileToSend.getFileName.toString)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.knora.webapi.e2e.v1

import java.io.{File, FileInputStream, FileOutputStream}
import java.net.URLEncoder
import java.nio.file.{Files, Paths, StandardCopyOption}

import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers._
Expand Down Expand Up @@ -298,24 +298,17 @@ class KnoraSipiIntegrationV1ITSpec
}

"create an 'p0803-incunabula:book' and an 'p0803-incunabula:page' with file parameters via XML import" in {
val fileToUpload = new File(pathToChlaus)
val fileToUpload = Paths.get(pathToChlaus)

// To be able to run packaged tests inside Docker, we need to copy
// the file first to a place which is shared with sipi
val dest = FileUtil.createTempFile(settings, Some("jpg"))
new FileOutputStream(dest).getChannel
.transferFrom(
new FileInputStream(fileToUpload).getChannel,
0,
Long.MaxValue
)

val absoluteFilePath = dest.getAbsolutePath
Files.copy(fileToUpload, dest, StandardCopyOption.REPLACE_EXISTING)

// Upload the image to Sipi.
val sipiUploadResponse: SipiUploadResponse = uploadToSipi(
loginToken = loginToken,
filesToUpload = Seq(FileToUpload(path = absoluteFilePath, mimeType = MediaTypes.`image/tiff`))
filesToUpload = Seq(FileToUpload(path = dest.toAbsolutePath.toString, mimeType = MediaTypes.`image/tiff`))
)

val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head
Expand Down Expand Up @@ -370,7 +363,7 @@ class KnoraSipiIntegrationV1ITSpec
val locdata = pageJson.fields("resinfo").asJsObject.fields("locdata").asJsObject
val origname = locdata.fields("origname").asInstanceOf[JsString].value
val imageUrl = locdata.fields("path").asInstanceOf[JsString].value
assert(origname == dest.getName)
assert(origname == dest.getFileName.toString)

// Request the file from Sipi.
val sipiGetRequest = Get(imageUrl) ~> addCredentials(BasicHttpCredentials(userEmail, password))
Expand Down Expand Up @@ -414,7 +407,7 @@ class KnoraSipiIntegrationV1ITSpec

// add a mapping referring to the XSLT as the default XSL transformation

val mapping = FileUtil.readTextFile(new File(pathToMappingWithXSLT))
val mapping = FileUtil.readTextFile(Paths.get(pathToMappingWithXSLT))

val updatedMapping = addXSLTIriToMapping(mapping, resId)

Expand Down Expand Up @@ -449,7 +442,7 @@ class KnoraSipiIntegrationV1ITSpec
}

"create a sample BEOL letter" in {
val mapping = FileUtil.readTextFile(new File(pathToBEOLLetterMapping))
val mapping = FileUtil.readTextFile(Paths.get(pathToBEOLLetterMapping))

val paramsForMapping =
s"""
Expand Down Expand Up @@ -481,7 +474,7 @@ class KnoraSipiIntegrationV1ITSpec

// create a letter via bulk import

val bulkXML = FileUtil.readTextFile(new File(pathToBEOLBulkXML))
val bulkXML = FileUtil.readTextFile(Paths.get(pathToBEOLBulkXML))

val bulkRequest = Post(
baseApiUrl + "/v1/resources/xmlimport/" + URLEncoder.encode("http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF",
Expand Down Expand Up @@ -532,7 +525,7 @@ class KnoraSipiIntegrationV1ITSpec

// add a mapping referring to the XSLT as the default XSL transformation

val mapping = FileUtil.readTextFile(new File(pathToBEOLStandoffTEIMapping))
val mapping = FileUtil.readTextFile(Paths.get(pathToBEOLStandoffTEIMapping))

val updatedMapping = addXSLTIriToMapping(mapping, resId)

Expand Down