James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
5e3521 1 /*
JM 2  * Copyright 2013 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  */
16 package com.gitblit.tickets;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.List;
23
24 import com.gitblit.models.TicketModel.Patchset;
25 import com.gitblit.models.TicketModel.Status;
26 import com.gitblit.models.TicketModel.Type;
f9c78c 27 import com.gitblit.models.TicketModel.Priority;
PM 28 import com.gitblit.models.TicketModel.Severity;
5e3521 29 import com.gitblit.utils.StringUtils;
JM 30
31 /**
32  * Represents the results of a query to the ticket index.
33  *
34  * @author James Moger
35  *
36  */
37 public class QueryResult implements Serializable {
38
39     private static final long serialVersionUID = 1L;
40
41     public String project;
42     public String repository;
43     public long number;
44     public String createdBy;
45     public Date createdAt;
46     public String updatedBy;
47     public Date updatedAt;
48     public String dependsOn;
49     public String title;
50     public String body;
51     public Status status;
52     public String responsible;
53     public String milestone;
54     public String topic;
55     public Type type;
56     public String mergeSha;
57     public String mergeTo;
58     public List<String> labels;
59     public List<String> attachments;
60     public List<String> participants;
61     public List<String> watchedby;
62     public List<String> mentions;
63     public Patchset patchset;
64     public int commentsCount;
65     public int votesCount;
66     public int approvalsCount;
f9c78c 67     public Priority priority;
PM 68     public Severity severity;
5e3521 69
JM 70     public int docId;
71     public int totalResults;
72
73     public Date getDate() {
74         return updatedAt == null ? createdAt : updatedAt;
75     }
76
77     public boolean isProposal() {
78         return type != null && Type.Proposal == type;
79     }
80
019958 81     public boolean isOpen() {
JM 82         return !status.isClosed();
83     }
84
85     public boolean isClosed() {
86         return status.isClosed();
87     }
88
5e3521 89     public boolean isMerged() {
JM 90         return Status.Merged == status && !StringUtils.isEmpty(mergeSha);
91     }
92
93     public boolean isWatching(String username) {
94         return watchedby != null && watchedby.contains(username);
95     }
96
97     public List<String> getLabels() {
98         List<String> list = new ArrayList<String>();
99         if (labels != null) {
100             list.addAll(labels);
101         }
102         if (topic != null) {
103             list.add(topic);
104         }
105         Collections.sort(list);
106         return list;
107     }
108
109     @Override
110     public boolean equals(Object o) {
111         if (o instanceof QueryResult) {
112             return hashCode() == o.hashCode();
113         }
114         return false;
115     }
116
117     @Override
118     public int hashCode() {
119         return (repository + number).hashCode();
120     }
121
122     @Override
123     public String toString() {
124         return repository + "-" + number;
125     }
126 }