/* * * Copyright (C) 2007-2015 Licensed to the Comunes Association (CA) under * one or more contributor license agreements (see COPYRIGHT for details). * The CA licenses this file to you under the GNU Affero General Public * License version 3, (the "License"); you may not use this file except in * compliance with the License. This file is part of kune. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package cc.kune.domain; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Indexed; import cc.kune.domain.utils.HasId; // TODO: Auto-generated Javadoc /** * GlobalizeTranslations generated by hbm2java from original rails globalize * schema. * * @author vjrj@ourproject.org (Vicente J. Ruiz Jurado) */ @Entity @Indexed @Table(name = "globalize_translations") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class I18nTranslation implements HasId { /** The Constant DEF_NAMESPACE. */ public static final String DEF_NAMESPACE = "kune_core"; /** The Constant DEF_PLUR_INDEX. */ public static final Integer DEF_PLUR_INDEX = 1; /** The Constant DEFAULT_LANG. */ public static final String DEFAULT_LANG = "en"; /** The Constant UNTRANSLATED_VALUE. */ public static final String UNTRANSLATED_VALUE = null; /** The facet. */ @Column(name = "facet") private String facet; /** The id. */ @Id @GeneratedValue @DocumentId @Column(name = "id", unique = true, nullable = false) private Long id; /** The item id. */ @Column(name = "item_id") private Integer itemId; /** The language. */ @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "language_id") private I18nLanguage language; /** The note for translators. */ private String noteForTranslators; /** The parent. */ @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "parent_id") private I18nTranslation parent; /** The pluralization index. */ @Column(name = "pluralization_index") private Integer pluralizationIndex; /** The table name. */ @Column(name = "table_name") private String tableName; /** The text. */ @Column(name = "text") private String text; /** The tr key. */ @org.hibernate.annotations.Index(name = "tr_key") @Column(name = "tr_key") private String trKey; /** The type. */ @org.hibernate.annotations.Index(name = "gtype") @Column(name = "gtype") private String type; /** * Instantiates a new i18n translation. */ public I18nTranslation() { this(null, null, null, null, null, "", null, null, null, null); } /** * Instantiates a new i18n translation. * * @param language * the language * @param text * the text * @param parent * the parent * @param noteForTranslators * the note for translators */ public I18nTranslation(final I18nLanguage language, final String text, final I18nTranslation parent, final String noteForTranslators) { this("", null, DEF_PLUR_INDEX, "", text, null, DEF_NAMESPACE, language, parent, noteForTranslators); } /** * Instantiates a new i18n translation. * * @param trKey * the tr key * @param language * the language * @param text * the text * @param noteForTranslators * the note for translators */ public I18nTranslation(final String trKey, final I18nLanguage language, final String text, final String noteForTranslators) { this("", null, DEF_PLUR_INDEX, "", text, trKey, DEF_NAMESPACE, language, null, noteForTranslators); } /** * Instantiates a new i18n translation. * * @param facet * the facet * @param itemId * the item id * @param pluralizationIndex * the pluralization index * @param tableName * the table name * @param text * the text * @param trKey * the tr key * @param type * the type * @param language * the language * @param parent * the parent * @param noteForTranslators * the note for translators */ public I18nTranslation(final String facet, final Integer itemId, final Integer pluralizationIndex, final String tableName, final String text, final String trKey, final String type, final I18nLanguage language, final I18nTranslation parent, final String noteForTranslators) { this.type = type; this.trKey = trKey; this.tableName = tableName; this.itemId = itemId; this.facet = facet; this.language = language; this.pluralizationIndex = pluralizationIndex; this.text = text; this.parent = parent; this.setNoteForTranslators(noteForTranslators); if (parent == null) { assert trKey != null; this.parent = this; } if (parent != null) { assert trKey == null; } } /** * Clone for new language. * * @return the i18n translation */ public I18nTranslation cloneForNewLanguage() { return new I18nTranslation(facet, itemId, pluralizationIndex, tableName, null, null, type, null, this, null); } /** * Gets the facet. * * @return the facet */ public String getFacet() { return this.facet; } /* * (non-Javadoc) * * @see cc.kune.domain.utils.HasId#getId() */ @Override public Long getId() { return this.id; } /** * Gets the item id. * * @return the item id */ public Integer getItemId() { return this.itemId; } /** * Gets the language. * * @return the language */ public I18nLanguage getLanguage() { return language; } /** * Gets the note for translators. * * @return the note for translators */ public String getNoteForTranslators() { if (parent == this) { return noteForTranslators; } return parent.getNoteForTranslators(); } /** * The id of what we are translating. * * @return the parent id */ public I18nTranslation getParent() { return parent; } /** * Gets the parent id. * * @return the parent id */ public Long getParentId() { if (parent == this) { return id; } return parent.getId(); } /** * Gets the pluralization index. * * @return the pluralization index */ public Integer getPluralizationIndex() { return this.pluralizationIndex; } /** * Gets the table name. * * @return the table name */ public String getTableName() { return this.tableName; } /** * Gets the text. * * @return the text */ public String getText() { return this.text; } /** * Gets the tr key. * * @return the tr key */ public String getTrKey() { if (parent == this) { return trKey; } return parent.getTrKey(); } /** * Gets the type. * * @return the type */ public String getType() { return this.type; } /** * Sets the facet. * * @param facet * the new facet */ public void setFacet(final String facet) { this.facet = facet; } /* * (non-Javadoc) * * @see cc.kune.domain.utils.HasId#setId(java.lang.Long) */ @Override public void setId(final Long id) { this.id = id; } /** * Sets the item id. * * @param itemId * the new item id */ public void setItemId(final Integer itemId) { this.itemId = itemId; } /** * Sets the language. * * @param language * the new language */ public void setLanguage(final I18nLanguage language) { this.language = language; } /** * Sets the note for translators. * * @param noteForTranslators * the new note for translators */ public void setNoteForTranslators(final String noteForTranslators) { this.noteForTranslators = noteForTranslators; } /** * Sets the parent id. * * @param parent * the new parent id */ public void setParentId(final I18nTranslation parent) { this.parent = parent; } /** * Sets the pluralization index. * * @param pluralizationIndex * the new pluralization index */ public void setPluralizationIndex(final Integer pluralizationIndex) { this.pluralizationIndex = pluralizationIndex; } /** * Sets the table name. * * @param tableName * the new table name */ public void setTableName(final String tableName) { this.tableName = tableName; } /** * Sets the text. * * @param text * the new text */ public void setText(final String text) { this.text = text; } /** * Sets the tr key. * * @param trKey * the new tr key */ public void setTrKey(final String trKey) { this.trKey = trKey; } /** * Sets the type. * * @param type * the new type */ public void setType(final String type) { this.type = type; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "I18nTranslation[" + getTrKey() + " (" + language + ") " + text + "]"; } }