forked from AtlasOfLivingAustralia/collectory-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollection.groovy
405 lines (359 loc) · 13.5 KB
/
Collection.groovy
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/* *************************************************************************
* Copyright (C) 2011 Atlas of Living Australia
* All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
***************************************************************************/
package au.org.ala.collectory
import grails.converters.JSON
class Collection extends ProviderGroup implements Serializable {
def idGeneratorService
static final String ENTITY_TYPE = 'Collection'
static final String ENTITY_PREFIX = 'co'
static auditable = [ignore: ['version','dateCreated','lastUpdated','userLastModified']]
String collectionType // list of type of collection as JSON e.g ['live', 'preserved', 'tissue', 'DNA']
String active // tdwg developmentStatus
int numRecords = ProviderGroup.NO_INFO_AVAILABLE
// total number of records held that are able to be digitised
int numRecordsDigitised = ProviderGroup.NO_INFO_AVAILABLE
// number of records that are digitised
/* Coverage - What the collection covers */
// Geographic Coverage
String states // states and territories that are covered by the collection - see state vocab
String geographicDescription// a free text description of where the data relates to
BigDecimal eastCoordinate = ProviderGroup.NO_INFO_AVAILABLE
// furthest point East for this collection in decimal degrees
BigDecimal westCoordinate = ProviderGroup.NO_INFO_AVAILABLE
// furthest point West for this collection in decimal degrees
BigDecimal northCoordinate = ProviderGroup.NO_INFO_AVAILABLE
// furthest point North for this collection in decimal degrees
BigDecimal southCoordinate = ProviderGroup.NO_INFO_AVAILABLE
// furthest point South for this collection in decimal degrees
//Temporal Coverage - Time period the collection covers single_date The single date that the collection covers
String startDate // the start date of the period the collection covers
String endDate // the end date of the period the collection covers
//Taxonomic - Taxonomic coverage
String kingdomCoverage // the higher taxonomy that the collection covers - see kingdom_coverage vocab
// a space-separated string that can contain any number of these values:
// Animalia Archaebacteria Eubacteria Fungi Plantae Protista
String scientificNames // as JSON array eg ["Insecta", "Arachnida"]
String subCollections // list of sub-collections as JSON
//TODO: add curatorialUnit - one of specimens, lots, cultures, samples, batches
// the owning institution
Institution institution
static belongsTo = Institution
// maps to exactly one providerMap
static hasOne = [providerMap: ProviderMap]
static transients = ['listOfCollectionCodesForLookup', 'listOfinstitutionCodesForLookup','mappable','inexactlyMapped','attributionList']
static mapping = {
sort: 'name'
subCollections type: 'text'
keywords type: 'text'
kingdomCoverage type: 'text'
scientificNames type: 'text'
pubDescription type: "text"
techDescription type: "text"
focus type: "text"
taxonomyHints type: "text"
notes type: "text"
networkMembership type: "text"
}
// based on TDWG Ontology - http://code.google.com/p/tdwg-ontology/source/browse/trunk/ontology/voc/CollectionType.rdf
static collectionTypes = ["archival","art","audio","cellcultures","electronic","facsimiles","fossils","genetic",
"living","observations","preserved","products","seedbank","taxonomic","texts","tissue","visual"]
// based on TDWG Ontology - http://code.google.com/p/tdwg-ontology/source/browse/trunk/ontology/voc/Collection.rdf
static kingdoms = ['Animalia', 'Archaebacteria', 'Eubacteria', 'Fungi', 'Plantae', 'Protista']
// based on TDWG Ontology - http://code.google.com/p/tdwg-ontology/source/browse/trunk/ontology/voc/Collection.rdf
static developmentStatuses = ['Active growth', 'Closed', 'Consumable', 'Decreasing', 'Lost', 'Missing', 'Passive growth', 'Static']
static constraints = {
collectionType(nullable: true, maxSize: 256,
validator: { ct ->
if (!ct) {return true}
ct.each {
if (!Collection.collectionTypes.contains(it)) {return false}
}
return true
})
keywords(nullable:true, maxSize:1024)
active(nullable:true, inList:developmentStatuses)
numRecords()
numRecordsDigitised()
states(nullable:true)
geographicDescription(nullable:true)
eastCoordinate(max:360.0, min:-360.0, scale:10)
westCoordinate(max:360.0, min:-360.0, scale:10)
northCoordinate(max:360.0, min:-360.0, scale:10)
southCoordinate(max:360.0, min:-360.0, scale:10)
startDate(nullable:true, maxSize:45)
endDate(nullable:true, maxSize:45)
kingdomCoverage(nullable:true, maxSize:1024,
validator: { kc ->
if (!kc) {
return true
}
boolean ok = true
// split value by spaces
kc.split(" ").each {
if (!kingdoms.contains(it)) {
ok = false // return false does not work here!
}
}
return ok
})
scientificNames(nullable:true, maxSize:2048)
subCollections(nullable:true, maxSize:8192)
providerMap(nullable:true)
institution(nullable:true)
}
/**
* Returns sub-collections as a list of maps where each contains a name and a description.
*
* @return List<Map>
*/
def listSubCollections() {
def result = []
if (subCollections) {
JSON.parse(subCollections).each {
result << [name: it.name, description: it.description]
}
}
return result
}
/**
* Returns collection types as a list of string.
*
* @return List<Map>
*/
def listCollectionTypes() {
if (!collectionType) {
return []
}
return JSON.parse(collectionType).collect { it.toString() }
}
/**
* Returns keywords as a list of string.
*
* @return List<Map>
*/
def listKeywords() {
if (!keywords) {
return []
}
return JSON.parse(keywords).collect { it.toString() }
}
/**
* Returns scientific names as a list of string.
*
* @return List<String>
*/
def listScientificNames() {
if (!scientificNames) {
return []
}
return JSON.parse(scientificNames).collect { it.toString() }
}
/**
* Returns kingdoms as a list of String.
*
* @return List<String>
*/
def listKingdoms() {
if (kingdomCoverage) {
return kingdomCoverage.tokenize(' ')
} else {
return []
}
}
/*
* Returns the list of collection codes that can be used to look up specimen records
*
* @return the list of codes - may be empty
* @.history 2-8-2010 changed to use code/map tables
*/
List<String> getListOfCollectionCodesForLookup() {
if (providerMap) {
return providerMap.getCollectionCodes()*.code
} else {
return []
}
}
/**
* Returns the list of provider codes for the institution. Used to look up specimen records.
*
* @return the list of codes - may be empty
* @.history 2-8-2010 changed to use code/map tables
*/
List<String> getListOfInstitutionCodesForLookup() {
if (providerMap) {
return providerMap.getInstitutionCodes()*.code
} else {
return []
}
}
/**
* Returns true only if there is a provider code mapping and that mapping is known to be inexact.
*
* @return
*/
boolean isInexactlyMapped() {
if (providerMap) {
return !providerMap.isExact()
}
return false
}
/**
* Returns a list of all hubs this collection belongs to.
*
* @return list of DataHub
*/
List listHubMembership() {
DataHub.list().findAll {it.isCollectionMember(uid)}
}
/**
* Returns a summary of the collection including:
* - id
* - name
* - acronym
* - lsid if available
* - institution (id,uid, name & logo url) if available
* - description
* - provider codes for matching with biocache records
*
* @return CollectionSummary
*/
CollectionSummary buildSummary() {
CollectionSummary cs = init(new CollectionSummary()) as CollectionSummary
if (institution) {
cs.institutionName = institution.name
cs.institutionId = institution.id
cs.institutionUid = institution.uid
if (institution.logoRef?.file) {
cs.institutionLogoUrl = au.org.ala.collectory.Utilities.buildInstitutionLogoUrl(institution.logoRef.file)
}
}
cs.collectionId = cs.id
cs.collectionUid = cs.uid
cs.collectionName = cs.name
cs.derivedInstCodes = getListOfInstitutionCodesForLookup()
cs.derivedCollCodes = getListOfCollectionCodesForLookup()
cs.hubMembership = listHubMembership().collect { [uid: it.uid, name: it.name] }
listProviders().each {
def pg = ProviderGroup._get(it)
if (pg) {
if (it[0..1] == 'dp') {
cs.relatedDataProviders << [uid: pg.uid, name: pg.name]
} else {
cs.relatedDataResources << [uid: pg.uid, name: pg.name]
}
}
}
return cs
}
/**
* Returns true if:
* a) parent institution is a partner
* b) has membership of a collection network (hub) (assumed that all hubs are partners)
* c) has isALAPartner set
*
* NOTE: restriction on abstract methods
*/
boolean isALAPartner() {
if (institution?.isALAPartner()) {
return true
} else if (networkMembership != null && networkMembership != "[]") {
return true
} else {
return this.isALAPartner
}
}
/**
* Returns true if the group can be mapped.
*
* Can be mapped if the collection or its institution have valid lat and long.
* @return
*/
boolean canBeMapped() {
if (latitude != 0.0 && latitude != -1 && longitude != 0.0 && longitude != -1) {
return true
}
// use parent institution if lat/long not defined
if (institution && institution.latitude != 0.0 && institution.latitude != -1 &&
institution.longitude != 0.0 && institution.longitude != -1) {
return true
}
return false
}
Map inheritedLatLng() {
if (institution && institution.latitude != 0.0 && institution.latitude != -1 &&
institution.longitude != 0.0 && institution.longitude != -1) {
return [lat: institution.latitude, lng: institution.longitude]
}
return [:]
}
def List<Attribution> getAttributionList() {
List<Attribution> list = super.getAttributionList();
// add institution
if (institution) {
list << new Attribution(name: institution.name, url: institution.websiteUrl, uid: institution.uid)
}
return list
}
/**
* Return the institution's address if the collection does not have one.
* @return
*/
@Override def resolveAddress() {
return super.resolveAddress() ?: institution?.resolveAddress()
}
/**
* Returns the entity that is responsible for creating this resource - the institution if there is one.
* @return
*/
@Override def createdBy() {
return institution ? institution.createdBy() : super.createdBy()
}
/**
* Return the institution's logo if the collection does not have one.
* @return
*/
@Override def buildLogoUrl() {
if (logoRef) {
return super.buildLogoUrl()
}
else {
return institution?.buildLogoUrl()
}
}
/**
* Returns the best available primary contact.
* @return
*/
@Override
ContactFor inheritPrimaryContact() {
return getPrimaryContact() ?: institution?.inheritPrimaryContact()
}
/**
* Returns the best available primary contact that can be published.
* @return
*/
@Override
ContactFor inheritPrimaryPublicContact() {
return getPrimaryPublicContact() ?: institution?.inheritPrimaryPublicContact()
}
@Override
def parent() {
return institution
}
long dbId() { return id }
String entityType() {
return ENTITY_TYPE
}
}