Commit 8fb4949f authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

copy i18n from Country to GeoRegion

parent 56cb04f3
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;
@Entity
@Table(name="georegion")
......@@ -17,16 +22,21 @@ public class GeoRegion extends BusinessModel {
@Column
private String name;
@Column
private Long parentId;
@Transient
private GeoRegion parentGeoRegion;
@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;
}
......@@ -43,15 +53,6 @@ public class GeoRegion extends BusinessModel {
this.name = name;
}
public GeoRegion getParentGeoRegion() {
return parentGeoRegion;
}
public void setParentGeoRegion(GeoRegion parentGeoRegion) {
this.parentGeoRegion = parentGeoRegion;
}
public List<Country> getMembers() {
return members;
}
......@@ -60,11 +61,44 @@ public class GeoRegion extends BusinessModel {
this.members = members;
}
public Long getParentId() {
public GeoRegion getParentId() {
return parentId;
}
public void setParentId(Long 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;
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.GeoRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
......@@ -14,8 +13,10 @@ import javax.annotation.Resource;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
......@@ -73,25 +74,25 @@ public class GeoRegionDataCLDR {
String forLatinAmerica = "029,013,005";
for (String isoCode : continents.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(world));
geoRegions.get(isoCode).setParentId(geoRegions.get(world));
}
for (String isoCode : forAfrica.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(continents.split(",")[0]));
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[0]));
}
for (String isoCode : forAmerica.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(continents.split(",")[1]));
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[1]));
}
for (String isoCode : forAsia.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(continents.split(",")[2]));
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[2]));
}
for (String isoCode : forEurope.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(continents.split(",")[3]));
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[3]));
}
for (String isoCode : forOceania.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(continents.split(",")[4]));
geoRegions.get(isoCode).setParentId(geoRegions.get(continents.split(",")[4]));
}
for (String isoCode : forLatinAmerica.split(",")) {
geoRegions.get(isoCode).setParentGeoRegion(geoRegions.get(forAmerica.split(",")[0]));
geoRegions.get(isoCode).setParentId(geoRegions.get(forAmerica.split(",")[0]));
}
return new ArrayList<>(geoRegions.values());
......
......@@ -16,35 +16,17 @@
package org.genesys2.server.servlet.controller.admin;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.service.CountryNamesUpdater;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.ContentSanitizer;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
import org.genesys2.server.service.worker.InstituteUpdater;
import org.genesys2.server.service.worker.SGSVUpdate;
import org.genesys2.server.service.worker.WorldClimUpdater;
import org.genesys2.server.service.worker.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jdbc.core.RowCallbackHandler;
......@@ -56,7 +38,14 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.xml.sax.SAXException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Controller
@RequestMapping("/admin")
......@@ -380,7 +369,9 @@ public class AdminController {
@RequestMapping(value = "/georegion", method = RequestMethod.POST)
public String updateGeoReg() throws IOException, ParserConfigurationException, SAXException {
geoRegionService.updateGeoRegionData();
if (geoRegionService.findAll().isEmpty()) {
geoRegionService.updateGeoRegionData();
}
return "redirect:/admin/";
}
}
Markdown is supported
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