Subversion Repositories XServices

Rev

Rev 30 | Rev 34 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 brianR 1
/*
2
 *   Mylyn Connector for Serena Business Mashups
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
4
 *
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
6
 *   you may not use this file except in compliance with the License.
7
 *   You may obtain a copy of the License at
8
 *
9
 *       http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *   Unless required by applicable law or agreed to in writing, software
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *   See the License for the specific language governing permissions and
15
 *   limitations under the License.
16
 *
17
 *   Serena, TeamTrack and Serena Business Mashup are
18
 * 	 registered trademarks of SERENA Software Inc.
19
 */
20
package net.brutex.mylyn.sbmconnector.core;
21
 
31 brianR 22
import java.util.List;
30 brianR 23
import java.util.Set;
24
 
25
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
31 brianR 26
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
27
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes;
28
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
29
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
30 brianR 30
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
31
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
32
import net.brutex.sbm.wsclient.TTItem;
33
 
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IProgressMonitor;
36
import org.eclipse.mylyn.tasks.core.ITaskMapping;
37
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
38
import org.eclipse.mylyn.tasks.core.TaskRepository;
39
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
40
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
41
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
42
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
43
import org.eclipse.mylyn.tasks.core.data.TaskData;
44
 
45
/**
46
 * The Class SBMTicketDataHandler.
47
 */
48
public class SBMTicketDataHandler extends AbstractTaskDataHandler {
49
 
50
	/** The connector. */
51
	private final SBMRepositoryConnector connector;
52
 
53
	/**
54
	 * Instantiates a new SBM ticket data handler.
55
	 *
56
	 * @param connector the connector
57
	 */
58
	public SBMTicketDataHandler(SBMRepositoryConnector connector) {
59
		this.connector = connector;
60
	}
61
 
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository)
64
	 */
65
	@Override
66
	public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
67
		return new SBMTicketAttributeMapper(taskRepository);
68
	}
69
 
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, org.eclipse.mylyn.tasks.core.ITaskMapping, org.eclipse.core.runtime.IProgressMonitor)
72
	 */
73
	@Override
74
	public boolean initializeTaskData(TaskRepository repository, TaskData taskData,
75
			ITaskMapping initializationData, IProgressMonitor monitor)
76
			throws CoreException {
77
 
78
		/*TaskAttribute attribute = taskData.getRoot().createAttribute(SBMStaticFields.TITLE);
79
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_SHORT_TEXT).setLabel("Summary:");
80
 
81
		/*attribute = taskData.getRoot().createAttribute(SBMStaticFields.DESCRIPTION);
82
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_LONG_TEXT).setLabel("Description:");
83
 
84
		attribute = taskData.getRoot().createAttribute(SBMStaticFields.SUBMITDATE);
85
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_DATETIME).setLabel("Create Date:");
86
 
87
 
88
		  if (!taskData.isNew()) {
89
			attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL);
90
			attribute.getMetaData().setReadOnly(true).setKind(TaskAttribute.KIND_DEFAULT).setType(
91
					TaskAttribute.TYPE_URL).setLabel("Location:");
92
			File file = client.getTask(taskData.getTaskId(), monitor);
93
			try {
94
				attribute.setValue(file.toURI().toURL().toString());
95
			} catch (MalformedURLException e) {
96
			}
97
		}
98
 
99
		attribute = taskData.getRoot().createAttribute(TaskAttribute.PRODUCT);
100
		attribute.getMetaData().setReadOnly(false).setKind(TaskAttribute.KIND_DEFAULT).setType(
101
				TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project");
102
				*/
103
		taskData.setPartial(true);
104
		return true;
105
	}
106
 
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set, org.eclipse.core.runtime.IProgressMonitor)
109
	 */
110
	@Override
111
	public RepositoryResponse postTaskData(TaskRepository repository,
112
			TaskData taskData, Set<TaskAttribute> oldAttributes,
113
			IProgressMonitor monitor) throws CoreException {
114
		// TODO Auto-generated method stub
115
		return null;
116
	}
117
 
118
	/**
119
	 * Convert.
120
	 *
121
	 * @param repository the repository
122
	 * @param ttitem the ttitem
123
	 * @param monitor the monitor
124
	 * @return the task data
125
	 * @throws CoreException the core exception
126
	 */
127
	public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor)
128
		throws CoreException {
31 brianR 129
		SBMClient client = SBMRepositoryConnector.getClient(repository);
30 brianR 130
		TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
131
				SBMConnectorPlugin.CONNECTOR_KIND,
132
				repository.getRepositoryUrl(),
133
				ttitem.getGenericItem().getValue().getItemID().getValue());
134
		initializeTaskData(repository, data, null, monitor);
135
		// Create Fields for all the generic SBM (system) fields
136
		for (SBMTicketAttribute f : SBMTicketAttribute.values()) {
137
			TaskAttribute attr;
138
			if(f.getTaskName()!=null) {
139
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
140
			} else {
141
				attr = data.getRoot().createAttribute(f.getSBMName());
142
			}
143
			try {
144
				SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list
145
				attr.getMetaData().setReadOnly(true);
146
			} catch (IllegalArgumentException e) {
147
				attr.getMetaData().setReadOnly(false);
148
			}
149
			attr.getMetaData().setType(f.getTaskType());
31 brianR 150
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName()));
30 brianR 151
			if(f.isVisible()) {
152
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
153
			} else {
154
				attr.getMetaData().setKind(null);
155
			}
31 brianR 156
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName()));
30 brianR 157
		}
158
 
31 brianR 159
		//Custom fields
160
		List<SBMField> customfields = client.getFields(client.getTableName(ttitem));
161
		for(SBMField f : customfields) {
162
			if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) {
163
				continue;
164
			}
165
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
166
			custom.getMetaData().setType(
167
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType()));
168
			custom.getMetaData().setLabel(f.getLabel());
169
			custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
170
			custom.getMetaData().setReadOnly(true);
171
			if(f.getType()==SBMFieldTypes.SELECTION &&
172
					client.getFieldValue(ttitem, f.getName())!=null) {
173
				String val = client.getFieldValue(ttitem, f.getName()).getValue();
174
				custom.putOption(val, val);
175
				custom.setValue(val);
176
			} else if(f.getType()==SBMFieldTypes.MULTIPLE_SELECTION
177
					|| f.getType()==SBMFieldTypes.MULTIPLE_RELATIONAL
178
					|| f.getType()==SBMFieldTypes.MULTIPLE_GROUP
179
					|| f.getType()==SBMFieldTypes.MULTIPLE_USERGROUP) {
180
				List<SBMFieldValue> values = client.getFieldValues(ttitem, f.getName());
181
				for(SBMFieldValue val : values) {
182
					custom.putOption(val.getInternalValue(), val.getValue());
183
					custom.addValue(val.getValue());
184
				}
185
			} else if(client.getFieldValue(ttitem, f.getName())!=null) {
186
					custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue());
187
			}
188
		}
30 brianR 189
 
190
		//Notes
31 brianR 191
		for(SBMNote n : client.getNotes(ttitem)) {
30 brianR 192
			TaskCommentMapper mapper = new TaskCommentMapper();
193
			mapper.setCommentId(n.getId());
194
			mapper.setNumber(Integer.valueOf(n.getId()));
195
			mapper.setText(n.getText());
196
			mapper.setCreationDate(n.getCreation());
197
 
198
			TaskAttribute a = data.getRoot().createAttribute("NOTE"+n.getId());
199
			mapper.applyTo(a);
200
		}
201
 
202
		data.setPartial(false);
203
		return data;
204
	}
205
}