-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bardia-p/milestone1_issue3_model_survey_an…
…d_questions Resolves #3 Added the Survey, Question, and Response
- Loading branch information
Showing
15 changed files
with
563 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/opinionowl/opinionowl/models/Answer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The class in charge of holding the indivdual answers for each response. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class Answer { | ||
// The id of the answer. | ||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
// The response which the answer belongs to. | ||
@ManyToOne | ||
private Response response; | ||
|
||
// The id of the question. | ||
private Long question; | ||
|
||
// The contents of the response. | ||
private String content; | ||
|
||
/** | ||
* The constructor for answer. | ||
* @param response the response for which the answe belongs to. | ||
* @param question the question id. | ||
* @param content the content of the reply. | ||
*/ | ||
public Answer(Response response, Long question, String content){ | ||
this.response = response; | ||
this.question = question; | ||
this.content = content; | ||
} | ||
|
||
/** | ||
* @return the answer in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
return "Answer#" + id + " value:" + content; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/opinionowl/opinionowl/models/LongAnswerQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The class used to describe the long answer questions. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
public class LongAnswerQuestion extends Question{ | ||
// The character limit for the question. | ||
private int charLimit; | ||
|
||
/** | ||
* The default constructor for the class. | ||
*/ | ||
public LongAnswerQuestion(){ | ||
this("", 0); | ||
} | ||
|
||
/** | ||
* The constructor for the class. | ||
* @param prompt the prompt for the question | ||
* @param charLimit the character limit for the response. | ||
*/ | ||
public LongAnswerQuestion(String prompt, int charLimit){ | ||
super(prompt, QuestionType.LONG_ANSWER); | ||
this.charLimit = charLimit; | ||
} | ||
|
||
/** | ||
* @return the question in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
return super.toString() + " charLimit:" + charLimit; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/opinionowl/opinionowl/models/Question.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* The Question class which keeps track of the survey questions. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) | ||
public class Question { | ||
// The id of the question. | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
// The prompt for the question. | ||
private String prompt; | ||
|
||
// The type of the question. | ||
private QuestionType type; | ||
|
||
/** | ||
* The constructor for the question class. | ||
* @param prompt the prompt for the question. | ||
* @param type the type of the question | ||
*/ | ||
public Question(String prompt, QuestionType type){ | ||
this.prompt = prompt; | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* @return the question in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
return "Question id:" + id + " prompt:" + prompt; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/opinionowl/opinionowl/models/QuestionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
/** | ||
* An Enum to keep track of the different question types. | ||
*/ | ||
public enum QuestionType { | ||
LONG_ANSWER, | ||
RADIO_CHOICE, | ||
RANGE | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/opinionowl/opinionowl/models/RadioChoiceQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The class used to describe the multiple choice questions. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
public class RadioChoiceQuestion extends Question { | ||
// The choices for the question. | ||
private String[] choices; | ||
|
||
/** | ||
* The default constructor for the class. | ||
*/ | ||
public RadioChoiceQuestion() { | ||
this("", new String[0]); | ||
} | ||
|
||
/** | ||
* The constructor for the class. | ||
* @param prompt the prompt for the question. | ||
* @param choices the choices for the question. | ||
*/ | ||
public RadioChoiceQuestion(String prompt, String[] choices){ | ||
super(prompt, QuestionType.RADIO_CHOICE); | ||
this.choices = choices; | ||
} | ||
|
||
/** | ||
* @return the question in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
String res = super.toString() + " choices:["; | ||
if (choices.length > 0) { | ||
for (int i = 0; i < choices.length - 1; i++){ | ||
res += choices[i] + ", "; | ||
} | ||
res += choices[choices.length - 1]; | ||
} | ||
res += "]"; | ||
return res; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/opinionowl/opinionowl/models/RangeQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The class used to describe the range questions. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
public class RangeQuestion extends Question { | ||
// The lower value for the range. | ||
int lower; | ||
|
||
// the upper value for the range. | ||
int upper; | ||
|
||
// the increment the range. | ||
int increment; | ||
|
||
/** | ||
* The default constructor for the class. | ||
*/ | ||
public RangeQuestion(){ | ||
this("", 0, 0); | ||
} | ||
|
||
/** | ||
* The constructor for the class without increment. | ||
* @param prompt the prompt for the question. | ||
* @param lower the lower value for the range. | ||
* @param upper the upper value for the range. | ||
*/ | ||
public RangeQuestion(String prompt, int lower, int upper){ | ||
this(prompt, lower, upper, 1); | ||
} | ||
|
||
/** | ||
* The constructor for the class with increment. | ||
* @param prompt the prompt for the question. | ||
* @param lower the lower value for the range. | ||
* @param upper the upper value for the range. | ||
* @param increment the increment value for the range. | ||
*/ | ||
public RangeQuestion(String prompt, int lower, int upper, int increment){ | ||
super(prompt, QuestionType.RANGE); | ||
this.lower = lower; | ||
this.upper = upper; | ||
this.increment = increment; | ||
} | ||
|
||
/** | ||
* @return the question in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
return super.toString() + " lower:" + lower + " upper:" + upper + " increment:" + increment; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/opinionowl/opinionowl/models/Response.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.opinionowl.opinionowl.models; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* The Response class in charge holding the survey response. | ||
*/ | ||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class Response { | ||
// The id of the response. | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
// The survey object used for the response. | ||
@ManyToOne | ||
private Survey survey; | ||
|
||
// The list of the questions for the response. | ||
@OneToMany(mappedBy = "response", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<Answer> answers; | ||
|
||
/** | ||
* The constructor for the Response class. | ||
*/ | ||
public Response(Survey survey) { | ||
this.survey = survey; | ||
this.answers = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Adds an answer to the survey. | ||
* @param question the question id. | ||
* @param content the content of the reply. | ||
*/ | ||
public void addAnswer(Long question, String content){ | ||
this.answers.add(new Answer(this, question, content)); | ||
} | ||
|
||
/** | ||
* @return the Response class in string form. | ||
*/ | ||
@Override | ||
public String toString(){ | ||
return "Response #" + id + " answers:" + answers; | ||
} | ||
} |
Oops, something went wrong.