Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2006-08-29 20:01:49 +0000
committerspingel2006-08-29 20:01:49 +0000
commit053b7ad1676c001e694dbeb21ae826a59def1f08 (patch)
tree61e4ae9c5fbd7f428881e7a21efeb3e9c27fc6fc /org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model
parentba276227c0635484a6f9fa29c9a971ad3f4c13d8 (diff)
downloadorg.eclipse.mylyn.tasks-053b7ad1676c001e694dbeb21ae826a59def1f08.tar.gz
org.eclipse.mylyn.tasks-053b7ad1676c001e694dbeb21ae826a59def1f08.tar.xz
org.eclipse.mylyn.tasks-053b7ad1676c001e694dbeb21ae826a59def1f08.zip
Progress on: 154876: extract trac.core plug-in from trac.ui
https://bugs.eclipse.org/bugs/show_bug.cgi?id=154876
Diffstat (limited to 'org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttachment.java77
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttribute.java39
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComment.java86
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComponent.java42
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracMilestone.java55
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracPriority.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearch.java150
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearchFilter.java108
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSeverity.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicket.java225
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketAttribute.java46
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketResolution.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketStatus.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketType.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracVersion.java44
15 files changed, 982 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttachment.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttachment.java
new file mode 100644
index 000000000..6125ababb
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttachment.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.util.Date;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracAttachment {
+
+ private String author;
+
+ private Date created;
+
+ private String description;
+
+ private String filename;
+
+ int size;
+
+ public TracAttachment(String filename) {
+ this.filename = filename;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setFilename(String filename) {
+ this.filename = filename;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ @Override
+ public String toString() {
+ return filename;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttribute.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttribute.java
new file mode 100644
index 000000000..5962eafba
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracAttribute.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.io.Serializable;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracAttribute implements Serializable {
+
+ private static final long serialVersionUID = -4535033208999685315L;
+
+ private String name;
+
+ public TracAttribute(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComment.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComment.java
new file mode 100644
index 000000000..d1be7585f
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComment.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.util.Date;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracComment {
+
+ private String author;
+
+ private Date created;
+
+ private String field;
+
+ private String newValue;
+
+ private String oldValue;
+
+ private boolean permanent;
+
+ public TracComment() {
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public String getNewValue() {
+ return newValue;
+ }
+
+ public String getOldValue() {
+ return oldValue;
+ }
+
+ public boolean isPermanent() {
+ return permanent;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ public void setField(String field) {
+ this.field = field;
+ }
+
+ public void setNewValue(String newValue) {
+ this.newValue = newValue;
+ }
+
+ public void setOldValue(String oldValue) {
+ this.oldValue = oldValue;
+ }
+
+ public void setPermanent(boolean permanent) {
+ this.permanent = permanent;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + field + "] " + author + ": " + oldValue + " -> " + newValue;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComponent.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComponent.java
new file mode 100644
index 000000000..00088e9e2
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracComponent.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracComponent extends TracAttribute {
+
+ private static final long serialVersionUID = -6181067219323677076L;
+
+ private String owner;
+
+ private String description;
+
+ public TracComponent(String name) {
+ super(name);
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracMilestone.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracMilestone.java
new file mode 100644
index 000000000..935689e12
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracMilestone.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracMilestone extends TracAttribute implements Serializable {
+
+ private static final long serialVersionUID = 6648558552508886484L;
+
+ private Date due;
+
+ private Date completed;
+
+ private String description;
+
+ public TracMilestone(String name) {
+ super(name);
+ }
+
+ public Date getCompleted() {
+ return completed;
+ }
+
+ public void setCompleted(Date completed) {
+ this.completed = completed;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getDue() {
+ return due;
+ }
+
+ public void setDue(Date due) {
+ this.due = due;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracPriority.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracPriority.java
new file mode 100644
index 000000000..eed975522
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracPriority.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracPriority extends TracTicketAttribute {
+
+ private static final long serialVersionUID = 3617078252773178266L;
+
+ public TracPriority(String name, int value) {
+ super(name, value);
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearch.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearch.java
new file mode 100644
index 000000000..bcc8784c8
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearch.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.mylar.context.core.MylarStatusHandler;
+import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.internal.trac.core.model.TracSearchFilter.CompareOperator;
+
+/**
+ * Represents a Trac search. A search can have multiple {@link TracSearchFilter}s
+ * that all need to match.
+ *
+ * @author Steffen Pingel
+ */
+public class TracSearch {
+
+ /** Stores search criteria in the order entered by the user. */
+ private Map<String, TracSearchFilter> filterByFieldName = new LinkedHashMap<String, TracSearchFilter>();
+
+ /** The field the result is ordered by. */
+ private String orderBy;
+
+ private boolean ascending = true;
+
+ public TracSearch() {
+ }
+
+ public void addFilter(String key, String value) {
+ TracSearchFilter filter = filterByFieldName.get(key);
+ if (filter == null) {
+ filter = new TracSearchFilter(key);
+ CompareOperator operator = CompareOperator.fromUrl(value);
+ filter.setOperator(operator);
+ filterByFieldName.put(key, filter);
+ }
+
+ filter.addValue(value.substring(filter.getOperator().getQueryValue().length()));
+ }
+
+ public void addFilter(TracSearchFilter filter) {
+ filterByFieldName.put(filter.getFieldName(), filter);
+ }
+
+ public List<TracSearchFilter> getFilters() {
+ return new ArrayList<TracSearchFilter>(filterByFieldName.values());
+ }
+
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ public void setOrderBy(String orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ public String getOrderBy() {
+ return orderBy;
+ }
+
+ /**
+ * Returns a Trac query string that conforms to the format defined at
+ * {@link http://projects.edgewall.com/trac/wiki/TracQuery#QueryLanguage}.
+ *
+ * @return the empty string, if no search order and criteria are defined; a
+ * string that starts with &amp;, otherwise
+ */
+ public String toQuery() {
+ StringBuilder sb = new StringBuilder();
+ if (orderBy != null) {
+ sb.append("&order=");
+ sb.append(orderBy);
+ if (!ascending) {
+ sb.append("&desc=1");
+ }
+ }
+ for (TracSearchFilter filter : filterByFieldName.values()) {
+ sb.append("&");
+ sb.append(filter.getFieldName());
+ sb.append(filter.getOperator().getQueryValue());
+ sb.append("=");
+ List<String> values = filter.getValues();
+ for (Iterator<String> it = values.iterator(); it.hasNext();) {
+ sb.append(it.next());
+ if (it.hasNext()) {
+ sb.append("|");
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns a URL encoded string that can be passed as an argument to the
+ * Trac query script.
+ *
+ * @return the empty string, if no search order and criteria are defined; a
+ * string that starts with &amp;, otherwise
+ */
+ public String toUrl() {
+ StringBuilder sb = new StringBuilder();
+ if (orderBy != null) {
+ sb.append("&order=");
+ sb.append(orderBy);
+ if (!ascending) {
+ sb.append("&desc=1");
+ }
+ } else if (filterByFieldName.isEmpty()) {
+ // TODO figure out why search must be ordered when logged in (otherwise
+ // no results will be returned)
+ sb.append("&order=id");
+ }
+
+ for (TracSearchFilter filter : filterByFieldName.values()) {
+ for (String value : filter.getValues()) {
+ sb.append("&");
+ sb.append(filter.getFieldName());
+ sb.append("=");
+ try {
+ sb.append(URLEncoder.encode(filter.getOperator().getQueryValue(), ITracClient.CHARSET));
+ sb.append(URLEncoder.encode(value, ITracClient.CHARSET));
+ } catch (UnsupportedEncodingException e) {
+ MylarStatusHandler.log(e, "Unexpected exception while decoding URL");
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearchFilter.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearchFilter.java
new file mode 100644
index 000000000..42f5c2942
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSearchFilter.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a search criterion. Each criterion is applied to a field such as
+ * milestone or priority. It has a compare operator and a list of values. The
+ * compare mode is <code>OR</code> for the operators <code>contains</code>,
+ * <code>starts with</code>, <code>ends with</code> and <code>is</code>.
+ * The compare mode is <code>AND</code> for all other (negated) operators.
+ *
+ * @author Steffen Pingel
+ */
+public class TracSearchFilter {
+
+ public enum CompareOperator {
+ CONTAINS("~"), CONTAINS_NOT("!~"), BEGINS_WITH("^"), NOT_BEGINS_WITH("!^"), ENDS_WITH("$"), NOT_ENDS_WITH("!$"), IS(
+ ""), IS_NOT("!");
+
+ public static CompareOperator fromUrl(String value) {
+ for (CompareOperator operator : values()) {
+ if (operator != IS && operator != IS_NOT && value.startsWith(operator.queryValue)) {
+ return operator;
+ }
+ }
+ if (value.startsWith(IS_NOT.queryValue)) {
+ return IS_NOT;
+ }
+ return IS;
+ }
+
+ /** The string that represent the operator in a Trac query. */
+ private String queryValue;
+
+ CompareOperator(String queryValue) {
+ this.queryValue = queryValue;
+ }
+
+ public String getQueryValue() {
+ return queryValue;
+ }
+
+ public String toString() {
+ switch (this) {
+ case CONTAINS:
+ return "contains";
+ case CONTAINS_NOT:
+ return "does not contain";
+ case BEGINS_WITH:
+ return "begins with";
+ case NOT_BEGINS_WITH:
+ return "does not begin with";
+ case ENDS_WITH:
+ return "ends with";
+ case NOT_ENDS_WITH:
+ return "does not end with";
+ case IS_NOT:
+ return "is not";
+ default:
+ return "is";
+ }
+ }
+
+ }
+
+ private String fieldName;
+
+ private CompareOperator operator;
+
+ private List<String> values = new ArrayList<String>();
+
+ public TracSearchFilter(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public void addValue(String value) {
+ values.add(value);
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public CompareOperator getOperator() {
+ return operator;
+ }
+
+ public List<String> getValues() {
+ return values;
+ }
+
+ public void setOperator(CompareOperator operator) {
+ this.operator = operator;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSeverity.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSeverity.java
new file mode 100644
index 000000000..7a516f4db
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracSeverity.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracSeverity extends TracTicketAttribute {
+
+ private static final long serialVersionUID = 2173932517704827316L;
+
+ public TracSeverity(String name, int value) {
+ super(name, value);
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicket.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicket.java
new file mode 100644
index 000000000..9c91acd5b
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicket.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.mylar.internal.trac.core.InvalidTicketException;
+import org.eclipse.mylar.internal.trac.core.util.TracUtils;
+
+/**
+ * Represents a Trac ticket as it is retrieved from a Trac repository.
+ *
+ * @author Steffen Pingel
+ */
+public class TracTicket {
+
+ /**
+ * Represents the key of a string propertiy of a ticket.
+ *
+ * @author Steffen Pingel
+ */
+ public enum Key {
+ CC("cc"), CHANGE_TIME("changetime"), COMPONENT("component"), DESCRIPTION("description"), ID("id"), KEYWORDS(
+ "keywords"), MILESTONE("milestone"), OWNER("owner"), PRIORITY("priority"), REPORTER("reporter"), RESOLUTION(
+ "resolution"), STATUS("status"), SEVERITY("severity"), SUMMARY("summary"), TIME("time"), TYPE("type"), VERSION(
+ "version");
+
+ public static Key fromKey(String name) {
+ for (Key key : Key.values()) {
+ if (key.getKey().equals(name)) {
+ return key;
+ }
+ }
+ return null;
+ }
+
+ private String key;
+
+ Key(String key) {
+ this.key = key;
+ }
+
+ public String toString() {
+ return key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+ }
+
+ public static final int INVALID_ID = -1;
+
+ private Date created;
+
+ /**
+ * User defined custom ticket fields.
+ *
+ * @see http://projects.edgewall.com/trac/wiki/TracTicketsCustomFields
+ */
+ private Map<String, String> customValueByKey;
+
+ private int id = INVALID_ID;
+
+ private Date lastChanged;
+
+ /** Trac's built-in ticket properties. */
+ private Map<Key, String> valueByKey = new HashMap<Key, String>();
+
+ private List<TracComment> comments;
+
+ private List<TracAttachment> attachments;
+
+ private String[] actions;
+
+ private String[] resolutions;
+
+ public TracTicket() {
+ }
+
+ /**
+ * Constructs a Trac ticket.
+ *
+ * @param id
+ * the nummeric Trac ticket id
+ */
+ public TracTicket(int id) {
+ this.id = id;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public Date getLastChanged() {
+ return lastChanged;
+ }
+
+ public String getCustomValue(String key) {
+ if (customValueByKey == null) {
+ return null;
+ }
+ return customValueByKey.get(key);
+ }
+
+ public String getValue(Key key) {
+ return valueByKey.get(key);
+ }
+
+ public Map<String, String> getValues() {
+ Map<String, String> result = new HashMap<String, String>();
+ for (Key key : valueByKey.keySet()) {
+ result.put(key.getKey(), valueByKey.get(key));
+ }
+ if (customValueByKey != null) {
+ result.putAll(customValueByKey);
+ }
+ return result;
+ }
+
+ public boolean isValid() {
+ return getId() != TracTicket.INVALID_ID;
+ }
+
+ public void putBuiltinValue(Key key, String value) throws InvalidTicketException {
+ valueByKey.put(key, value);
+ }
+
+ public void putCustomValue(String key, String value) {
+ if (customValueByKey == null) {
+ customValueByKey = new HashMap<String, String>();
+ }
+ customValueByKey.put(key, value);
+ }
+
+ /**
+ * Stores a value as it is retrieved from the repository.
+ *
+ * @throws InvalidTicketException
+ * thrown if the type of <code>value</code> is not valid
+ */
+ public boolean putValue(String keyName, String value) throws InvalidTicketException {
+ Key key = Key.fromKey(keyName);
+ if (key != null) {
+ if (key == Key.ID || key == Key.TIME || key == Key.CHANGE_TIME) {
+ return false;
+ }
+ putBuiltinValue(key, value);
+ } else if (value instanceof String) {
+ putCustomValue(keyName, (String) value);
+ } else {
+ throw new InvalidTicketException("Expected string value for custom key '" + keyName + "', got '" + value
+ + "'");
+ }
+ return true;
+ }
+
+ public void setCreated(int created) {
+ this.created = TracUtils.parseDate(created);
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public void setLastChanged(int lastChanged) {
+ this.lastChanged = TracUtils.parseDate(lastChanged);
+ }
+
+ public void addComment(TracComment comment) {
+ if (comments == null) {
+ comments = new ArrayList<TracComment>();
+ }
+ comments.add(comment);
+ }
+
+ public void addAttachment(TracAttachment attachment) {
+ if (attachments == null) {
+ attachments = new ArrayList<TracAttachment>();
+ }
+ attachments.add(attachment);
+ }
+
+ public TracComment[] getComments() {
+ return (comments != null) ? comments.toArray(new TracComment[0]) : null;
+ }
+
+ public TracAttachment[] getAttachments() {
+ return (attachments != null) ? attachments.toArray(new TracAttachment[0]) : null;
+ }
+
+ public void setActions(String[] actions) {
+ this.actions = actions;
+ }
+
+ public String[] getActions() {
+ return actions;
+ }
+
+ public void setResolutions(String[] resolutions) {
+ this.resolutions = resolutions;
+ }
+
+ public String[] getResolutions() {
+ return resolutions;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketAttribute.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketAttribute.java
new file mode 100644
index 000000000..01e4d5b2d
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketAttribute.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.io.Serializable;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTicketAttribute implements Comparable<TracTicketAttribute>, Serializable {
+
+ private static final long serialVersionUID = -8611030780681519787L;
+
+ private String name;
+
+ private int value;
+
+ public TracTicketAttribute(String name, int value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public int compareTo(TracTicketAttribute o) {
+ return value - o.value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketResolution.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketResolution.java
new file mode 100644
index 000000000..71c863c3e
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketResolution.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTicketResolution extends TracTicketAttribute {
+
+ private static final long serialVersionUID = -6933211257044813716L;
+
+ public TracTicketResolution(String name, int value) {
+ super(name, value);
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketStatus.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketStatus.java
new file mode 100644
index 000000000..d95baba3f
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketStatus.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTicketStatus extends TracTicketAttribute {
+
+ private static final long serialVersionUID = -8844909853931772506L;
+
+ public TracTicketStatus(String name, int value) {
+ super(name, value);
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketType.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketType.java
new file mode 100644
index 000000000..c87673fa0
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracTicketType.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracTicketType extends TracTicketAttribute {
+
+ private static final long serialVersionUID = -3157354751904259304L;
+
+ public TracTicketType(String name, int value) {
+ super(name, value);
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracVersion.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracVersion.java
new file mode 100644
index 000000000..f65a6b007
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracVersion.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.core.model;
+
+import java.util.Date;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracVersion extends TracAttribute {
+
+ private static final long serialVersionUID = 9018237956062697410L;
+
+ private Date time;
+
+ private String description;
+
+ public TracVersion(String name) {
+ super(name);
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+}

Back to the top