Skip to content

Commit 7f16c57

Browse files
committed
Merge remote-tracking branch 'origin/develop' into release/1.21.0
2 parents 952f496 + 2819451 commit 7f16c57

File tree

13 files changed

+225
-15
lines changed

13 files changed

+225
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ script prior to upgrading to minimize the downtime.
1717

1818
### Added
1919
- api.Files jsonfile, adds two fields "downloads" and "views" [#228](https://github.com/clowder-framework/clowder/issues/228)
20+
- Dataset and file scala.html pages incl schema.org jsonld metadata for (google)datasetsearch [#335](https://github.com/clowder-framework/clowder/issues/335)
21+
- MiniUser and LicenseData now have to_jsonld methods to return string part of [#335](https://github.com/clowder-framework/clowder/issues/335) metadata
22+
- LicenseData has urlViaAttributes used by it's to_jsonld to guess url when empty, for [#335](https://github.com/clowder-framework/clowder/issues/335)
2023
- MRI previewer for NIFTY (.nii) files.
2124
- Dataset page usually defaults to Files tab, but if no files will now show Metadata first
2225
- HEIC (.heic) and HEIF (.heif) mimetypes to support new Apple iPhone image file format.
@@ -31,6 +34,9 @@ script prior to upgrading to minimize the downtime.
3134
- github actions would fail for docker builds due to secrets not existing
3235
- Fix to remove dataset from a space [#349](https://github.com/clowder-framework/clowder/issues/349)
3336

37+
### Changed
38+
- Utils.baseURL now on RequestHeader instead of Request[Any]
39+
3440
## 1.20.3 - 2022-06-10
3541

3642
### Fixed
@@ -64,6 +70,7 @@ script prior to upgrading to minimize the downtime.
6470
- Documentation: Added "How to contribute documentation" page
6571
- Documentation: New Sphinx plugins for dropdowns and menus.
6672

73+
6774
## 1.20.0 - 2022-02-07
6875

6976
### Added

app/controllers/Datasets.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,4 +836,4 @@ class Datasets @Inject() (
836836
implicit val user = request.user
837837
Ok(views.html.generalMetadataSearch())
838838
}
839-
}
839+
}

app/controllers/Utils.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ object Utils {
1313
/**
1414
* Return base url given a request. This will add http or https to the front, for example
1515
* https://localhost:9443 will be returned if it is using https.
16+
*
1617
*/
17-
def baseUrl(request: Request[Any], absolute: Boolean = true) = {
18+
def baseUrl(request: RequestHeader, absolute: Boolean = true) = {
1819
if (absolute) {
19-
routes.Files.list().absoluteURL(https(request))(request).replace("/files", "")
20+
routes.Files.list().absoluteURL(https(request))(request).replace("/files", "")
2021
} else {
21-
routes.Files.list().url.replace("/files", "")
22+
routes.Files.list().url.replace("/files", "")
2223
}
2324
}
2425

@@ -171,4 +172,4 @@ object Utils {
171172
decodedReplies.toList
172173
}
173174
}
174-
}
175+
}

app/models/Dataset.scala

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.util.Date
55
import play.api.libs.json.{Writes, Json}
66
import play.api.libs.json._
77
import play.api.libs.functional.syntax._
8+
import _root_.util.Formatters
89

910
/**
1011
* A dataset is a collection of files, and streams.
@@ -38,6 +39,53 @@ case class Dataset(
3839
def isDefault:Boolean = status == DatasetStatus.DEFAULT.toString
3940
def isTRIAL:Boolean = status == DatasetStatus.TRIAL.toString
4041
def inSpace:Boolean = spaces.size > 0
42+
43+
/**
44+
* Caps a list at 'max'
45+
* then turns it's ID's into resolvable URLs of that 'apiRoute' type
46+
* end with appending "..." to the List, to signify that it was abridged
47+
*
48+
* todo: issue 354 to the max configurable
49+
*/
50+
def cap_api_list (l: List[UUID], max: Int, URLb: String, apiRoute: String) : List[String] = {
51+
if (l.length <= max) {
52+
return l.map(f => URLb + apiRoute + f)
53+
} else {
54+
val cl = l.take(max)
55+
val r : List[String] = cl.map(f => URLb + apiRoute + f)
56+
return r.::("...").reverse
57+
}
58+
}
59+
60+
/**
61+
* return Dataset as JsValue in jsonld format
62+
*/
63+
def to_jsonld(url: String) : JsValue = {
64+
val so = JsObject(Seq("@vocab" -> JsString("https://schema.org/")))
65+
val URLb = url.replaceAll("/$", "")
66+
var pic_id = thumbnail_id.getOrElse("")
67+
if (pic_id != "") {
68+
pic_id = URLb + pic_id
69+
} else {
70+
""
71+
}
72+
val datasetLD = Json.obj(
73+
"@context" -> so,
74+
"identifier" -> id.toString,
75+
"name" -> name,
76+
"author" -> author.to_jsonld(),
77+
"description" -> description,
78+
"dateCreated" -> Formatters.iso8601(created),
79+
"DigitalDocument" -> Json.toJson(cap_api_list(files, 10, URLb, "/files/")),
80+
"Collection" -> Json.toJson(cap_api_list(spaces, 10, URLb, "/spaces/")),
81+
"thumbnail" -> Json.toJson(pic_id),
82+
"license" -> licenseData.to_jsonld(),
83+
"dateModfied" -> Formatters.iso8601(lastModifiedDate),
84+
"keywords" -> tags.map(x => x.to_json()),
85+
"creator" -> Json.toJson(creators)
86+
)
87+
return datasetLD
88+
}
4189
}
4290

4391
object DatasetStatus extends Enumeration {
@@ -68,8 +116,9 @@ object Dataset {
68116
}
69117

70118

119+
71120
case class DatasetAccess(
72121
showAccess: Boolean = false,
73122
access: String = "N/A",
74123
accessOptions: List[String] = List.empty
75-
)
124+
)

app/models/File.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java.util.Date
44

55
import models.FileStatus.FileStatus
66
import play.api.libs.json.{JsObject, Json, Writes}
7+
import play.api.libs.json._
8+
import _root_.util.Formatters
79

810
/**
911
* Uploaded files.
@@ -32,7 +34,33 @@ case class File(
3234
licenseData: LicenseData = new LicenseData(),
3335
followers: List[UUID] = List.empty,
3436
stats: Statistics = new Statistics(),
35-
status: String = FileStatus.UNKNOWN.toString) // can't use enums in salat
37+
status: String = FileStatus.UNKNOWN.toString) { // can't use enums in salat
38+
/**
39+
* return File as JsValue in jsonld format
40+
*/
41+
def to_jsonld() : JsValue = {
42+
val so = JsObject(Seq("@vocab" -> JsString("https://schema.org/")))
43+
val fileLD = Json.obj(
44+
"@context" -> so,
45+
"identifier" -> id.toString,
46+
"name" -> filename,
47+
"author" -> author.to_jsonld(),
48+
"isBasedOn" -> originalname,
49+
"uploadDate" -> Formatters.iso8601(uploadDate),
50+
"contentType" -> contentType,
51+
"MenuSection" -> sections.map(x => x.to_jsonld()),
52+
"keywords" -> tags.map(x => x.to_json()),
53+
"thumbnail" -> Json.toJson(thumbnail_id.filterNot(_.isEmpty).getOrElse("")),
54+
"description" -> description,
55+
"license" -> licenseData.to_jsonld(),
56+
"FollowAction" -> Json.toJson(followers),
57+
"interactionStatistic" -> stats.to_jsonld,
58+
"status" -> status
59+
)
60+
return fileLD
61+
}
62+
}
63+
3664

3765
// what is the status of the file
3866
object FileStatus extends Enumeration {

app/models/LicenseData.scala

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package models
22

33
import api.Permission
44

5+
import play.api.libs.json._
6+
7+
58
/**
69
* case class to handle specific license information. Currently attached to individual Datasets and Files.
710
*/
@@ -41,5 +44,67 @@ case class LicenseData (
4144
def isRightsOwner(aName: String) = {
4245
m_rightsHolder == aName
4346
}
44-
}
4547

48+
/**
49+
* Utility to return a url even if empty, but enough other attributes available to determine it
50+
* this is repurposed from:
51+
* function updateData(id, imageBase, sourceObject, authorName)
52+
* in updateLicenseInfo.js line:88
53+
*/
54+
def urlViaAttributes() : String = {
55+
if (m_licenseUrl != "") return m_licenseUrl
56+
var licenseUrl = m_licenseUrl;
57+
if (m_licenseType == "license2") {
58+
//No checkboxes selected
59+
if (!m_ccAllowCommercial && !m_ccAllowDerivative && !m_ccRequireShareAlike) {
60+
licenseUrl = "http://creativecommons.org/licenses/by-nc-nd/3.0/";
61+
}
62+
//Only commercial selected
63+
else if (m_ccAllowCommercial && !m_ccAllowDerivative && !m_ccRequireShareAlike) {
64+
licenseUrl = "http://creativecommons.org/licenses/by-nd/3.0/";
65+
}
66+
//Only remixing selected
67+
else if (!m_ccAllowCommercial && m_ccAllowDerivative && !m_ccRequireShareAlike) {
68+
licenseUrl = "http://creativecommons.org/licenses/by-nc/3.0/";
69+
}
70+
//Remixing and Sharealike selected
71+
else if (!m_ccAllowCommercial && m_ccAllowDerivative && m_ccRequireShareAlike) {
72+
licenseUrl = "http://creativecommons.org/licenses/by-nc-sa/3.0/";
73+
}
74+
//All checkboxes selected
75+
else if (m_ccAllowCommercial && m_ccAllowDerivative && m_ccRequireShareAlike) {
76+
licenseUrl = "http://creativecommons.org/licenses/by-sa/3.0/";
77+
}
78+
//Commercial and Remixing selected
79+
else if (m_ccAllowCommercial && m_ccAllowDerivative && !m_ccRequireShareAlike) {
80+
licenseUrl = "http://creativecommons.org/licenses/by/3.0/";
81+
}
82+
//else { rightsHolder = 'Creative Commons';
83+
// licenseText = 'Specific level info'; }
84+
}
85+
else if (m_licenseType == "license3") {
86+
licenseUrl = "http://creativecommons.org/publicdomain/zero/1.0/";
87+
}
88+
else {
89+
licenseUrl = "https://dbpedia.org/page/All_rights_reserved";
90+
}
91+
return licenseUrl
92+
}
93+
94+
/**
95+
* Utility function, similar to a json Write, to return string version in json-ld format
96+
* Should also return key
97+
*/
98+
def to_jsonld () : JsValue = {
99+
val licURI = this.urlViaAttributes() //URI = URL except in one case:
100+
val licURL = if (licURI != "https://dbpedia.org/page/All_rights_reserved") licURI
101+
else ""
102+
val licLD = JsObject(Seq(
103+
"@id" -> JsString(licURI),
104+
"URL" -> JsString(licURL),
105+
"@type" -> JsString("license"),
106+
"Text" -> JsString(m_licenseText) //added this DataType
107+
))
108+
return licLD
109+
}
110+
}

app/models/Section.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package models
22

3+
import play.api.libs.json._
4+
35
/**
46
* A portion of a file.
57
*
@@ -17,12 +19,17 @@ case class Section(
1719
metadataCount: Long = 0,
1820
@deprecated("use Metadata","since the use of jsonld") jsonldMetadata : List[Metadata]= List.empty,
1921
thumbnail_id: Option[String] = None,
20-
tags: List[Tag] = List.empty)
22+
tags: List[Tag] = List.empty) {
23+
def to_jsonld() : JsValue = {
24+
return Json.toJson(description)
25+
}
26+
}
27+
2128

2229
case class Rectangle(
2330
x: Double,
2431
y: Double,
2532
w: Double,
2633
h: Double) {
2734
override def toString() = f"x: $x%.2f, y: $y%.2f, width: $w%.2f, height: $h%.2f"
28-
}
35+
}

app/models/ServerStartTime.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package models
22

33
import java.util.Date
44

5+
56
/**
67
* Keeps track of server start time
78
* Used in Global Object
@@ -10,4 +11,4 @@ import java.util.Date
1011
object ServerStartTime {
1112
var startTime: Date=null
1213

13-
}
14+
}

app/models/Statistic.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ case class Statistics (
1010
downloads: Int = 0,
1111
last_viewed: Option[Date] = None,
1212
last_downloaded: Option[Date] = None
13-
)
13+
) {
14+
def to_jsonld() : JsValue = {
15+
return Json.toJson(views)
16+
}
17+
}
18+
1419

1520
case class StatisticUser (
1621
user_id: UUID,

app/models/Tag.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package models
22

33
import java.util.Date
44

5+
import play.api.libs.json._
6+
7+
58
/**
69
* Add and remove tags
710
*
@@ -11,4 +14,8 @@ case class Tag(
1114
name: String,
1215
userId: Option[String],
1316
extractor_id: Option[String],
14-
created: Date)
17+
created: Date) {
18+
def to_json() : JsValue = {
19+
return Json.toJson(name)
20+
}
21+
}

0 commit comments

Comments
 (0)