Commit 7cb1fdd2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Model fixed: country belongs to one region, regions have parentRegions

parent 8fb4949f
......@@ -55,9 +55,9 @@ public class Country extends BusinessModel {
private String codeNum;
private Long refnameId;
@ManyToOne()
@JoinTable(name = "georegioncountry", joinColumns = @JoinColumn(name = "coutryId"), inverseJoinColumns = @JoinColumn(name = "georegionId"))
private GeoRegion region;
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "regionId")
private GeoRegion region;
/**
* Localized names
......@@ -195,11 +195,11 @@ public class Country extends BusinessModel {
});
}
public GeoRegion getRegion() {
return region;
}
public GeoRegion getRegion() {
return region;
}
public void setRegion(GeoRegion region) {
this.region = region;
}
public void setRegion(GeoRegion region) {
this.region = region;
}
}
package org.genesys2.server.model.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.genesys2.server.model.VersionedModel;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@Entity
@Table(name="georegion")
public class GeoRegion extends BusinessModel {
private static final long serialVersionUID = -1L;
@Column
private String isoCode;
@Column
private String name;
@ManyToOne()
@JoinColumn(name = "parentId")
private GeoRegion parentId;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "georegioncountry", joinColumns = @JoinColumn(name = "georegionId"), inverseJoinColumns = @JoinColumn(name = "countryId"))
private List<Country> members;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String nameL;
@Transient
private JsonNode nameJ;
public String getIsoCode() {
return isoCode;
}
public void setIsoCode(String isoCode) {
this.isoCode = isoCode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Country> getMembers() {
return members;
}
public void setMembers(List<Country> members) {
this.members = members;
}
public GeoRegion getParentId() {
return parentId;
}
public void setParentId(GeoRegion parentId) {
this.parentId = parentId;
}
public String getNameL() {
return nameL;
}
public void setNameL(String nameL) {
this.nameL = nameL;
}
public void setName(Locale locale, String name) {
// TODO Fix this
final ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
// ObjectNode newLang =
// mapper.createObjectNode().put(locale.getLanguage(), name);
// System.err.println(newLang);
} catch (final IOException e) {
}
}
private synchronized String getNameLocal(Locale locale) {
if (this.nameJ == null && this.nameL != null) {
final ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
} catch (final IOException e) {
e.printStackTrace();
}
}
return this.nameJ != null && this.nameJ.has(locale.getLanguage()) ? this.nameJ.get(locale.getLanguage()).textValue() : this.name;
}
@Table(name = "georegion")
public class GeoRegion extends VersionedModel {
private static final long serialVersionUID = -1L;
@Column
private String isoCode;
@Column
private String name;
@ManyToOne()
@JoinColumn(name = "parentId")
private GeoRegion parentRegion;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "region")
private List<Country> countries;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String nameL;
@Transient
private JsonNode nameJ;
public String getIsoCode() {
return isoCode;
}
public void setIsoCode(String isoCode) {
this.isoCode = isoCode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Country> getCountries() {
return countries;
}
public void setCountries(List<Country> countries) {
this.countries = countries;
}
public GeoRegion getParentRegion() {
return parentRegion;
}
public void setParentRegion(GeoRegion parentRegion) {
this.parentRegion = parentRegion;
}
public String getNameL() {
return nameL;
}
public void setNameL(String nameL) {
this.nameL = nameL;
}
public void setName(Locale locale, String name) {
// TODO Fix this
final ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
// ObjectNode newLang =
// mapper.createObjectNode().put(locale.getLanguage(), name);
// System.err.println(newLang);
} catch (final IOException e) {
}
}
private synchronized String getNameLocal(Locale locale) {
if (this.nameJ == null && this.nameL != null) {
final ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
} catch (final IOException e) {
e.printStackTrace();
}
}
return this.nameJ != null && this.nameJ.has(locale.getLanguage()) ? this.nameJ.get(locale.getLanguage()).textValue() : this.name;
}
}
\ No newline at end of file
......@@ -74,25 +74,25 @@ public class GeoRegionDataCLDR {
String forLatinAmerica = "029,013,005";
for (String isoCode : continents.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(world));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(world));
}
for (String isoCode : forAfrica.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[0]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(continents.split(",")[0]));
}
for (String isoCode : forAmerica.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[1]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(continents.split(",")[1]));
}
for (String isoCode : forAsia.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[2]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(continents.split(",")[2]));
}
for (String isoCode : forEurope.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[3]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(continents.split(",")[3]));
}
for (String isoCode : forOceania.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[4]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(continents.split(",")[4]));
}
for (String isoCode : forLatinAmerica.split(",")) {
geoRegions.get(isoCode).setParentId(geoRegions.get(forAmerica.split(",")[0]));
geoRegions.get(isoCode).setParentRegion(geoRegions.get(forAmerica.split(",")[0]));
}
return new ArrayList<>(geoRegions.values());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment