source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/Comment.java @ 1892

Last change on this file since 1892 was 1892, checked in by twagoo, 12 years ago

Added canDelete property to Comment
ComponentRegistryDbImpl? sets property for all returned comments based on current principal
Comment retrieval methods of ComponentRegistry interface now require principal as parameter

Tests modified and extended

File size: 3.3 KB
Line 
1package clarin.cmdi.componentregistry.model;
2
3import java.text.ParseException;
4import java.util.Date;
5import javax.xml.bind.annotation.XmlAccessType;
6import javax.xml.bind.annotation.XmlAccessorType;
7import javax.xml.bind.annotation.XmlRootElement;
8import javax.xml.bind.annotation.XmlTransient;
9import org.apache.commons.lang.time.DateFormatUtils;
10import org.apache.commons.lang.time.DateUtils;
11
12/**
13 *
14 * @author Jean-Charles FerriÚres <jean-charles.ferrieres@mpi.nl>
15 * @author Twan Goosen <twan.goosen@mpi.nl>
16 */
17@XmlRootElement(name = "comment")
18@XmlAccessorType(XmlAccessType.FIELD)
19public class Comment {
20
21    private String comments;
22    private String commentDate;
23    private String componentDescriptionId;
24    private String profileDescriptionId;
25    private String id;
26    private String userName;
27    private boolean canDelete;
28    @XmlTransient // this prevents userId from being serialized to XML and thus exposed (which is useless and undesirable)
29    private String userId;
30
31    public void setComment(String comment) {
32        this.comments = comment;
33    }
34
35    public String getComment() {
36        return comments;
37    }
38
39    public void setCommentDate(String commentDate) {
40        this.commentDate = commentDate;
41    }
42
43    public String getCommentDate() {
44        return commentDate;
45    }
46
47    public void setId(String commentId) {
48        this.id = commentId;
49    }
50
51    public String getId() {
52        return id;
53    }
54
55    public String getComponentDescriptionId() {
56        return componentDescriptionId;
57    }
58
59    public void setComponentDescriptionId(String ComponentDescriptionId) {
60        this.componentDescriptionId = ComponentDescriptionId;
61    }
62
63    public void setProfileDescriptionId(String profileDescriptionId) {
64        this.profileDescriptionId = profileDescriptionId;
65    }
66
67    public String getProfileDescriptionId() {
68        return profileDescriptionId;
69    }
70
71    public void setUserId(String userId) {
72        this.userId = userId;
73    }
74
75    public String getUserId() {
76        return userId;
77    }
78
79    /**
80     *
81     * @return userName, that is the user's 'real' name, not login name
82     */
83    public String getUserName() {
84        return userName;
85    }
86
87    /**
88     * @param userName the user's 'real' name, not login name
89     */
90    public void setUserName(String userName) {
91        this.userName = userName;
92    }
93
94    /**
95     * @return whether comment can be deleted
96     */
97    public boolean isCanDelete() {
98        return canDelete;
99    }
100
101    /**
102     * @param canDelete whether comment can be deleted
103     */
104    public void setCanDelete(boolean canDelete) {
105        this.canDelete = canDelete;
106    }
107
108    public static Date getDate(String registrationDate) throws ParseException {
109        return DateUtils.parseDate(registrationDate, new String[]{DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()});
110    }
111
112    /*
113     * Helper method to set the Date
114     */
115    public static String createNewDate() {
116        return createNewDate(new Date().getTime());
117    }
118
119    /*
120     * Helper method to set the Date in the same format
121     * @param time, long that contains the time to be set
122     */
123    public static String createNewDate(long time) {
124        return DateFormatUtils.formatUTC(time, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
125    }
126
127    public static Comment createANewComment() {
128        Comment com = new Comment();
129        com.setCommentDate(createNewDate());
130        return com;
131    }
132}
Note: See TracBrowser for help on using the repository browser.