-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDataset.scala
More file actions
134 lines (124 loc) · 4.55 KB
/
Dataset.scala
File metadata and controls
134 lines (124 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package models
import com.mongodb.casbah.Imports._
import java.util.Date
import play.api.libs.json.{Writes, Json}
import play.api.libs.json._
import play.api.libs.functional.syntax._
import _root_.util.Formatters
/**
* A dataset is a collection of files, and streams.
*/
case class Dataset(
id: UUID = UUID.generate,
name: String = "N/A",
author: MiniUser,
description: String = "N/A",
created: Date,
files: List[UUID] = List.empty,
folders: List[UUID] = List.empty,
streams_id: List[ObjectId] = List.empty,
tags: List[Tag] = List.empty,
metadataCount: Long = 0,
collections: List[UUID] = List.empty,
thumbnail_id: Option[String] = None,
licenseData: LicenseData = new LicenseData(),
spaces: List[UUID] = List.empty,
lastModifiedDate: Date = new Date(),
trash : Boolean = false,
dateMovedToTrash : Option[Date] = None,
followers: List[UUID] = List.empty,
stats: Statistics = new Statistics(),
status: String = DatasetStatus.PRIVATE.toString, // dataset has four status: trial, default, private and public. yet editors of the dataset
// can only see the default, private and public, where trial equals to private. viewers can only see private and
// public, where trial and default equals to private/public of its space
creators: List[String] = List.empty
){
def isPublic:Boolean = status == DatasetStatus.PUBLIC.toString
def isDefault:Boolean = status == DatasetStatus.DEFAULT.toString
def isTRIAL:Boolean = status == DatasetStatus.TRIAL.toString
def inSpace:Boolean = spaces.size > 0
/**
* Caps a list at 'max'
* then turns it's ID's into resolvable URLs of that 'apiRoute' type
* end with appending "..." to the List, to signify that it was abridged
*
* todo: issue 354 to the max configurable
*/
def cap_api_list (l: List[UUID], max: Int, URLb: String, apiRoute: String) : List[String] = {
if (l.length <= max) {
return l.map(f => URLb + apiRoute + f)
} else {
val cl = l.take(max)
val r : List[String] = cl.map(f => URLb + apiRoute + f)
return r.::("...").reverse
}
}
/**
* return Dataset as JsValue in jsonld format
*/
def to_jsonld(url: String) : JsValue = {
val so = JsObject(Seq("@vocab" -> JsString("https://schema.org/")))
val URLb = url.replaceAll("/$", "")
var pic_id = thumbnail_id.getOrElse("")
if (pic_id != "") {
pic_id = URLb + pic_id
} else {
""
}
val datasetLD = Json.obj(
"@context" -> so,
"identifier" -> id.toString,
"name" -> name,
"author" -> author.to_jsonld(),
"description" -> description,
"dateCreated" -> Formatters.iso8601(created),
"DigitalDocument" -> Json.toJson(cap_api_list(files, 10, URLb, "/files/")),
"Collection" -> Json.toJson(cap_api_list(spaces, 10, URLb, "/spaces/")),
"thumbnail" -> Json.toJson(pic_id),
"license" -> licenseData.to_jsonld(),
"dateModfied" -> Formatters.iso8601(lastModifiedDate),
"keywords" -> tags.map(x => x.to_json()),
"creator" -> Json.toJson(creators)
)
return datasetLD
}
}
object DatasetStatus extends Enumeration {
type DatasetStatus = Value
val PUBLIC, PRIVATE, DEFAULT, TRIAL = Value
}
object Dataset {
implicit val datasetWrites = new Writes[Dataset] {
def writes(dataset: Dataset): JsValue = {
val datasetThumbnail = if(dataset.thumbnail_id.isEmpty) {
null
} else {
dataset.thumbnail_id.toString().substring(5,dataset.thumbnail_id.toString().length-1)
}
Json.obj(
"id" -> dataset.id.toString,
"name" -> dataset.name,
"description" -> dataset.description,
"created" -> dataset.created.toString,
"thumbnail" -> datasetThumbnail,
"authorId" -> dataset.author.id,
"spaces" -> dataset.spaces,
"resource_type" -> "dataset",
"license" -> Json.obj(
"license_type" -> dataset.licenseData.m_licenseType,
"license_url" -> dataset.licenseData.m_licenseUrl,
"license_text" -> dataset.licenseData.m_licenseText,
"holders" -> dataset.licenseData.m_rightsHolder,
"ccAllowCommercial" -> dataset.licenseData.m_ccAllowCommercial,
"ccAllowDerivative" -> dataset.licenseData.m_ccAllowDerivative,
"ccRequireShareAlike" -> dataset.licenseData.m_ccRequireShareAlike
)
)
}
}
}
case class DatasetAccess(
showAccess: Boolean = false,
access: String = "N/A",
accessOptions: List[String] = List.empty
)