BrightSide Workbench Full Report + Source Code
Response.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.students.entities;
20 
21 import java.util.Date;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25 import javax.persistence.Column;
26 import javax.persistence.ElementCollection;
27 import javax.persistence.Entity;
28 import javax.persistence.FetchType;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.Lob;
33 import javax.persistence.ManyToOne;
34 import javax.persistence.Temporal;
35 import org.turro.string.Strings;
36 import org.turro.action.Contacts;
37 import org.turro.jpa.entity.IDaoEntity;
38 import org.turro.parser.wiki.WikiCompiler;
39 import org.turro.plugin.contacts.ContactList;
40 import org.turro.plugin.contacts.IContact;
41 
46 @Entity
47 public class Response implements java.io.Serializable, IDaoEntity {
48 
49  @Id
50  @GeneratedValue(strategy=GenerationType.IDENTITY)
51  @Column(name="IDENTIFIER")
52  private Long id;
53 
54  @ManyToOne
55  private Challenge challenge;
56 
57  @ElementCollection(fetch = FetchType.EAGER)
58  private Set<String> studentIds = new HashSet<>();
59 
60  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
61  private java.util.Date creation;
62 
63  @Lob
64  @Column(length=4096)
65  private String text;
66 
67  @Lob
68  @Column(length=4096)
69  private String wikiText;
70 
71  public Long getId() {
72  return id;
73  }
74 
75  public void setId(Long id) {
76  this.id = id;
77  }
78 
80  return challenge;
81  }
82 
83  public void setChallenge(Challenge challenge) {
84  this.challenge = challenge;
85  }
86 
87  public Set<String> getStudentIds() {
88  return studentIds;
89  }
90 
91  public void setStudentIds(Set<String> studentIds) {
92  this.studentIds = studentIds;
93  }
94 
95  public Date getCreation() {
96  return creation;
97  }
98 
99  public void setCreation(Date creation) {
100  this.creation = creation;
101  }
102 
103  public String getText() {
104  return text;
105  }
106 
107  public void setText(String text) {
108  this.text = text;
109  }
110 
111  public String getWikiText() {
112  return wikiText;
113  }
114 
115  public void setWikiText(String wikiText) {
116  this.wikiText = wikiText;
117  this.text = WikiCompiler.source(this.wikiText).html();
118  }
119 
120  /* IDaoEntity */
121 
122  @Override
123  public Object entityId() {
124  return id;
125  }
126 
127  @Override
128  public boolean isEmpty() {
129  return studentIds.isEmpty() || Strings.isBlank(text);
130  }
131 
134  public List<IContact> getStudentList() {
135  ContactList list = new ContactList();
136  studentIds.forEach(idContact -> {
137  list.add(Contacts.getContactById(idContact));
138  });
139  return list;
140  }
141 
142  public void addStudent(IContact contact) {
143  if(contact != null && contact.isValid()) {
144  studentIds.add(contact.getId());
145  }
146  }
147 
148  public void removeStudent(IContact contact) {
149  if(contact != null && contact.isValid()) {
150  studentIds.remove(contact.getId());
151  }
152  }
153 
154 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setCreation(Date creation)
Definition: Response.java:99
void setWikiText(String wikiText)
Definition: Response.java:115
void setChallenge(Challenge challenge)
Definition: Response.java:83
void removeStudent(IContact contact)
Definition: Response.java:148
void addStudent(IContact contact)
Definition: Response.java:142
void setStudentIds(Set< String > studentIds)
Definition: Response.java:91