Last active
December 11, 2015 03:29
-
-
Save wombat/4538159 to your computer and use it in GitHub Desktop.
Dynamic product description translations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@XmlRootElement | |
@Entity | |
@Table(name = "sc_table") | |
@Inheritance(strategy = InheritanceType.JOINED) | |
@DiscriminatorColumn(name = "sc_table_type", discriminatorType = DiscriminatorType.STRING) | |
public class ScTable extends ScModel implements Serializable { | |
@Getter | |
@Setter | |
@Column(name = "code") | |
private String code; | |
@Getter | |
@Setter | |
@OneToMany(mappedBy = "scTable", cascade = CascadeType.ALL, orphanRemoval = true) | |
private List<Translation> translations = new ArrayList<Translation>(); | |
@Transient | |
private String description = ""; | |
public String getDescription() { | |
return getDescription("it"); | |
} | |
public void setDescription(String value) { | |
setDescription("it", value); | |
} | |
public String getDescription(String languageCode) { | |
String result = ""; | |
Translation translation = null; | |
for (Translation localeTranslation : translations) { | |
if (localeTranslation.getLanguageCode().equalsIgnoreCase( | |
languageCode)) { | |
translation = localeTranslation; | |
break; | |
} | |
} | |
if (translation != null) { | |
result = translation.getDescription(); | |
} | |
return result; | |
} | |
public void setDescription(String languageCode, String value) { | |
boolean localeUpdated = false; | |
if (translations == null) { | |
translations = new ArrayList<Translation>(); | |
} | |
for (Translation translation : translations) { | |
if (translation.getLanguageCode().equals(languageCode)) { | |
localeUpdated = true; | |
translation.setDescription(value); | |
break; | |
} | |
} | |
if (!localeUpdated) { | |
Translation ct = new Translation(); | |
ct.setLanguageCode(languageCode); | |
ct.setDescription(value); | |
ct.setScTable(this); | |
translations.add(ct); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@XmlRootElement | |
@Entity | |
@Table(name = "size") | |
@DiscriminatorValue(value = "size") | |
public class Size extends ScTable implements Serializable { | |
@Getter | |
@Setter | |
private String size = ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment