source: src/main/java/com/project/beautycenter/model/Uslugi.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[850b344]1package com.project.beautycenter.model;
2
3import org.hibernate.annotations.OnDelete;
4import org.hibernate.annotations.OnDeleteAction;
5
6import javax.persistence.*;
7import java.lang.reflect.Array;
8import java.util.ArrayList;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12
13import static java.lang.Float.NaN;
14
15@Entity
16@Table(name = "uslugi",schema = "project")
17public class Uslugi {
18 @Id
19 @Column(name = "usluga_id", nullable = false, length = 100)
20 private String id;
21
22 @Column(name = "dejnost", length = 100)
23 private String dejnost;
24
25 @Column(name = "cena", nullable = false, length = 100)
26 private String cena;
27
28 @OneToMany(mappedBy = "uslugi",cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
29 private Set<Ocena> ocenas = new LinkedHashSet<>();
30
31 public Uslugi(){}
32 public Uslugi(String id, String dejnost, String cena) {
33 this.id = id;
34 this.dejnost = dejnost;
35 this.cena = cena;
36 }
37
38 public Set<Ocena> getOcenas() {
39 return ocenas;
40 }
41
42 public void setOcenas(Set<Ocena> ocenas) {
43 this.ocenas = ocenas;
44 }
45
46 public Float getAvgRating(){
47 List<Ocena> oceni = oceniToList();
48 float sum = 0;
49 float num = 0;
50 for (Ocena x : oceni){
51 if(x.getUslugi().id.equals(this.id)){
52 sum+= x.getVrednost();
53 num++;
54 }
55
56 }
57 float avg = sum/num;
58 return avg;
59 }
60 public List<Ocena> oceniToList(){
61 List<Ocena> oceni = new ArrayList<Ocena>(ocenas.size());
62 for (Ocena x : ocenas)
63 oceni.add(x);
64 return oceni;
65 }
66 @PreRemove
67 private void removeUslugaOdOcena() {
68 for (Ocena o : oceniToList()) {
69 o.getUslugi().oceniToList().remove(this);
70 }
71 }
72 public List<Ocena> removeOcenaOdUsluga(Ocena o){
73 oceniToList().remove(o);
74 return oceniToList();
75 }
76
77 public String getCena() {
78 return cena;
79 }
80
81 public void setCena(String cena) {
82 this.cena = cena;
83 }
84
85 public String getDejnost() {
86 return dejnost;
87 }
88
89 public void setDejnost(String dejnost) {
90 this.dejnost = dejnost;
91 }
92
93 public String getId() {
94 return id;
95 }
96
97 public void setId(String id) {
98 this.id = id;
99 }
100}
Note: See TracBrowser for help on using the repository browser.