Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
83b4786b
Commit
83b4786b
authored
May 03, 2018
by
Matija Obreza
Browse files
Merge branch '255-rename-model' into 'master'
Resolve "Rename model" Closes
#255
See merge request genesys-pgr/genesys-server!150
parents
b0af34c4
d5cc8be7
Changes
30
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/dataset/DS.java
View file @
83b4786b
...
...
@@ -3,6 +3,7 @@ package org.genesys2.server.model.dataset;
import
java.util.List
;
import
java.util.UUID
;
import
javax.persistence.CascadeType
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.OneToMany
;
...
...
@@ -23,12 +24,12 @@ public class DS extends BasicModel {
private
UUID
uuid
;
@OrderBy
(
"index"
)
@OneToMany
(
mappedBy
=
"dataset"
)
@OneToMany
(
mappedBy
=
"dataset"
,
cascade
=
{
CascadeType
.
ALL
}
)
private
List
<
DSQualifier
>
qualifiers
;
@OrderBy
(
"index"
)
@OneToMany
(
mappedBy
=
"dataset"
)
private
List
<
DS
Descriptor
>
descriptor
s
;
@OneToMany
(
mappedBy
=
"dataset"
,
cascade
=
{
CascadeType
.
ALL
}
)
private
List
<
DS
Column
>
column
s
;
/**
* Generate UUID if missing
...
...
@@ -56,11 +57,11 @@ public class DS extends BasicModel {
this
.
qualifiers
=
qualifiers
;
}
public
List
<
DS
Descriptor
>
getDescriptor
s
()
{
return
descriptor
s
;
public
List
<
DS
Column
>
getColumn
s
()
{
return
column
s
;
}
public
void
set
Descriptors
(
List
<
DSDescriptor
>
descriptor
s
)
{
this
.
descriptors
=
descriptor
s
;
public
void
set
Columns
(
List
<
DSColumn
>
column
s
)
{
this
.
columns
=
column
s
;
}
}
src/main/java/org/genesys2/server/model/dataset/DSColumn.java
0 → 100644
View file @
83b4786b
package
org.genesys2.server.model.dataset
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.Table
;
import
org.genesys.blocks.model.BasicModel
;
/**
* Dataset column.
*/
@Entity
@Table
(
name
=
"ds2column"
)
public
class
DSColumn
extends
BasicModel
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
7693331325536594367L
;
@Column
(
name
=
"idx"
)
private
float
index
=
1.0f
;
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"ds"
)
private
DS
dataset
;
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"d"
)
private
DSDescriptor
descriptor
;
public
float
getIndex
()
{
return
index
;
}
public
void
setIndex
(
float
index
)
{
this
.
index
=
index
;
}
public
DS
getDataset
()
{
return
dataset
;
}
public
void
setDataset
(
DS
dataset
)
{
this
.
dataset
=
dataset
;
}
public
DSDescriptor
getDescriptor
()
{
return
descriptor
;
}
public
void
setDescriptor
(
DSDescriptor
descriptor
)
{
this
.
descriptor
=
descriptor
;
}
@Override
public
String
toString
()
{
return
"DSD "
+
this
.
getId
();
}
}
src/main/java/org/genesys2/server/model/dataset/DSDescriptor.java
View file @
83b4786b
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.model.dataset
;
import
java.text.MessageFormat
;
import
java.util.UUID
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.
JoinColumn
;
import
javax.persistence.
ManyToOne
;
import
javax.persistence.
Lob
;
import
javax.persistence.
PrePersist
;
import
javax.persistence.Table
;
import
org.genesys.blocks.model.BasicModel
;
import
org.
genesys2.server.model.impl.Descriptor
;
import
org.
hibernate.annotations.Type
;
/**
* Dataset descriptor
* A DSDescriptor represents a dimension of a sparse vector.
*
* @author mobreza
*/
@Entity
@Table
(
name
=
"ds2descriptor"
)
public
class
DSDescriptor
extends
BasicModel
{
private
static
final
long
serialVersionUID
=
3832200593904442940L
;
@Column
(
unique
=
true
,
nullable
=
false
,
updatable
=
false
)
@Type
(
type
=
"uuid-binary"
)
private
UUID
uuid
;
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
private
String
title
;
@Column
(
nullable
=
false
,
length
=
200
)
private
String
code
;
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
private
String
description
;
@Column
(
length
=
20
)
private
String
uom
;
/**
*
*
Generate UUID if missing
*/
private
static
final
long
serialVersionUID
=
-
7693331325536594367L
;
@PrePersist
protected
void
prepersist
()
{
if
(
this
.
uuid
==
null
)
{
this
.
uuid
=
UUID
.
randomUUID
();
}
}
@Column
(
name
=
"idx"
)
private
float
index
=
1.0f
;
public
UUID
getUuid
()
{
return
uuid
;
}
public
void
setUuid
(
UUID
uuid
)
{
this
.
uuid
=
uuid
;
}
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"ds"
)
private
DS
dataset
;
public
String
getTitle
()
{
return
title
;
}
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"d"
)
private
Descriptor
descriptor
;
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
float
get
In
de
x
()
{
return
in
de
x
;
public
String
get
Co
de
()
{
return
co
de
;
}
public
void
set
Index
(
float
in
de
x
)
{
this
.
in
de
x
=
in
de
x
;
public
void
set
Code
(
String
co
de
)
{
this
.
co
de
=
co
de
;
}
public
DS
getDataset
()
{
return
d
ataset
;
public
String
getDescription
()
{
return
d
escription
;
}
public
void
setD
ataset
(
DS
dataset
)
{
this
.
d
ataset
=
dataset
;
public
void
setD
escription
(
final
String
description
)
{
this
.
d
escription
=
description
;
}
public
Descriptor
getDescriptor
()
{
return
descriptor
;
public
String
getUom
()
{
return
uom
;
}
public
void
set
Descriptor
(
Descriptor
descriptor
)
{
this
.
descriptor
=
descriptor
;
public
void
set
Uom
(
String
uom
)
{
this
.
uom
=
uom
;
}
@Override
public
String
toString
()
{
return
"DSD "
+
this
.
getId
(
);
return
MessageFormat
.
format
(
"DSDescriptor id={0,number,#} name={1}"
,
getId
(),
code
);
}
}
src/main/java/org/genesys2/server/model/dataset/DSQualifier.java
View file @
83b4786b
...
...
@@ -7,10 +7,9 @@ import javax.persistence.ManyToOne;
import
javax.persistence.Table
;
import
org.genesys.blocks.model.BasicModel
;
import
org.genesys2.server.model.impl.Descriptor
;
/**
*
D
ataset qualifier
specification
*
The d
ataset qualifier
is a key lookup component for dataset rows.
*/
@Entity
@Table
(
name
=
"ds2qualifier"
)
...
...
@@ -30,7 +29,7 @@ public class DSQualifier extends BasicModel {
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"d"
)
private
Descriptor
descriptor
;
private
DS
Descriptor
descriptor
;
public
float
getIndex
()
{
return
index
;
...
...
@@ -48,11 +47,11 @@ public class DSQualifier extends BasicModel {
this
.
dataset
=
dataset
;
}
public
Descriptor
getDescriptor
()
{
public
DS
Descriptor
getDescriptor
()
{
return
descriptor
;
}
public
void
setDescriptor
(
Descriptor
descriptor
)
{
public
void
setDescriptor
(
DS
Descriptor
descriptor
)
{
this
.
descriptor
=
descriptor
;
}
...
...
src/main/java/org/genesys2/server/model/dataset/DSRow.java
View file @
83b4786b
package
org.genesys2.server.model.dataset
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
import
javax.persistence.CascadeType
;
...
...
@@ -12,23 +13,36 @@ import javax.persistence.Id;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OneToMany
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreUpdate
;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.genesys.blocks.model.EntityId
;
/**
* Represents a row in a DS2 dataset. The row has a unique {@link #id} and
* groups together different {@link DSValue} values (column values).
*
* The row is qualified by a list of row qualifiers ({@link DSRowQualifier})
* that represent the "keys" of the row. Their SHA-1 and MD5 sums are calculated
* and stored in {@link #sha1} and {@link #md5} respectively.
*
* @author Matija Obreza
*/
@Entity
@Table
(
name
=
"ds2row"
,
uniqueConstraints
=
{
@UniqueConstraint
(
columnNames
=
{
"md5"
,
"sha1"
})
})
public
class
DSRow
implements
EntityId
{
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"ds"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"ds"
)
private
DS
dataset
;
@OneToMany
(
fetch
=
FetchType
.
LAZY
,
mappedBy
=
"row"
,
cascade
=
{
CascadeType
.
REMOVE
})
@OneToMany
(
fetch
=
FetchType
.
LAZY
,
mappedBy
=
"row"
,
cascade
=
{
CascadeType
.
ALL
})
private
List
<
DSRowQualifier
<?>>
rowQualifiers
;
@OneToMany
(
fetch
=
FetchType
.
LAZY
,
mappedBy
=
"row"
)
@OneToMany
(
fetch
=
FetchType
.
LAZY
,
mappedBy
=
"row"
,
cascade
=
{
CascadeType
.
ALL
}
)
private
List
<
DSValue
<?>>
values
;
@Id
...
...
@@ -41,6 +55,19 @@ public class DSRow implements EntityId {
@Column
(
columnDefinition
=
"binary(20)"
,
updatable
=
false
)
private
byte
[]
sha1
;
@PrePersist
@PreUpdate
private
void
prePersist
()
{
ByteBuffer
keyBuffer
=
ByteBuffer
.
allocate
(
500
);
for
(
DSRowQualifier
<?>
dsq
:
this
.
getRowQualifiers
())
{
dsq
.
putKey
(
keyBuffer
);
}
byte
[]
array
=
keyBuffer
.
array
();
this
.
md5
=
DigestUtils
.
md5
(
array
);
this
.
sha1
=
DigestUtils
.
sha1
(
array
);
}
@Override
public
Long
getId
()
{
return
this
.
id
;
...
...
@@ -53,11 +80,11 @@ public class DSRow implements EntityId {
public
DS
getDataset
()
{
return
dataset
;
}
public
void
setDataset
(
DS
dataset
)
{
this
.
dataset
=
dataset
;
}
public
List
<
DSRowQualifier
<?>>
getRowQualifiers
()
{
return
rowQualifiers
;
}
...
...
src/main/java/org/genesys2/server/model/dataset/DSRowQualifier.java
View file @
83b4786b
package
org.genesys2.server.model.dataset
;
import
java.nio.ByteBuffer
;
import
javax.persistence.DiscriminatorColumn
;
import
javax.persistence.DiscriminatorType
;
import
javax.persistence.Entity
;
...
...
@@ -14,6 +16,16 @@ import javax.persistence.JoinColumn;
import
javax.persistence.ManyToOne
;
import
javax.persistence.Table
;
/**
* Abstract class {@link DSRowQualifier} represents the "columns" of a
* {@link DSRow} that serve as "keys" or qualifying columns to a row. A row may
* have more than one qualifier and are not necessarily unique, but provide a
* fast mechanism to look up values in a row ({@link DSValue}).
*
* @author Matija Obreza
*
* @param <T> type of qualifier value
*/
@Entity
@Table
(
name
=
"ds2rowqualifier"
,
indexes
=
{
@Index
(
columnList
=
"dsq, vall"
)
})
@Inheritance
(
strategy
=
InheritanceType
.
SINGLE_TABLE
)
...
...
@@ -70,4 +82,5 @@ public abstract class DSRowQualifier<T> {
return
null
;
}
public
abstract
void
putKey
(
ByteBuffer
keyBuffer
);
}
src/main/java/org/genesys2/server/model/dataset/DSRowQualifierLong.java
View file @
83b4786b
package
org.genesys2.server.model.dataset
;
import
java.nio.ByteBuffer
;
import
javax.persistence.Column
;
import
javax.persistence.DiscriminatorValue
;
import
javax.persistence.Entity
;
...
...
@@ -20,5 +22,9 @@ public class DSRowQualifierLong extends DSRowQualifier<Long> {
public
void
setValue
(
Long
value
)
{
this
.
value
=
value
;
}
@Override
public
void
putKey
(
ByteBuffer
keyBuffer
)
{
keyBuffer
.
putLong
(
this
.
value
);
}
}
src/main/java/org/genesys2/server/model/dataset/DSValue.java
View file @
83b4786b
...
...
@@ -15,7 +15,7 @@ import javax.persistence.ManyToOne;
import
javax.persistence.Table
;
@Entity
@Table
(
name
=
"ds2value"
,
indexes
=
{
@Index
(
columnList
=
"r,ds
d
"
),
@Index
(
columnList
=
"ds
d
,vall"
),
@Index
(
columnList
=
"ds
d
,vald"
)
})
@Table
(
name
=
"ds2value"
,
indexes
=
{
@Index
(
columnList
=
"r,ds
c
"
),
@Index
(
columnList
=
"ds
c
,vall"
),
@Index
(
columnList
=
"ds
c
,vald"
)
})
@Inheritance
(
strategy
=
InheritanceType
.
SINGLE_TABLE
)
@DiscriminatorColumn
(
discriminatorType
=
DiscriminatorType
.
INTEGER
,
name
=
"typ"
)
public
abstract
class
DSValue
<
T
>
{
...
...
@@ -28,8 +28,8 @@ public abstract class DSValue<T> {
private
DSRow
row
;
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"ds
d
"
)
private
DS
Descriptor
datasetDescriptor
;
@JoinColumn
(
name
=
"ds
c
"
)
private
DS
Column
datasetColumn
;
public
abstract
T
getValue
();
...
...
@@ -51,12 +51,12 @@ public abstract class DSValue<T> {
this
.
row
=
row
;
}
public
DS
Descriptor
getDataset
Descriptor
()
{
return
dataset
Descriptor
;
public
DS
Column
getDataset
Column
()
{
return
dataset
Column
;
}
public
void
setDataset
Descriptor
(
DSDescriptor
datasetDescriptor
)
{
this
.
dataset
Descriptor
=
datasetDescriptor
;
public
void
setDataset
Column
(
DSColumn
datasetColumn
)
{
this
.
dataset
Column
=
datasetColumn
;
}
public
static
DSValue
<?>
make
(
Object
v
)
{
...
...
src/main/java/org/genesys2/server/model/genesys/AccessionGeo.java
View file @
83b4786b
...
...
@@ -21,12 +21,15 @@ import javax.persistence.Entity;
import
javax.persistence.FetchType
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.OneToOne
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreUpdate
;
import
javax.persistence.Table
;
import
javax.persistence.Version
;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys.blocks.auditlog.annotations.Audited
;
import
org.genesys.blocks.model.BasicModel
;
import
org.genesys.worldclim.WorldClimUtil
;
import
org.genesys2.server.model.impl.GeoReferencedEntity
;
@Entity
...
...
@@ -57,6 +60,15 @@ public class AccessionGeo extends BasicModel implements GeoReferencedEntity, Acc
private
Long
tileIndex
;
/**
* Recalculate {@link #tileIndex} on insert and update
*/
@PrePersist
@PreUpdate
private
void
prePersist
()
{
tileIndex
=
WorldClimUtil
.
getTileIndex
(
5
,
this
.
longitude
,
this
.
latitude
);
}
public
long
getVersion
()
{
return
version
;
}
...
...
src/main/java/org/genesys2/server/model/impl/Descriptor.java
deleted
100644 → 0
View file @
b0af34c4
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.model.impl
;
import
java.text.MessageFormat
;
import
java.util.UUID
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Lob
;
import
javax.persistence.PrePersist
;
import
javax.persistence.Table
;
import
org.genesys.blocks.model.BasicModel
;
import
org.hibernate.annotations.Type
;
/**
* A Descriptor represents a dimension of a sparse vector.
*
* @author mobreza
*/
@Entity
@Table
(
name
=
"descriptor"
)
public
class
Descriptor
extends
BasicModel
{
private
static
final
long
serialVersionUID
=
3832200593904442940L
;
@Column
(
unique
=
true
,
nullable
=
false
,
updatable
=
false
)
@Type
(
type
=
"uuid-binary"
)
private
UUID
uuid
;
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
private
String
title
;
@Column
(
nullable
=
false
,
length
=
200
)
private
String
code
;
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
private
String
description
;
@Column
(
length
=
20
)
private
String
uom
;
/**
* Generate UUID if missing
*/
@PrePersist
protected
void
prepersist
()
{
if
(
this
.
uuid
==
null
)
{
this
.
uuid
=
UUID
.
randomUUID
();
}
}
public
UUID
getUuid
()
{
return
uuid
;
}
public
void
setUuid
(
UUID
uuid
)
{
this
.
uuid
=
uuid
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
final
String
description
)
{
this
.
description
=
description
;
}
public
String
getUom
()
{
return
uom
;
}
public
void
setUom
(
String
uom
)
{
this
.
uom
=
uom
;
}
@Override
public
String
toString
()
{
return
MessageFormat
.