This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create object to handle RWW configuration with fail-fast behavior. fixes
#3 #29
- Loading branch information
Showing
4 changed files
with
60 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package controllers | ||
|
||
import play.api.Play | ||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
|
||
object RwwConfiguration { | ||
|
||
val RdfViewerHtmlTemplatePathKey = "rww.rdf.html.viewer.template.path" | ||
val RootContainerPathKey = "rww.root.container.path" | ||
|
||
/** | ||
* we check the existence of the file because Resource.fromFile creates the file if it doesn't exist | ||
* (the doc says it raises an exception but it's not the case) | ||
* @param key | ||
* @return | ||
*/ | ||
def getFileForConfigurationKey(key: String): File = { | ||
val path = Play.current.configuration.getString(key) | ||
require(path.isDefined,s"Missing configuration for key $key") | ||
val file = new File(path.get) | ||
require(file.exists() && file.canRead,s"Unable to find or read file/directory: $file") | ||
file | ||
} | ||
|
||
|
||
val rdfViewerHtmlTemplate: String = { | ||
import scalax.io.{Resource=>xResource} | ||
val file = getFileForConfigurationKey(RdfViewerHtmlTemplatePathKey) | ||
require(file.isFile,s"The RDF viewer template file ($file) is not a file") | ||
xResource.fromFile(file).string | ||
} | ||
|
||
|
||
val rootContainerPath: Path = { | ||
val file = getFileForConfigurationKey(RootContainerPathKey) | ||
require(file.isDirectory,s"The root container ($file) is not a directory") | ||
file.toPath.toAbsolutePath | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters