Commit 962bbbcd authored by Matija Obreza's avatar Matija Obreza
Browse files

All character @Lob need Hibernate

@Type(type="org.hibernate.type.TextType") for PostgreSQL
parent d9d5366c
......@@ -16,22 +16,22 @@
package org.genesys2.server.model;
import javax.persistence.Lob;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
/**
* This superclass adds a Resource Description Framework (RDF) Uniform Resource Identifier (URI)
* to records to link them with semantic web linked open (meta-)data
* This superclass adds a Resource Description Framework (RDF) Uniform Resource
* Identifier (URI) to records to link them with semantic web linked open
* (meta-)data
*
* @author Richard Bruskiewich
*
*
*/
@MappedSuperclass
public abstract class GlobalVersionedAuditedModel extends VersionedAuditedModel {
@Lob
@Column(length = 500)
private String rdfUri;
public String getRdfUri() {
return this.rdfUri;
......@@ -40,23 +40,22 @@ public abstract class GlobalVersionedAuditedModel extends VersionedAuditedModel
public void setRdfUri(final String rdfUri) {
this.rdfUri = rdfUri;
}
public String getRdfUriId()
{
if(this.rdfUri == null)
return "" ;
public String getRdfUriId() {
if (this.rdfUri == null)
return "";
else {
// first, check for hash URIs
String[] hashpart = rdfUri.split("#") ;
if(hashpart.length>1)
String[] hashpart = rdfUri.split("#");
if (hashpart.length > 1)
// assumed well-formed URI.. tail part is the RDF ID
return hashpart[1] ;
else
// not a hash uri... hmmm...
// since this should be a term URI,
return hashpart[1];
else
// not a hash uri... hmmm...
// since this should be a term URI,
// then take the tail part of the path as the RDF ID
return rdfUri.substring(rdfUri.lastIndexOf('/')+1) ;
return rdfUri.substring(rdfUri.lastIndexOf('/') + 1);
}
}
}
......@@ -26,6 +26,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.annotations.Type;
/**
* AllAcqBreeding generated by hbm2java
......@@ -46,6 +47,7 @@ public class AccessionBreeding extends BusinessModel {
@Column(name = "pedigree")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String pedigree;
public AccessionBreeding() {
......
......@@ -26,6 +26,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.annotations.Type;
/**
* Collecting data
......@@ -55,14 +56,17 @@ public class AccessionCollect extends BusinessModel {
@Column(name = "collName")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String collName;
@Column(name = "collInstAddress")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String collInstAddress;
@Column(name = "collSite")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String collSite;
@Column
......
......@@ -26,6 +26,7 @@ import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.annotations.Type;
/**
* AllAccnames generated by hbm2java
......@@ -43,10 +44,12 @@ public class AllAccnames extends BusinessModel {
@Column(name = "names")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String accNames;
@Column(name = "otherIds")
@Lob
@Type(type = "org.hibernate.type.TextType")
private String otherIds;
public AllAccnames() {
......
......@@ -33,6 +33,7 @@ import javax.persistence.TemporalType;
import org.apache.commons.lang.math.RandomUtils;
import org.genesys2.server.model.VersionedAuditedModel;
import org.genesys2.server.servlet.controller.rest.serialization.MaterialRequestSerializer;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
......@@ -55,17 +56,18 @@ public class MaterialRequest extends VersionedAuditedModel {
@Column(length = 100000)
@Lob
@Type(type = "org.hibernate.type.TextType")
private String body;
@Column(length = 32, nullable = true)
private String pid;
@OneToMany(cascade={}, mappedBy="sourceRequest")
@OneToMany(cascade = {}, mappedBy = "sourceRequest")
private List<MaterialSubRequest> subRequests;
@Temporal(TemporalType.TIMESTAMP)
private Date lastReminderDate;
@PrePersist
void prepersist() {
if (this.uuid == null)
......@@ -131,15 +133,15 @@ public class MaterialRequest extends VersionedAuditedModel {
public List<MaterialSubRequest> getSubRequests() {
return this.subRequests;
}
public void setSubRequests(List<MaterialSubRequest> subRequests) {
this.subRequests = subRequests;
}
public Date getLastReminderDate() {
return lastReminderDate;
}
public void setLastReminderDate(Date lastReminderDate) {
this.lastReminderDate = lastReminderDate;
}
......
......@@ -32,6 +32,7 @@ import javax.persistence.TemporalType;
import org.apache.commons.lang.math.RandomUtils;
import org.genesys2.server.model.VersionedAuditedModel;
import org.genesys2.server.servlet.controller.rest.serialization.MaterialSubRequestSerializer;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
......@@ -63,6 +64,7 @@ public class MaterialSubRequest extends VersionedAuditedModel {
@Column(length = 100000)
@Lob
@Type(type = "org.hibernate.type.TextType")
private String body;
@ManyToOne(cascade = {}, optional = false)
......
......@@ -28,6 +28,7 @@ import javax.persistence.Table;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.VersionedAuditedModel;
import org.genesys2.server.model.impl.GeoReferencedEntity;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
......@@ -64,10 +65,12 @@ public class Metadata extends VersionedAuditedModel implements AclAwareModel, Ge
private Double elevation;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(store = Store.NO)
private String citation;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(name = "body", store = Store.NO)
private String description;
......
......@@ -34,6 +34,7 @@ import javax.persistence.Transient;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -53,6 +54,7 @@ public class Method extends GlobalVersionedAuditedModel implements AclAwareModel
@Column(nullable = false)
@Lob
@Type(type = "org.hibernate.type.TextType")
private String method;
@Lob
......@@ -65,6 +67,7 @@ public class Method extends GlobalVersionedAuditedModel implements AclAwareModel
private String unit;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String options;
@Column(nullable = false, length = 32)
......@@ -104,37 +107,39 @@ public class Method extends GlobalVersionedAuditedModel implements AclAwareModel
}
}
}
@Transient
private Map<String,String> methodMap = new HashMap<String,String>();
private Map<String, String> methodMap = new HashMap<String, String>();
/**
* Method to return the map of available languages keys
* @return Map<String,String> with language code as the key and the vernacular string as the value.
*
* @return Map<String,String> with language code as the key and the
* vernacular string as the value.
*/
public Map<String,String> getLocalMethodMap() {
return buildLocalMethodMap() ;
public Map<String, String> getLocalMethodMap() {
return buildLocalMethodMap();
}
private synchronized Map<String,String> buildLocalMethodMap() {
if (this.methodMap.isEmpty() && this.i18n != null) {
parseMethodLocal() ;
Iterator<String> languages = this.methodJ.fieldNames() ;
while(languages.hasNext()) {
String language = languages.next() ;
methodMap.put(language, this.methodJ.get(language).textValue()) ;
private synchronized Map<String, String> buildLocalMethodMap() {
if (this.methodMap.isEmpty() && this.i18n != null) {
parseMethodLocal();
Iterator<String> languages = this.methodJ.fieldNames();
while (languages.hasNext()) {
String language = languages.next();
methodMap.put(language, this.methodJ.get(language).textValue());
}
}
return methodMap ;
return methodMap;
}
public String getMethod(Locale locale) {
return getMethodLocal(locale);
}
private synchronized String getMethodLocal(Locale locale) {
parseMethodLocal() ;
parseMethodLocal();
return this.methodJ != null && this.methodJ.has(locale.getLanguage()) ? this.methodJ.get(locale.getLanguage()).textValue() : this.method;
}
......
......@@ -35,6 +35,7 @@ import javax.persistence.Transient;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.genesys2.server.model.impl.Crop;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -61,6 +62,7 @@ public class Parameter extends GlobalVersionedAuditedModel implements AclAwareMo
private String title;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String i18n;
@Transient
......@@ -103,6 +105,7 @@ public class Parameter extends GlobalVersionedAuditedModel implements AclAwareMo
public void setI18n(String i18n) {
this.i18n = i18n;
}
private synchronized void parseTitleLocal() {
if (this.titleJ == null && this.i18n != null) {
ObjectMapper mapper = new ObjectMapper();
......@@ -111,39 +114,41 @@ public class Parameter extends GlobalVersionedAuditedModel implements AclAwareMo
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Transient
private Map<String,String> titleMap = new HashMap<String,String>();
private Map<String, String> titleMap = new HashMap<String, String>();
/**
* Method to return the map of available languages keys
* @return Map<String,String> with language code as the key and the vernacular string as the value.
*
* @return Map<String,String> with language code as the key and the
* vernacular string as the value.
*/
public Map<String,String> getLocalTitleMap() {
return buildLocalTitleMap() ;
}
private synchronized Map<String,String> buildLocalTitleMap() {
if (this.titleMap.isEmpty() && this.i18n != null) {
parseTitleLocal() ;
Iterator<String> languages = this.titleJ.fieldNames() ;
while(languages.hasNext()) {
String language = languages.next() ;
titleMap.put(language, this.titleJ.get(language).textValue()) ;
public Map<String, String> getLocalTitleMap() {
return buildLocalTitleMap();
}
private synchronized Map<String, String> buildLocalTitleMap() {
if (this.titleMap.isEmpty() && this.i18n != null) {
parseTitleLocal();
Iterator<String> languages = this.titleJ.fieldNames();
while (languages.hasNext()) {
String language = languages.next();
titleMap.put(language, this.titleJ.get(language).textValue());
}
}
return titleMap ;
return titleMap;
}
public String getTitle(Locale locale) {
return getTitleLocal(locale);
}
private synchronized String getTitleLocal(Locale locale) {
parseTitleLocal() ;
parseTitleLocal();
return this.titleJ != null && this.titleJ.has(locale.getLanguage()) ? this.titleJ.get(locale.getLanguage()).textValue() : this.title;
}
......
......@@ -28,6 +28,7 @@ import javax.persistence.Lob;
import javax.persistence.Transient;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -38,6 +39,7 @@ public class ParameterCategory extends GlobalVersionedAuditedModel {
private String name;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String nameL;
@Transient
......@@ -71,35 +73,37 @@ public class ParameterCategory extends GlobalVersionedAuditedModel {
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Transient
private Map<String,String> nameMap = new HashMap<String,String>();
private Map<String, String> nameMap = new HashMap<String, String>();
/**
* Method to return the map of available languages keys
* @return Map<String,String> with language code as the key and the vernacular string as the value.
*
* @return Map<String,String> with language code as the key and the
* vernacular string as the value.
*/
public Map<String,String> getLocalNameMap() {
return buildLocalNameMap() ;
public Map<String, String> getLocalNameMap() {
return buildLocalNameMap();
}
private synchronized Map<String,String> buildLocalNameMap() {
if (this.nameMap.isEmpty() && this.nameL != null) {
parseNameLocal() ;
Iterator<String> languages = this.nameJ.fieldNames() ;
while(languages.hasNext()) {
String language = languages.next() ;
nameMap.put(language, this.nameJ.get(language).textValue()) ;
private synchronized Map<String, String> buildLocalNameMap() {
if (this.nameMap.isEmpty() && this.nameL != null) {
parseNameLocal();
Iterator<String> languages = this.nameJ.fieldNames();
while (languages.hasNext()) {
String language = languages.next();
nameMap.put(language, this.nameJ.get(language).textValue());
}
}
return nameMap ;
return nameMap;
}
private synchronized String getNameLocal(Locale locale) {
parseNameLocal() ;
parseNameLocal();
return this.nameJ != null && this.nameJ.has(locale.getLanguage()) ? this.nameJ.get(locale.getLanguage()).textValue() : this.name;
}
......
......@@ -31,6 +31,7 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Indexed;
@Entity
......@@ -58,6 +59,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@Column(nullable = false)
@Lob
@Type(type = "org.hibernate.type.TextType")
private String taxonName;
private Long taxGenus;
......
......@@ -26,6 +26,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys2.server.model.AuditedModel;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
......@@ -42,6 +43,7 @@ public class ActivityPost extends AuditedModel {
private String title;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(name = "body", store = Store.NO)
private String body;
......
......@@ -28,6 +28,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys2.server.model.AuditedModel;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
......@@ -56,10 +57,12 @@ public class Article extends AuditedModel {
private String lang;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(name = "title", store = Store.NO)
private String title;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Column(length = 100000)
@Field(name = "body", store = Store.NO)
private String body;
......
......@@ -33,6 +33,7 @@ import javax.persistence.Transient;
import org.genesys2.server.model.BusinessModel;
import org.genesys2.server.servlet.controller.rest.serialization.CountrySerializer;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
......@@ -69,10 +70,12 @@ public class Country extends BusinessModel {
* Localized names
*/
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(name = "body", store = Store.NO)
private String nameL;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String wikiLink;
@Transient
......
......@@ -17,7 +17,6 @@
package org.genesys2.server.model.impl;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
//import java.util.Iterator;
......@@ -36,6 +35,7 @@ import javax.persistence.Transient;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
......@@ -52,9 +52,9 @@ import org.genesys2.server.servlet.controller.rest.serialization.CropSerializer;
@Indexed
@JsonSerialize(using = CropSerializer.class)
public class Crop extends GlobalVersionedAuditedModel {
private static final long serialVersionUID = -2686341831839109257L;
public static final Log LOG = LogFactory.getLog(Crop.class);
/**
......@@ -68,10 +68,12 @@ public class Crop extends GlobalVersionedAuditedModel {
private String name;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Field(name = "body", store = Store.NO)
private String description;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String i18n;
/**
......@@ -125,7 +127,7 @@ public class Crop extends GlobalVersionedAuditedModel {
public void updateI18n(String i18n) {
// additional sanity check (but already checked elsewhere?)
if(!(i18n == null || StringUtils.isBlank(i18n)))
if (!(i18n == null || StringUtils.isBlank(i18n)))
update(i18n);
}
......@@ -136,41 +138,29 @@ public class Crop extends GlobalVersionedAuditedModel {
private JsonNode i18nJU;
/*
* This is meant to be a complex language tag merge operation... is there an easier way?
* This is meant to be a complex language tag merge operation... is there an
* easier way?
*/
private synchronized void update(String i18n) {
this.i18n = i18n ;
/** TODO Need to properly code and test this!
ObjectMapper mapper = new ObjectMapper();
try {
this.i18nJO = mapper.readTree(this.i18n);
this.i18nJU = mapper.readTree(i18n);
} catch (IOException e) {
System.err.println("I18n = " + i18n);
e.printStackTrace();