Commit 6d04d874 authored by Matija Obreza's avatar Matija Obreza

Dataview: Support translations for Dataviews

parent 9e7a14bd
......@@ -124,4 +124,36 @@ public abstract class AuditedModel extends EmptyModel implements LazyLoading<Aud
return this;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AuditedModel other = (AuditedModel) obj;
if (getId() == null) {
return super.equals(obj);
} else if (getId().equals(other.getId())) {
return true;
}
return super.equals(obj);
}
@Override
public String toString() {
return this.getClass() + "#id=" + getId();
}
}
\ No newline at end of file
......@@ -15,9 +15,12 @@
*/
package org.gringlobal.model;
import java.util.List;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
......@@ -90,6 +93,10 @@ public class SysDataviewField extends CooperatorOwnedModel {
@Column(name = "table_alias_name", length = 100)
private String tableAliasName;
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "sysDataviewField")
@JsonIgnore
private List<SysDataviewFieldLang> langs;
public SysDataviewField() {
}
......@@ -208,4 +215,12 @@ public class SysDataviewField extends CooperatorOwnedModel {
public void setTableAliasName(final String tableAliasName) {
this.tableAliasName = tableAliasName;
}
public List<SysDataviewFieldLang> getLangs() {
return langs;
}
public void setLangs(List<SysDataviewFieldLang> langs) {
this.langs = langs;
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@
*/
package org.gringlobal.model;
import java.util.Locale;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
......@@ -124,4 +126,8 @@ public class SysLang extends CooperatorOwnedModel {
public void setTitle(final String title) {
this.title = title;
}
public Locale toLocale() {
return Locale.forLanguageTag(this.ietfTag);
}
}
\ No newline at end of file
......@@ -15,10 +15,13 @@
*/
package org.gringlobal.model;
import java.util.List;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
......@@ -117,6 +120,10 @@ public class SysTableField extends CooperatorOwnedModel {
@JsonIdentityInfo(scope = SysTable.class, property = "tableName", generator = ObjectIdGenerators.PropertyGenerator.class)
private SysTable table;
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "sysTableField")
@JsonIgnore
private List<SysTableFieldLang> langs;
public SysTableField() {
}
......@@ -283,4 +290,12 @@ public class SysTableField extends CooperatorOwnedModel {
public void setTable(final SysTable sysTable) {
this.table = sysTable;
}
public List<SysTableFieldLang> getLangs() {
return langs;
}
public void setLangs(List<SysTableFieldLang> langs) {
this.langs = langs;
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@
package org.gringlobal.service;
import java.util.List;
import java.util.Locale;
import org.gringlobal.model.SysLang;
......@@ -39,4 +40,12 @@ public interface LanguageService extends CRUDService<SysLang> {
*/
List<SysLang> listAll();
/**
* Gets the language for the specified locale.
*
* @param locale the locale
* @return the language
*/
SysLang getLanguage(Locale locale);
}
......@@ -16,6 +16,7 @@
package org.gringlobal.service.impl;
import java.util.List;
import java.util.Locale;
import org.gringlobal.model.SysLang;
import org.gringlobal.persistence.SysLangRepository;
......@@ -59,6 +60,22 @@ public class LanguageServiceImpl extends CRUDServiceImpl<SysLang, SysLangReposit
}
return sysLang;
}
@Override
public SysLang getLanguage(Locale locale) {
SysLang sysLang = null;
List<SysLang> languages = repository.findAll();
for (SysLang sl : languages) {
if (sysLang == null && sl.getIetfTag().startsWith(locale.getLanguage() + "-")) {
sysLang = sl;
}
if (sl.getIetfTag().equalsIgnoreCase(locale.toLanguageTag())) {
sysLang = sl;
break;
}
}
return sysLang;
}
@Override
public List<SysLang> listAll() {
......
......@@ -38,6 +38,7 @@ import org.gringlobal.persistence.SysUserRepository;
import org.gringlobal.service.UserService;
import org.gringlobal.service.filter.SysUserFilter;
import org.gringlobal.spring.TransactionHelper;
import org.hibernate.Hibernate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......@@ -189,7 +190,8 @@ public class UserServiceImpl implements UserService, InitializingBean {
assert user != null;
if (user.getCooperator() != null) {
user.getCooperator().getId();
Hibernate.initialize(user.getCooperator());
Hibernate.initialize(user.getCooperator().getSysLang());
}
user.getAuthorities().size(); // loads SysGroupUserMap
}
......
......@@ -22,6 +22,7 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import org.apache.commons.lang3.StringUtils;
import org.gringlobal.model.SysUser;
import org.gringlobal.service.UserService;
import org.gringlobal.soap.BaseEndpoint;
import org.jdom2.Document;
......@@ -34,6 +35,7 @@ import org.jdom2.xpath.XPathFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
......@@ -100,6 +102,10 @@ public class SoapAuthenticationInterceptor extends EndpointInterceptorAdapter {
final Authentication authToken = authenticationManager.authenticate(request);
LOG.debug("Auth authorities: {}", authToken.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authToken);
if (user instanceof SysUser) {
// Setting user locale
LocaleContextHolder.setLocale(((SysUser) user).getCooperator().getSysLang().toLocale());
}
}
}
return true;
......
......@@ -133,7 +133,7 @@ public class OrderRequestControllerTest extends AbstractApiV1Test {
Cooperator shipToCooperator = cooperatorRepository.findById(cooperator.getId()).orElse(null);
assertThat(shipToCooperator, is(notNullValue()));
assertThat(shipToCooperator, not(equalToObject(cooperator)));
assertThat(shipToCooperator, equalToObject(cooperator));
orderRequest.setShipToCooperator(shipToCooperator);
assertThat(orderRequest.getShipToCooperator(), is(notNullValue()));
......
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