summaryrefslogtreecommitdiffstats
path: root/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/Project.java
blob: 68e4655886abc3783e4a30bd804edb6c74ca5a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.reviewdb;

import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.StringKey;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Projects match a source code repository managed by Gerrit */
public final class Project {
  /** Project name key */
  public static class NameKey extends
      StringKey<com.google.gwtorm.client.Key<?>> implements Comparable<NameKey> {
    private static final long serialVersionUID = 1L;

    @Column(id = 1)
    protected String name;

    protected NameKey() {
    }

    public NameKey(final String n) {
      name = n;
    }

    @Override
    public String get() {
      return name;
    }

    @Override
    protected void set(String newValue) {
      name = newValue;
    }

    @Override
    public int compareTo(NameKey other) {
      return get().compareTo(other.get());
    }

    /** Parse a Project.NameKey out of a string representation. */
    public static NameKey parse(final String str) {
      final NameKey r = new NameKey();
      r.fromString(str);
      return r;
    }
  }

  public static class ApprovalFooterValue {
    String category;
    boolean hidden;

    protected ApprovalFooterValue() {
    }

    protected ApprovalFooterValue(final String category, final boolean on) {
      this.category = category;
      this.hidden = on;
    }

    public String getCategory() {
      return category;
    }

    public boolean getHidden() {
      return hidden;
    }
  }

  public static enum SubmitType {
    FAST_FORWARD_ONLY,

    MERGE_IF_NECESSARY,

    MERGE_ALWAYS,

    CHERRY_PICK;
  }

  protected NameKey name;

  protected String description;

  protected boolean useContributorAgreements;

  protected boolean useSignedOffBy;

  protected SubmitType submitType;

  protected NameKey parent;

  protected boolean requireChangeID;

  protected boolean allowTopicReview;

  protected boolean useContentMerge;

  protected boolean hideReviewedOn;

  protected boolean includeOnlyMaximumApprovals;

  protected List<ApprovalFooterValue> hiddenFooters;

  protected Project() {
    hiddenFooters = new ArrayList<Project.ApprovalFooterValue>();
  }

  public Project(Project.NameKey nameKey) {
    name = nameKey;
    submitType = SubmitType.MERGE_IF_NECESSARY;
    hiddenFooters = new ArrayList<Project.ApprovalFooterValue>();
  }

  public Project.NameKey getNameKey() {
    return name;
  }

  public String getName() {
    return name != null ? name.get() : null;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(final String d) {
    description = d;
  }

  public boolean isUseContributorAgreements() {
    return useContributorAgreements;
  }

  public void setUseContributorAgreements(final boolean u) {
    useContributorAgreements = u;
  }

  public boolean isUseSignedOffBy() {
    return useSignedOffBy;
  }

  public boolean isUseContentMerge() {
    return useContentMerge;
  }

  public boolean isRequireChangeID() {
    return requireChangeID;
  }

  public boolean isAllowTopicReview() {
    return allowTopicReview;
  }

  public boolean isHideReviewedOn() {
    return hideReviewedOn;
  }

  public boolean isIncludeOnlyMaxApproval() {
    return includeOnlyMaximumApprovals;
  }

  public Map<String, Boolean> getHiddenFooters() {
    HashMap<String, Boolean> footers = new HashMap<String, Boolean>();
    for (ApprovalFooterValue value : hiddenFooters) {
      footers.put(value.getCategory(), value.getHidden());
    }
    return footers;
  }

  public void setUseSignedOffBy(final boolean sbo) {
    useSignedOffBy = sbo;
  }

  public void setUseContentMerge(final boolean cm) {
    useContentMerge = cm;
  }

  public void setRequireChangeID(final boolean cid) {
    requireChangeID = cid;
  }

  public void setAllowTopicReview(final boolean atr) {
    allowTopicReview = atr;
  }

  public void setHideReviewedOn(boolean includeReviewedOn) {
    this.hideReviewedOn = includeReviewedOn;
  }

  public void setIncludeOnlyMaxApproval(boolean includeOnlyMaxApproval) {
    this.includeOnlyMaximumApprovals = includeOnlyMaxApproval;
  }

  public SubmitType getSubmitType() {
    return submitType;
  }

  public void setSubmitType(final SubmitType type) {
    submitType = type;
  }

  public void addHiddenFooter(final String category, final boolean on) {
    for (ApprovalFooterValue value : hiddenFooters) {
      if (value.category.equals(category)) {
        value.hidden = on;
        return;
      }
    }

    hiddenFooters.add(new ApprovalFooterValue(category, on));
  }

  public void copySettingsFrom(final Project update) {
    description = update.description;
    useContributorAgreements = update.useContributorAgreements;
    useSignedOffBy = update.useSignedOffBy;
    useContentMerge = update.useContentMerge;
    requireChangeID = update.requireChangeID;
    allowTopicReview = update.allowTopicReview;
    submitType = update.submitType;
    includeOnlyMaximumApprovals = update.includeOnlyMaximumApprovals;
    hideReviewedOn = update.hideReviewedOn;
    hiddenFooters = update.hiddenFooters;
  }

  public Project.NameKey getParent() {
    return parent;
  }

  public String getParentName() {
    return parent != null ? parent.get() : null;
  }

  public void setParentName(String n) {
    parent = n != null ? new NameKey(n) : null;
  }
}