Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/gazetteer/bo/LGTopic.java @ 41:ba9515f22897
new: topic management and adding sections from searching result into topic
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 17 Dec 2015 13:44:08 +0100 |
parents | |
children | 9dbbbfd474f4 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGTopic.java Thu Dec 17 13:44:08 2015 +0100 @@ -0,0 +1,227 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.json.JSONArray; + +import cl.maps.duplex.DuplexKey; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; + + +@Entity +@Table(name="Topic") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGTopic extends DBEntry implements Cloneable, Serializable { + private static final long serialVersionUID = 7805209462045170778L; + + @Column(name="userId") + private Long userId; + + @Column(name="contributors") + private String contributors = "[]"; + + @Column(name="nameEn") + private String nameEn; + + @Column(name="nameCh") + private String nameCh; + + @Column(name="namePinyin") + private String namePinyin; + + @Column(name="description") + private String description; + + + @Transient + private List<Long> contributorsList; + + + @Transient + private boolean transientDataLoaded = false; + + + + public boolean isEmpty() { + if (nameEn.equals("") || nameCh.equals("") || namePinyin.equals("") ) { + return true; + } else { + return false; + } + } + + + + + public boolean isTransientDataLoaded() { + return transientDataLoaded; + } + + + + public Object clone() throws CloneNotSupportedException { + LGTopic clone = (LGTopic)super.clone(); + clone.setContributorsList(new ArrayList<Long>(clone.getContributorsList())); + + return clone; + } + + + + public boolean hasContributor(Long userId){ + for(Long id : getContributorsList()){ + if(id.equals(userId)){ + return true; + } + } + return false; + } + + public List<Long> getContributorsList(){ + if(contributorsList == null){ + reloadContributorsList(); + } + return contributorsList; + } + + public List<String> getContributorsNameList(){ + List<String> list = new ArrayList<String>(); + for(Long userId : getContributorsList()){ + list.add(DataverseUtils.getUsername(userId)); + } + return list; + } + + public String getUsername(){ + if(this.userId != null){ + return DataverseUtils.getUsername(this.userId); + } + return null; + } + + private void reloadContributorsList(){ + this.contributorsList = new ArrayList<Long>(); + try { + JSONArray array = new JSONArray(this.contributors); + for(int i=0; i<array.length(); i++){ + this.contributorsList.add(array.getLong(i)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void addContributor(Long userId){ + if(!getContributorsList().contains(userId)){ + getContributorsList().add(userId); + } + upgradeContributors(); + } + + public void removeContributor(Long userId){ + if(getContributorsList().contains(userId)){ + getContributorsList().remove(userId); + this.upgradeContributors(); + } + } + + public void upgradeContributors(){ + JSONArray array = new JSONArray(getContributorsList()); + this.contributors = array.toString(); + } + + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getContributors() { + return contributors; + } + + public void setContributors(String contributors) { + this.contributors = contributors; + } + + + public String getNameEn() { + return nameEn; + } + + + public void setNameEn(String nameEn) { + this.nameEn = nameEn; + } + + + public String getNameCh() { + return nameCh; + } + + + public void setNameCh(String nameCh) { + this.nameCh = nameCh; + } + + + public String getNamePinyin() { + return namePinyin; + } + + + public void setNamePinyin(String namePinyin) { + this.namePinyin = namePinyin; + } + + + public String getDescription() { + return description; + } + + + + public void setDescription(String description) { + this.description = description; + } + + + + public void setContributorsList(List<Long> contributorsList) { + this.contributorsList = contributorsList; + } + + + public void setTransientDataLoaded(boolean transientDataLoaded) { + this.transientDataLoaded = transientDataLoaded; + } + + public DuplexKey<Long, Long> getKey(){ + return new DuplexKey<Long, Long>(this.userId, this.id); + } + + + @Override + public String toString(){ + return "LGTopic[nameEn=" + nameEn + ", nameCh=" + nameCh + ", namePinyin=" + namePinyin + "]"; + } + + +}