James Moger
2012-09-10 fabe060d3a435f116128851f828e35c2af5fde67
commit | author | age
f13c4c 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
1f9dae 16 package com.gitblit.models;
232890 17
JM 18 import java.io.Serializable;
19 import java.text.ParseException;
20 import java.util.ArrayList;
21 import java.util.Date;
22 import java.util.List;
23
d9f687 24 /**
JM 25  * TicketModel is a serializable model class that represents a Ticgit ticket.
26  * 
27  * @author James Moger
28  * 
29  */
9802a7 30 public class TicketModel implements Serializable, Comparable<TicketModel> {
232890 31
JM 32     private static final long serialVersionUID = 1L;
33
34     public String id;
35     public String name;
36     public String title;
37     public String state;
38     public Date date;
39     public String handler;
40     public String milestone;
41     public String email;
42     public String author;
43     public List<Comment> comments;
44     public List<String> tags;
45
9802a7 46     public TicketModel(String ticketName) throws ParseException {
232890 47         state = "";
JM 48         name = ticketName;
49         comments = new ArrayList<Comment>();
50         tags = new ArrayList<String>();
51
52         String[] chunks = name.split("_");
53         if (chunks.length == 3) {
2a7306 54             date = new Date(Long.parseLong(chunks[0]) * 1000L);
232890 55             title = chunks[1].replace('-', ' ');
155bf7 56         }
232890 57     }
JM 58
d9f687 59     @Override
JM 60     public int hashCode() {
61         return id.hashCode();
62     }
63
64     @Override
65     public boolean equals(Object o) {
66         if (o instanceof TicketModel) {
67             TicketModel other = (TicketModel) o;
68             return id.equals(other.id);
69         }
70         return super.equals(o);
71     }
72
73     @Override
74     public int compareTo(TicketModel o) {
75         return date.compareTo(o.date);
76     }
77
78     /**
79      * Comment is a serializable model class that represents a Ticgit ticket
80      * comment.
81      * 
82      * @author James Moger
83      * 
84      */
232890 85     public static class Comment implements Serializable, Comparable<Comment> {
155bf7 86
232890 87         private static final long serialVersionUID = 1L;
155bf7 88
232890 89         public String text;
JM 90         public String author;
91         public Date date;
92
93         public Comment(String filename, String content) throws ParseException {
94             String[] chunks = filename.split("_", -1);
2a7306 95             this.date = new Date(Long.parseLong(chunks[1]) * 1000L);
232890 96             this.author = chunks[2];
JM 97             this.text = content;
2a7306 98         }
JM 99
100         @Override
101         public int hashCode() {
102             return text.hashCode();
103         }
104
105         @Override
106         public boolean equals(Object o) {
107             if (o instanceof Comment) {
108                 Comment other = (Comment) o;
109                 return text.equals(other.text);
110             }
111             return super.equals(o);
232890 112         }
JM 113
114         @Override
115         public int compareTo(Comment o) {
116             return date.compareTo(o.date);
117         }
118     }
119 }