1 | package clarin.cmdi.componentregistry.model; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.ComponentRegistry; |
---|
4 | import clarin.cmdi.componentregistry.IdSequence; |
---|
5 | import java.text.ParseException; |
---|
6 | import java.util.Date; |
---|
7 | import javax.xml.bind.annotation.XmlAccessType; |
---|
8 | import javax.xml.bind.annotation.XmlAccessorType; |
---|
9 | import javax.xml.bind.annotation.XmlRootElement; |
---|
10 | import org.apache.commons.lang.time.DateFormatUtils; |
---|
11 | import org.apache.commons.lang.time.DateUtils; |
---|
12 | |
---|
13 | /** |
---|
14 | * |
---|
15 | * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl> |
---|
16 | */ |
---|
17 | @XmlRootElement(name = "comment") |
---|
18 | @XmlAccessorType(XmlAccessType.FIELD) |
---|
19 | public class Comment { |
---|
20 | |
---|
21 | private String comments; |
---|
22 | private String commentDate; |
---|
23 | private String componentDescriptionId; |
---|
24 | private String profileDescriptionId; |
---|
25 | private String userId; |
---|
26 | private String id; |
---|
27 | |
---|
28 | public void setComment(String comment) { |
---|
29 | this.comments = comment; |
---|
30 | } |
---|
31 | |
---|
32 | public String getComment() { |
---|
33 | return comments; |
---|
34 | } |
---|
35 | |
---|
36 | public void setCommentDate(String commentDate) { |
---|
37 | this.commentDate = commentDate; |
---|
38 | } |
---|
39 | |
---|
40 | public String getCommentDate() { |
---|
41 | return commentDate; |
---|
42 | } |
---|
43 | |
---|
44 | public void setId(String commentId) { |
---|
45 | this.id = commentId; |
---|
46 | } |
---|
47 | |
---|
48 | public String getId() { |
---|
49 | return id; |
---|
50 | } |
---|
51 | |
---|
52 | public String getComponentDescriptionId() { |
---|
53 | return componentDescriptionId; |
---|
54 | } |
---|
55 | |
---|
56 | public void setComponentDescriptionId(String ComponentDescriptionId) { |
---|
57 | this.componentDescriptionId = ComponentDescriptionId; |
---|
58 | } |
---|
59 | |
---|
60 | public void setProfileDescriptionId(String profileDescriptionId) { |
---|
61 | this.profileDescriptionId = profileDescriptionId; |
---|
62 | } |
---|
63 | |
---|
64 | public String getProfileDescriptionId() { |
---|
65 | return profileDescriptionId; |
---|
66 | } |
---|
67 | |
---|
68 | public void setUserId(String userId) { |
---|
69 | this.userId = userId; |
---|
70 | } |
---|
71 | |
---|
72 | public String getUserId() { |
---|
73 | return userId; |
---|
74 | } |
---|
75 | |
---|
76 | public static Date getDate(String registrationDate) throws ParseException { |
---|
77 | return DateUtils.parseDate(registrationDate, new String[]{DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()}); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | * Helper method to set the Date |
---|
82 | */ |
---|
83 | public static String createNewDate() { |
---|
84 | return createNewDate(new Date().getTime()); |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * Helper method to set the Date in the same format |
---|
89 | * @param time, long that contains the time to be set |
---|
90 | */ |
---|
91 | |
---|
92 | public static String createNewDate(long time) { |
---|
93 | return DateFormatUtils.formatUTC(time, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); |
---|
94 | } |
---|
95 | |
---|
96 | public static Comment createANewComment() { |
---|
97 | String Id = ComponentRegistry.REGISTRY_ID + IdSequence.get(); |
---|
98 | Comment com = new Comment(); |
---|
99 | com.setId(Id); |
---|
100 | com.setCommentDate(createNewDate()); |
---|
101 | return com; |
---|
102 | } |
---|
103 | } |
---|