Skip to content

Commit

Permalink
Merge pull request #293 from outcobra/release/1.2.0
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
jmesserli authored Aug 21, 2017
2 parents 39b762a + c0940ae commit ce31400
Show file tree
Hide file tree
Showing 326 changed files with 10,053 additions and 3,285 deletions.
49 changes: 44 additions & 5 deletions backend-model/src/main/java/outcobra/server/model/Exam.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package outcobra.server.model;

import com.querydsl.core.annotations.QueryInit;
import outcobra.server.model.interfaces.ParentLinked;

import javax.persistence.*;
Expand All @@ -18,28 +19,56 @@ public class Exam implements ParentLinked {
@NotNull
private String name;

private String description;

@NotNull
private LocalDate date;

@OneToMany(mappedBy = "exam")
@OneToMany(mappedBy = "exam", cascade = CascadeType.MERGE)
private List<ExamTask> tasks;

@NotNull
@ManyToOne
@QueryInit("semester.schoolYear.schoolClass.institution.user")
private Subject subject;

@OneToOne
private Mark mark;
private MarkValue mark;

//region constructors

public Exam(Long id, String name, LocalDate date, List<ExamTask> tasks, Subject subject, Mark mark) {
/**
* @param id
* @param name
* @param date
* @param tasks
* @param subject
* @param mark
*/
public Exam(Long id, String name, String description, LocalDate date, List<ExamTask> tasks, Subject subject, MarkValue mark) {
this.id = id;
this.name = name;
this.description = description == null ? "" : description;
this.date = date;
this.tasks = tasks;
this.subject = subject;
this.mark = mark;
}

/**
* @param name
* @param date
* @param tasks
* @param subject
* @param mark
*/
public Exam(String name, LocalDate date, List<ExamTask> tasks, Subject subject, MarkValue mark) {
this.name = name;
this.date = date;
this.tasks = tasks;
this.subject = subject;
this.mark = mark;
this.description = "";
}

public Exam() {
Expand Down Expand Up @@ -90,14 +119,22 @@ public void setSubject(Subject subject) {
this.subject = subject;
}

public Mark getMark() {
public MarkValue getMark() {
return mark;
}

public void setMark(Mark mark) {
public void setMark(MarkValue mark) {
this.mark = mark;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@SuppressWarnings("SimplifiableIfStatement")
@Override
public boolean equals(Object o) {
Expand All @@ -108,6 +145,7 @@ public boolean equals(Object o) {

if (!id.equals(exam.id)) return false;
if (name != null ? !name.equals(exam.name) : exam.name != null) return false;
if (description != null ? !name.equals(exam.description) : exam.description != null) return false;
if (date != null ? !date.equals(exam.date) : exam.date != null) return false;
if (tasks != null ? !tasks.equals(exam.tasks) : exam.tasks != null) return false;
if (subject != null ? !subject.equals(exam.subject) : exam.subject != null) return false;
Expand All @@ -119,6 +157,7 @@ public boolean equals(Object o) {
public int hashCode() {
int result = id.hashCode();
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (date != null ? date.hashCode() : 0);
result = 31 * result + (tasks != null ? tasks.hashCode() : 0);
result = 31 * result + (subject != null ? subject.hashCode() : 0);
Expand Down
14 changes: 12 additions & 2 deletions backend-model/src/main/java/outcobra/server/model/ExamTask.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package outcobra.server.model;

import outcobra.server.model.interfaces.ParentLinked;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import outcobra.server.model.interfaces.ParentLinked;

@Entity
public class ExamTask implements ParentLinked {
Expand All @@ -30,6 +29,17 @@ public ExamTask(Long id, String task, Exam exam, boolean finished) {
this.finished = finished;
}

/**
* @param task
* @param exam
* @param finished
*/
public ExamTask(String task, Exam exam, boolean finished) {
this.task = task;
this.exam = exam;
this.finished = finished;
}

public ExamTask() {
}

Expand Down
50 changes: 25 additions & 25 deletions backend-model/src/main/java/outcobra/server/model/Mark.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ public abstract class Mark implements ParentLinked {
protected Double weight;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@OneToOne(mappedBy = "mark")
private Exam exam;
protected Long id;

@NotNull
protected String description;

@ManyToOne
private MarkGroup markGroup;
protected MarkGroup markGroup;

//region constructors
public Mark(Double weight, Exam exam, MarkGroup markGroup) {
public Mark(Double weight, MarkGroup markGroup, String description) {
this.weight = weight;
this.exam = exam;
this.markGroup = markGroup;
this.description = description;
}

public Mark() {
this.weight = 1.0;
}
//endregion

Expand All @@ -47,14 +49,6 @@ public void setId(Long id) {
this.id = id;
}

public Exam getExam() {
return exam;
}

public void setExam(Exam exam) {
this.exam = exam;
}

public MarkGroup getMarkGroup() {
return markGroup;
}
Expand All @@ -63,6 +57,14 @@ public void setMarkGroup(MarkGroup markGroup) {
this.markGroup = markGroup;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@SuppressWarnings("SimplifiableIfStatement")
@Override
public boolean equals(Object o) {
Expand All @@ -71,22 +73,20 @@ public boolean equals(Object o) {

Mark mark = (Mark) o;

if (!id.equals(mark.id)) return false;
if (getWeight() != mark.getWeight())
return false;
if (getValue() != mark.getValue())
return false;
if (exam != null ? !exam.equals(mark.exam) : mark.exam != null) return false;
return markGroup != null ? markGroup.equals(mark.markGroup) : mark.markGroup == null;
if (getWeight() != mark.getWeight()) return false;
if (!getId().equals(mark.getId())) return false;
if (!getDescription().equals(mark.getDescription())) return false;
return getMarkGroup() != null ? getMarkGroup().equals(mark.getMarkGroup()) : mark.getMarkGroup() == null;
}

@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + (int) getWeight();
result = 31 * result + (exam != null ? exam.hashCode() : 0);
result = 31 * result + (markGroup != null ? markGroup.hashCode() : 0);
int result = Double.valueOf(getWeight()).hashCode();
result = 31 * result + getId().hashCode();
result = 31 * result + getDescription().hashCode();
result = 31 * result + (getMarkGroup() != null ? getMarkGroup().hashCode() : 0);
return result;
}

//endregion
}
40 changes: 30 additions & 10 deletions backend-model/src/main/java/outcobra/server/model/MarkGroup.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package outcobra.server.model;

import outcobra.server.model.interfaces.ParentLinked;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import java.util.ArrayList;
import java.util.List;
import outcobra.server.model.interfaces.ParentLinked;

@Entity
public class MarkGroup extends Mark {
Expand All @@ -17,29 +16,44 @@ public class MarkGroup extends Mark {
@OneToOne(mappedBy = "markGroup")
private Subject subject;

public MarkGroup(Double weight, Exam exam, MarkGroup markGroup, List<Mark> marks, Subject subject) {
super(weight, exam, markGroup);
//region constructors
/**
* @param weight
* @param markGroup
* @param description
* @param marks
* @param subject
*/
public MarkGroup(Double weight, MarkGroup markGroup, String description, List<Mark> marks, Subject subject) {
super(weight, markGroup, description);
this.marks = marks;
this.subject = subject;
}

public MarkGroup(List<Mark> marks, Subject subject) {
super();
this.marks = marks;
this.subject = subject;
}

public MarkGroup(Subject subject) {
super();
this.subject = subject;
this.description = subject.getName();
}

public MarkGroup() {
super();
this.marks = new ArrayList<>();
}
//endregion

//region mark functions
// Todo persist
public void addMark(Mark mark) {
marks.add(mark);
}

//region constructors

// Todo persist
public void removeMark(Mark mark) {
marks.remove(mark);
Expand All @@ -52,6 +66,9 @@ public double getWeight() {

@Override
public double getValue() {
if (getMarks().size() == 0) {
return 0;
}
double valueSum = 0, weightSum = 0;

for (Mark mark : getMarks()) {
Expand All @@ -64,7 +81,6 @@ public double getValue() {
//endregion

//region default functions

public List<Mark> getMarks() {
return marks;
}
Expand Down Expand Up @@ -106,7 +122,11 @@ public int hashCode() {

@Override
public ParentLinked getParent() {
return subject;
if (this.markGroup == null) {
return subject;
}
return markGroup;

}
//endregion
}
Loading

0 comments on commit ce31400

Please sign in to comment.