Rev 1782 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
808 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | |||
5 | import java.io.Serializable; |
||
6 | import java.util.List; |
||
7 | import java.util.Set; |
||
8 | |||
9 | /** |
||
10 | * Created by IntelliJ IDEA. |
||
11 | * User: Filipe Matos |
||
12 | * Date: 4/Abr/2013 |
||
13 | * Time: 17:02:06 |
||
14 | * To change this template use File | Settings | File Templates. |
||
15 | */ |
||
16 | public class AssessmentImpl extends Assessment implements IOwned, IEdit |
||
17 | { |
||
18 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(AssessmentImpl.class); |
||
19 | |||
20 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1782 | jmachado | 21 | public boolean checkIsOwnedBy(GenericUser u) { |
22 | return checkIsOwnedBy(u, false); |
||
808 | jmachado | 23 | } |
24 | |||
25 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1782 | jmachado | 26 | public boolean checkIsOwnedBy(GenericUser u, boolean transaction) { |
808 | jmachado | 27 | return u.getId() == getOwner().getId(); |
28 | } |
||
29 | |||
30 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
31 | public GenericUser getOwner() { |
||
32 | return super.getOwner(); |
||
33 | } |
||
34 | |||
35 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole() { |
||
36 | logger.warn("Invoke not implemented method in class:" + getClass().getName()); |
||
37 | return null; //To change body of implemented methods use File | Settings | File Templates. |
||
38 | } |
||
39 | |||
40 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
41 | public List<String> getOwnerRoles() { |
||
42 | logger.warn("Invoke not implemented method in class:" + getClass().getName()); |
||
43 | return null; //To change body of implemented methods use File | Settings | File Templates. |
||
44 | } |
||
45 | |||
46 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
47 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
48 | return getId(); |
||
49 | } |
||
50 | |||
51 | public boolean isTypeOf(1.5.0/docs/api/java/lang/String.html">String type) |
||
52 | { |
||
53 | return (getType().equals(type)); |
||
54 | } |
||
55 | |||
56 | public boolean canEdit(GenericUserImpl u) |
||
57 | { |
||
58 | return canEditAssessment(u,false); |
||
59 | } |
||
60 | |||
61 | public boolean canEdit(GenericUserImpl u,boolean transaction) |
||
62 | { |
||
63 | return canEditAssessment(u,true); |
||
64 | } |
||
65 | |||
66 | private boolean canEditAssessment(GenericUserImpl user, boolean transaction) |
||
67 | { |
||
68 | Set<AssessmentResponse> responses = this.getResponses(); |
||
69 | if(responses.size() ==0) |
||
70 | { |
||
1782 | jmachado | 71 | return user != null && checkIsOwnedBy(user, transaction); |
808 | jmachado | 72 | } |
73 | if(responses.size()>0) |
||
74 | { |
||
75 | for(AssessmentResponse response : responses) |
||
76 | { |
||
1782 | jmachado | 77 | return response.getAnswers().size() == 0 && user != null && checkIsOwnedBy(user, transaction); |
808 | jmachado | 78 | } |
79 | } |
||
80 | return false; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | |||
85 |