Commit 3aa65c2b authored by Richard Bruskiewich's avatar Richard Bruskiewich Committed by Matija Obreza
Browse files

Defined a method, called getLocalNameMap(), returning a

Map<String,String> of language indexed vernacular strings
parent e2eedf80
......@@ -17,7 +17,10 @@
package org.genesys2.server.model.genesys;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
......@@ -60,7 +63,7 @@ public class ParameterCategory extends GlobalVersionedAuditedModel {
return getNameLocal(locale);
}
private synchronized String getNameLocal(Locale locale) {
private synchronized void parseNameLocal() {
if (this.nameJ == null && this.nameL != null) {
ObjectMapper mapper = new ObjectMapper();
try {
......@@ -68,7 +71,35 @@ public class ParameterCategory extends GlobalVersionedAuditedModel {
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Transient
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.
*/
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()) ;
}
}
return nameMap ;
}
private synchronized String getNameLocal(Locale locale) {
parseNameLocal() ;
return this.nameJ != null && this.nameJ.has(locale.getLanguage()) ? this.nameJ.get(locale.getLanguage()).textValue() : this.name;
}
......
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