Skip to main content
summaryrefslogtreecommitdiffstats
blob: 837f6185839af5fbc7c3cff1cb80d8f3b9043bf2 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.bugzilla.core;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
import org.eclipse.mylyn.tasks.core.data.TaskData;

/**
 * @author Frank Becker
 * @since 3.1
 */
public class BugzillaFlagMapper {

	private String requestee;

	private String setter;

	private String state;

	private String flagId;

	private int number;

	private final BugzillaRepositoryConnector connector;

	public BugzillaFlagMapper(BugzillaRepositoryConnector connector) {
		this.connector = connector;
	}

	public String getRequestee() {
		return requestee;
	}

	public void setRequestee(String requestee) {
		this.requestee = requestee;
	}

	public String getSetter() {
		return setter;
	}

	public void setSetter(String setter) {
		this.setter = setter;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getFlagId() {
		return flagId;
	}

	public void setFlagId(String flagId) {
		this.flagId = flagId;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	private String description;

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void applyTo(TaskAttribute taskAttribute) {
		Assert.isNotNull(taskAttribute);
		TaskData taskData = taskAttribute.getTaskData();
		TaskAttributeMapper mapper = taskData.getAttributeMapper();
		TaskAttributeMetaData meta = taskAttribute.getMetaData().defaults();
		meta.setType(IBugzillaConstants.EDITOR_TYPE_FLAG);
		meta.setLabel(description);
		BugzillaVersion bugzillaVersion = null;
		RepositoryConfiguration repositoryConfiguration;
		try {
			repositoryConfiguration = connector.getRepositoryConfiguration(mapper.getTaskRepository(), false,
					new NullProgressMonitor());
			bugzillaVersion = repositoryConfiguration.getInstallVersion();
		} catch (CoreException e) {
			bugzillaVersion = BugzillaVersion.MIN_VERSION;
		}

		if (bugzillaVersion.compareTo(BugzillaVersion.BUGZILLA_3_2) >= 0) {
			meta.setKind(TaskAttribute.KIND_DEFAULT);
		}
		meta.setReadOnly(false);

		if (getNumber() != 0) {
			TaskAttribute child = taskAttribute.createMappedAttribute("number"); //$NON-NLS-1$
			child.getMetaData().defaults().setType(TaskAttribute.TYPE_INTEGER);
			mapper.setIntegerValue(child, getNumber());
		}
		if (getRequestee() != null) {
			TaskAttribute child = taskAttribute.createMappedAttribute("requestee"); //$NON-NLS-1$
			child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
			mapper.setValue(child, getRequestee());
		}
		if (getSetter() != null) {
			TaskAttribute child = taskAttribute.createMappedAttribute("setter"); //$NON-NLS-1$
			child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
			mapper.setValue(child, getSetter());
		}
		if (getState() != null) {
			TaskAttribute child = taskAttribute.createMappedAttribute("state"); //$NON-NLS-1$
			child.getMetaData().defaults().setType(TaskAttribute.TYPE_SINGLE_SELECT);
			child.getMetaData().setLabel(flagId);
			child.getMetaData().setReadOnly(false);
			mapper.setValue(child, getState());
			taskAttribute.getMetaData().putValue(TaskAttribute.META_ASSOCIATED_ATTRIBUTE_ID, "state"); //$NON-NLS-1$

		}
	}

}

Back to the top