Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.beligum.futuretalents.fttv.models.project;
- import com.beligum.core.framework.models.BasicModel;
- import com.beligum.futuretalents.fttv.models.Contribution;
- import com.beligum.futuretalents.fttv.models.Tuples.Author;
- import com.beligum.futuretalents.fttv.models.Tuples.Collaboration;
- import com.beligum.futuretalents.fttv.models.Tuples.MediaModel;
- import com.beligum.futuretalents.fttv.models.media.Media;
- import com.beligum.futuretalents.fttv.models.media.MediaVimeo;
- import com.beligum.futuretalents.fttv.models.taxonomy.Comment;
- import com.beligum.futuretalents.fttv.models.taxonomy.Tag;
- import com.beligum.futuretalents.fttv.models.taxonomy.Tool;
- import org.joda.time.LocalDateTime;
- import javax.persistence.*;
- import javax.xml.bind.annotation.XmlRootElement;
- import javax.xml.bind.annotation.XmlTransient;
- import java.lang.Integer;
- import java.lang.String;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Set;
- /**
- * Created by Ruben on 08/08/14
- */
- @Entity
- @XmlRootElement
- @Table(name = "projects")
- @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
- @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
- @DiscriminatorValue("default")
- public class Project extends BasicModel
- {
- public Integer version;
- private String title;
- @Lob
- private String description;
- private int status;
- @OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
- private List<Contribution> contributions;
- @OneToOne(mappedBy = "project", cascade = CascadeType.ALL)
- private Media media;
- @OneToMany(mappedBy = "selectedProject", cascade = CascadeType.ALL)
- private List<Comment> comments;
- private LocalDateTime date;
- @ManyToMany
- @JoinTable(
- name="project_tags",
- joinColumns={@JoinColumn(name="proj_id")},
- inverseJoinColumns={@JoinColumn(name="tag_id")})
- private Set<Tag> tags;
- @ManyToMany(mappedBy = "toolsTaggedProjects")
- private Set<Tool> tools;
- //-----CACHED VARIABLES-----
- @Transient
- private Author cachedAuthor;
- public Project() {
- }
- 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) {
- this.version = version;
- this.title = title;
- this.description = description;
- this.status = status;
- this.contributions = contributions;
- this.media = media;
- this.comments = comments;
- this.date = date;
- this.tags = tags;
- this.tools = tools;
- this.cachedAuthor = cachedAuthor;
- }
- public String getTitle()
- {
- return this.title;
- }
- public void setTitle(String title)
- {
- this.title = title;
- }
- public String getDescription()
- {
- return this.description;
- }
- public void setDescription(String description)
- {
- this.description = description;
- }
- @XmlTransient
- public int getStatus()
- {
- return this.status;
- }
- public void setStatus(int status)
- {
- this.status = status;
- }
- @XmlTransient
- public List<Contribution> getContributions() {
- return contributions;
- }
- public void setContributions(List<Contribution> contributions) {
- this.contributions = contributions;
- }
- public void setComments(List<Comment> comments)
- {
- this.comments = comments;
- }
- @XmlTransient
- public Integer getVersion() {
- return version;
- }
- public void setVersion(Integer version) {
- this.version = version;
- }
- @XmlTransient
- public LocalDateTime getCreatedAt(){
- return super.getCreatedAt();
- }
- @XmlTransient
- public LocalDateTime getUpdatedAt(){
- return super.getUpdatedAt();
- }
- @XmlTransient
- public String getJSonHash(){
- return super.getJsonHash();
- }
- @XmlTransient
- public Author getCachedAuthor() {
- return cachedAuthor;
- }
- public void setCachedAuthor(Author cachedAuthor) {
- this.cachedAuthor = cachedAuthor;
- }
- @Transient
- public Author getAuthor(){
- if (this.cachedAuthor == null) {
- Contribution tempContr = new Contribution();
- if(this.getContributions() != null){
- for (int i = 0; i < this.getContributions().size(); i++) {
- tempContr = this.getContributions().get(i);
- if (tempContr.getStudent().getId() == this.getCreatedBy().getId()) {
- cachedAuthor = new Author(tempContr.getStudent());
- break;
- }
- }
- }
- }
- return this.cachedAuthor;
- }
- @Transient
- public List<Collaboration> getCollaborations() {
- ArrayList collaborations = new ArrayList();
- if(this.getContributions()!=null) {
- for (int i = 0; i < this.getContributions().size(); i++) {
- collaborations.add(new Collaboration(this.getContributions().get(i).getStudent(), this.getContributions().get(i).getJob()));
- }
- }
- return collaborations;
- }
- @Transient
- public LocalDateTime getCreated_at(){
- return this.createdAt;
- }
- @Transient
- public LocalDateTime getUpdated_at(){
- return this.updatedAt;
- }
- public Set<Tool> getTools() {
- return tools;
- }
- public void setTools(Set<Tool> tools) {
- this.tools = tools;
- }
- public Set<Tag> getTags() {
- return tags;
- }
- public void setTags(Set<Tag> tags) {
- this.tags = tags;
- }
- public Media getMedia() {
- return media;
- }
- public void setMedia(Media media) {
- this.media = media;
- }
- @Transient
- public List<String> getPromoted(){
- ArrayList promoted = new ArrayList();
- if(this.getAllComments()!=null) {
- for (int i = 0; i < this.getAllComments().size(); i++) {
- if (this.getAllComments().get(i).getRating() != 0) {
- promoted.add(this.getAllComments().get(i).getUserName());
- }
- }
- }
- return promoted;
- }
- public LocalDateTime getDate() {
- return date;
- }
- public void setDate(LocalDateTime date) {
- this.date = date;
- }
- @XmlTransient
- public List<Comment> getAllComments()
- {
- return this.comments;
- }
- @Transient
- public List<Comment> getComments()
- {
- return this.comments;
- }
- //@Transient
- //public MediaModel getMedia(){
- // return new MediaModel();
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement