Advertisement
Guest User

project

a guest
Sep 16th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. package com.beligum.futuretalents.fttv.models.project;
  2.  
  3. import com.beligum.core.framework.models.BasicModel;
  4. import com.beligum.futuretalents.fttv.models.Contribution;
  5. import com.beligum.futuretalents.fttv.models.Tuples.Author;
  6. import com.beligum.futuretalents.fttv.models.Tuples.Collaboration;
  7. import com.beligum.futuretalents.fttv.models.Tuples.MediaModel;
  8. import com.beligum.futuretalents.fttv.models.media.Media;
  9. import com.beligum.futuretalents.fttv.models.media.MediaVimeo;
  10. import com.beligum.futuretalents.fttv.models.taxonomy.Comment;
  11. import com.beligum.futuretalents.fttv.models.taxonomy.Tag;
  12. import com.beligum.futuretalents.fttv.models.taxonomy.Tool;
  13. import org.joda.time.LocalDateTime;
  14.  
  15. import javax.persistence.*;
  16. import javax.xml.bind.annotation.XmlRootElement;
  17. import javax.xml.bind.annotation.XmlTransient;
  18. import java.lang.Integer;
  19. import java.lang.String;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.Set;
  23.  
  24. /**
  25. * Created by Ruben on 08/08/14
  26. */
  27.  
  28. @Entity
  29. @XmlRootElement
  30. @Table(name = "projects")
  31. @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  32. @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
  33. @DiscriminatorValue("default")
  34. public class Project extends BasicModel
  35. {
  36.  
  37. public Integer version;
  38.  
  39. private String title;
  40.  
  41. @Lob
  42. private String description;
  43.  
  44. private int status;
  45.  
  46. @OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
  47. private List<Contribution> contributions;
  48.  
  49. @OneToOne(mappedBy = "project", cascade = CascadeType.ALL)
  50. private Media media;
  51.  
  52. @OneToMany(mappedBy = "selectedProject", cascade = CascadeType.ALL)
  53. private List<Comment> comments;
  54.  
  55. private LocalDateTime date;
  56.  
  57. @ManyToMany
  58. @JoinTable(
  59. name="project_tags",
  60. joinColumns={@JoinColumn(name="proj_id")},
  61. inverseJoinColumns={@JoinColumn(name="tag_id")})
  62. private Set<Tag> tags;
  63.  
  64. @ManyToMany(mappedBy = "toolsTaggedProjects")
  65. private Set<Tool> tools;
  66.  
  67. //-----CACHED VARIABLES-----
  68. @Transient
  69. private Author cachedAuthor;
  70.  
  71. public Project() {
  72.  
  73. }
  74.  
  75. public Project(Integer version, String title, String description, int status, List<Contribution> contributions, Media media, List<Comment> comments, LocalDateTime date, Set<Tag> tags, Set<Tool> tools, Author cachedAuthor) {
  76. this.version = version;
  77. this.title = title;
  78. this.description = description;
  79. this.status = status;
  80. this.contributions = contributions;
  81. this.media = media;
  82. this.comments = comments;
  83. this.date = date;
  84. this.tags = tags;
  85. this.tools = tools;
  86. this.cachedAuthor = cachedAuthor;
  87. }
  88.  
  89. public String getTitle()
  90. {
  91. return this.title;
  92. }
  93.  
  94. public void setTitle(String title)
  95. {
  96. this.title = title;
  97. }
  98.  
  99. public String getDescription()
  100. {
  101. return this.description;
  102. }
  103. public void setDescription(String description)
  104. {
  105. this.description = description;
  106. }
  107.  
  108. @XmlTransient
  109. public int getStatus()
  110. {
  111. return this.status;
  112. }
  113. public void setStatus(int status)
  114. {
  115. this.status = status;
  116. }
  117.  
  118. @XmlTransient
  119. public List<Contribution> getContributions() {
  120. return contributions;
  121. }
  122. public void setContributions(List<Contribution> contributions) {
  123. this.contributions = contributions;
  124. }
  125.  
  126. public void setComments(List<Comment> comments)
  127. {
  128. this.comments = comments;
  129. }
  130.  
  131. @XmlTransient
  132. public Integer getVersion() {
  133. return version;
  134. }
  135. public void setVersion(Integer version) {
  136. this.version = version;
  137. }
  138.  
  139. @XmlTransient
  140. public LocalDateTime getCreatedAt(){
  141. return super.getCreatedAt();
  142. }
  143.  
  144. @XmlTransient
  145. public LocalDateTime getUpdatedAt(){
  146. return super.getUpdatedAt();
  147. }
  148.  
  149. @XmlTransient
  150. public String getJSonHash(){
  151. return super.getJsonHash();
  152. }
  153.  
  154. @XmlTransient
  155. public Author getCachedAuthor() {
  156. return cachedAuthor;
  157. }
  158.  
  159. public void setCachedAuthor(Author cachedAuthor) {
  160. this.cachedAuthor = cachedAuthor;
  161. }
  162.  
  163. @Transient
  164. public Author getAuthor(){
  165.  
  166. if (this.cachedAuthor == null) {
  167.  
  168. Contribution tempContr = new Contribution();
  169. if(this.getContributions() != null){
  170. for (int i = 0; i < this.getContributions().size(); i++) {
  171. tempContr = this.getContributions().get(i);
  172. if (tempContr.getStudent().getId() == this.getCreatedBy().getId()) {
  173. cachedAuthor = new Author(tempContr.getStudent());
  174. break;
  175. }
  176. }
  177. }
  178. }
  179.  
  180. return this.cachedAuthor;
  181. }
  182.  
  183. @Transient
  184. public List<Collaboration> getCollaborations() {
  185. ArrayList collaborations = new ArrayList();
  186. if(this.getContributions()!=null) {
  187. for (int i = 0; i < this.getContributions().size(); i++) {
  188. collaborations.add(new Collaboration(this.getContributions().get(i).getStudent(), this.getContributions().get(i).getJob()));
  189. }
  190. }
  191. return collaborations;
  192. }
  193.  
  194. @Transient
  195. public LocalDateTime getCreated_at(){
  196. return this.createdAt;
  197. }
  198.  
  199. @Transient
  200. public LocalDateTime getUpdated_at(){
  201. return this.updatedAt;
  202. }
  203.  
  204.  
  205. public Set<Tool> getTools() {
  206. return tools;
  207. }
  208.  
  209. public void setTools(Set<Tool> tools) {
  210. this.tools = tools;
  211. }
  212.  
  213. public Set<Tag> getTags() {
  214. return tags;
  215. }
  216.  
  217. public void setTags(Set<Tag> tags) {
  218. this.tags = tags;
  219. }
  220.  
  221. public Media getMedia() {
  222. return media;
  223. }
  224.  
  225. public void setMedia(Media media) {
  226. this.media = media;
  227. }
  228.  
  229. @Transient
  230. public List<String> getPromoted(){
  231. ArrayList promoted = new ArrayList();
  232. if(this.getAllComments()!=null) {
  233. for (int i = 0; i < this.getAllComments().size(); i++) {
  234. if (this.getAllComments().get(i).getRating() != 0) {
  235. promoted.add(this.getAllComments().get(i).getUserName());
  236. }
  237. }
  238. }
  239. return promoted;
  240. }
  241.  
  242. public LocalDateTime getDate() {
  243. return date;
  244. }
  245.  
  246. public void setDate(LocalDateTime date) {
  247. this.date = date;
  248. }
  249.  
  250. @XmlTransient
  251. public List<Comment> getAllComments()
  252. {
  253. return this.comments;
  254. }
  255.  
  256. @Transient
  257. public List<Comment> getComments()
  258. {
  259. return this.comments;
  260. }
  261.  
  262. //@Transient
  263. //public MediaModel getMedia(){
  264. // return new MediaModel();
  265. //}
  266.  
  267.  
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement